← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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