← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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