← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 34
  2. let
  3. a pop-up box
  4. 39
  5. for
  6. <script>
  7. if
  8. 52
  9. Welcome, Riya!
  10. 132
  11. 44
  12. console.log()
  13. let
  14. 45
  15. alert()
  16. 25
  17. 23
  18. Hello, Meera!
  19. 16
  20. 73
  21. Hi, Riya!
  22. Hi, Zoya!
  23. Hello, Kabir!
  24. in the console
  25. 11
  26. 98
  27. 21
  28. 62
  29. 50
  30. 16
  31. Hello, Aman!
  32. 27
  33. 10
  34. Hi, Aman!
  35. 25
  36. 1
  37. 84
  38. 2
  39. 13
  40. .js

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