I am fairly new to programming and i have gone through a few flash cs4 as3 tutorials and recently i have started to try and alter them. The one i need help with is a number guessing game where you guess a number between 1 and 10, and i am trying to change it to a color guessing game, where you guess either “red” or “blue”.
I keep getting an error in line 5 “var red = true;”. The error is 1151: A conflict exists with the definition red in namespace internal. There is also a “Warning:3596: Duplicate variable definition” for the same line.
Here is the code:
var random = floor(Math.random()*2);
if(random == 0){
var red = false;
}else if (random == 1){
var red = true;
}
guess_btn.addEventListener(MouseEvent.CLICK, onGuessClick);
function onGuessClick(event){
var guess = String(guess_txt.text)
if (guess == "red" && red == true){
response_txt.text = "Red is the correct answer.";
}else if (guess == "red" && red == false){
response_txt.text = "Red is not the correct answer.";
}else if(guess == "blue" && red == false){
response_txt.text = "Blue is the correct answer.";
}else if (guess == "blue" && red == true){
response_txt.text = "Blue is not the correct answer.";
}else if (guess != "blue" || guess != "red"){
response_txt.text = "I said red or blue!";
}
}
Any help is much appreciated.