← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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