← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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