I want to compare two number of using JavaScipt and find a bigger number. Specifically, I have the following two numbers: adjustY-100 40 I want to compare these two and find a bigger number. Is there a function to do this ...? Or I need to use an operator to find the bigger number?
You would need to actually have 2 input field and and a button to compare and then replace the values with their element names ex. x = document.form1.name1.value y = document.form1.name2.value and the button would be there to activate the function function compare() { var x=100 var y=40 if ( x > y ){ document.write("x is the bigger number"); } else{ document.write("y is the bigger number"); } }
Function should be: function compare() { var x=100; var y=40; if ( x > y ){ document.write("x is the bigger number"); } else{ if(x==y){ document.write("y is equal to x"); }else{ document.write("y is the bigger number"); } } }
If you only need the larger of the two values you can do it like this: biggest = Math.max(AdjustY - 100, 40); Code (markup):