← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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