← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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