There is another question like this, but it is a bit different. As a total beginner I had thought conditionals were based around if/else
always.
Then I realized you could have a series of ifs
w/o elses, if they are seperated (at least I think I’ve seen this).
My point? I have no idea why the braces in this are so important.
This does not fulfill the challenge-
function mutation(arr){ var target = arr.splice(0,1); var test = arr; target = target[0].toLowerCase() test = test[0].toLowerCase() for(var i=0;i<test.length;i++){ if (target.indexOf(test[i]) < 0){ return false } return true } }
But this does
> for(var i=0;i<test.length;i++){
> if (target.indexOf(test[i]) < 0) //missing brace HERE is only diff
return false } return true
First- how does this even run? Normally a missing brace causes the code to fail, at least in my browsers and node.
Second- how does it work? Since this exact syntax is imperative, and this kind of thing has bitten me before, were can I find info on this?
Docs all refer to the basic syntax and never how to know about case like this?
if (condition) {
code
} else {
code
When is it possible to leave a brace off?