If statement is used for when only running code if condition is true.
For example:
Let rating=3;
If ( rating ===3) {
console.lot( “ you superstar!”)
}
If condition is false if doesn’t run.
Can also combine with else if or else to form full conditional.
Else I’d is not first but if first thing doesn’t happen then it’s added in.
To demonstrate else if:
Else if (rating ===2) {
console.log( “ meets expectations“);
}
Its possible to add it to the end of a fag or can make a new one.
Strings can also be added within too.
Else is used for when nothing else is true this is when it comes in play
To demonstrate it would look like this:
else {
console.log( “ invalid rating!”)
}
Comments