← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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