Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
603 B
1
Indexable
Never
let mineField = [
    false, false, false, true, true,
    false, false, false, false, true
]

hp = 2
i = 1

while (i < hp) {
    for (i; i < mineField.length && hp > 0; i++) {
        if (mineField[i]) {
            hp--;
            if (hp == 0) {
                console.log('moved at', i, 'point', 'and got destroyed,', 'hp is', hp);
                break
            } else {
                console.log('moved at', i, 'point', 'and got damaged,', 'hp is', hp); 
            }
            
        } else {
            console.log('moved at', i, 'point', 'its safe,', 'hp is', hp)
        }
    }
}