← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hello, Aman!
  2. Welcome, Arjun!
  3. 38
  4. 75
  5. 94
  6. Welcome, Meera!
  7. 2
  8. 16
  9. let
  10. 12
  11. alert()
  12. 28
  13. 18
  14. 2
  15. console.log()
  16. Hi, Arjun!
  17. 81
  18. let
  19. 120
  20. Hello, Kabir!
  21. a pop-up box
  22. 95
  23. for
  24. .js
  25. 91
  26. 4
  27. 33
  28. actions and changes
  29. 47
  30. 21
  31. 5
  32. 98
  33. Hi, Kabir!
  34. Well done, Aman!
  35. Well done, Aman!
  36. if
  37. Well done, Meera!
  38. 19
  39. <script>
  40. 22

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