← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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