← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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