if statement in javascript always true

前端 未结 5 878
無奈伤痛
無奈伤痛 2020-12-11 18:54

So, I have the code, its not done, but all i want it to do is display one alert box if I write the word \'help\', and say something else if anything else is entered.

<
5条回答
  •  生来不讨喜
    2020-12-11 19:05

    The problem is here:

    if (reply === 'help' || 'Help') // <-- 'Help' evaluates to TRUE
                                    //      so condition is always TRUE
    

    The equality operator doesn't "distribute", try

    if (reply === 'help' || reply === 'Help')
    

提交回复
热议问题