← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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