So I am basically trying to change the variable "status" when I execute the code below.
const Ship = (length) => {
let status = "good"
let array = []
for (let i = 1; i <= length; i++) {
array.push(i)
}
const hit = (number) => {
if (!number) {
return array
}
array[number - 1] = number + 10
status = "bad"
}
return {
length,
hit,
array,
status
}
}
const ships = Ship(2)
console.log(ships.status) //initial status
console.log(ships.array) //initial array
ships.hit(1)
console.log(ships.array) //modified array
console.log(ships.status) //not modified status
It should work,since the array gets modified, but for some reason it doesn't. I want to know WHY it doesn't work, not a work around.