← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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