If, Else If, and Else in Javascript
var gygy="London";
if (gygy == "Paris") {
document.write("The city is Paris");
}
else if (gygy == "Tokyo") {
document.write("The city is Tokyo");
}
else {
document.write("The city is London.");
}
In plain English:
-The variable we named gygy equals London.
-We say: If gygy equals Paris, print one thing.
-We then say: Else If gygy equals Tokyo, print a different thing.
-We then say: or Else! If all else fails, print this other thing.
Copy and Paste Javascript Code:
<script type=text/javascript>
<!--
var gygy="London";
if (gygy == "Paris") {
document.write("The city is Paris. ");
}
else if (gygy == "Tokyo") {
document.write("The city is Tokyo. ");
}
else {
document.write("The city is London. ");
}
if (gygy == 1) {
document.write("One");
}
else if (gygy == 2) {
document.write("Two");
}
else {
document.write("Three");
}
-->
</script>
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group