Event 7 was just an error checking event so no need to post on that.
Event 8 though was pretty straightforward.
1: [int]$winningNumber=(New-Object random).Next(0,50)
2:
3: function CheckIfWinner {
4: $guessCount++
5: [int]$guessedNumber=Read-Host "Enter a number between 0 and 50"
6: if ($guessedNumber -eq $winningNumber) {"Random: $winningNumber `nTotalGuesses: $guessCount"}
7: elseif ($guessedNumber -lt $winningNumber) {Write-Host "Too Low" -ForegroundColor green;CheckifWinner}
8: else {Write-Host "Too High" -ForegroundColor red;CheckIfWinner}
9: }
10: CheckIfWinner
No comments:
Post a Comment