← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 18
  2. 33
  3. Hello, Aman!
  4. 21
  5. 52
  6. 10
  7. in the console
  8. 79
  9. Hello, Meera!
  10. 14
  11. if
  12. 73
  13. actions and changes
  14. 40
  15. .js
  16. a pop-up box
  17. alert()
  18. 96
  19. 10
  20. 34
  21. 32
  22. <script>
  23. 13
  24. 17
  25. 14
  26. Well done, Zoya!
  27. 85
  28. Hello, Meera!
  29. 53
  30. 20
  31. 33
  32. 29
  33. 38
  34. 11
  35. 7
  36. 25
  37. 6
  38. 84
  39. let
  40. 80

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