← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 35
  2. a pop-up box
  3. Welcome, Riya!
  4. 3
  5. 68
  6. Well done, Meera!
  7. 56
  8. 13
  9. Hello, Zoya!
  10. let
  11. 29
  12. 54
  13. 5
  14. <script>
  15. for
  16. in the console
  17. 33
  18. 26
  19. 12
  20. 24
  21. alert()
  22. Welcome, Aman!
  23. 60
  24. 20
  25. console.log()
  26. if
  27. 92
  28. 1
  29. 18
  30. 3
  31. 63
  32. 28
  33. Well done, Riya!
  34. 75
  35. 61
  36. 27
  37. Hello, Meera!
  38. Welcome, Zoya!
  39. let
  40. 20

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