← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 21
  2. in the console
  3. alert()
  4. 8
  5. 65
  6. let
  7. <script>
  8. 72
  9. 17
  10. for
  11. 5
  12. 26
  13. 6
  14. 24
  15. 17
  16. console.log()
  17. 49
  18. if
  19. 3
  20. 64
  21. .js
  22. 20
  23. Hi, Arjun!
  24. 29
  25. Hi, Arjun!
  26. Hello, Kabir!
  27. Hello, Zoya!
  28. 93
  29. let
  30. 76
  31. Hi, Aman!
  32. 27
  33. 24
  34. a pop-up box
  35. 37
  36. 15
  37. 12
  38. 44
  39. 3
  40. 80

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