← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 582 · 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 = 20;
    let b = 28;
    console.log(a + b);
  2. 2.⚡ A JavaScript file usually ends with which extension? (a) .css (b) .html (c) .jpg (d) .js
  3. 3.⚡ What number does this code print?
    let runs = 21;
    runs = runs + 15;
    runs = runs - 11;
    console.log(runs);
  4. 4.⚡ What number does this code print?
    let a = 56;
    let b = 38;
    console.log(a - b);
  5. 5.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 6;
    console.log(x + y);
    (a) 86 (b) 14 (c) Error
  6. 6.⚡ What number does this code print?
    let marks = 6;
    marks = marks + 18;
    marks = marks - 15;
    console.log(marks);
  7. 7.⚡ What number does this code print?
    let a = 9;
    let b = 3;
    console.log(a * b);
  8. 8.⚡ What number does this code print?
    let a = 17;
    let b = 19;
    console.log(a + b);
  9. 9.⚡ What number does this code print?
    let a = 55;
    let b = 25;
    console.log(a + b);
  10. 10.⚡ What number does this code print?
    let a = 11;
    let b = 22;
    console.log(a + b);
  11. 11.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <js> (c) <code> (d) <script>
  12. 12.⚡ What number does this code print?
    let marks = 12;
    marks = marks + 20;
    marks = marks - 25;
    console.log(marks);
  13. 13.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hello, " + name + "!");
    (a) Kabir (b) name (c) Hello, Kabir! (d) Hello, name!
  14. 14.⚡ What number does this code print?
    let runs = 27;
    runs = runs + 12;
    runs = runs - 28;
    console.log(runs);
  15. 15.⚡ What number does this code print?
    let a = 23;
    let b = 38;
    console.log(a + b);
  16. 16.⚡ Which JavaScript word writes in the console? (a) let (b) for (c) console.log() (d) if
  17. 17.⚡ What number does this code print?
    let apples = 8;
    apples = apples + 6;
    apples = apples - 3;
    console.log(apples);
  18. 18.⚡ Which JavaScript word runs code when true? (a) if (b) for (c) console.log() (d) alert()
  19. 19.⚡ What does this code print? (Look at the quotes!)
    let x = "6";
    let y = 9;
    console.log(x + y);
    (a) 15 (b) Error (c) 69
  20. 20.⚡ What number does this code print?
    let coins = 9;
    coins = coins + 5;
    coins = coins - 12;
    console.log(coins);
  21. 21.⚡ What number does this code print?
    let books = 30;
    books = books + 2;
    books = books - 28;
    console.log(books);
  22. 22.⚡ What number does this code print?
    let a = 11;
    let b = 1;
    console.log(a + b);
  23. 23.⚡ Which JavaScript word repeats code? (a) alert() (b) for (c) if (d) console.log()
  24. 24.⚡ 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
  25. 25.⚡ What number does this code print?
    let a = 59;
    let b = 29;
    console.log(a + b);
  26. 26.⚡ What number does this code print?
    let marks = 10;
    marks = marks + 20;
    marks = marks - 3;
    console.log(marks);
  27. 27.⚡ Which JavaScript word makes a new variable? (a) for (b) console.log() (c) alert() (d) let
  28. 28.⚡ Which JavaScript word shows a pop-up box? (a) let (b) if (c) for (d) alert()
  29. 29.⚡ Which word makes a new variable? (a) make (b) give (c) put (d) let
  30. 30.⚡ What number does this code print?
    let a = 44;
    let b = 32;
    console.log(a + b);
  31. 31.⚡ What does this code print? (Look at the quotes!)
    let x = "4";
    let y = 1;
    console.log(x + y);
    (a) Error (b) 5 (c) 41
  32. 32.⚡ What number does this code print?
    let a = 35;
    let b = 17;
    console.log(a - b);
  33. 33.⚡ What number does this code print?
    let books = 22;
    books = books + 7;
    books = books - 5;
    console.log(books);
  34. 34.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 8;
    console.log(x + y);
    (a) 13 (b) 58 (c) Error
  35. 35.⚡ What number does this code print?
    let books = 29;
    books = books + 2;
    books = books - 2;
    console.log(books);
  36. 36.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 3;
    console.log(x + y);
    (a) 53 (b) Error (c) 8
  37. 37.⚡ What number does this code print?
    let apples = 15;
    apples = apples + 12;
    apples = apples - 23;
    console.log(apples);
  38. 38.⚡ What number does this code print?
    let a = 5;
    let b = 39;
    console.log(a + b);
  39. 39.⚡ What does this code show?
    let name = "Meera";
    console.log("Hello, " + name + "!");
    (a) Meera (b) Hello, name! (c) name (d) Hello, Meera!
  40. 40.⚡ What number does this code print?
    let a = 31;
    let b = 23;
    console.log(a - b);

Answer key

  1. 48
  2. .js
  3. 25
  4. 18
  5. 86
  6. 9
  7. 27
  8. 36
  9. 80
  10. 33
  11. <script>
  12. 7
  13. Hello, Kabir!
  14. 11
  15. 61
  16. console.log()
  17. 11
  18. if
  19. 69
  20. 2
  21. 4
  22. 12
  23. for
  24. in the console
  25. 88
  26. 27
  27. let
  28. alert()
  29. let
  30. 76
  31. 41
  32. 18
  33. 24
  34. 58
  35. 29
  36. 53
  37. 4
  38. 44
  39. Hello, Meera!
  40. 8

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