← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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