Tell us what’s happening:
Describe your issue in detail here.
Why do the two for loops at the beginning here behave differently? Their only difference is that one uses a “+” in the console.log() call and the next uses a comma.
I’ve just spent an hour searching and reading about "+’ and “,” and strings and still don’t understand. If you can point to a source to help me understand, I’d appreciate it.
(I’m not asking for help solving the challenge. My working solution is commented out here. Just trying to understand behavior I encountered while trying to debug an earlier attempt.)
FYI, the code as written outputs the following:
Iteration#0: [object Object]
Iteration#1: [object Object]
Iteration#2: [object Object]
Iteration#3: [object Object]
Iteration#0: { user: ‘Tinky-Winky’, sex: ‘male’ }
Iteration#1: { user: ‘Dipsy’, sex: ‘male’ }
Iteration#2: { user: ‘Laa-Laa’, sex: ‘female’ }
Iteration#3: { user: ‘Po’, sex: ‘female’ }
**Your code so far**
function truthCheck(collection, pre) {
for( let i = 0; i < collection.length; i++){
console.log("Iteration#" + i + ": " + collection[i]);
} //this one uses all plus signs to concat the output and doesn't behave the way I'd expected
for( let i = 0; i < collection.length; i++){
console.log("Iteration#" + i + ": " , collection[i]);
} //this one uses a plus and a comma and behaves as I thought the first one would
//below is my working solution, which I've commented out. Please ignore for the context of this question -- unless you see room for improvement :) -- Thanks
/*
for (var i = 0; i < collection.length; i++) {
if (collection[i].hasOwnProperty(pre)) {
if (!collection[i][pre]){
return false;
}
} else return false;
}
*/
return true;
}
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14388.52.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.91 Safari/537.36
Challenge: Everything Be True
Link to the challenge: