← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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