← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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