← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hi, Kabir!
  2. let
  3. for
  4. 14
  5. console.log()
  6. 17
  7. 12
  8. 71
  9. 16
  10. 16
  11. 14
  12. 63
  13. 19
  14. 16
  15. actions and changes
  16. 29
  17. a pop-up box
  18. 28
  19. 144
  20. if
  21. alert()
  22. in the console
  23. 25
  24. <script>
  25. Welcome, Riya!
  26. 8
  27. 60
  28. 46
  29. 15
  30. 30
  31. Hi, Riya!
  32. Hi, Aman!
  33. 19
  34. 72
  35. 95
  36. 1
  37. 88
  38. Well done, Meera!
  39. 49
  40. 54

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