← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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