← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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