← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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