Workshop › Missile Command-style Defense › Step 4 of 35
A city can be destroyed, so each city needs to remember whether it is still standing. reset() turns the list of x
positions into a list of city objects.
```js
let cities
function reset() {
cities = CITY_XS.map((x) => ({ x, alive: true }))
}
reset()
```map makes a new list by passing every item through a function: each x becomes { x, alive: true }.{ x } is shorthand for { x: x }. The extra ( ) around the object are needed, or { would start a function body.reset() is called once, before the loop starts.const CITY_XS = ... leave an empty line and write let cities and the reset function.reset() just above the last requestAnimationFrame(loop).Skills: Arrays and objects, Game states
← Draw again and again Rubble →