← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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