Do you really put this as a condition?
Code: Select all
Answer == Answer.trim().match(/^No Miss|No Ma'am|no|no Sir|No *goddess$/i)
You are comparing "Answer" to the result of triming and matching. match returns null if there is no match, so it should be:
Code: Select all
null != Answer.trim().match(/^No Miss|No Ma'am|no|no Sir|No *goddess$/i)
The reason you get true for "no" is, that | has priority over ^ and $, so your expression matches something that starts with "No Miss", contains "No Ma'am", "no" or "no Sir" or ends with "No goddess". If you then compare Answer to that match result it will convert the match result for whatever has been matched.
For "no" that works, even for "No" it wont work. "No" is also matched for "No Goddess" because Javascript takes the first match, which is "no" as you are not requiring it to match to the end.
What you actually want is this:
Code: Select all
null != Answer.trim().match(/^no( +(Miss|Ma'am|Sir|goddess))?$/i)
And because javascript is actually converting most values to true and null and some others to false, you could directly use:
Code: Select all
Answer.trim().match(/^no( +(Miss|Ma'am|Sir|*goddess))?$/i)
as a condition for if.
If you press f12 in Chrome or Firefox you will get a javascript console, where you can evaluate expressions and see what you get as a result.