← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 417 · 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 = "2";
    let y = 1;
    console.log(x + y);
    (a) 21 (b) 3 (c) Error
  2. 2.⚡ What does JavaScript add to a web page? (a) actions and changes (b) only colours (c) the domain name (d) the page title
  3. 3.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 6;
    console.log(x + y);
    (a) 36 (b) Error (c) 9
  4. 4.⚡ Which JavaScript word repeats code? (a) alert() (b) console.log() (c) let (d) for
  5. 5.⚡ What number does this code print?
    let a = 55;
    let b = 6;
    console.log(a - b);
  6. 6.⚡ What number does this code print?
    let a = 53;
    let b = 8;
    console.log(a + b);
  7. 7.⚡ What does this code print? (Look at the quotes!)
    let x = "4";
    let y = 6;
    console.log(x + y);
    (a) 10 (b) Error (c) 46
  8. 8.⚡ What number does this code print?
    let a = 5;
    let b = 6;
    console.log(a * b);
  9. 9.⚡ What number does this code print?
    let a = 7;
    let b = 6;
    console.log(a * b);
  10. 10.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <js> (c) <code> (d) <script>
  11. 11.⚡ Which JavaScript word runs code when true? (a) if (b) console.log() (c) let (d) alert()
  12. 12.⚡ Which JavaScript word writes in the console? (a) alert() (b) if (c) let (d) console.log()
  13. 13.⚡ Which JavaScript word makes a new variable? (a) for (b) console.log() (c) let (d) alert()
  14. 14.⚡ 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
  15. 15.⚡ What number does this code print?
    let apples = 22;
    apples = apples + 4;
    apples = apples - 3;
    console.log(apples);
  16. 16.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 9;
    console.log(x + y);
    (a) 12 (b) 39 (c) Error
  17. 17.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 9;
    console.log(x + y);
    (a) 17 (b) Error (c) 89
  18. 18.⚡ What number does this code print?
    let a = 22;
    let b = 18;
    console.log(a - b);
  19. 19.⚡ A JavaScript file usually ends with which extension? (a) .html (b) .js (c) .jpg (d) .css
  20. 20.⚡ What does this code show?
    let name = "Aman";
    alert("Well done, " + name + "!");
    (a) Well done, Aman! (b) name (c) Aman (d) Well done, name!
  21. 21.⚡ What number does this code print?
    let runs = 17;
    runs = runs + 12;
    runs = runs - 12;
    console.log(runs);
  22. 22.⚡ What number does this code print?
    let a = 15;
    let b = 32;
    console.log(a + b);
  23. 23.⚡ What does this code show?
    let name = "Riya";
    console.log("Well done, " + name + "!");
    (a) Riya (b) Well done, Riya! (c) Well done, name! (d) name
  24. 24.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 3;
    console.log(x + y);
    (a) Error (b) 8 (c) 53
  25. 25.⚡ What does this code show?
    let name = "Kabir";
    alert("Welcome, " + name + "!");
    (a) Welcome, name! (b) Kabir (c) Welcome, Kabir! (d) name
  26. 26.⚡ What number does this code print?
    let a = 10;
    let b = 5;
    console.log(a * b);
  27. 27.⚡ What number does this code print?
    let apples = 27;
    apples = apples + 12;
    apples = apples - 10;
    console.log(apples);
  28. 28.⚡ What number does this code print?
    let marks = 8;
    marks = marks + 18;
    marks = marks - 6;
    console.log(marks);
  29. 29.⚡ What number does this code print?
    let a = 52;
    let b = 36;
    console.log(a - b);
  30. 30.⚡ What does this code show?
    let name = "Zoya";
    console.log("Well done, " + name + "!");
    (a) Zoya (b) Well done, Zoya! (c) name (d) Well done, name!
  31. 31.⚡ What number does this code print?
    let a = 31;
    let b = 1;
    console.log(a - b);
  32. 32.⚡ What number does this code print?
    let a = 52;
    let b = 23;
    console.log(a + b);
  33. 33.⚡ What number does this code print?
    let a = 56;
    let b = 23;
    console.log(a + b);
  34. 34.⚡ What number does this code print?
    let a = 6;
    let b = 12;
    console.log(a * b);
  35. 35.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 7;
    console.log(x + y);
    (a) 8 (b) 17 (c) Error
  36. 36.⚡ What does this code print? (Look at the quotes!)
    let x = "7";
    let y = 1;
    console.log(x + y);
    (a) 71 (b) Error (c) 8
  37. 37.⚡ What number does this code print?
    let a = 6;
    let b = 9;
    console.log(a * b);
  38. 38.⚡ What number does this code print?
    let a = 5;
    let b = 4;
    console.log(a * b);
  39. 39.⚡ What number does this code print?
    let a = 33;
    let b = 19;
    console.log(a - b);
  40. 40.⚡ What does this code show?
    let name = "Riya";
    alert("Welcome, " + name + "!");
    (a) Welcome, name! (b) Riya (c) name (d) Welcome, Riya!

Answer key

  1. 21
  2. actions and changes
  3. 36
  4. for
  5. 49
  6. 61
  7. 46
  8. 30
  9. 42
  10. <script>
  11. if
  12. console.log()
  13. let
  14. in the console
  15. 23
  16. 39
  17. 89
  18. 4
  19. .js
  20. Well done, Aman!
  21. 17
  22. 47
  23. Well done, Riya!
  24. 53
  25. Welcome, Kabir!
  26. 50
  27. 29
  28. 20
  29. 16
  30. Well done, Zoya!
  31. 30
  32. 75
  33. 79
  34. 72
  35. 17
  36. 71
  37. 54
  38. 20
  39. 14
  40. Welcome, Riya!

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