← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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