← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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