← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. console.log()
  2. let
  3. a pop-up box
  4. 61
  5. 14
  6. 72
  7. 0
  8. if
  9. let
  10. 95
  11. <script>
  12. Hi, Kabir!
  13. 3
  14. 8
  15. alert()
  16. 23
  17. 94
  18. in the console
  19. for
  20. 12
  21. 25
  22. 37
  23. Hello, Kabir!
  24. 65
  25. 71
  26. 63
  27. .js
  28. 78
  29. 65
  30. 62
  31. 34
  32. 17
  33. 39
  34. 19
  35. actions and changes
  36. 2
  37. 56
  38. 89
  39. 53
  40. 22

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