← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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