← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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