This is my first post here, sorry if the guidelines are incorrect.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Color Guessing Game</title>
</head>
<body>
<h1>Color Guessing Game</h1>
<button type=button onclick="runGame()">Start Game</button>
<script>
const COLORS_ARRAY = array ('blue', 'cyan', 'gold');
const targetIndex = Math.floor(Math.random() * COLORS_ARRAY.length);
const target = COLORS_ARRAY[targetIndex];
function runGame() {
let guess = '';
let correct= false;
let numTries = '0';
console.log ('color picked')
do {
guess = prompt('I am thinking of one of these colors:\n\n' + COLORS_ARRAY +
'\n\nWhat color am I thinking of?\n');
if (guess === null) {
alert ('The game has been aborted');
}
correct = checkGuess (guess, target)
} while (!correct);
alert ('Congradulations');
numTries += 1;
}
function checkGuess(guess, target); {
let correct = false;
if (COLORS_ARRAY.includes(guess)) {
alert ('You have not entered a color on the list.');
}else if (guess > target) {
alert ('The color is lower in alphebetical order');
}else if (guess < target) {
alert ('The color is higher in alphebetical order');
}else correct= true;
}
document.body.style.background = guess;
</script>
</body>
</html>
You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!
console.log('Hello world!');
console.log('Hello world!');