← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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