# 죽은카드 정리하기

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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/zerocho-javascript/undefined-34.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
