Why my code in printing the numbers rather than calculating them

So I am doing the project of Sleep dept calculator. I would like to calculated the actual sleeping hours but instead it just print out 8765432 rather than the sum of 8+7+6+5+4+3+2

const getSleepHours = day => {

   if (day === 'Monday'){
     return '8';
   }
   else if (day === 'Tuesday'){
     return '7';
   }
   else if (day === 'Wednesday'){
     return '6';
   }
   else if (day === 'Thursday'){
     return '5';
   }
   else if (day === 'Friday'){
     return '4';
   }
   else if (day === 'Saturday'){
     return '3';
   }
   else {
     return '2';
   }
  } 
const getActualSleepHours =() => 
  getSleepHours('Monday')+
  getSleepHours('Tuesday')+
  getSleepHours('Wednesday')+
  getSleepHours('Thursday')+
  getSleepHours('Friday')+
  getSleepHours('Saturday')+
  getSleepHours('Sunday'); 


const getIdealSleepHours = () =>{
  const idealHours = 8 ;
  return idealHours * 7 ;
}
console.log (getActualSleepHours());
console.log (getIdealSleepHours());

Look at all of the numbers you’re returning from the getSleepHours function. Are they strings or integers? When you use the + operator with strings, it concatenates (or joins) them:

console.log("some" + "thing");
//prints: something

When you use the + operator on integers or floats, it adds them:

console.log(1+2);
//prints: 3
console.log(1.5+2.5);
//prints: 4

now I get it, thank you

1 Like