← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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