← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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