I have been using angularjs to develop a mini quiz application. I created 4 if
statements, but for some reason, the last condition is always executed even if no answers have been selected.
Why does $scope.makeup
consistently display You should have makeup Four
?
Shouldn't an if
statement be ignored if none of its conditions are met?
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';
}