<!doctype html>
<html>
<head>
<title>Largest number</title>
</head>
<body>
<center>
<h2>largest number</h2>
<script language="Javascript" type="text/Javascript">
function Max(num1,num2,num3)
{
var largest=arguments[num1,num2,num3]
for(i=0;i<arguments.length;i++)
{
if((num1>num2)&&(num1>num3))
largest=num1
else if((num2>num1)&&(num2>num3))
largest=num2
else
largest=num3
}
return(largest)
}
document.write("</br>")
var num1 = prompt("Enter first number"," ")
var num2 = prompt("Enter second number"," ")
var num3 = prompt("Enter third number"," ")
var large = Max(num1,num2,num3)
document.write("You entered",num1,",",num2,",",num3)
document.write("</br>")
document.write("The largest number is :",large)
</script>
</center>
</body>
</html>
This program accepts 3 numbers through prompt. Only for specific numbers it gives strange and unexpected output. If I give input for this program as 5,21 and 100 when each prompt appears, the output will be given 5 as a largest number. Even for the input 10,24 and 5, the output will be 5.
Is there any problem while using if condition or array.
Please help me.
UPDATE The suggested question specifically asks for how to convert a string to integer. However my question is about not getting proper result, in this case, I was not getting Maximum of given 3 inputs. Only after fellow members pointed out that the inputs are being treated as String and not as integers and provided proper answer, I realized my mistake.
Now, while adding "Update" part to this question, I also got a suggestion from Stackoverflow to edit the title of the question. So, I've properly provided the title now.
Hence I think this question is different than suggested question.
arguments[num1,num2,num3]? What happened to the indentation and semicolons?Mathwith a methodmax. Won't interfere, although it is probably not useful...