← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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