← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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