← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 55
  2. 17
  3. <script>
  4. 88
  5. if
  6. 39
  7. 24
  8. 43
  9. 47
  10. 19
  11. 27
  12. console.log()
  13. a pop-up box
  14. 23
  15. 64
  16. 14
  17. Hi, Riya!
  18. 78
  19. actions and changes
  20. 2
  21. Well done, Aman!
  22. alert()
  23. 1
  24. Hello, Meera!
  25. 12
  26. let
  27. .js
  28. 54
  29. 4
  30. Welcome, Aman!
  31. 66
  32. 42
  33. Hello, Riya!
  34. 36
  35. for
  36. 33
  37. 10
  38. 31
  39. Hi, Zoya!
  40. 39

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