javascript last if if语句总是读

时间:2015-08-24 15:09:26

标签: javascript angularjs if-statement

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

$scope.makeup始终显示You should have makeup Four,为什么?

如果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';
}

0 个答案:

没有答案