mardi 28 février 2017

JavaScript Guess the letter expected an identifier and instead saw else

I am doing one of the tutorials on http://ift.tt/2m4xWhB. I´ve done 1, 2 and 3, but I am getting: "expected an identifier and instead saw else" when I run the code.

My code is:

var solution = ["F", "O", "X"];
var guessed = ["_", "_", "_"];
var reward = 0;
var numberofGuess = 0;

function guessLetter(letter) {
  for (var i = 0; i < solution.length; i++) {
    if (solution[i] == letter) {
      guessed[i] = letter;
      numberofGuess++;
      reward += Math.floor((Math.random() * 100) + 1);
      console.log("Current guessed letters " + guessed + ". Congratulations on finding a letter.");
    }
    if (numberofGuess == solution.length) {
      console.log("You won the game!");
      console.log("Your final reward is: " + reward);
    }
  } else {
    console.log("Thats not right");
    reward -= Math.floor((Math.random() * 100) + 1);
  }

}

guessLetter("D");
guessLetter("F");
guessLetter("O");
guessLetter("X");

Aucun commentaire:

Enregistrer un commentaire