← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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