← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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