← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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