← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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