$greeting is assigned "Hello" and $name is assigned "Sam".
Step 2: Understand string interpolation in double quotes
Inside double quotes, variables like $greeting and $name are replaced by their values.
Final Answer:
Hello, Sam! -> Option D
Quick Check:
Variables inside "" show their values [OK]
Hint: Use double quotes to insert variables inside strings [OK]
Common Mistakes:
Using single quotes which do not expand variables
Expecting variable names to print literally
Forgetting to assign variables before use
4. Identify the error in this PowerShell script:
$number = 10
$number = $number + 5
Write-Output number
medium
A. Cannot add numbers in PowerShell
B. Variable $number not declared
C. Missing $ before 'number' in Write-Output
D. Write-Output cannot print variables
Solution
Step 1: Check variable usage in Write-Output
The script tries to print 'number' without $, so it prints the word literally.
Step 2: Correct usage of variable in output
To print the variable value, it should be Write-Output $number.
Final Answer:
Missing $ before 'number' in Write-Output -> Option C
Quick Check:
Variables need $ to be recognized [OK]
Hint: Always use $ before variable names when printing [OK]
Common Mistakes:
Forgetting $ before variable in output
Thinking variables need declaration keyword
Assuming Write-Output can't print variables
5. You want to create a variable $fullName by combining two variables $firstName and $lastName with a space in between. Which code correctly does this in PowerShell?
hard
A. $fullName = $firstName + " " + $lastName
B. $fullName = '$firstName $lastName'
C. $fullName = $firstName $lastName
D. $fullName = "$firstName$lastName"
Solution
Step 1: Understand string concatenation in PowerShell
Use + to join strings and include a space as " ".
Step 2: Analyze each option
$fullName = $firstName + " " + $lastName correctly adds $firstName, a space, and $lastName to form full name.