← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. console.log()
  2. a pop-up box
  3. 17
  4. 0
  5. in the console
  6. 98
  7. .js
  8. 2
  9. if
  10. Well done, Meera!
  11. 4
  12. 14
  13. 25
  14. 43
  15. for
  16. 10
  17. 85
  18. alert()
  19. 16
  20. Hello, Meera!
  21. 7
  22. let
  23. Hello, Riya!
  24. 20
  25. 46
  26. 32
  27. 4
  28. 2
  29. 15
  30. actions and changes
  31. let
  32. 40
  33. 83
  34. <script>
  35. 92
  36. 15
  37. 66
  38. 56
  39. 9
  40. 50

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