← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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