0
Dont know why my "else if statement" doesn't work
am writing a code to give the scientific notation of a number https://code.sololearn.com/Wo6qbx2iPIpW/?ref=app
5 Respuestas
+ 1
I assume your else if statement is for fractional number like 0.37, 0.1763, etc. you should write input < 1 instead
You should write this instead
if(input >= 10 || input <= -10){
while(input >= 10 || input <= -10){
input = input / 10;
ix();
}
document.write(input + " x 10^" + x);
}else if(input < 1 && input > -1){
while(input < 1 && input > -1){
input = input * 10;
iy();
}
Hence, it will work on any number
0
but if my input is = 0.056
it will only return "0"
Agent_I
0
Michael Okolie
Sorry, I think I forgot to put document.write in the else if statement
else if(input < 1 && input > -1){
while(input < 1 && input > -1){
input = input * 10;
iy();
}
document.write(input + " x 10^" + y); }
0
Agent_I
thanks alot Ur first answer worked
but y didn't it work when the code was
else if ( input < 0){
while (input < 0){
*****
****
}
}
but it works when it's
else if ( input < 1){
while (input < 1){
*****
****
}
}
0
Michael Okolie
The first one didn't work because the fractional number like 0.723, 0.16, 0.019, etc. is below 1 and above 0
0.723 < 1
0.723 > 0
So if you put the condition to input < 0, it won't work