← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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