← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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