← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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