0
0
PowerShellscripting~20 mins

String concatenation in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell String Concatenation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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
AHello+ World
BHelloWorld
CHello World
DHello + World
Attempts:
2 left
💡 Hint
Look at how the + operator works with strings in PowerShell.
💻 Command Output
intermediate
2: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
APower+Shell
BPowerShell
C$str1$str2
DPower Shell
Attempts:
2 left
💡 Hint
Check how variables inside double quotes behave in PowerShell.
📝 Syntax
advanced
2: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.
A$greeting = "Good" + " " + "Morning"
B$greeting = "Good" . " " . "Morning"
C$greeting = "Good" & " " & "Morning"
D$greeting = "Good" -join " " -join "Morning"
Attempts:
2 left
💡 Hint
Remember the operator PowerShell uses for string concatenation.
🔧 Debug
advanced
2: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
ANo error; the code outputs 'HelloWorld'.
BError because + operator cannot concatenate strings in PowerShell.
CError because single quotes do not allow string concatenation.
DError because variables must be declared with $ before each use.
Attempts:
2 left
💡 Hint
Try running the code to see if it produces an error.
🚀 Application
expert
2: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
A8
B11
C9
D10
Attempts:
2 left
💡 Hint
Count letters in 'Anna', a space, and 'Smith'.