Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f for string formatting.
Using * or % which are arithmetic operators.
✗ Incorrect
The -f operator in PowerShell formats the string by replacing placeholders like {0} with the provided arguments.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + to concatenate instead of -f for formatting.
Using * or % which do not format strings.
✗ Incorrect
The -f operator formats the string by replacing {0} and {1} with $first and $last respectively.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f causes a concatenation error.
Using * or % which are not string formatting operators.
✗ Incorrect
The -f operator formats the number with the specified format string 'N2' for two decimal places.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f for formatting.
Mixing up the order of variables.
✗ Incorrect
The -f operator is used to format the string, and $date and $time are the variables to fill placeholders {0} and {1}.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of -f.
Incorrect order of variables.
Missing commas between variables.
✗ Incorrect
The -f operator formats the string, and $name, $age, $city fill the placeholders {0}, {1}, and {2} respectively.