> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/zerocho-javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/zerocho-javascript/undefined-34.md).

# 죽은카드 정리하기

필드에 있는 카드의 인덱스가 -1보다 크면 쫄병이 죽었다는 의미이고, -1보다 작다면 영웅이 죽었음을 의미하므로, 영웅이 죽으면 승리 또는 패배 메세지를 출력하고 초기세팅함수를 호출한다.

```javascript
if(데이터.hp <= 0) {//카드가 죽었을 때
                    var 인덱스 = 상대.필드data.indexOf(데이터);
                    if(인덱스 > -1) {//쫄병이 죽었을 때
                        상대.필드data.splice(인덱스,1);//중간에 있는 데이터를 뺄 수 있다.
                    } else {//영웅이 죽었을 때
                        alert('승리하셨습니다');
                        초기세팅();
                    }
                    
                }
```
