← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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