← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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