← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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