← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. let
  2. 16
  3. 60
  4. a pop-up box
  5. 97
  6. let
  7. 36
  8. 38
  9. <script>
  10. 13
  11. 63
  12. 2
  13. Hello, Zoya!
  14. 1
  15. console.log()
  16. 4
  17. 8
  18. Hi, Arjun!
  19. 42
  20. Welcome, Riya!
  21. .js
  22. 48
  23. alert()
  24. Well done, Aman!
  25. 1
  26. 18
  27. 99
  28. 72
  29. 79
  30. 7
  31. 46
  32. Hello, Zoya!
  33. 7
  34. 96
  35. 19
  36. 30
  37. 12
  38. 15
  39. 25
  40. 18

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