← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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