← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Welcome, Aman!
  2. 84
  3. 17
  4. console.log()
  5. 17
  6. actions and changes
  7. Hi, Riya!
  8. 18
  9. 12
  10. in the console
  11. .js
  12. alert()
  13. 98
  14. for
  15. let
  16. let
  17. <script>
  18. Hi, Arjun!
  19. Hi, Arjun!
  20. 28
  21. 65
  22. 26
  23. Hello, Kabir!
  24. Hi, Zoya!
  25. 29
  26. 43
  27. Hello, Riya!
  28. 2
  29. Hello, Aman!
  30. 24
  31. 7
  32. if
  33. 0
  34. 29
  35. 58
  36. 10
  37. 8
  38. 47
  39. 10
  40. 132

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