
Wie würden Sie in einem Quizskript eine Lückentextfrage und eine Antwort eingeben, wie beim Seinfeld-Quizspiel in „Programmieren für Anfänger“?
Antwort1
SowieRead-Host
Sie können direkt dieSystem.Console
Klasse, um ein einzelnes Zeichen zu lesen (ohne die Eingabetaste zu benötigen):
$key = [Console]::ReadKey()
$char = $key.KeyChar
Antwort2
Dort ist derCmdlet „Read-Host“zum Lesen von Benutzereingaben, und Sie benötigen einigeBedingte Logikmit der richtigen Antwort zu vergleichen.
Antwort3
#Ask the player the seventh question
while (($question7 -eq "")) {
Clear-Host #Clear the Windows command console screen
Write-Host
Write-Host " What food item did Jerry say Newman wouldn't eat even if it was deep fried in chocolate sauce?"
Write-Host
Write-Host " Broccoli"
Write-Host " Peas"
Write-Host " Apples"
Write-Host " Carrots"
Write-Host
$question7 = Read-Host " Type the word representing the correct answer" `
"and press the Enter key"
}