← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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