← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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