← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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