lundi 24 août 2015

javascript last if statement always read

I'm using angularjs as the framework to write a small quiz. I wrote 4 if statements. But for some unexplained reason, the last condition is always read even though none of the conditions/answers has been chosen.

The $scope.makeup always shows You should have makeup Four, why?

Shouldn't an if statement be overlooked if no condition is met in it, yet?

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

Aucun commentaire:

Enregistrer un commentaire