← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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