-
Compare two numbers
about 9 years ago
-
over 7 years ago
var a = document.getElementById("a").value
-
-
about 9 years ago
Hi, You are passing value in displayResults function in a wrong way. Your code should be like this:
var a = document.getElementById("a").value; var b = document.getElementById("b").value; var compare = document.getElementById("comparison"); var submit = document.getElementById("submit"); submit.onClick = function() { WhoWins(a,b); } function WhoWins(a, b) { if(a === b){ displayResults ("="); }else if(a > b){ displayResults (">"); }else if(a < b){ displayResults ("<"); } function displayResults(result) { compare.innerHTML = result; }
I hope it will give you expected result in field with compare id.
-
2 Answer(s)