← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 71
  2. .js
  3. 17
  4. if
  5. Well done, Kabir!
  6. let
  7. 72
  8. 8
  9. 79
  10. 89
  11. alert()
  12. console.log()
  13. 1
  14. 9
  15. Hello, Aman!
  16. 9
  17. 31
  18. 22
  19. for
  20. Hello, Arjun!
  21. in the console
  22. 24
  23. 90
  24. 26
  25. 63
  26. 95
  27. 1
  28. 21
  29. 13
  30. 5
  31. 67
  32. 5
  33. 22
  34. 81
  35. 31
  36. 19
  37. 88
  38. 62
  39. <script>
  40. 16

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