← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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