← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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