← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. let
  2. 46
  3. 95
  4. 69
  5. 42
  6. 36
  7. Hello, Meera!
  8. for
  9. 14
  10. alert()
  11. console.log()
  12. .js
  13. 36
  14. 6
  15. 25
  16. 72
  17. in the console
  18. 12
  19. 56
  20. 66
  21. actions and changes
  22. 19
  23. Welcome, Arjun!
  24. <script>
  25. 7
  26. 9
  27. 63
  28. 36
  29. 19
  30. let
  31. 43
  32. Welcome, Riya!
  33. 10
  34. 10
  35. if
  36. 22
  37. 23
  38. 55
  39. 36
  40. 13

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