← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hi, Kabir!
  2. Hello, Riya!
  3. if
  4. alert()
  5. for
  6. 90
  7. 62
  8. 18
  9. 29
  10. 44
  11. in the console
  12. 29
  13. a pop-up box
  14. 24
  15. 99
  16. 1
  17. 93
  18. Hello, Riya!
  19. 1
  20. 11
  21. 11
  22. <script>
  23. 9
  24. .js
  25. let
  26. console.log()
  27. Welcome, Riya!
  28. 83
  29. 27
  30. 31
  31. Welcome, Aman!
  32. 65
  33. 108
  34. Hi, Arjun!
  35. 12
  36. 2
  37. 47
  38. 29
  39. Welcome, Aman!
  40. 48

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