← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 51
  2. 39
  3. 89
  4. 23
  5. 8
  6. console.log()
  7. 72
  8. in the console
  9. 66
  10. 6
  11. Hello, Zoya!
  12. alert()
  13. 63
  14. Welcome, Kabir!
  15. 94
  16. 48
  17. 18
  18. 27
  19. 44
  20. Hi, Meera!
  21. 4
  22. let
  23. <script>
  24. 14
  25. 27
  26. let
  27. 82
  28. for
  29. Hi, Zoya!
  30. 5
  31. .js
  32. 42
  33. 49
  34. a pop-up box
  35. 66
  36. 75
  37. 21
  38. 21
  39. Hi, Aman!
  40. Hi, Riya!

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