← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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