Workshop › Battleship › Step 9 of 35
Your shots are kept in a grid, myShots: null for a square not tried yet, 'miss' or 'hit'. fire shoots at a
square of a fleet, writes the result into a grid and returns it.
```js
let myShots // myShots[r][c]: null, 'miss' or 'hit' (on the enemy's sea)
myShots = grid(null)
// Fire at a square of a fleet and record the result on that shots grid.
function fire(fleet, record, r, c) {
const ship = shipAt(fleet, r, c)
if (!ship) {
record[r][c] = 'miss'
return 'miss'
}
record[r][c] = 'hit'
return 'hit'
}
```reset starts myShots as a grid of null.fire looks for a ship on the square. None: record and return 'miss'. Otherwise record and return 'hit'.!ship is true when shipAt gave undefined.let myFleet write let myShots with its comment.reset, under myFleet = placeFleet(), write myShots = grid(null).function drawSea(, write fire with its comment, followed by an empty line.Skills: Functions, Arrays and objects
← Which ship is here? Show the shots →