how can i block code using if else if else , if its a alphabet in Javascript?
Hey! It seems like I’m having trouble understanding what you’re trying to achieve. Could you provide an example of what you’re attempting to do and maybe share the error message you’re encountering?
Most JavaScript statements look like this:
statement (condition) {
code
}
The if
statement is no different:
if (condition) {
// code
}
You can then chain as many else if
statements as you want:
if (condition1) {
// code1
} else if (condition2) {
// code2
}
Note that the else if
means this condition will only be checked if the previous condition evaluated to false
.
At the end of this chain, you can use an else
statement to cover any other conditions:
if (condition1) {
// code1
} else if (condition2) {
// code2
} else {
// code3
}
It might help your understanding to see this in plain english:
if condition 1 is true, then
do code 1
otherwise, if condition 2 is true, then
do code 2
lastly, if none of the above were true, then
do code 3
3 Likes