← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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