← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 12
  2. 52
  3. in the console
  4. let
  5. 5
  6. 26
  7. actions and changes
  8. for
  9. 26
  10. Welcome, Riya!
  11. <script>
  12. 71
  13. a pop-up box
  14. 81
  15. alert()
  16. 52
  17. 17
  18. 97
  19. Well done, Kabir!
  20. 13
  21. 68
  22. 36
  23. 5
  24. 21
  25. Hi, Aman!
  26. Welcome, Kabir!
  27. 49
  28. 86
  29. 91
  30. 63
  31. 16
  32. 17
  33. 55
  34. 32
  35. 22
  36. 74
  37. 64
  38. 56
  39. 12
  40. 20

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