title: Why my shipsSunk property in the model object is 9 instead of 3?
body: <p>I am practicing Javascript by creating a battleship game, and I am trying to display the user a message when it finishes the game.</p>
  
  <pre><code>if (hit &amp;&amp; model.shipsSunk === model.numShips) {
                  view.displayMessage("You Sank all my battleships, in " + this.guesses + " guesses");
              }
  </code></pre>
  
  <p>But nothing happens and when I console.log the value of shipsSunk is equal 9 instead of 3 (numShips = 3, so I need that exact number to be able to run the code above).</p>
  
  <pre><code>var view = {
      displayMessage: function(msg) {
          var messageArea = document.getElementById("messageArea");
          messageArea.innerHTML = msg;
      },
      displayHit: function(location) {
          var cell = document.getElementById(location);
          cell.setAttribute("class", "hit");
      },
      displayMiss: function(location) {
          var cell = document.getElementById(location);
          cell.setAttribute("class", "miss");
      }
  };
  
  var model = {
      boardSize: 7,
      numShips: 3,
      shiplength: 3,
      shipsSunk: 0,
      ships: [
              {locations: ["06", "16", "26"], hits: ["", "", ""] },
              {locations: ["24", "34", "44"], hits: ["", "", ""] },
              {locations: ["10", "11", "12"], hits: ["", "", ""] }],
      fire: function(guess) {
          for (var i = 0; i &lt; this.numShips; i++) {
              var ship = this.ships[i];
              var index = ship.locations.indexOf(guess);
              if (index &gt;= 0) {
                  ship.hits[index] = "hit";
                  view.displayHit(guess);
                  view.displayMessage("HIT!");
                  if (this.isSunk(ship)) {
                      view.displayMessage("You sank my battleship!");
                      this.shipsSunk++;
                  }
                  return true;
              }
          }
          view.displayMiss(guess);
          view.displayMessage("You missed.");
          return false;
      },
      isSunk: function(ship) {
          for (var i = 0; i &lt; this.shipLength; i++) {
              if (ship.hits[i] !== "hit") {
                  return false;
              }
          }
          return true;
      }
  };
  
  var controller = {
      guesses: 0,
      processGuess: function(guess) {
          var location = parseGuess(guess);
          if (location) {
              this.guesses++;
              var hit = model.fire(location);
              if (hit &amp;&amp; model.shipsSunk === model.numShips) {
                  view.displayMessage("You Sank all my battleships, in " + this.guesses + " guesses");
              }
          }
      } 
  };
  function parseGuess(guess) {
      var alphabet = ["A", "B", "C", "D", "E", "F", "G"];
      if (guess === null || guess.length !== 2) {
          alert("Oops, please enter a letter and a number on the board.");
      }  else {
          firstChar = guess.charAt(0);
          var row = alphabet.indexOf(firstChar);
          var column = guess.charAt(1);
  
          if (isNaN(row) || isNaN(column)) {
              alert("Oops, that isn't on the board.");
          } else if (row &lt; 0 || row &gt;= model.boardSize || column &lt; 0 || column &gt;= model.boardSize) {
              alert("Oops, that's off the board!");
          } else {
              return row + column;
          }
      }
      return null;
  };
  
  controller.processGuess("A0");
  
  controller.processGuess("A6");
  controller.processGuess("B6");
  controller.processGuess("C6");
  
  controller.processGuess("C4");
  controller.processGuess("D4");
  controller.processGuess("E4");
  
  controller.processGuess("B0");
  controller.processGuess("B1");
  controller.processGuess("B2");
  
  console.log(model.shipsSunk);
  
  </code></pre>