← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 3
  2. 15
  3. 20
  4. in the console
  5. let
  6. alert()
  7. 16
  8. a pop-up box
  9. for
  10. actions and changes
  11. 4
  12. <script>
  13. Hi, Aman!
  14. 56
  15. 13
  16. 6
  17. 39
  18. 32
  19. 23
  20. 41
  21. 61
  22. .js
  23. 83
  24. 37
  25. 62
  26. 4
  27. 12
  28. console.log()
  29. 20
  30. 63
  31. if
  32. Welcome, Meera!
  33. 14
  34. 23
  35. Well done, Arjun!
  36. 48
  37. 8
  38. 70
  39. 55
  40. 38

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