Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need help running the code through visual code studio making sure it runs right then through a github link so that others can play it
need help running the code through visual code studio making sure it runs right then through a github link so that others can play it and needs a logo
const easyWords star "moon", "mars";
const mediumWords rocket "astronaut", "gravity";
const hardWords constellation "nebula", "blackhole";
const difficultyLevels
easy: easyWords,
medium: mediumWords,
hard: hardWords,
;
let guessedLetters ;
const maxWrongGuesses ;
let wordToGuess;
let wrongGuesses;
let displayWord;
console.logWelcome to Spaceman! Guess the spacethemed word.";
function chooseDifficulty
let difficulty;
while difficulty
difficulty promptChoose difficulty easy medium, hard:toLowerCase;
if difficultyLevels.hasOwnPropertydifficulty
console.errorInvalid difficulty. Please choose easy, medium, or hard.";
difficulty null;
return difficulty;
function newGame
try
const difficulty chooseDifficulty;
const wordList difficultyLevelsdifficulty;
wordToGuess wordListMathfloorMathrandom wordList.length;
guessedLetters ;
wrongGuesses ;
displayWord repeatwordToGuesslength;
catch error
console.errorError starting a new game:", error;
finally
gameLoop;
function displayGameState
console.logWord: displayWord.splitjoin;
console.logGuessed Letters: guessedLetters.join;
console.logWrong guesses left: maxWrongGuesses wrongGuesses;
function gameLoop
while wrongGuesses maxWrongGuesses && displayWord.includes
displayGameState;
let guess;
try
guess promptEnter a letter to guess:"toLowerCase;
if guesslength guess.matchazi
throw new ErrorInvalid guess. Please enter a single letter.";
catch error
console.errorerrormessage;
continue;
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;
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