← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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