//let's put their o's, O's and 0's in the right places
if ($zip[1] == ("O" || "o")) {
$zip[1] = '0';
}
This code does not do what you think – your comparison logic are wrong, because so is your understanding of the ||
operator.
Use console.log(("O" || "o"))
and see what you get in console – ooops, that’s just the letter O
. Why? Because the ||
logical or operator in JS returns the first value that is not false-y.
You need to either write two individual comparisons here, and or-conjoin those – $zip[1] == "O" || $zip[1] == "o"
, or use an array with possible values and then check whether your variable value is among those (but the latter would be a bit over the top here).
Edit: Or, as bigmandan pointed out, you could also transform your letter to upper- or lower-case first, then you only have to do one comparison: ($zip[1]).toLowerCase() == "o"
(Of course this works only in a special case like this – if it was not O
or o
, but a
or b
instead, you would still have to do individual comparisons.)