← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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