Helpppppp (Introduction to Functions in JS 12/13) Can't seem to get the right answer


#1
// Write your function below. 
// Don't forget to call your function!
var sleepCheck=function(numHours)
{
return numHours
};
if (numHours>=8)
{
console.log("You're getting plenty of sleep! Maybe even too much!")
};
else
{
console.log("Get some more shut eye!")
};
sleepCheck(10)
sleepCheck(5)
sleepCheck(5)

Introduction to Function in JS 12/13
#2

Hi,

look in your function sleepCheck there is a return of numHours. This is not needed.


#3

The problem is that you're closing your function to early:

var sleepCheck=function(numHours)
{
return numHours
};

all the rest is now outside but this:

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

should be inside of the function instead of what you currently use there. And as it is now back in a function you can now use return again instead of console.log.

Last but not least if you want to see more than the last statements echo in the console you need to wrap your outputs:

sleepCheck(10)
sleepCheck(5)
sleepCheck(5)

in console.logs.


#4

Hi there haxor789 and dooko_de,

Thanks for assisting but unfortunately I am still not getting it fully.I understand bits of what you are trying to explain but I am still not getting the right code.Would it be alright if you could help show me the correct code so that I can reverse engineer the answer and understand it from there?Also it seems to me that the correct code has many different permutations,one using the "return numHours" and one without based on what I am seeing from the other threads in the Q&A forum here. Is this true?


#5

Hello! The problem is you shouldn't be returning the numHours. This exercise calls for an if/else statement. So delete the part that say " return numHours }; . Then replace console.log with the word return and remove the parenthesis for both the if and else statement. Now for the sleep check part, that's when you use console.log and write it as follows : console.log(sleepCheck(10));.


#6

There are always some permutations of the code but as byterockstar63844 already explains, few to non of them include return numHours as the idea is to return one of 2 sentences depending on the value of numHours. And for posting "the solution". I guess it is better that you try to get around it yourself. Post what you already got what you did or did not understand and we'll try to explain it and give you the rest but I don't think that solutions in the style "This code worked for me: ...." will really help and if you explain any line it gets tl;dr so at least the topic of your problem would be necessary.


#7

Hi there guys, I finally got the right code after quite a number of tries. byterockstar63844, your tip was spot on but I dont remember the part about "Now for the sleep check part, that's when you use console.log and write it as follows : console.log(sleepCheck(10));."being taught before. Can you please explain it to me?