← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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