I have this javascript code that is working mostly as intended. It is two functions, the first prompts the user for two values on a button press, and the second compares them and displays an output on another button press.
It works almost perfectly, except the outputs don't make sense. It is supposed to output 'true' if inpOne is greater than inpTwo, and 'false' otherwise.
If both inputted numbers are less than 10 i.e. inpOne = 8, inpTwo = 1, it will output true, as it should. However, if inpOne = 20, and inpTwo = 3, it outputs 'false' which is incorrect. I've tried with many other values and it seems to be random to some extent... Can someone look over my code and tell me what I'm doing wrong? Thanks!
Edit: I realize it is three functions, the last function just displays the results to an HTML element...
let inpOne;
let inpTwo;
function promptForCompare() {
inpOne = prompt('Enter first number','');
inpTwo = prompt('Enter second number','');
}
function checkIfGreater() {
let valComp = inpOne > inpTwo ? true : false;
return displayResult(valComp), console.log(valComp);
}
function displayResult(input) {
if (input == true) {
document.getElementById("resDisp").innerHTML = "Number is greater!";
} else {
document.getElementById("resDisp").innerHTML = "Number is NOT greater!";
}
}