← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 21
  2. console.log()
  3. let
  4. alert()
  5. 92
  6. let
  7. 43
  8. 6
  9. for
  10. 1
  11. .js
  12. 22
  13. 11
  14. 5
  15. <script>
  16. 67
  17. 33
  18. 46
  19. 85
  20. 15
  21. 16
  22. 8
  23. Well done, Meera!
  24. Welcome, Arjun!
  25. 28
  26. Hello, Aman!
  27. a pop-up box
  28. 28
  29. 72
  30. 81
  31. 68
  32. Hello, Meera!
  33. in the console
  34. 1
  35. Hello, Zoya!
  36. 13
  37. Welcome, Kabir!
  38. 7
  39. 8
  40. 3

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