← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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