← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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