← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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