← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. let
  2. <script>
  3. 10
  4. 19
  5. alert()
  6. 20
  7. actions and changes
  8. let
  9. console.log()
  10. 33
  11. Hi, Kabir!
  12. for
  13. Welcome, Riya!
  14. Hi, Aman!
  15. 4
  16. 3
  17. in the console
  18. if
  19. 17
  20. Hello, Meera!
  21. 63
  22. 94
  23. 26
  24. 8
  25. 12
  26. 44
  27. 84
  28. 30
  29. 50
  30. 30
  31. 1
  32. 81
  33. 20
  34. 22
  35. 17
  36. 18
  37. 12
  38. 19
  39. 0
  40. Hello, Aman!

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