← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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