← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. actions and changes
  2. 1
  3. .js
  4. 63
  5. 43
  6. 22
  7. 42
  8. 18
  9. 61
  10. Hello, Aman!
  11. 83
  12. 44
  13. let
  14. 66
  15. <script>
  16. 30
  17. 31
  18. 22
  19. let
  20. for
  21. alert()
  22. a pop-up box
  23. 25
  24. 69
  25. Hi, Aman!
  26. in the console
  27. 14
  28. 79
  29. 12
  30. Welcome, Riya!
  31. console.log()
  32. 51
  33. 36
  34. 33
  35. 19
  36. 91
  37. 2
  38. 46
  39. 48
  40. 20

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