← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. actions and changes
  2. 17
  3. a pop-up box
  4. 76
  5. alert()
  6. 36
  7. 121
  8. 16
  9. if
  10. let
  11. 8
  12. 13
  13. Hello, Arjun!
  14. 4
  15. 24
  16. 6
  17. 83
  18. 99
  19. <script>
  20. 90
  21. 27
  22. Welcome, Riya!
  23. 14
  24. 28
  25. 37
  26. console.log()
  27. .js
  28. Hello, Arjun!
  29. 53
  30. 9
  31. 8
  32. 72
  33. 7
  34. 48
  35. Hello, Riya!
  36. 21
  37. 58
  38. for
  39. 46
  40. Hi, Zoya!

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