#Bob Response Exercise

4 messages · Page 1 of 1 (latest)

chilly spear
#

I'm stuck on the first exercise inwhich I'm support to generate responses from Bob, but I get 25 errors and I'm not sure as to what they mean as I've tested everything in ISE and it works as expected. Can someone that's passed this test give him a hint as to where I'm going wrong?

Function Get-BobResponse {
[CmdletBinding()]
Param(
[string]$HeyBob = $(read-host "Say something to Bob")
)

#.SYNOPSIS
#Bob is a lackadaisical teenager. In conversation, his responses are very limited.

#.DESCRIPTION
#Bob is a lackadaisical teenager. In conversation, his responses are very limited.

#Bob answers 'Sure.' if you ask him a question.

    #He says 'Fine. Be that way!' if you address him without actually saying anything.

if([string]::IsNullOrWhiteSpace($HeyBob)){
write-host "Fine. Be that way!"
}

#He answers 'Calm down, I know what I'm doing!' if you yell a question at him.

elseif($HeyBob -eq $HeyBob.ToUpper() -and $HeyBob.EndsWith("?") -and $HeyBob -match "[A-Z]"){
write-host "Calm down, I know what I'm doing!"
}

elseif ($HeyBob.EndsWith("?")){
write-host "Sure"
}

#He answers 'Whoa, chill out!' if you yell at him.

elseif ($HeyBob -ceq $HeyBob.ToUpper() -and $HeyBob -match "[A-Z]"){
write-host "Whoa, chill out!"
}

#He answers 'Whatever.' to anything else.

else{
write-host "Whatever"
}

}
Get-BobResponse

I don't understand the errors presented such as the first one:
Test Failure
Message: Expected exactly 'Whatever.', but got $null.

Stack-trace: at Get-BobResponse -HeyBob "Tom-ay-to, tom-aaaah-to." | Should -BeExactly "Whatever.", /mnt/exercism-iteration/BobResponse.tests.ps1:8
at <ScriptBlock>, /mnt/exercism-iteration/BobResponse.tests.ps1:8

desert citrus
#

Hi, if you post the code in code blocks it's much easier to figure out what could be wrong 😉
Same goes for the error message.

FYI code blocks are 3x backticks before and after the text
like this

desert citrus
#
  • Why are you using write-host?
  • The "Message: Expected exactly 'Whatever.', but got $null." means that when calling the Get-BobResponse function it expects something but got a null value
pearl crownBOT