I am currently trying to pass a little challenge on a website, it's basically asking me to write conditional statements to make sure the time is morning and evening between certain times and also that if it is a certain country at that time it needs to be certain greetings. I will add the code here and a pasted snipped of the challenge.
What is frustrating is that it is saying that I have it correct for the France one but not the other two which I don't understand as I have done them all exactly the same so I don't know how one can be correct while the rest are wrong, but I'm more than likely missing something.
The code you write should assign a value to
greetingthat is correct depending on the country that is being visited and the time of day.
It is morning if the time is 0 or more, but less than 12. If the time is 12 or more, but less than 24, it is evening. If time is any other value, greeting should always be null, whatever the language.
If country is Spain or Mexico, greeting should be buenos dias in the morning and buenas noches in the evening. If country is France, greeting should be bon matin in the morning and bon soir in the evening. If country is any other value, greeting should always be null, whatever the time (we don't have many languages in our dictionary yet...)
function sayHello(country, time) {
let greeting;
if (time >= 0 && time < 12 && country === 'Spain' || 'Mexico') {
greeting = 'buenos dias';
} else if (time >= 12 && time < 24 && country === 'Spain' || 'Mexico') {
greeting = 'buenas noches';
} else {
greeting = null;
}
if (time >= 0 && time < 12 && country === 'France') {
greeting = 'bon matin';
} else if (time >= 12 && time < 24 && country === 'France') {
greeting = 'bon soir';
} else {
greeting = null;
}
// Don't change code below this line
return greeting;
}
And the errors I'm getting:
6 Passing 4 Failing
Greeting should be correct for Spain in the morning
✕ AssertionError: expected null to equal 'buenos dias'
Greeting should be correct for Spain in the evening
✕ AssertionError: expected null to equal 'buenas noches'
Greeting should be null if the time is invalid in Spain
✓ Well done!
Greeting should be correct for Mexico in the morning
✕ AssertionError: expected null to equal 'buenos dias'
Greeting should be correct for Mexico in the evening
✕ AssertionError: expected null to equal 'buenas noches'
Greeting should be null if the time is invalid in Mexico
✓ Well done!
Greeting should be correct for France in the morning
✓ Well done!
Greeting should be correct for France in the evening
✓ Well done!
Greeting should be null if the time is invalid in France (remembering that 24 is an invalid time)
✓ Well done!
Greeting should be null for other countries
✓ Well done!
Any help with this would be greatly appreciated, even if it's not the direct answer just to point me in the right direction as to what it is I'm clearly not getting here.