← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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