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:

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

    <center class="boxes">
        <div>
          <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>
        <div id="result">0 are checked.</div>
      </center>
<script src="java.js"></script>
</body>

Here’s the JavaScript:

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

Source: Ask Javascript Questions

LEAVE A COMMENT