 Which is the biggest number? | SoloLearn: Learn to code for FREE!

+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!

8 Answers

New Answer

+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.

+9

If you do not want to use arrays. Then you can: 1) var num1 = 10, num2 = 20, num3 = 30; var max = Math.max(num1, num2, num3); 2) var num1 = 10, num2 = 20, num3 = 30; function Max() { var max = arguments; for (var i = 1; i < arguments.length; i++) { if (max < arguments[i]) { max = arguments[i]; } } return max; } var mymax = Max(num1, num2, num3);

+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); //_ 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

+1

Thanks Vincent Berger! But I mean we can run it using a if statement!

+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!