← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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