← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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