← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 72
  2. 90
  3. Welcome, Aman!
  4. console.log()
  5. 15
  6. 94
  7. if
  8. in the console
  9. 74
  10. Hi, Riya!
  11. Well done, Aman!
  12. Hi, Zoya!
  13. 88
  14. let
  15. for
  16. 49
  17. 19
  18. 60
  19. a pop-up box
  20. alert()
  21. actions and changes
  22. 80
  23. 21
  24. 25
  25. 12
  26. let
  27. 13
  28. Welcome, Kabir!
  29. <script>
  30. Welcome, Riya!
  31. 48
  32. 92
  33. 84
  34. 47
  35. 27
  36. 70
  37. Hello, Aman!
  38. 38
  39. Hi, Riya!
  40. .js

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