it is used to convert the string value that we get from the users to integer data type
Chat with our AI personalities
parseInt() interprets the next available token as an int.
In C# you can do that in the following way Convert.ToInt32(yourStringHere), for instance Convert.ToInt32("wikianswers"). But not all string can be converted to int type. If it happens compilator will throw the exception converting error which you can handle using structure try { ...//your code } catch (Exception) { ... //your code in the case of the exception }
Here is the code: <html> <head> <script type="text/javascript" langage="javascript"> function getHighest() { var a = parseInt(document.getElementById("num1").value); var b = parseInt(document.getElementById("num2").value); var c = parseInt(document.getElementById("num3").value); if((a>b)&&(a>c)) { alert(a+" is the highest number"); } else if((b>a)&&(b>c)) { alert(b+ " is the highest number"); } else if((c>a)&&(c>b)) { alert(c+ " is the highest number"); } else { alert("One of them is not an int"); } } </script> </head> <body> Input a: <input type="text" name="number1" id="num1" /><br /> Input b: <input type="text" name="number2" id="num2" /><br/> Input c: <input type="text" name="number3" id="num3" /><br/> Submit: <input type="submit" name="submit" value="submit" onclick="javascript:getHighest();return false;" /> </body> </html>
A JavaScript tutorial contains instructions that will teach you how to code in JavaScript.
HTML, CSS, & JavaScript.