← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. alert()
  2. 77
  3. let
  4. 99
  5. actions and changes
  6. Hello, Kabir!
  7. console.log()
  8. 42
  9. <script>
  10. 25
  11. 45
  12. 82
  13. 4
  14. 7
  15. 1
  16. in the console
  17. 16
  18. 66
  19. for
  20. 15
  21. .js
  22. let
  23. Well done, Aman!
  24. 11
  25. 65
  26. 7
  27. 25
  28. 8
  29. 12
  30. Hello, Aman!
  31. if
  32. 3
  33. 39
  34. 10
  35. 10
  36. Hi, Kabir!
  37. 18
  38. Hi, Riya!
  39. 5
  40. 15

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