← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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