← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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