← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. if
  2. for
  3. 52
  4. 8
  5. 34
  6. .js
  7. let
  8. console.log()
  9. <script>
  10. 66
  11. alert()
  12. 11
  13. 94
  14. 40
  15. Well done, Arjun!
  16. 93
  17. 32
  18. 44
  19. 0
  20. 88
  21. 52
  22. 29
  23. 2
  24. 30
  25. Well done, Zoya!
  26. 62
  27. a pop-up box
  28. 24
  29. 55
  30. 34
  31. 73
  32. 58
  33. in the console
  34. Hello, Meera!
  35. 30
  36. 84
  37. 99
  38. Welcome, Aman!
  39. actions and changes
  40. Hi, Kabir!

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