javascript - I need to check for equality with a switch statement -
i'm writing hot or cold app. , need switch statement decide whether user hot or cold. here's code far:
switch(true) { case (userguess / secretnumber === 1): setfeedback("you win"); finish = true; break; case ((userguess - secretnumber) > 50): setfeedback("you're ice cold!"); break; case ((userguess - secretnumber) > 30): setfeedback("you're cold!"); break; case ((userguess - secretnumber) > 20): setfeedback("you're warm!"); break; case ((userguess - secretnumber) > 10): setfeedback("you're hot!"); break; case ((userguess - secretnumber) > 0): setfeedback("you're blazing hot!"); break; }
edit: i'm trying replace following if/else statement switch. please tell me if it's possible , if so: how. here's old code:
if (userguess / secretnumber === 1){ setfeedback("you win"); finish = true; } else if ((secretnumber - userguess) > 60.5){ setfeedback("wow! freezing!"); } else if ((secretnumber - userguess) > 55.5){ setfeedback("wow! better put on jacket cause super cold!"); } else if ((secretnumber - userguess) > 50.5){ setfeedback("its super cold man!"); } else if ((secretnumber - userguess) > 40.5) { setfeedback("now cold!"); } else if ((secretnumber - userguess) > 30.5) { setfeedback("it's getting warm around here"); } else if((secretnumber - userguess) > 20.5) { setfeedback("it's getting warm in here!"); } else if((secretnumber - userguess) > 15.5) { setfeedback("it's getting very warm in here!"); } else if ((secretnumber - userguess) > 7.5){ setfeedback("it's hot!"); } else if ((secretnumber - userguess) > 5.5){ setfeedback("it hot here!"); } else if ((secretnumber - userguess) > 1.5){ setfeedback("i burning here!!"); } else if ((secretnumber - userguess) > 0.5){ setfeedback("its hotter sun!!!!!"); } else { }
int value = secretnumber-userguess; if ((userguess / secretnumber) == 1) { setfeedback("you win"); finish = true; } else if (value > 60.5) setfeedback("wow! freezing!"); else if (value > 55.5) setfeedback("wow! better put on jacket cause super cold!"); else if (value > 50.5) setfeedback("its super cold man!"); else if (value > 40.5) setfeedback("now cold!"); else if (value > 30.5) setfeedback("it's getting warm around here"); else if (value > 20.5) setfeedback("it's getting warm in here!"); else if(value > 15.5) setfeedback("it's getting very warm in here!"); else if (value > 7.5) setfeedback("it's hot!"); else if (value > 5.5) setfeedback("it hot here!"); else if (value > 1.5) setfeedback("i burning here!!"); else if (value > 0.5) setfeedback("its hotter sun!!!!!"); else { }
Comments
Post a Comment