[Learning]#15 JS: if else statement

if statement

If the statement is true, the code inside of {} would be executed.
On the contrary, it would be ignored when it’s false.

var money=prompt("How much money would you like to withdraw?");
if(money>30000) {
alert("You've reached the withdraw money limit within a day.");
}

if else statement

Following the statement above, if the first statement is false, else {} would be executed.

var money=prompt("How much money would you like to withdraw?", "");
if(money>30000) {
alert("You've reached the withdraw money limit within a day.");
}else{
alert("Your money is preparing. Don't forget your ATM card.");
}

if else statement (multiple filters)

Following the 2nd statement, when we need more filters to execute the statements, that is, if both of the first statement and the former else if {} are false, the latter else if {} would be executed until the value complies with the string.

var n=prompt("How much money would you like to withdraw?", "");
if(n>500) {
alert(n+">500");
}else if (n>300){
alert(n+">300");
}else if (n>150){
alert(n+">150");
}else {
alert(n+"<=150");
}
var n1=prompt("Please key in a random number.","");
var n2=prompt("Please key in a random number.","");
var op=prompt("Please key in a math symbol: +, -, *, /",""); //op = operator
var result;
if(op=="+") {
result=n1+n2;
}else if (op=="-"){
result=n1-n2;
}else if (op=="*"){
result=n1*n2;
}else if (op=="/"){
result=n1/n2;
}else {
result="This operator does not comply with the rule.";
}
alert(result);
var n1=prompt("Please key in a random number.","");
var n2=prompt("Please key in a random number.","");
var op=prompt("Please key in a math symbol: +, -, *, /",""); //op = operator
var result;
if(op=="+") {
result=n1+n2;
}else if (op=="-"){
result=n1-n2;
}else if (op=="*"){
result=n1*n2;
}else if (op=="/"){
result=n1/n2;
}else {
result="This operator does not comply with the rule.";
}
alert(result);

Music of Today: 絕對 Absolutely by 張震嶽 ayal komod

Clap/Share/Follow

If you guys find this article helpful, please kindly do the writer a favor — giving 5 clicks at the GREEN area and 10~50 claps at the bottom of this page.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vida Lin

Vida Lin

43 Followers

PM, Relationship, Travel, or anything quirky but interesting.|Subscribe & buy Vida a drink @LikerLand, the bottom of each article. 在文章底下LikerLand訂閱、請Vida喝一杯飲料 ❤