Well I have just written this code, Ill post it here and the question is after the code, please help me. <script type="text/javascript"> var a1=(5) var a2=(3) if (a1=Math.max) { a1-- document.write("google") } else if (a2=Math.max) { a2-- document.write("yahoo") } else { document.write("DigitalPoint") } </script> There is some problem with this code, What I want this code to do? As you can see there are var' a1 and a2, both has values a1=5, a2=3 I want the system to choose the var' with the highest value and show the text which is assigned to this var, If a1 chosen show "Google", if a2 "yahoo",else "Digitalpoint". Once the var is chosen and text is showen the var' value will be lowered by (one). At first it shall choose a1 with value (5) and show "google" than a1 value will be lowered to (4) and again show "google" than both values a1 and a2 will be (3) it will choose a random one since the values are same and no Maximum and so on... until both values get to (0) and than will be showen the (else) "DigitalPoint". Where is the problem here? Hope you read and understood it. Need your Help ASP .
<script type="text/javascript"> var a1 = 5; var a2 = 3; while(a1 && a2) { if(a1 > a2) { a1--; document.write("google"); } else if(a1 < a2) { a2--; document.write("yahoo"); } else { if(Math.round(Math.random())) { a1--; document.write("google"); } else { a2--; document.write("yahoo"); } } } document.write("DigitalPoint"); </script> HTML:
Math.max takes only two arguments so you can't use it. Create an array instead of using variables. Then you just have to find the maximum element in an array..