← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. for
  2. 57
  3. Welcome, Aman!
  4. <script>
  5. 9
  6. if
  7. 80
  8. alert()
  9. 19
  10. 0
  11. in the console
  12. Welcome, Riya!
  13. Hello, Aman!
  14. a pop-up box
  15. 95
  16. 35
  17. Well done, Aman!
  18. console.log()
  19. 13
  20. .js
  21. 15
  22. Hello, Riya!
  23. Hello, Meera!
  24. 44
  25. 20
  26. 2
  27. 25
  28. 15
  29. 52
  30. 0
  31. 4
  32. 42
  33. 86
  34. 30
  35. 33
  36. 8
  37. 69
  38. 24
  39. 45
  40. 35

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