+ 3

Which is the biggest number?

Hi everyone! I wanna find the biggest number of I entered! For Example: var num1, num2, num3; num1 = 20; num2 = 40; num3 = 60; How we can find the biggest number of this in JavaScript? I wanna use for it ifelse statemantes but I don't have any experience in JavaScript! Help me, Please!

3rd Nov 2018, 4:37 PM
Maksat Orazsahedow
Maksat Orazsahedow - avatar
7 Respuestas
+ 6
Maksat, I think I can help u . if my suggestion is wrong means sorry. u can compare those variables values using if and else if statements and print the one which is bigger. if(num1>num2&&num1>num3) { document.write(num1); } else if(num2>num3){ document.write(num2); } else{ document.write(num3); } in the if statement, if both conditions are true then num1 is printed.else it checks whether num2 is bigger than num3, if num2 is bigger then it is printed on the screen else num 3 is printed.
4th Nov 2018, 2:34 PM
Bhuvana Karthigeyan
Bhuvana Karthigeyan - avatar
+ 5
One if the options is get the highest value is to do it from an array. Sort it and then reverse for the hightest value to come first. So to find the highest value: var arr=[10,30,60], cnt=arr.sort().reverse(); Console.log(cnt[0]); //_ output is 60 Hope this helps you understand it👍
3rd Nov 2018, 4:59 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 3
Maksat Orazsahedow, Excuse me👍☺ Here is a snippet with an if statement, hope it helps👍 https://code.sololearn.com/WTkyUXF4Fb0R/?ref=app
3rd Nov 2018, 5:25 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 2
Thanks rudolph flash!
4th Nov 2018, 7:29 AM
Maksat Orazsahedow
Maksat Orazsahedow - avatar
+ 1
Thanks Vincent Berger! But I mean we can run it using a if statement!
3rd Nov 2018, 5:11 PM
Maksat Orazsahedow
Maksat Orazsahedow - avatar
+ 1
Thanks a lot!
3rd Nov 2018, 5:26 PM
Maksat Orazsahedow
Maksat Orazsahedow - avatar
+ 1
Yeah! It helped me to understand ifelse statement better! And I waited like this answer for my question. It's the best answer! Thanks a lot bhuvana!
5th Nov 2018, 8:19 AM
Maksat Orazsahedow
Maksat Orazsahedow - avatar