← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 26
  2. 20
  3. for
  4. console.log()
  5. <script>
  6. let
  7. 29
  8. 91
  9. 20
  10. 76
  11. 25
  12. 4
  13. in the console
  14. 78
  15. if
  16. 60
  17. 8
  18. 17
  19. 30
  20. 31
  21. Hello, Riya!
  22. 38
  23. 29
  24. .js
  25. alert()
  26. 25
  27. 12
  28. 51
  29. a pop-up box
  30. 29
  31. 46
  32. let
  33. 74
  34. 3
  35. Hi, Zoya!
  36. 55
  37. Well done, Arjun!
  38. 144
  39. 60
  40. 18

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