← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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