← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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