I'm using var numbersInString = input.match(/\d+/g); to put into an array the first 2 digital numbers.
Such as: Is 6 greater than 5?
Note: (A person types this into an input box and the answer is displayed in a similar input box. So I must keep this in a similar format.)
numbersInString[0] - will give the first number
numbersInString[1] - will give the second number
I then want to compare the numbers as either > < or =
I can't seem to get any combinations that works. Any Help would be appreciated.
Code:
if ((input.search("what is greater")!= -1) && (input.search(/\d{1,10}/)!=-1) && (input.search(/\d{1,10}/)!=-1))
{var numbersInString = input.match(/\d+/g);
var num1 = parseInt( numbersInString[0], 10 );
var num2 = parseInt( numbersInString[1], 10 );
if (num1 < num2) document.result.result.value = ""+num1+" is less than "+num2+"";
if (num1 > num2) document.result.result.value = ""+num1+" is greater than "+num2+"";
if (num1 = num2) document.result.result.value = "Both numbers are equal";
return true;}