← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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