Conditions let your code make decisions.
if (marks >= 60) {
grade = 'First';
} else if (marks >= 45) {
grade = 'Second';
} else {
grade = 'Fail';
}
ifruns its block when the condition is trueelse ifchecks another conditionelseruns when nothing above was true
Only one block runs — the first one whose condition is true.
Combine conditions
if (age >= 18 && hasId) { ... }
Short form
For simple choices use the ternary operator: const msg = age >= 18 ? 'Adult' : 'Minor';
Example
Example — Grade calculator
HTML
<input id="marks" type="number" value="72">
<button onclick="check()">Get grade</button>
<p id="out"></p>
<script>
function check() {
const marks = Number(document.getElementById('marks').value);
let grade;
if (marks >= 90) {
grade = 'A+';
} else if (marks >= 75) {
grade = 'A';
} else if (marks >= 60) {
grade = 'B';
} else if (marks >= 33) {
grade = 'C';
} else {
grade = 'Fail';
}
document.getElementById('out').textContent = 'Grade: ' + grade;
}
</script>