+ 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!
7 odpowiedzi
+ 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.
+ 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👍
+ 3
Maksat Orazsahedow,
Excuse me👍☺
Here is a snippet with an if statement, hope it helps👍
https://code.sololearn.com/WTkyUXF4Fb0R/?ref=app
+ 2
Thanks rudolph flash!
+ 1
Thanks Vincent Berger! But I mean we can run it using a if statement!
+ 1
Thanks a lot!
+ 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!