← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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