Switch function form "Sleep Debt Calculator" why it's undefined,? Doesn't return number

const getSleepHours = day =>{
  switch (day){
    case 'monday':return 1
    case 'tuesday':return 2
    case 'wednesday':return 3
    case 'thursday':return 4
    case 'friday':return 5
    case 'saturday':return 6
    case day='sunday':return 7
    default: console.log('switch default')




before your code, and



Otherwise people can’t run your code, can’t reproduce. In other words they won’t be able to look at your situation.

(You might have noticed that the code looks different, this is a problem because code is very sensitive to changes. Code should be shared as exact copies. There are buttons in the post editor which you can use to apply formatting, one of them is for ensuring your code remains intact. Use it.)


That prints 5
Did you post the right code? Maybe you forgot to add the function call which produces a bad result.


I don’t know… I tried once again and it works! Maybe cause I changed syntax?


Thank you ionatan! I spent 1,5 hours to figure out what is wrong…(((
Just in the beginning of my path.


Well, in any case, let me suggest an alternative way of writing that. Switches bother me.

  hours = {
    'monday': 1,
    'tuesday': 2,
    'wednesday': 3,
    'thursday': 4,
    'friday': 5,
    'saturday': 6,
    'sunday': 7,
  return hours[day]

(Probably shouldn’t be a function at all, but just an object and then other code can read from it)