javascript / beginner
Snippet
Simple If-Else Control Flow
Control flow allows your program to make decisions. The 'if' block runs only if the condition in parentheses is true; otherwise, the 'else' block runs.
snippet.js
1
2
3
4
5
6
const score = 85;if (score > 50) {console.log("Passed!");} else {console.log("Try again.");}
Breakdown
1
if (score > 50)
Checks if the variable 'score' is greater than 50.
2
else { ... }
Defines what happens if the 'if' condition is false.