← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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