← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. if
  2. alert()
  3. Hi, Meera!
  4. for
  5. <script>
  6. 22
  7. in the console
  8. 16
  9. Hi, Riya!
  10. 87
  11. 23
  12. 28
  13. 64
  14. 32
  15. let
  16. console.log()
  17. 81
  18. 52
  19. 62
  20. 19
  21. 13
  22. 36
  23. a pop-up box
  24. 21
  25. 72
  26. Welcome, Kabir!
  27. 0
  28. 18
  29. Hello, Zoya!
  30. 96
  31. 58
  32. Hello, Aman!
  33. 63
  34. 43
  35. 4
  36. 41
  37. 10
  38. 42
  39. 24
  40. Welcome, Riya!

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