← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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