← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 91
  2. actions and changes
  3. 53
  4. 65
  5. 51
  6. 7
  7. .js
  8. alert()
  9. for
  10. 3
  11. 43
  12. <script>
  13. 56
  14. in the console
  15. Hello, Aman!
  16. 27
  17. 2
  18. if
  19. 13
  20. 10
  21. 5
  22. a pop-up box
  23. 74
  24. 24
  25. let
  26. 79
  27. 31
  28. 0
  29. console.log()
  30. 12
  31. 29
  32. 14
  33. 3
  34. 2
  35. 61
  36. 0
  37. Welcome, Aman!
  38. 12
  39. 98
  40. 25

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