← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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