js switch case
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
js switch case
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
js convert if/else statement to switch case
var gradeOut = 70;
var totalGrade = 80;
if (gradeOut >= 90)
gradeOut+= "My letter grade is: A";
else if (totalGrade < 90 && totalGrade >= 80)
gradeOut+= "My letter grade is: B";
else if (totalGrade < 80 && totalGrade >= 70)
gradeOut+= "My letter grade is: C";
else if (totalGrade < 70 && totalGrade >= 60)
gradeOut+= "My letter grade is: D";
else if (totalGrade < 60)
gradeOut+= "My letter grade is: F";
//here's the same thing using switch(true). Requires var gradeOut (is currently at top of page
switch(true) {
case gradeOut<60:
gradeOut= "My letter grade is: F";
break;
case gradeOut<70:
gradeOut= "My letter grade is: D";
break;
case gradeOut<80:
gradeOut="My letter grade is: C";
break;
}
js convert if/else statement to switch case
switch (true) {
case bid < 100000:
currentIncrease = 1000;
break;
case type != 1 && bid - 1000 < 100000:
currentIncrease = 1000;
break;
case type != 1 && bid - 2000 < 1000000:
currentIncrease = 2000;
break;
case bid < 1000000:
currentIncrease = 2000;
break;
default:
currentIncrease = 10000;
}
js convert if/else statement to switch case
const randomNumber = Math.floor(Math.random() * 100);
console.log(randomNumber);
if (randomNumber < 20) {
console.log('randomNumber меньше 20');
} else if (randomNumber > 50) {
console.log('randomNumber больше 50');
} else {
console.log('randomNumber больше 20, и меньше 50')
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us