← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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