← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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