Sleep debt calculator


#1
const getSleepHours = (day) =>{
 if (day === "Monday") {
   return 3;
 }else if (day === "Tuesday"){
   return 4;
 }
};

const getActualSleepHours = () =>{
getSleepHours('Monday') + getSleepHours('Tuesday') 
};

console.log(getActualSleepHours());

Hi just wondering where I am going wrong here, I’m sure it is something small but it has been bugging me that it keeps returning “undefined”


#2

here:

console.log(getActualSleepHours());

you log the returned value, which is undefined because of absence of a return keyword in your function


#3
const getSleepHours = (day) =>{
 if (day === "Monday") {
   return 2;
 }else if (day === "Tuesday"){
   return 4;
 }
};

const getActualSleepHours = () =>{
return getSleepHours('Monday') + getSleepHours('Tuesday') 
};

const getIdealSleepHours = () =>{
  const idealHours = 8
  return idealHours * 2;
};

const calculateSleepDebt = () =>{
  const actualSleepHours = getActualSleepHours();
  const idealSleepHours = getIdealSleepHours();
  if (actualSleepHours === idealSleepHours){
    console.log("A good week of sleep G")
  }else if(actualSleepHours < idealSleepHours){
    console.log("guy you no try at all sleep more!")
  }else{
    console.log("Are you on vacation!?")
  };
}

console.log(getActualSleepHours());
console.log(getIdealSleepHours());
console.log(calculateSleepDebt());

Thanks but I have the return keyword but it still returns undefined?


#4

same problem but for a different function?


#5

I am not quite sure where the problem is. I have looked through the code but do not understand why I am getting “Undefined” as an output.


#6

only this time, its caused by the calculateSleepDebt function.


#7

so where is this return keyword going to go?


#8

do you want a return keyword? You could also consider not logging anything if it doesn’t add value (like undefined)