← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 18
  2. alert()
  3. in the console
  4. Hi, Riya!
  5. 0
  6. <script>
  7. 96
  8. 99
  9. actions and changes
  10. let
  11. a pop-up box
  12. for
  13. console.log()
  14. .js
  15. 98
  16. 21
  17. 3
  18. 34
  19. Welcome, Kabir!
  20. if
  21. 49
  22. 54
  23. 81
  24. 84
  25. 6
  26. 28
  27. 20
  28. let
  29. 84
  30. Hi, Kabir!
  31. 42
  32. 75
  33. 55
  34. 26
  35. Hello, Zoya!
  36. 71
  37. 79
  38. 19
  39. 17
  40. 40

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