← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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