← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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