← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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