Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
and then, there's this
i dont know why peoples are complaining but they forget this part if it works doesnt matter what it is! it works
@Johan it will not generate a syntax error unless there's an else after it...
else it will do weird stuff, and definitely not what you want...
Nice Easter egg! :]
if () {} else if () {} ..
is shortcircuited. Ifage<14
, its whole else branch will be skipped.Thank you for your point of view, but you're wrong.
Now, using the undeclared variable
drink
is ++UnGood - it will become global. Also, the whole variable is unnecessary; justreturn $somethingAppropriate;
.This is not a Best Practice solution.
They're only necessary if there's more than one statement.
Of course, if you don't have them and add another statement to do more cool stuff, you should not forget to enclose them with curly brackets. Or interestingness happens ( it may not even generate a syntax error ).
thats what i did cause i i had trouble doing a switch case.
Hey, I can't understand why you people use
if(condition)
do cool stuff;
else if(condition)
instead of
if(condition){
do cool stuff
}else if(condition){
do cool stuf
}
I had to unlock the answer, but I can't seem to find anything that explains this. Why don't you use curly brackets {}?
Hi! I just want to say this practice is quite bad. Why? Because no matter what all possible cases will be compared. Function is like a crossing of roads - you have to leave it as soon it is possible. Ofcourse with results you want.
Anyway thanks for your point of view!
As far as I know, not using var will put any declaration in the global scope. So while you wouldn't want to do that on a real production app. Using it for these little solutions isn't necessarily wrong. As you probably don't need to worry about your namespace
here's an example:
drink = 'beer'
function drunk () {
console.log(drink)
}
drunk()
//'beer'
function wino () {
var drink = 'wine';
console.log(drink)
}
wino()
// 'wine'
drink
// 'beer'
why
var
is not used in this solution?Dunno if it was a typo or intended, but
else if(age => 21)
actually means "else if function(age) returning 21 exists" which will always evaluate to true.