Switch statement


#1

Qn: Why does my code not return 8 as an output?
Answer returned: Invalid Input

const getSleepHours=day=> {
switch(getSleepHours) { case ‘Monday’:
return 8;
break;
case ‘Tuesday’:
return 8;
break;
case ‘Wednesday’:
return 8;
break;
case ‘Thursday’:
return 8;
break;
case ‘Friday’:
return 8;
break;
case ‘Saturday’:
return 8;
break;
case ‘Sunday’:
return 8;
break;
default:
return ‘Invalid Input’;
break;
};
};
console.log(getSleepHours(‘Monday’));


#2

switch(getSleepHours)

what is getSleepHours here?isn’t a function?

what should you use inside parentheses instead of getSleepHours so that the value you pass for that function can be use for the switch statement?


#3

Grreat thank you!

I used switch(Day)


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.