Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        13天前关闭。
                                                                                            
                
        
我有以下代码:

if (insurance != ("amica" || "travelers" || "national general" || "infinity" || "cincinatti")) {
    amount = "$200";
} else {
    amount = "$300";
}


我试图让我的网页显示出来,如果不是上述五家公司之一,那么您会得到200美元。

不幸的是,我似乎无法使其正常工作。我用几种不同的方式写
我已开始
if (insurance === "amica || insurance === "travelers || ...,但似乎没有任何作用。

我究竟做错了什么?

最佳答案

当您这样做时:

if (insurance != ("amica" || "travelers" || "national general" || "infinity" || "cincinatti"))


首先评估("amica" || "travelers" || "national general" || "infinity" || "cincinatti"),然后检查它是否与保险价值不同。

我想你想做:

if (insurance != "amica" && insurance != "travelers" && insurance != "national general" && insurance != "infinity" && insurance != "cincinatti")


这也可以通过定义一个数组并检查它是否包含该值来解决:

const insurances = ["amica", "travelers", "national general",
"infinity", "cincinatti"];

if (!insurances.includes(insurance))

10-08 00:05