← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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