← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 32
  2. 87
  3. Hi, Riya!
  4. 35
  5. 50
  6. actions and changes
  7. Welcome, Riya!
  8. Hi, Aman!
  9. 33
  10. 26
  11. 20
  12. <script>
  13. for
  14. 3
  15. 88
  16. 26
  17. 84
  18. Welcome, Aman!
  19. in the console
  20. if
  21. 29
  22. 18
  23. Hi, Meera!
  24. 1
  25. Hello, Kabir!
  26. alert()
  27. 91
  28. 33
  29. let
  30. Hello, Aman!
  31. 79
  32. 28
  33. Welcome, Kabir!
  34. console.log()
  35. 22
  36. Hello, Arjun!
  37. let
  38. 9
  39. Hello, Arjun!
  40. 20

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