← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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