← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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