← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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