← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 38
  2. 56
  3. .js
  4. in the console
  5. Hi, Aman!
  6. 19
  7. Welcome, Riya!
  8. if
  9. Well done, Kabir!
  10. actions and changes
  11. Hi, Riya!
  12. a pop-up box
  13. Hi, Meera!
  14. Well done, Kabir!
  15. Hi, Zoya!
  16. let
  17. Hello, Meera!
  18. alert()
  19. let
  20. for
  21. 26
  22. 12
  23. 23
  24. console.log()
  25. 49
  26. 11
  27. 24
  28. 58
  29. <script>
  30. 46
  31. 51
  32. 43
  33. 15
  34. Welcome, Aman!
  35. 63
  36. 77
  37. Well done, Meera!
  38. 87
  39. 32
  40. 29

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