← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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