← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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