← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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