← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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