To make an If statement, you must first have a script element. It should look like this:
<script>
</script>
Next, write "if () {", add two lines, and put a condition inside "()". Put code inside of the second line, and a "}" in the third.
<script>
if (variable == 3) {
alert("TRUE");
}
</script>
You can also add "else" to the "}" line, and repeat the previous steps to execute different code if the condition is false.
<script>
if (variable == 3) {
alert("TRUE");
} else {
alert("FALSE");
}
</script>
Finally, you can also add "else if" or "elif", as well as another condition. This allows you to have multiple outcomes. You can have one for if condition 1 succeeds, for if condition 1 fails but condition 2 succeeds, for if 1 and 2 fail but 3 succeeds, etc.
<script>
if (variable == 1) {
alert("one");
} else if (variable == 2) {
alert("Two");
} else {
alert("Not one or two");
}
</script>
This page is currently using the 'Red' scheme.