← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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