← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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