I'm having problem with the conditional always returning true. I'm not sure if it's the value it's seeing as truthy in general but it's messing with me.
Problem: Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char.
Examples input/output:
XO("ooxx") => true
XO("xooxx") => false
XO("ooxXm") => true
XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true
XO("zzoo") => false
function XO(str) {
let on = 0
let xn = 0
let result = ""
for (let i = 0; i <=str.length; i++) {
if (str[i] = "x" || "X"){
xn++
} if (str[i] = "o" || "O") {
on++
};
if (xn == on || xn && on == 0){
result = true
}else if (xn !== on) {
result = false
}
return result
}
}
Seems the conditional is always returning true. Not sure if it's because the types are true (which is why I kept it strict).