I was trying to make a comparison between num1 and num2:
<form>
<input placehoder="num1" type="text" id="num1"/>
<input placehoder="num1" type="text" id="num2"/>
<button type="button" id="comparar">Compara</button>
</form>
The issue is that until I found out that to declare that the inputs are going to be numbers with the comands let num1 = parseInt(document.getElementById("num1").value);
the systme worked but sometimes it did not show the correct alert.
let compare = document.getElementById("comparar");
function comparator(){
let num1 = parseInt(document.getElementById("num1").value);
let num2 = parseInt(document.getElementById("num2").value);
if ( num1 > num2){
alert('num1 higher');
}else if(num1 == num2){
alert('are equal');
}
else{
alert('num2 higher')
}
}
compare.addEventListener('click', comparator);
Does anyone knows why when not using parseInt to compare two numbers it show random results?, basiccally what is it comparing?.
thanks