Bird
Raised Fist0
PowerShellscripting~20 mins

String concatenation in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 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'.

Practice

(1/5)
1. Which operator is used in PowerShell to join two strings together?
easy
A. /
B. -
C. +
D. *

Solution

  1. Step 1: Understand string joining in PowerShell

    PowerShell uses the plus sign (+) to concatenate or join strings.
  2. Step 2: Identify the correct operator

    Among the options, only + is used for string concatenation.
  3. Final Answer:

    + -> Option C
  4. Quick Check:

    String concatenation operator = + [OK]
Hint: Use + to join strings simply in PowerShell [OK]
Common Mistakes:
  • Using - instead of +
  • Trying to use * for strings
  • Using / which is division
2. Which of the following is the correct syntax to concatenate variables $a and $b with a space between them in PowerShell?
easy
A. $a + ' ' + $b
B. $a - ' ' - $b
C. $a * ' ' * $b
D. $a / ' ' / $b

Solution

  1. Step 1: Check operator for concatenation

    PowerShell uses + to join strings, so + is correct here.
  2. Step 2: Confirm space inclusion

    Adding ' ' between variables adds a space between the joined strings.
  3. Final Answer:

    $a + ' ' + $b -> Option A
  4. Quick Check:

    Concatenate with + and add space as ' ' [OK]
Hint: Add spaces manually with ' ' when joining strings [OK]
Common Mistakes:
  • Using - instead of +
  • Forgetting to add space
  • Using * or / operators
3. What will be the output of this PowerShell code?
$name = "John"
$greeting = "Hello, " + $name + "!"
Write-Output $greeting
medium
A. Hello, John!
B. Hello, $name!
C. Hello, !
D. JohnHello, !

Solution

  1. Step 1: Understand variable values

    $name contains "John" and is concatenated with strings using +.
  2. Step 2: Evaluate concatenation

    "Hello, " + $name + "!" becomes "Hello, John!" as $name is replaced by its value.
  3. Final Answer:

    Hello, John! -> Option A
  4. Quick Check:

    Concatenate strings and variable value = Hello, John! [OK]
Hint: Variables inside double quotes concatenate with + correctly [OK]
Common Mistakes:
  • Expecting $name to print literally
  • Missing + operator
  • Confusing output order
4. Identify the error in this PowerShell code snippet:
$first = "Good"
$second = "Morning"
$message = $first + $second
Write-Output $message
medium
A. Incorrect use of + operator
B. Missing space between words in concatenation
C. Variables not declared properly
D. Write-Output is invalid command

Solution

  1. Step 1: Check concatenation result

    $first + $second joins "Good" and "Morning" without space, resulting in "GoodMorning".
  2. Step 2: Identify missing space

    To separate words, a space string ' ' should be added between variables.
  3. Final Answer:

    Missing space between words in concatenation -> Option B
  4. Quick Check:

    Concatenation lacks space, so words join directly [OK]
Hint: Add ' ' between strings to include spaces [OK]
Common Mistakes:
  • Assuming + adds space automatically
  • Thinking variables are undeclared
  • Believing Write-Output is wrong
5. You want to create a full name string from variables $firstName and $lastName with a space in between. Which of these PowerShell commands correctly does this and outputs the full name?
hard
A. Write-Output $firstName * ' ' * $lastName
B. Write-Output $firstName + $lastName
C. Write-Output $firstName - $lastName
D. Write-Output "$firstName $lastName"

Solution

  1. Step 1: Understand string interpolation in double quotes

    Using double quotes with variables inside inserts their values with spaces as typed.
  2. Step 2: Compare options

    Write-Output "$firstName $lastName" uses double quotes with space between variables, producing correct full name with space.
  3. Final Answer:

    Write-Output "$firstName $lastName" -> Option D
  4. Quick Check:

    Double quotes allow variable insertion with spaces easily [OK]
Hint: Use double quotes to insert variables with spaces easily [OK]
Common Mistakes:
  • Forgetting space in concatenation
  • Using - or * operators incorrectly
  • Not using double quotes for interpolation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard