为什么第一个条件不满足?

问题描述 投票:0回答:1

我正在申请 Northcoders 训练营,但我被 if/else/ 和 switch 语句困住了。我将发布说明、我的代码和我收到的错误消息。如果有人能帮助我找到我做错了什么,我将非常感激,因为据我所知,代码应该可以正常工作

使用说明

一群 Northcoder 正在计划他们的假期,并希望使用此代码来帮助他们练习用所访问国家/地区的语言进行问候。

您编写的代码应该为问候语分配一个正确的值,具体取决于所访问的国家/地区和一天中的时间。

如果时间为 0 点或以上但小于 12 点,则为早上。如果时间为 12 点或以上但小于 24 点,则为晚上。如果时间是任何其他值,则问候语应始终为空,无论语言如何。

如果国家是西班牙或墨西哥,问候语应该是早上 buenos dias 和晚上 buenas noches。如果国家是法国,问候语应该是早上的 bon matin 和晚上的 bon soir。如果国家/地区是任何其他值,则问候语应始终为空,无论何时(我们的字典中还没有很多语言......)

提醒一下:您可以像任何其他变量一样在表达式中使用国家/地区和时间。有很多方法可以解决这个挑战!使用您迄今为止学到的任何工具。

function sayHello(country, time) {
    let greeting = null;

    if (time >= 0 && time < 12) {
        if (country === 'Spain') {
            greeting = 'buenos días';
        } else if (country === 'Mexico') {
            greeting = 'buenos días';
        } else if (country === 'France') {
            greeting = 'bon matin';
        }
    } else if (time >= 12 && time < 24) {
        if (country === 'Spain') {
            greeting = 'buenas noches';
        } else if (country === 'Mexico') {
            greeting = 'buenas noches';
        } else if (country === 'France') {
            greeting = 'bon soir';
        }
    }

    return greeting;
}

错误信息

9 Passing
2 Failing

Greeting should be correct for Spain in the morning

  ✕ AssertionError: expected 'buenos días' to equal 'buenos dias'

 

Greeting should be correct for Spain in the evening

    ✓  Well done!

 

Greeting should be null if the time is invalid in Spain

    ✓  Well done!

 

Greeting should be correct for Mexico in the morning

  ✕ AssertionError: expected 'buenos días' to equal 'buenos dias'

 

Greeting should be correct for Mexico in the evening

    ✓  Well done!

 

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 if the time is invalid in France

    ✓  Well done!

 

Greeting should be null for other countries

    ✓  Well done!
javascript if-statement
1个回答
-1
投票

问题似乎是您使用重音字符:

预期“buenos dias”等于“buenos dias”

请注意错误消息中两种不同形式的

i

如果您将代码更改为使用普通的

i
而不是重音字符,它可能会通过。

© www.soinside.com 2019 - 2024. All rights reserved.