← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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