← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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