← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. <script>
  2. 1
  3. 19
  4. alert()
  5. 0
  6. 30
  7. 20
  8. 15
  9. .js
  10. 7
  11. 69
  12. 57
  13. let
  14. if
  15. 29
  16. Welcome, Aman!
  17. 12
  18. 5
  19. 62
  20. a pop-up box
  21. console.log()
  22. 24
  23. Welcome, Riya!
  24. let
  25. 55
  26. in the console
  27. 21
  28. 68
  29. 89
  30. 81
  31. 67
  32. for
  33. 3
  34. 47
  35. 44
  36. 9
  37. 84
  38. 10
  39. 16
  40. 43

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