← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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