我使用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';
}