← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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