← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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