javascript last if语句始终读取

javascript last if语句始终读取,javascript,angularjs,if-statement,Javascript,Angularjs,If Statement,我正在使用angularjs作为框架来编写一个小测验。我写了4个if语句。但由于某些无法解释的原因,即使未选择任何条件/答案,也始终会读取最后一个条件 $scope.compose总是显示您应该有四个化妆,为什么 如果if语句中没有满足任何条件,那么它不应该被忽略吗 var silverMetal = ($scope.userChoices.metal === 'silver'); var goldMetal = ($scope.userChoices.metal === 'gold'); v

我正在使用angularjs作为框架来编写一个小测验。我写了4个
if
语句。但由于某些无法解释的原因,即使未选择任何条件/答案,也始终会读取最后一个条件

$scope.compose
总是显示
您应该有四个化妆
,为什么

如果
if
语句中没有满足任何条件,那么它不应该被忽略吗

var silverMetal = ($scope.userChoices.metal === 'silver');
var goldMetal = ($scope.userChoices.metal === 'gold');

var greenTone = ($scope.userChoices.tone === 'green');
var blueTone = ($scope.userChoices.tone === 'blue');

var greyBlueBlackEye = ($scope.userChoices.eye === 'grey' || 'blue' || 'black');
var greenHazelBrownEye = ($scope.userChoices.eye === 'green' || 'hazel' || 'brown');

var lightblondeGingerDarkblondeHair = ($scope.userChoices.hair === 'light blonde' || 'ginger' || 'dark blonde');
var lightbrownDarkbrownBlackHair = ($scope.userChoices.hair === 'light brown' || 'dark brown' || 'black');


if (silverMetal && greenTone && greyBlueBlackEye && lightblondeGingerDarkblondeHair) {
  $scope.makeup = 'You should have makeup One';
}

if (silverMetal && greenTone && greyBlueBlackEye && lightbrownDarkbrownBlackHair) {
  $scope.makeup = 'You should have makeup Two';
}

if (silverMetal && greenTone && greenHazelBrownEye && lightblondeGingerDarkblondeHair) {
  $scope.makeup = 'You should have makeup Three';
}

if (silverMetal && greenTone && greenHazelBrownEye && lightbrownDarkbrownBlackHair) {
  $scope.makeup = 'You should have makeup Four';
}

问题是这样的线路:

var greyBlueBlackEye=($scope.userChoices.eye==='grey'| | |'blue'| |'black');


像“blue”这样的字符串是真实的,因此计算结果为
($scope.userChoices.eye===“grey”)| true
,因此计算结果为true。您需要分别进行比较,或者检查该值是否位于包含“灰色”、“蓝色”和“黑色”的数组中。

$scope.userChoices.eye===“灰色”| |“蓝色”|“黑色”
与您认为的不同。
|
运算符不能以这种方式分解。感谢@StephenTG提供的解决方案。它单独工作。即使我知道规则,我也没想到。我想这就是编码导致睡眠不足的原因。再次感谢。