I am just looking into the javascript portion of this code and it will run when you click the button but I don’t get a return value. I’ve been attempting to fix this for hours now. The purpose of the code is to generate a random color from the list provided but when I type in any of the colors I get no return value. I tried to debug my cold and it doesn’t give me any errors that I could fix. Is there anything that you see wrong with my code?
<body>
<h1>Colors Guessing Game</h1>
<button type="button" onclick="runGame()">Start Game</button>
<script>
const COLORS_ARRAY = ['blue', 'cyan', 'gold', 'gray', 'green', 'magenta', 'orange', 'red', 'white', 'yellow'];
console.log(elements.join());
function runGame() {
let guess = "";
let correct = false;
let numTries = 0;
const targetIndex = [Math.floor(Math.random() * COLORS_ARRAY.length - 1)];
const target = COLORS_ARRAY[targetIndex];
console.log(target);
do {
guess = prompt('I am thinking of one of these colors:nn' + COLORS_ARRAY + 'What color am I thinking ofn');
guess = guess.toLowerCase();
numTries += 1;
if (guess == null) {
alert('Have a great day!');
}
return "";
} while (!correct);
alert("Congrats! You got it" + target + " nnIt took you" + numTries + "tries to guess correctly");
document.body.style.background = guess;
}
function checkGuess(guessNumber, target) {
let correct = false;
if (!(COLORS_ARRAY.indexOf(guess) == -1)) {
alert('You have not entered a color from the listnnPlease choose a color from the before mentioned list.');
} else if (guessNumber > target) {
alert('Your choice is alphabetically higher than the color.');
} else if (guessNumber < target) {
alert('Your choice is alphabetically lower than the color.');
} else {
correct = true;
}
return correct;
}
</script>