0

I don't understand why my function is not giving similar output as the first example of powershell code

PS C:\Users\shane> $x = 3
PS C:\Users\shane> $y = 6
PS C:\Users\shane> $a = $x + $y
PS C:\Users\shane> Write-Host "The answer is $a"
The answer is 9

My function using similar logic

PS C:\Users\shane> Function Add ($x, $y){
>> $a = $x + $y
>> Write-Host “The Answer is $a”
>> }
>>
PS C:\Users\shane> add 3,6
The Answer is 3 6

I would expect the output to say "The Answer is 9" instead of "The Answer is 3 6"

What am I doing wrong?

1
Contributor
1
Reply
12
Views
1 Year
Discussion Span
Last Post by shanenin
1

I see what I was doing wrong. I was calling the function with a comma between the arguments
add 3,6 #incorrect
it should have been
add 3 6 #correct

I need to really brush up on the basics :-)

Edited by shanenin: added

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.