← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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