← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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