var isEven = function(n)
{
if (n % 2 === 0)
{
return true;
}else
{
return false;
}
};
The way that I would do it(if I was to use an <if/else> and not a ternary operator) it would look like this:
var isEven = function(n){
if(n%2===0){
return true;
}else{
return false;
}
};
I never realized hov spread out my code was. Yes, I know it acn be more compact, but this is the easiest way for me to read it.
The other thing we have is this:
//using typeof in <for/in> loop to print what we want.
var languages = {
english: "Hello!",
french: "Bonjour!",
notALanguage: 4,
spanish: "Hola!"
};
// print hello in the 3 different languages
for (var i in languages){
if(typeof languages[i]==="string"){
console.log(languages[i]);
}
}
How cool is that?? using a <for-in> loop and the <typeof> method, we're able to print out just what we want and ignore the rest. That could be super useful. Ok. Well kids, this a rather short post today, but fret not mein Kinder, ther will be plenty for you on Wednesday! See y'all!
No comments:
Post a Comment