当用户猜出鱼的名字错误时,我有一个想要动摇的图像。我正在使用条件ng-class="{'shake':error}"
。但是,即使答案正确,图像也会抖动。我不相信在任何时候$scope.error
都设置为真。我在这里错过了什么?
答案 0 :(得分:0)
我认为您要做的是return
guessIsCorrect或guessIsWrong来自compare
函数。
$scope.compare = function(guess) {
guess = guess.replace(/\s/g, '').toLowerCase();
var answers = [];
answers.push($scope.name.replace(/\s/g, '').toLowerCase());
currentAnimal.alts.forEach(function(alt) {
answers.push(alt.toLowerCase().replace(/\s/g, ''));
});
//console.log(answers);
//console.log("Guess: " + guess + "\n");
//console.log("Answer: " + answers + "\n");
for (var x = 0; x <= answers.length; x++) {
if (guess === answers[x]) {
return guessIsCorrect();
}
if (x === answers.length) {
return guessIsWrong();
}
}
};