← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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