Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need help reviewing my code for my game called spaceman. Need to follow the rubric and want to make sure im following everything. / /
need help reviewing my code for my game called spaceman. Need to follow the rubric and want to make sure im following everything.
List of words to choose from
const wordList space "galaxy", "astronaut", "planet";
let guessedLetters ;
const maxWrongGuesses ;
let wordToGuess;
let wrongGuesses;
let displayWord;
Function to start a new game
function newGame
Choose a random word from the word list
wordToGuess wordListMathfloorMathrandom wordList.length;
guessedLetters ;
wrongGuesses ;
displayWord repeatwordToGuesslength;
gameLoop;
Function to display the current state of the game
function displayGameState
console.logWord: displayWord.splitjoin;
console.logGuessed Letters: guessedLetters.join;
console.logWrong guesses left: maxWrongGuesses wrongGuesses;
Function to process the game loop
function gameLoop
while wrongGuesses maxWrongGuesses && displayWord.includes
displayGameState;
let guess promptEnter a letter to guess:"toLowerCase;
if guessedLettersincludesguess
console.logYou already guessed that letter.";
continue;
guessedLetters.pushguess;
if wordToGuessincludesguess
for let i ; i wordToGuess.length; i
if wordToGuessi guess
displayWord displayWord.substr i guess displayWord.substri ;
else
wrongGuesses;
if displayWord.includes
console.logCongratulations You've guessed the word: wordToGuess;
else
console.logGame Over! The word was: wordToGuess;
Start the game
newGame;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started