← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 0
  2. 20
  3. 144
  4. 7
  5. console.log()
  6. 7
  7. 8
  8. alert()
  9. 8
  10. 21
  11. 98
  12. if
  13. Hi, Kabir!
  14. 24
  15. let
  16. Hello, Aman!
  17. 15
  18. Well done, Arjun!
  19. <script>
  20. 25
  21. in the console
  22. Hi, Riya!
  23. 82
  24. 18
  25. 10
  26. 6
  27. Hello, Arjun!
  28. Welcome, Aman!
  29. for
  30. 62
  31. .js
  32. Hello, Riya!
  33. 28
  34. 24
  35. Hello, Riya!
  36. 33
  37. 50
  38. 20
  39. 13
  40. 23

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