Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to format the number as currency.
C Sharp (C#)
double price = 1234.56; string formatted = price.ToString("[1]"); Console.WriteLine(formatted);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'D' which is for decimal integers, not currency.
Using 'F' which formats as fixed-point number without currency symbol.
✗ Incorrect
The format specifier C formats the number as currency.
2fill in blank
mediumComplete the code to format the date as year-month-day.
C Sharp (C#)
DateTime today = new DateTime(2024, 6, 15); string formatted = today.ToString("[1]"); Console.WriteLine(formatted);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'MM/dd/yyyy' which formats as month/day/year.
Using 'dd-MM-yyyy' which puts day first.
✗ Incorrect
The format specifier yyyy-MM-dd formats the date as year-month-day.
3fill in blank
hardFix the error in the code to format a number with two decimal places.
C Sharp (C#)
double value = 3.14159; string result = value.ToString("[1]"); Console.WriteLine(result);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'D2' which is for decimal integers, not floating numbers.
Using 'N' without specifying decimals may show default decimals.
✗ Incorrect
The format specifier F2 formats the number with two decimal places.
4fill in blank
hardFill both blanks to format the date as full month name and 24-hour time.
C Sharp (C#)
DateTime dt = new DateTime(2024, 6, 15, 18, 30, 0); string formatted = dt.ToString("[1] [2]"); Console.WriteLine(formatted);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hh:mm tt' which is 12-hour time with AM/PM.
Using 'ddd' which shows abbreviated day name.
✗ Incorrect
MMMM shows the full month name, and HH:mm shows 24-hour time with minutes.
5fill in blank
hardFill all three blanks to create a dictionary with word lengths for words longer than 3 letters.
C Sharp (C#)
string[] words = {"apple", "bat", "carrot", "dog"};
var lengths = new Dictionary<string, int>()
{
{"[1]", [2]
};
foreach (var word in words)
{
if (word.Length [3] 3)
{
lengths[word] = word.Length;
}
}
foreach (var kvp in lengths)
{
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which selects words shorter than 3 letters.
Using 'word.Length' as key which is incorrect.
✗ Incorrect
The dictionary key is the word (word), the value is its length (word.Length), and the condition checks if length is greater than 3 (>).