I'm attempting to create a wepbage where when the user clicks a button, they receive a compliment. I'm doing this using button.addEventListener("click", generator);
. However, I kept getting the error Uncaught SyntaxError: Unexpected token else
when I checked the console. I suspected it was an issue with the if/else syntax, and I removed the semicolons I accidentally put after each block in order to see if that was the issue. That switched it from Uncaught SyntaxError: Unexpected token else
to Uncaught SyntaxError: Unexpected token {
. I've looked over it a number of times to try and find a mistake but I just can't find the problem.
Here's the function:
var generator = function(){
var complimentNum = round(random(1,5));
if(complimentNum == 1){
compliment.textContent = "You have a great smile!";
}
else if(complimentNum == 2){
compliment.textContent = "You are so kind to others!";
}
else if(complimentNum == 3){
compliment.textContent = "Your laugh is beautiful!";
}
else if(complimentNum == 4){
compliment.textContent = "Your eyes are beautiful!";
}
else(complimentNum == 5){
compliment.textContent = "You have good taste.";
}
}
Aucun commentaire:
Enregistrer un commentaire