← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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