Issue with Calculate Sleep Debt Programming Excersice

So, I am in the sleep debt practice from the JavaScript section of the Web Development course. I honestly can’t find what is wrong with my code. I tried looking at the video but it seems that the way I interpolate the text and the variables is the same to the way it should be. I get an error message about a missing parameter but I can’t find what’s wrong with it! I am feeling really frustrated as I cannot find the error and I just don’t wanna copy and paste code without knowing what I am doing, I want to know what am I doing wrong in the exercise.

function getSleepHours(day){
  if (day === 'monday'){
    return 8;
} else if (day === 'tuesday'){
    return 5;
} else if (day === 'wednesday') {
    return 6;
}  else if (day === 'thursday') {
    return 6;
}  else if (day === 'friday') {
    return 5;
}  else if (day === 'saturday') {
    return 8;
}  else if (day === 'sunday') {
    return 10;
} else {
  return 'Not a valid day!'


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

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

const calculateSleepDebt= () => {
  let actualSleepHours = getActualSleepHours();
  let idealSleepHours = getIdealSleepHours();
  if (actualSleepHours === idealSleepHours) {
    return "Congratulations, you got the perfect amount  of sleep!";
  } else if (actualSleepHours > idealSleepHours) { 
      console.log("You got " + (actualSleepHours - idealSleepHours) +  "more hour(s) of sleep than you need. Try to set up an alarm)";
    } else if (actualSleepHours < idealSleepHours) {
        console.log("You got " + (idealSleepHours - actualSleepHours) + " hours(s) less of sleep than you need. You need more rest");


I would really appreciate to know what am I doing wrong.

Hello, @silvfang.

Could you post the error message, or just read it carefully. It should give you an idea of where to start looking for the problem.

I could point you right to the issue, but I’d prefer to show you how to use the error message to find it yourself.

Reading your code, I found you missed a pair of {} to start this function. Hope this helps :slightly_smiling_face:

The curly braces are not required for a concise body arrow function.

oh God that’s true…sorry for sharing wrong info, my bad :cry:

1 Like

No worries!

Sure! I should have posted that in first place. To be honest I see the error message as if it were written in chinese lol

      console.log("You got " + (actualSleepHours - idealSleepHours) +  "more hour(s) of sleep than you need. Try to set up an alarm)";
SyntaxError: missing ) after argument list
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)

That’s what I get after trying to run the code

1 Like

Ok. I know you know how to use console.log() to log a string literal like so:

console.log("Hello World!)";

Actually that line will throw the same error your code is throwing, and for the exact same reason. If you read the message, it gives you a line number:

Line 37.
Then it quotes that whole line, and at the end, you can see the mistake.

Oh well, now I see you’re missing a parenthesis before the semicolon at this line of code. I think you accidently put it inside the quote marks :upside_down_face:

Edit: Nevermind, they answered before I did…and they provided a better explanation :stuck_out_tongue:

Thank you both @midlindner @yizuhi for helping me find the issue with my code :star_struck:

And thank you @midlindner for the concise explanation!