← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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