Sleep Debt: keep getting unknown posted on the console

When solving the Sleep Debt Calculator I keep getting unkown posted on the console under my answer. I really don’t know why. this is my code.Can you help me?

const getSleepHours = day =>{
if(day === ‘monday’){
return 8;
} else if(day === ‘tuesday’){
return 8;
} else if(day === ‘wednesday’){
return 8;
} else if(day === ‘thursday’){
return 8;
} else if(day === ‘friday’){
return 8;
} else if(day === ‘saturday’){
return 8;
} else if(day === ‘sunday’){
return 8;
}
};

const getActualSleepHours = () => getSleepHours(‘monday’) + getSleepHours(‘tuesday’) + getSleepHours(‘wednesday’) + getSleepHours(‘thursday’) + getSleepHours(‘friday’) + getSleepHours(‘saturday’) + getSleepHours(‘sunday’);

const getIdealSleepHours = () => {
let idealHours = 9;
return idealHours*7;
};

const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours() ;
const idealSleepHours = getIdealSleepHours() ;
if(
actualSleepHours === idealSleepHours){
console.log(‘Well done you slept enough’);
}
else if( actualSleepHours > idealSleepHours){ console.log(‘Well done you slept too much’);
}
else {
console.log(‘Well done you slept too little’);
}
};
console.log(calculateSleepDebt())

unknown, or undefined?

Your function logs a result, but then your call expression is also logged. The return from console.log() is undefined.

8 Likes

@net9066285782 When I put your code into my VS Code, it returned a lot of errors. The main thing I noticed was your apostrophe or single quote is much different than mine. It appears you are using smart punctuation, which I have read gives users in Javascript a bit of a problem.

Can anyone else confirm or deny?

No, it’s because the OP hasn’t used the code formatting option on Discourse.

The default ’ characters the forum uses don’t parse well in code editors otherwise. Lost count of the number of times a REPL has complained about them because of this.

I think @mtf has solved it, though. :slight_smile:

1 Like

@thepitycoder Ok, cool. I learn something new everyday. It sounds like the same thing as when I used to write reports in Microsoft Word then copy and paste to the program we used to submit the reports.

Thanks for the info.

Yes exactly undefined (it was pretty late in the night when I posted this). oh wow such an easy answer. Thanks a lot for the help! I have been breaking my head over this.

3 Likes

You’re welcome. Happy coding!