← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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