← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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