← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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