← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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