← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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