← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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