← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 52
  2. 74
  3. a pop-up box
  4. 7
  5. let
  6. 6
  7. let
  8. console.log()
  9. Welcome, Aman!
  10. 1
  11. alert()
  12. actions and changes
  13. .js
  14. 75
  15. 59
  16. <script>
  17. if
  18. 16
  19. 95
  20. 54
  21. 2
  22. Hi, Arjun!
  23. 86
  24. 79
  25. in the console
  26. for
  27. 82
  28. 14
  29. 72
  30. Hi, Arjun!
  31. 13
  32. Hi, Zoya!
  33. 22
  34. 10
  35. 43
  36. 23
  37. 78
  38. 1
  39. 15
  40. Hi, Aman!

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