← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. alert()
  2. Hello, Riya!
  3. 12
  4. 45
  5. let
  6. 24
  7. Hi, Meera!
  8. 16
  9. 29
  10. 71
  11. .js
  12. actions and changes
  13. <script>
  14. 24
  15. 41
  16. Hi, Riya!
  17. 54
  18. a pop-up box
  19. in the console
  20. 35
  21. 24
  22. 39
  23. 10
  24. console.log()
  25. 76
  26. 17
  27. for
  28. if
  29. 42
  30. 33
  31. 9
  32. 65
  33. 62
  34. 57
  35. let
  36. 60
  37. Well done, Arjun!
  38. 41
  39. 11
  40. Hello, Riya!

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