← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 7
  2. 35
  3. Hi, Zoya!
  4. 97
  5. 20
  6. 10
  7. 71
  8. for
  9. Hi, Meera!
  10. Hello, Zoya!
  11. .js
  12. 12
  13. 5
  14. 50
  15. Hi, Riya!
  16. 79
  17. 11
  18. Welcome, Kabir!
  19. 7
  20. let
  21. 46
  22. in the console
  23. 91
  24. 31
  25. let
  26. 14
  27. 27
  28. 18
  29. 49
  30. 16
  31. 40
  32. Well done, Riya!
  33. alert()
  34. if
  35. actions and changes
  36. a pop-up box
  37. Hello, Kabir!
  38. 74
  39. Well done, Aman!
  40. 42

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