← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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