← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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