← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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