Hi all I can’t make sense of why the code below would not return the desired outcome from the toLowerCase method:
const getSleepHours = day => {
day = day.toLowerCase();
switch (day) {
case 'Monday':
return 8
break;
case 'Tuesday':
return 8
break;
case 'Wednesday':
return 6
break;
case 'Thursday':
return 8
break;
case 'Friday':
return 4
break;
case 'Saturday':
return 8
break;
case 'Sunday':
return 8
break;
default:
return 'Error'
}
}
// Calculate Total Sleep getSleepHours
const getActualSleepHours = () => {
getSleepHours('Monday')
+ getSleepHours('Tuesday')
+ getSleepHours('Wednesday')
+ getSleepHours('Thursday')
+ getSleepHours('Friday')
+ getSleepHours('Saturday')
+ getSleepHours('Sunday');
}
console.log(getSleepHours('Sunday'))
````Preformatted text`
The console.log would print return as if the toLowerCase is not actually transforming the text of the string 'Sunday' to 'sunday'.
I have tried to reposition the attribute (day) outside of the switch function but this message returns:

Can you please help with the nature of this ?
Is it because I am making a syntax error and why, or is it where I position the code within the function?
Within your getSleepHours function, you are converting whatever string argument is passed to your function to lowercase. But, in your cases, you have strings such as 'Monday', 'Tuesday' etc. . A lowercase string will not match any of the cases and you will end up returning the default string 'Error'. You should edit your cases to lowercase.
The arguments can be lowercase, uppercase or mixed case,
// Arguments can be lowercase/uppercase/mixed
console.log(getSleepHours('Sunday'))
console.log(getSleepHours('sunday'))
console.log(getSleepHours('SUNDAY'))
console.log(getSleepHours('SuNdaY'))
but within the function, you are converting them to lowercase. So, your cases need to be lowercase.
day = day.toLowerCase();
switch (day) {
case 'monday':
return 8;
case 'tuesday':
...
Also, since you are returning in your cases and thereby immediately exiting the function, so there is no danger of fall-through and the break statements can be omitted. If instead of returning, suppose you were printing to the console in your cases, then the break statements would be necessary.
Since you are using curly braces for the body of the getActualSleepHours arrow function, so you need to use the return keyword for an explicit return. If you want to omit the return keyword and do an implicit return, you need to remove the curly braces, If you use curly braces, you can’t return implicitly. If you omit curly braces, you can’t return explicitly.
// Explicit Return
// (Curly braces for body of arrow function, so return keyword needed)
const getActualSleepHours = () => {
return getSleepHours('Monday') +
getSleepHours('Tuesday') +
...
// Implicit Return
// (No curly braces for body of arrow function, so return keyword not needed)
const getActualSleepHours = () => getSleepHours('Monday') +
getSleepHours('Tuesday') +
...