← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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