← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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