← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 22
  2. 64
  3. a pop-up box
  4. in the console
  5. console.log()
  6. for
  7. 7
  8. 62
  9. 85
  10. 96
  11. 58
  12. let
  13. Hi, Aman!
  14. 94
  15. 60
  16. Hi, Kabir!
  17. 44
  18. <script>
  19. 6
  20. if
  21. Welcome, Arjun!
  22. 5
  23. 49
  24. 46
  25. 42
  26. let
  27. .js
  28. 36
  29. 62
  30. 96
  31. Hi, Kabir!
  32. Welcome, Riya!
  33. Welcome, Zoya!
  34. 51
  35. 62
  36. 72
  37. 25
  38. 46
  39. 47
  40. 4

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