← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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