← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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