← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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