← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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