Hi i am having an issue changing the three variables back to false. What am i missing? It seems like i’ve missed something elementary out regarding booleans and the altering of their values?
if (eye == true || mouth == true || nose == true ) {
eye = false && nose = false && mouth = false }
thanks
function countSmileys(arr) {
let smileycounter = 0;
let eye = false;
let nose = false;
let mouth = false;
for (let i = 0; i < arr.length; i++) {
var subArray = arr[i];
for (let j = 0; j < subArray.length; j++) {
if (subArray[j] === ":" || subArray[j] === ";") {
eye = true;
}
if (subArray[j] === "-" || subArray[j] === "~") {
nose = true;
}
if (subArray[j] === ")" || subArray[j] === "D") {
mouth = true;
}
}
if (eye === true && mouth === true) {
smileycounter++;
}
if (eye == true || mouth == true || nose == true ) {
eye = false && nose = false && mouth = false }
}
return smileycounter;
}
countSmileys([":)", ":(", ":D", ":O", ":;"]);
Take another look at what you have in the inside the if statement, I think I know what you are trying to accomplish… but what would a=a && b=b return? true or false ?
`eye = false && nose = false` is ALWAYS false because you changed eye to `false` and the code will stop (since it found `false` )
`||` & `&&` are operators, so This OR This … or … This AND this … resulting in True/False …
oh so operators || & && only look for the first value and then return true/false based on the first answer. didn’t know.
Good work! … and yes in general operators || & && are looking going to give a true/false, so they are good to use inside of the if( ) , and it will stop once it gets a false. So if there were a million things to check, it could stop once it found the first false… instead of running through all 3 for a total of 3 millions times every time.
The only other minor thing I’d note that is that you can just use the variable name for “truthiness”
if (eye == true || mouth == true || nose == true ) {
is the same as: if (eye || mouth || nose ) { ...