← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. let
  2. alert()
  3. 18
  4. 96
  5. .js
  6. 14
  7. a pop-up box
  8. <script>
  9. console.log()
  10. 80
  11. 87
  12. if
  13. for
  14. in the console
  15. 10
  16. actions and changes
  17. 30
  18. 31
  19. 35
  20. 73
  21. let
  22. 70
  23. 17
  24. 55
  25. Hi, Aman!
  26. 14
  27. 15
  28. 61
  29. 13
  30. 18
  31. 29
  32. 64
  33. 83
  34. 77
  35. 99
  36. 5
  37. 72
  38. 35
  39. 5
  40. 62

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