Challenge - 5 Problems
PowerShell String Concatenation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell string concatenation?
Consider the following PowerShell code snippet. What will it output?
PowerShell
$a = "Hello" $b = "World" $c = $a + " " + $b Write-Output $c
Attempts:
2 left
💡 Hint
Look at how the + operator works with strings in PowerShell.
✗ Incorrect
In PowerShell, the + operator concatenates strings exactly as written. The code adds a space between $a and $b, so the output is 'Hello World'.
💻 Command Output
intermediate2:00remaining
What does this PowerShell code output?
What is the output of this code snippet?
PowerShell
$str1 = "Power" $str2 = "Shell" $result = "$str1$str2" Write-Output $result
Attempts:
2 left
💡 Hint
Check how variables inside double quotes behave in PowerShell.
✗ Incorrect
Variables inside double quotes are expanded in PowerShell, so "$str1$str2" becomes 'PowerShell' without spaces.
📝 Syntax
advanced2:00remaining
Which option correctly concatenates strings with a space in PowerShell?
Select the option that correctly concatenates the strings "Good" and "Morning" with a space between them.
Attempts:
2 left
💡 Hint
Remember the operator PowerShell uses for string concatenation.
✗ Incorrect
In PowerShell, the + operator concatenates strings. The dot (.) and ampersand (&) are not used for string concatenation, and -join is used differently.
🔧 Debug
advanced2:00remaining
Why does this PowerShell string concatenation fail?
This code throws an error. What is the cause?
$part1 = 'Hello'
$part2 = 'World'
$combined = $part1 + $part2
Write-Output $combined
PowerShell
$part1 = 'Hello' $part2 = 'World' $combined = $part1 + $part2 Write-Output $combined
Attempts:
2 left
💡 Hint
Try running the code to see if it produces an error.
✗ Incorrect
PowerShell allows string concatenation with + operator regardless of single or double quotes. The code runs fine and outputs 'HelloWorld'.
🚀 Application
expert2:00remaining
How many characters are in the concatenated string?
Given this PowerShell code, how many characters does the variable $fullName contain?
$firstName = "Anna"
$lastName = "Smith"
$fullName = $firstName + " " + $lastName
Count the characters including spaces.
PowerShell
$firstName = "Anna" $lastName = "Smith" $fullName = $firstName + " " + $lastName
Attempts:
2 left
💡 Hint
Count letters in 'Anna', a space, and 'Smith'.
✗ Incorrect
The string 'Anna Smith' has 4 (Anna) + 1 (space) + 5 (Smith) = 10 characters.