← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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