+ 1

Can anyone help with the code

I shall find the max and min of 3 numbers. How should I write the isNaN part <!DOCTYPE html> <head> <title>If</title> </head> <body> <script> var a = parseFloat(prompt("insert a")), b = parseFloat(prompt("insert b")), c = parseFloat(prompt("insert c")); if (isNaN(a,b,c)){ alert("please insert a number"); if (a>b && a>c){ document.write("max=a") }else if(b>a && b>c) { document.write("max=b") }else (c>a && c>b){ document.write("max=c") } if (a<b && a<c){ document.write("min=a") }else if(b<a && b<c) { document.write("min=b") }else (c<a && c<b){ document.write("min=c") } </script> </body> </html>

19th May 2017, 9:05 AM
Manik Tafralian
Manik Tafralian - avatar
4 Answers
+ 19
<!DOCTYPE html> <head> <title>If</title> </head> <body> <script> var a = parseFloat(prompt("insert a")), b = parseFloat(prompt("insert b")), c = parseFloat(prompt("insert c")); if (isNaN(a)&&isNaN(b)&&isNaN(c)){ alert("please insert a number"); }else if (a>b && a>c){ document.write("max=a<br>") }else if(b>a && b>c) { document.write("max=b<br>") }else if (c>a && c>b){ document.write("max=c<br>") } if (a<b && a<c){ document.write("min=a") }else if(b<a && b<c) { document.write("min=b") }else if (c<a && c<b){ document.write("min=c") } </script> </body> </html>
19th May 2017, 9:24 AM
Valen.H. ~
Valen.H. ~ - avatar
0
I didn`t get why the output is false in both cases ? NaN == NaN //false Aren`t the values same in this case? NaN === NaN // false Isn`t th type undefined in both cases ?
21st May 2017, 9:54 AM
Manik Tafralian
Manik Tafralian - avatar
- 1
Just for more info :) Some NaN rules : NaN == NaN //false NaN === NaN // false So you can check just like if (a !=a && b != b && c != c) Guess you will not use it,but it's pretty helpful info :)
19th May 2017, 10:05 AM
Rose Sevenyears
Rose  Sevenyears - avatar
- 2
@Manik Tafralian var x = NaN; console.log(x == x); //false console.log(x === x); //false console.log(typeof(x)); //number 1.Yep,values are same,but if we're talkin about comparing NaN to NaN - it doesn't equal itself anyway. 2.Type is "number" Yeah...NaN(Not a Number) is number. You can try it by yourself. That's just one one weird things in js you should keep in mind. Here should be reply... "Welcome to JavaScript !" :D
21st May 2017, 9:39 PM
Rose Sevenyears
Rose  Sevenyears - avatar