← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 28
  2. console.log()
  3. 21
  4. Welcome, Riya!
  5. 77
  6. 33
  7. <script>
  8. 24
  9. 86
  10. Hi, Meera!
  11. 21
  12. actions and changes
  13. .js
  14. 50
  15. Hi, Kabir!
  16. 23
  17. 70
  18. 27
  19. for
  20. 25
  21. 86
  22. if
  23. 11
  24. let
  25. 22
  26. 62
  27. 108
  28. 5
  29. 98
  30. in the console
  31. alert()
  32. Hi, Meera!
  33. 12
  34. 63
  35. Well done, Aman!
  36. 33
  37. 3
  38. 37
  39. Hi, Riya!
  40. 79

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