← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 928 · 40 questions
TalentJR

Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".

NameDateTime takenScore ___ / 40
  1. 1.⚡ Which JavaScript word writes in the console? (a) alert() (b) let (c) if (d) console.log()
  2. 2.⚡ What does this code show?
    let name = "Meera";
    alert("Hello, " + name + "!");
    (a) Hello, Meera! (b) Meera (c) Hello, name! (d) name
  3. 3.⚡ What number does this code print?
    let a = 24;
    let b = 20;
    console.log(a - b);
  4. 4.⚡ A JavaScript file usually ends with which extension? (a) .js (b) .jpg (c) .html (d) .css
  5. 5.⚡ Which JavaScript word runs code when true? (a) alert() (b) if (c) let (d) for
  6. 6.⚡ Which tag holds JavaScript in a page? (a) <js> (b) <code> (c) <script> (d) <style>
  7. 7.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hello, " + name + "!");
    (a) Hello, name! (b) Hello, Kabir! (c) Kabir (d) name
  8. 8.⚡ Which JavaScript word makes a new variable? (a) let (b) if (c) for (d) console.log()
  9. 9.⚡ What does this code print? (Look at the quotes!)
    let x = "7";
    let y = 9;
    console.log(x + y);
    (a) 16 (b) Error (c) 79
  10. 10.⚡ What does this code show?
    let name = "Aman";
    console.log("Hello, " + name + "!");
    (a) Hello, name! (b) Aman (c) Hello, Aman! (d) name
  11. 11.⚡ What does this code show?
    let name = "Meera";
    alert("Hi, " + name + "!");
    (a) Hi, Meera! (b) name (c) Meera (d) Hi, name!
  12. 12.⚡ What does this code show?
    let name = "Arjun";
    console.log("Hi, " + name + "!");
    (a) Hi, name! (b) Arjun (c) name (d) Hi, Arjun!
  13. 13.⚡ Which JavaScript word shows a pop-up box? (a) if (b) let (c) alert() (d) for
  14. 14.⚡ What does this code show?
    let name = "Zoya";
    alert("Hi, " + name + "!");
    (a) name (b) Zoya (c) Hi, name! (d) Hi, Zoya!
  15. 15.⚡ What does this code show?
    let name = "Meera";
    console.log("Hi, " + name + "!");
    (a) Meera (b) Hi, Meera! (c) Hi, name! (d) name
  16. 16.⚡ What number does this code print?
    let marks = 11;
    marks = marks + 17;
    marks = marks - 16;
    console.log(marks);
  17. 17.⚡ What number does this code print?
    let a = 12;
    let b = 7;
    console.log(a * b);
  18. 18.⚡ What does alert() show? (a) a picture (b) a table (c) a new tab (d) a pop-up box
  19. 19.⚡ What does this code show?
    let name = "Riya";
    alert("Well done, " + name + "!");
    (a) Riya (b) name (c) Well done, Riya! (d) Well done, name!
  20. 20.⚡ What does JavaScript add to a web page? (a) the domain name (b) the page title (c) actions and changes (d) only colours
  21. 21.⚡ What number does this code print?
    let a = 25;
    let b = 5;
    console.log(a + b);
  22. 22.⚡ What number does this code print?
    let score = 28;
    score = score + 19;
    score = score - 24;
    console.log(score);
  23. 23.⚡ What number does this code print?
    let a = 58;
    let b = 20;
    console.log(a - b);
  24. 24.⚡ Which JavaScript word repeats code? (a) if (b) for (c) let (d) console.log()
  25. 25.⚡ Where does console.log() show its output? (a) in the console (b) on the title bar (c) in the address bar (d) on the printer
  26. 26.⚡ What does this code print? (Look at the quotes!)
    let x = "4";
    let y = 3;
    console.log(x + y);
    (a) 7 (b) 43 (c) Error
  27. 27.⚡ What number does this code print?
    let books = 24;
    books = books + 17;
    books = books - 35;
    console.log(books);
  28. 28.⚡ Which word makes a new variable? (a) let (b) make (c) put (d) give
  29. 29.⚡ What number does this code print?
    let a = 23;
    let b = 2;
    console.log(a + b);
  30. 30.⚡ What number does this code print?
    let marks = 8;
    marks = marks + 6;
    marks = marks - 2;
    console.log(marks);
  31. 31.⚡ What number does this code print?
    let a = 49;
    let b = 5;
    console.log(a - b);
  32. 32.⚡ What number does this code print?
    let a = 11;
    let b = 6;
    console.log(a * b);
  33. 33.⚡ What number does this code print?
    let apples = 8;
    apples = apples + 18;
    apples = apples - 23;
    console.log(apples);
  34. 34.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 4;
    console.log(x + y);
    (a) 7 (b) Error (c) 34
  35. 35.⚡ What does this code show?
    let name = "Aman";
    alert("Well done, " + name + "!");
    (a) Well done, name! (b) Aman (c) Well done, Aman! (d) name
  36. 36.⚡ What does this code show?
    let name = "Meera";
    alert("Welcome, " + name + "!");
    (a) Welcome, Meera! (b) Welcome, name! (c) name (d) Meera
  37. 37.⚡ What number does this code print?
    let a = 3;
    let b = 4;
    console.log(a * b);
  38. 38.⚡ What number does this code print?
    let apples = 25;
    apples = apples + 4;
    apples = apples - 24;
    console.log(apples);
  39. 39.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 3;
    console.log(x + y);
    (a) 23 (b) Error (c) 5
  40. 40.⚡ What does this code show?
    let name = "Aman";
    alert("Hi, " + name + "!");
    (a) Hi, name! (b) Hi, Aman! (c) name (d) Aman

Answer key

  1. console.log()
  2. Hello, Meera!
  3. 4
  4. .js
  5. if
  6. <script>
  7. Hello, Kabir!
  8. let
  9. 79
  10. Hello, Aman!
  11. Hi, Meera!
  12. Hi, Arjun!
  13. alert()
  14. Hi, Zoya!
  15. Hi, Meera!
  16. 12
  17. 84
  18. a pop-up box
  19. Well done, Riya!
  20. actions and changes
  21. 30
  22. 23
  23. 38
  24. for
  25. in the console
  26. 43
  27. 6
  28. let
  29. 25
  30. 12
  31. 44
  32. 66
  33. 3
  34. 34
  35. Well done, Aman!
  36. Welcome, Meera!
  37. 12
  38. 5
  39. 23
  40. Hi, Aman!

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids