← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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