← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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