← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. let
  2. 3
  3. 41
  4. for
  5. 1
  6. alert()
  7. let
  8. 6
  9. .js
  10. Hi, Kabir!
  11. 21
  12. 76
  13. 6
  14. 48
  15. Hi, Meera!
  16. Well done, Riya!
  17. Hi, Riya!
  18. if
  19. console.log()
  20. 30
  21. 7
  22. 3
  23. in the console
  24. 28
  25. actions and changes
  26. <script>
  27. 82
  28. 19
  29. 9
  30. 83
  31. 12
  32. Welcome, Zoya!
  33. 84
  34. 4
  35. 3
  36. Hi, Arjun!
  37. Hi, Riya!
  38. 57
  39. 15
  40. 28

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