← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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