← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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