← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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