← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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