← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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