> For the complete documentation index, see [llms.txt](https://westsilver.gitbook.io/study-script/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://westsilver.gitbook.io/study-script/nomad-script/vanillajs/dom/conditional.md).

# Conditional

조건문

## 1. if 문법

```javascript
if(condition){ //true 의미하면 무엇이든 넣을 수 있음
	block;
} else{
	block;
}
```

## 2. >, ===, &&, ||

{% tabs %}
{% tab title=" else" %}

```javascript
if (10 > 5) {
    console.log("hi");
} else {
    console.log("ho");
}

//10이 5보다 크므로 true -> hi 출력
```

{% endtab %}

{% tab title="else if" %}

```javascript
if ("10" === 10) { //"10"문자, 10숫자이기 때문에 서로 다름
    console.log("hi");
} else if ("10" === "11") {
    console.log("lalala");
} else {
    console.log("ho");
} 
//if와 else if의 조건문 둘 다 false -> else의 ho 출력
```

{% endtab %}

{% tab title="and" %}

* **&&**
* 두 조건의 값이 **모두** 일치해야 true
* 하나라도 일치하지 않으면 false

```javascript
if (20 > 5 && "nicolas" === "nicolas") {
    console.log("yes");
} else {
    console.log("no");
}
//두 조건 모두 일치 -> true -> yes 출력
```

{% endtab %}

{% tab title="or" %}

* **||**
* **둘 중 하나**의 조건만 일치해도 true

```javascript
if (20 > 5 || "CHO" === "cho") {
    console.log("yes");
} else {
    console.log("no");
}
//뒤의 조건 불일치 but 하나의 조건만 일치하면 됨 -> true -> yes 출력
```

{% endtab %}
{% endtabs %}

### 2-1. 예시

```javascript
const age = prompt("How old are you"); 
//prompt 함수는 아주 오래된 함수로 현재는 사용하지 않음
​
if(age >= 18 && age <= 21) {
	console.log("you can drink but you shold not");
} else if(age>21){
	console.log("go ahead")
} else{
	console.log("too young");
}
```
