← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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