So I am trying to write code that uses the time and country to determine the correct greeting…..what is wrong with this code? If the country is Spain or Mexico and the time is between 0 and 12 I want it to make the greeting ‘buenos dias’ and if it is evening ‘beunas noches’. Similarly if it is France I want it to spit out a good morning or evening greeting depending on the time of day.
function sayHello(country, time) {
let greeting;
if (time >= 0 < 12) {
switch (country) {
case 'Spain':
case 'Mexico':
greeting = 'buenos dias'
break;
case 'France':
greeting = 'bon matin'
break;
default:
null
break;
}
} else if (time >= 12 < 24) {
switch (country) {
case 'Spain':
case 'Mexico':
greeting = 'buenas noches'
break;
case 'France':
greeting = 'bon soir'
break;
default:
null
break;
}
} else {
greeting = null
}
// Don't change code below this line
return greeting;
}
console.log(sayHello('Spain', 11));
console.log(sayHello('France', 11));
0
The expressions used in your conditionals (time >= 0 < 12
and time >= 12 < 24
) is not the correct way to achieve what you’re trying to do.
For the time >= 0 < 12
case, JavaScript first interprets the time >= 0
portion, resulting in true
or false
, then compares that result as [true or false] < 12
.
The proper way to check that would be time >= 0 && time < 12