0
0
PowerShellscripting~10 mins

Formatting with -f operator in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to format the string with the variable $name.

PowerShell
"Hello, {0}!" [1] $name
Drag options to blanks, or click blank then click option'
A%
B-f
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f for string formatting.
Using * or % which are arithmetic operators.
2fill in blank
medium

Complete the code to format two variables $first and $last into a full name.

PowerShell
"{0} {1}" [1] $first, $last
Drag options to blanks, or click blank then click option'
A+
B*
C-f
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using + to concatenate instead of -f for formatting.
Using * or % which do not format strings.
3fill in blank
hard

Fix the error in the code to correctly format the number with two decimal places.

PowerShell
"{0:N2}" [1] $number
Drag options to blanks, or click blank then click option'
A-f
B+
C*
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f causes a concatenation error.
Using * or % which are not string formatting operators.
4fill in blank
hard

Fill all three blanks to format the date and time using the -f operator.

PowerShell
"Date: {0:yyyy-MM-dd}, Time: {1:HH:mm}" [1] [2], [3]
Drag options to blanks, or click blank then click option'
A-f
B$date
C$time
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f for formatting.
Mixing up the order of variables.
5fill in blank
hard

Fill all four blanks to format a string with name, age, and city using the -f operator.

PowerShell
"Name: {0}, Age: {1}, City: {2}" [1] [2], [3], [4]
Drag options to blanks, or click blank then click option'
A-f
B$name
C$age
D$city
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f.
Incorrect order of variables.
Missing commas between variables.