← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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