Missing statement block after 'else' keyword.

if($guess -lt ($number + 10)) { #The player's guess was too high Clear-Host #Clear the Windows command console screen Write-Host "`n Sorry. Your guess was too high. You are getting hot. Press Enter to" ` "guess again." Write-Host "`n The secret number was: $number." $guess = "" #Reset the player's guess Read-Host #Pause the game until the player presses the Enter key } elseif($guess -lt ($number + 20)) { #The player's guess was too high Clear-Host #Clear the Windows command console screen Write-Host "`n Sorry. Your guess was too high. You are getting warmer. Press Enter to" ` "guess again." Write-Host "`n The secret number was: $number." $guess = "" #Reset the player's guess Read-Host #Pause the game until the player presses the Enter key } else ($guess -gt $number) { #The player's guess was too high Clear-Host #Clear the Windows command console screen Write-Host "`n Sorry. Your guess was too high. You are getting warmer. Press Enter to" ` "guess again." Write-Host "`n The secret number was: $number." $guess = "" #Reset the player's guess Read-Host #Pause the game until the player presses the Enter key } if ($guess -gt ($number - 10)) { #The player's guess was too low Clear-Host #Clear the Windows command console screen Write-Host "`n Sorry. Your guess was too low. You are getting hot. Press Enter to" ` "guess again." Write-Host "`n The secret number was: $number." $guess = "" #Reset the player's guess Read-Host #Pause the game until the player presses the Enter key } elseif ($guess -gt ($number - 20)) { #The player's guess was too low Clear-Host #Clear the Windows command console screen Write-Host "`n Sorry. Your guess was too low. You are getting warm. Press Enter to" ` "guess again." Write-Host "`n The secret number was: $number." $guess = "" #Reset the player's guess Read-Host #Pause the game until the player presses the Enter key } else ($guess -lt $number) { #The player's guess was too low Clear-Host #Clear the Windows command console screen Write-Host "`n Sorry. Your guess was too low. You are getting warmer. Press Enter to" ` "guess again." Write-Host "`n The secret number was: $number." $guess = "" #Reset the player's guess Read-Host #Pause the game until the player presses the Enter key } if ($guess -eq $number) { #The player has guessed the game's secret number Clear-Host #Clear the Windows command console screen Write-Host "`n Congratulations. You guessed my number! Press Enter" ` "to continue." Write-Host "`n The secret number was: $number." $status = "Stop" #Reset the player's guess Read-Host #Pause the game until the player presses the Enter key } #The player has elected to play again if ($reply -eq "Y") { #Reset variables to their default values $number = 0 $noOfGuesses = 0 $status = "Play" $guess = 0 } else { #The player has decided to quit playing $playGame = "No" #Modify variable indicating that it is time to #terminate game play } #Clear the Windows command console screen Clear-Host What does this mean?

It says my very first "else" statement running properly. I am not sure why this error is occuring




August 24th, 2015 2:06pm

Hi Steven,

the question is? Find the error? I've copied it to ISE and it think you should have a look in Line 147:

else  ($guess -lt $number) {  #The player's guess was too low

This isn't possible. You've to use If or ElseIf.

  • Proposed as answer by heyko Monday, August 24, 2015 2:09 PM
Free Windows Admin Tool Kit Click here and download it now
August 24th, 2015 2:09pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics