← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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