# Seleksi Kondisi

Seleksi kondisi digunakan untuk melakukan tindakan yang berbeda berdasarkan kondisi yang berbeda. Kode akan dieksekusi jika syarat yang diminta terpenuhi.

### if

```markup
<h1>If</h1>

<script>
  let cuaca = prompt("apa cuaca hari ini ?", "cerah");

  if (cuaca === "cerah") {
    console.log("cuaca", cuaca, ", saya pergi bermain di luar rumah");
  }
</script>
```

### if else

```markup
<h1>If Else</h1>

<script>
  let cuaca = prompt("apa cuaca hari ini ?", "cerah");

  if (cuaca === "cerah") {
    console.log("cuaca", cuaca, ", saya pergi bermain di luar rumah");
  } else {
    console.log("cuaca", cuaca, ", saya baca buku di ruang tamu");
  }
</script>
```

### nested if else&#x20;

```markup
<h1>Nested If Else</h1>

<script>
  let cuaca = prompt("apa cuaca hari ini ?", "cerah");

  if (cuaca === "cerah") {
    console.log("cuaca", cuaca, ", saya pergi bermain di luar rumah");
  } else if (cuaca === "berawan") {
    console.log("cuaca", cuaca, ", saya baca buku di teras");
  } else {
    console.log("cuaca", cuaca, ", saya baca buku di ruang tamu");
  }
</script>
```

### switch

Jika nested if else terkalu banyak, itu tandanya anda membutuhkan switch.

```markup
<h1>Switch</h1>

<script>
  let cuaca = prompt("apa cuaca hari ini ?", "cerah");

  switch (cuaca) {
    case "cerah":
      console.log("cuaca", cuaca, ", saya pergi bermain di luar rumah");
      break
    case "berawan":
      console.log("cuaca", cuaca, ", saya baca buku di teras");
      break
    default:
      console.log("cuaca", cuaca, ", saya baca buku di ruang tamu");
  }
</script>
```


---

# 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://seri-belajar-pemrograman.rijalasepnugroho.com/javascript/seleksi-kondisi.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.
