← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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