← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 4
  2. alert()
  3. let
  4. 92
  5. 15
  6. actions and changes
  7. Welcome, Riya!
  8. a pop-up box
  9. 10
  10. 36
  11. 35
  12. if
  13. <script>
  14. 17
  15. 4
  16. 9
  17. Well done, Riya!
  18. 19
  19. 55
  20. 65
  21. 52
  22. 64
  23. 22
  24. 2
  25. 27
  26. 4
  27. 45
  28. 67
  29. 41
  30. 27
  31. Hello, Kabir!
  32. console.log()
  33. Hello, Riya!
  34. let
  35. 42
  36. 24
  37. 98
  38. 8
  39. 19
  40. 13

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