← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. .js
  2. if
  3. 31
  4. a pop-up box
  5. alert()
  6. <script>
  7. 21
  8. 53
  9. in the console
  10. let
  11. 15
  12. 27
  13. 88
  14. 46
  15. 8
  16. 56
  17. 60
  18. 18
  19. 14
  20. console.log()
  21. 7
  22. actions and changes
  23. 14
  24. 26
  25. Hello, Aman!
  26. 22
  27. 77
  28. 87
  29. 34
  30. 79
  31. 23
  32. 25
  33. 13
  34. 23
  35. 3
  36. for
  37. 59
  38. 2
  39. 35
  40. 54

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