I only know how to use if, elif and else in Python, but how do I write “elif” in Javascript? I would also like to know how to add a “repeat” and “target” ability to it.
Any help would be welcome.
1 Like
The JavaScript equivalent of Python’s elif
is else if
:
if (someCondition) {
// Do something if `someCondition` is true
} else if (anotherCondition) {
// Do something if `someCondition` is false and `anotherCondition` is true
} else if (yetAnotherCondition) {
// Do something if both `someCondition` and `anotherCondition` are false
// and `yetAnotherCondition` is true
}
Note that the syntax above is just a nicer way to write nested else/if
statements and is completely equivalent to this:
if (someCondition) {
// Do something if `someCondition` is true
} else {
if (anotherCondition) {
// Do something if `someCondition` is false and `anotherCondition` is true
} else {
if (yetAnotherCondition) {
// Do something if both `someCondition` and `anotherCondition` are
// false and `yetAnotherCondition` is true
}
}
}
As for repeat
and target
, can you a bit more specific about what kind of behavior you want to achieve?
1 Like