← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. console.log()
  2. alert()
  3. 30
  4. if
  5. <script>
  6. 33
  7. 16
  8. actions and changes
  9. Well done, Aman!
  10. 32
  11. 24
  12. a pop-up box
  13. 0
  14. 15
  15. 20
  16. in the console
  17. 8
  18. 31
  19. 24
  20. Hi, Meera!
  21. for
  22. let
  23. 18
  24. 48
  25. 21
  26. 91
  27. 25
  28. 9
  29. 72
  30. Hello, Meera!
  31. 81
  32. 4
  33. 76
  34. 1
  35. 46
  36. 66
  37. 9
  38. 1
  39. Well done, Meera!
  40. Well done, Zoya!

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