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


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

#2

Put

```javascript

before your code, and

```

after

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.)


#3

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


#4

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


#5

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


#6

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)