← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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