← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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