← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. for
  2. in the console
  3. 31
  4. 19
  5. 11
  6. 44
  7. Well done, Aman!
  8. 9
  9. 12
  10. 89
  11. 18
  12. alert()
  13. console.log()
  14. 90
  15. Welcome, Riya!
  16. 63
  17. Hi, Riya!
  18. .js
  19. let
  20. a pop-up box
  21. 17
  22. 64
  23. 72
  24. 83
  25. 35
  26. 85
  27. 72
  28. 28
  29. Hi, Aman!
  30. 37
  31. <script>
  32. 27
  33. 3
  34. 0
  35. 9
  36. 22
  37. 3
  38. 61
  39. 25
  40. Well done, Aman!

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