← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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