← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hi, Zoya!
  2. .js
  3. let
  4. 12
  5. in the console
  6. 0
  7. console.log()
  8. 9
  9. let
  10. 33
  11. 45
  12. 94
  13. 10
  14. actions and changes
  15. a pop-up box
  16. 84
  17. 21
  18. for
  19. 71
  20. Hi, Kabir!
  21. if
  22. Well done, Arjun!
  23. 13
  24. 22
  25. 32
  26. Hello, Riya!
  27. 1
  28. 36
  29. 34
  30. 63
  31. 108
  32. <script>
  33. Hi, Aman!
  34. Welcome, Aman!
  35. 30
  36. 14
  37. Hello, Arjun!
  38. Hello, Meera!
  39. 10
  40. 28

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