← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. alert()
  2. 60
  3. for
  4. <script>
  5. if
  6. 87
  7. Well done, Meera!
  8. Well done, Zoya!
  9. in the console
  10. 76
  11. 9
  12. 47
  13. 74
  14. 36
  15. 90
  16. 108
  17. 30
  18. a pop-up box
  19. let
  20. 32
  21. Hi, Zoya!
  22. Welcome, Aman!
  23. 19
  24. .js
  25. Hi, Riya!
  26. 24
  27. actions and changes
  28. 12
  29. 83
  30. 21
  31. 99
  32. 53
  33. 0
  34. 26
  35. 27
  36. 51
  37. 39
  38. Hello, Zoya!
  39. 8
  40. console.log()

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