← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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