11. Something els


#1

Hi guys. I have typed this:

var sleepCheck = function(numHours) {
if(numHours >= 8) {
return "You're getting plenty of sleep! Maybe even too much!";
}
else {
return "Get some more shut eye!";
}
};
console.log(sleepCheck(10, 5, 8));

And it prints only the "You're getting plenty of sleep! Maybe even too much!". I think this only applies for the 10 but I'm not sure you guys tell me, but when I press check reult I can go futher to the next lesson while it not even has shown the other 2: 5 and 8. I know you have to do it like this:

console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

But when I do it my way it works aswell but it doesnt show the other 2. Is this a mistake in codecademy? BTW can I type:

console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

shorter? I tried it with my code and thats how i stumbled on to that.


#2

Well parameters and arguments work like this:

The variable names that you use after function are called parameters and they get their values by the values used in the function call called arguments. So as you have only one parameter you only use one of your 3 arguments the other two are just ignored (other programming languages would probably raise an error about having more arguments then needed but JS doesn't seem to care).

On the passing aspect: Well I guess the main task is to get a working function and that is achieved so as it can be tested that seems to be enough.

Lastly what do you mean by shorter?


#3

well I rather don't type console.log(sleepCheck(10)); console.log(sleepCheck(5)); console.log(sleepCheck(8)); all over again if I had for example much more sleepChecks. So is there a way so that I can type it shorter.


#4

Well in the next exercises after trying functions you'll be introduced to loops and probably they are what you're looking for.