← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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