← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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