JavaScript not working? (Checked Checkbox Counter) [duplicate]

  html, javascript

So I’m running a JavaScript text in my code and its not working. I can’t work out why its not working. I’m planning on it being a 100% completion for a video game. There’s some code that is not here but it shouldn’t affect the code. (Thanks in advance)

Here’s the HTML:

    <title>100% Completion</title>
    <link rel="stylesheet" href="style.css" />

    <center class="boxes">
          <label><input type="checkbox" name="red"/>Red</label>
          <label><input type="checkbox" name="green"/>Green</label>
          <label><input type="checkbox" name="blue"/>Blue</label>
          <label><input type="checkbox" name="black"/>Black</label>
        <div id="result">0 are checked.</div>
<script src="java.js"></script>

Here’s the JavaScript:

    var checked = 0;
    function count() {
      checked = $("input:checked").length;
      $("#result").text(checked+" are checked");

Source: Ask Javascript Questions