I have written the following PowerShell script below:
if ($Animal -eq "Chicken") {
if ($Food -eq "Egg") {
Write-Host "This chicken eats egg"
} ElseIf ($Food -eq "Soup") {
Write-Host "This chicken eats soup"
} ElseIf ($Animal -eq "Cow") {
if ($Food -eq "Egg") {
Write-Host "This cow eats egg"
} ElseIf ($Food -eq "Soup") {
Write-Host "This cow eats soup"
} ElseIf ($Animal -eq "Zebra") {
if ($Food -eq "Egg") {
Write-Host "This zebra eats egg"
} ElseIf ($Food -eq "Soup") {
Write-Host "This zebra eats soup"
The script works for the Chicken and the Cow but does not register the zebra portion of the code. I am not sure of what I am doing wrong as there are no errors being returned. Can someone please provide some guidance?
$Animal = "Cow", because you've nested theelseifinside the firstifstatement). Please post code that can actually be executed :)}s as{s.