← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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