← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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