why does using 'i' in the if statement return different results than using 'str[i]'?
function ExOh(str) {
xCount = 0;
oCount = 0;
for (var i=0;i<str.length;i++){
if (str[i]=='x') {
xCount++;
} else if (str[i]=='o') {
oCount++;
}
}
if (xCount==oCount) {
return true;
} else {
return false;
}
}
console.log(ExOh("xox"));
Aucun commentaire:
Enregistrer un commentaire