← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 12
  2. 2
  3. if
  4. for
  5. 16
  6. actions and changes
  7. let
  8. 64
  9. Well done, Meera!
  10. 78
  11. <script>
  12. alert()
  13. 19
  14. Welcome, Kabir!
  15. 50
  16. .js
  17. 19
  18. 37
  19. 5
  20. 43
  21. Welcome, Zoya!
  22. 10
  23. 32
  24. 0
  25. 49
  26. 17
  27. 15
  28. 50
  29. in the console
  30. let
  31. 20
  32. 83
  33. 39
  34. console.log()
  35. 132
  36. 23
  37. 27
  38. 82
  39. 14
  40. 28

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