You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
],
fire: function(guess) {
for (var i = 0; i < this.numShips; i++) {
var ship = this.ships[i];
var index = ship.locations.indexOf(guess);
if (index >= 0) {
ship.hits[index] = "hit"; if (this.isSunk(ship)) {
this.shipsSunk++;
}
return true;
}
}
return false;
}, isSunk: function(ship) {
for (var i = 0; i < this.shipLength; i++) {
if (ship.hits[i] !== "hit") {
return false;
}
}
return true;
}
};
`
Edit: The first if-statement above calls the method isSunk and then the body of the isSunk method will be executed. And if it's true, the code jumps back to if (this.isSunk(ship)) and executes the body.
The text was updated successfully, but these errors were encountered:
`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 < this.numShips; i++) {
var ship = this.ships[i];
var index = ship.locations.indexOf(guess);
if (index >= 0) {
ship.hits[index] = "hit";
if (this.isSunk(ship)) {
this.shipsSunk++;
}
return true;
}
}
return false;
},
isSunk: function(ship) {
for (var i = 0; i < this.shipLength; i++) {
if (ship.hits[i] !== "hit") {
return false;
}
}
return true;
}
};
`
Edit: The first if-statement above calls the method isSunk and then the body of the isSunk method will be executed. And if it's true, the code jumps back to if (this.isSunk(ship)) and executes the body.
The text was updated successfully, but these errors were encountered: