← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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