Bird
Raised Fist0
Angularframework~20 mins

Built-in pipes (date, currency, uppercase) in Angular - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Angular Pipes Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the rendered output of this Angular template?
Given the component property today = new Date('2024-06-15T12:00:00Z'), what will be displayed by this template?

<p>{{ today | date:'fullDate' }}</p>
Angular
<p>{{ today | date:'fullDate' }}</p>
ASaturday, June 15, 2024
BJun 15, 2024
C15/06/2024
D2024-06-15
Attempts:
2 left
💡 Hint
The 'fullDate' format shows the day of the week, month name, day, and year.
📝 Syntax
intermediate
2:00remaining
Which option correctly formats a number as US dollars with 2 decimals using Angular currency pipe?
You want to display the number 1234.5 as $1,234.50 in your template. Which pipe usage is correct?
Angular
<p>{{ amount | currency:??? }}</p>
Acurrency:'USD':'symbol':'1.0-0'
Bcurrency:'USD':'code':'1.0-0'
Ccurrency:'USD':'symbol':'2.0-2'
Dcurrency:'USD':'symbol':'1.2-2'
Attempts:
2 left
💡 Hint
The format string '1.2-2' means minimum 1 digit before decimal, minimum 2 decimals, maximum 2 decimals.
❓ component_behavior
advanced
2:00remaining
What is the output of this Angular template using uppercase pipe?
Given the component property name = 'Angular', what will this template render?

<h1>{{ name | uppercase }}</h1>
Angular
<h1>{{ name | uppercase }}</h1>
AANGULAR
Bangular
CAngular
DAnGuLaR
Attempts:
2 left
💡 Hint
The uppercase pipe converts all letters to capital letters.
🔧 Debug
advanced
2:00remaining
What happens in this Angular template with null input?
Consider this template snippet:

{{ price | currency:'USD':'symbol':'1.2-2' }}

Given price = null in the component, what occurs and why?
Angular
{{ price | currency:'USD':'symbol':'1.2-2' }}
ASyntax error due to wrong pipe usage
BNo error; renders an empty string because the pipe returns null for null input
CRuntime error: Cannot read property 'toString' of null
DDisplays 'null' as string without formatting
Attempts:
2 left
💡 Hint
Angular currency pipe returns null for null or undefined inputs, which renders as empty string in the template.
🧠 Conceptual
expert
2:00remaining
How does Angular's date pipe handle timezone differences in output?
Given date = new Date('2024-06-15T12:00:00Z') and template {{ date | date:'short' }}, which statement is true about the displayed time?
Angular
{{ date | date:'short' }}
AThe time is always shown in UTC
BThe time is shown in the server's timezone
CThe time is shown in the browser's local timezone
DThe time is shown in GMT regardless of user location
Attempts:
2 left
💡 Hint
Angular date pipe formats dates according to the client environment.

Practice

(1/5)
1. What does the Angular uppercase pipe do when applied to a string in a template?
easy
A. Reverses the string characters.
B. Converts all letters in the string to lowercase.
C. Capitalizes only the first letter of the string.
D. Converts all letters in the string to uppercase.

Solution

  1. Step 1: Understand the purpose of the uppercase pipe

    The uppercase pipe is designed to transform text to all capital letters in Angular templates.
  2. Step 2: Compare with other text transformations

    Unlike lowercase or capitalize, uppercase changes every letter to uppercase.
  3. Final Answer:

    Converts all letters in the string to uppercase. -> Option D
  4. Quick Check:

    uppercase pipe = all caps [OK]
Hint: Uppercase pipe makes all letters capital [OK]
Common Mistakes:
  • Confusing uppercase with lowercase pipe
  • Thinking it only capitalizes first letter
  • Assuming it reverses the string
2. Which of the following is the correct syntax to format a date using Angular's date pipe to show only the year in a template?
easy
A. {{ myDate | date:'yyyy' }}
B. {{ myDate | date:'YYYY' }}
C. {{ myDate | date:'year' }}
D. {{ myDate | date:'yy' }}

Solution

  1. Step 1: Recall Angular date pipe format codes

    Angular uses lowercase 'yyyy' to represent the full year in date pipe formatting.
  2. Step 2: Check each option's format string

    {{ myDate | date:'yyyy' }} uses 'yyyy' correctly; A uses uppercase which is invalid; C uses 'year' which is not a valid format; D uses 'yy' which shows two-digit year.
  3. Final Answer:

    {{ myDate | date:'yyyy' }} -> Option A
  4. Quick Check:

    Year format = 'yyyy' [OK]
Hint: Use lowercase 'yyyy' for full year in date pipe [OK]
Common Mistakes:
  • Using uppercase 'YYYY' instead of 'yyyy'
  • Using descriptive words like 'year' instead of format codes
  • Using 'yy' which shows only two digits
3. Given the Angular template code:
{{ 1234.5 | currency:'USD':'symbol':'1.2-2' }}

What will be the rendered output?
medium
A. $1,234.50
B. $1234.5
C. USD 1234.50
D. $1,234.5

Solution

  1. Step 1: Understand the currency pipe parameters

    The currency pipe format is: currency code 'USD', display as symbol '$', and digit info '1.2-2' means minimum 1 digit before decimal, minimum 2 decimals, maximum 2 decimals.
  2. Step 2: Apply formatting to the number 1234.5

    Number 1234.5 is formatted with commas and two decimals: $1,234.50.
  3. Final Answer:

    $1,234.50 -> Option A
  4. Quick Check:

    Currency pipe with '1.2-2' = two decimals [OK]
Hint: Currency pipe '1.2-2' means two decimals [OK]
Common Mistakes:
  • Ignoring decimal places and showing one decimal
  • Using currency code instead of symbol
  • Not adding thousand separators
4. Identify the error in this Angular template code:
{{ today | date:'MM-DD-YYYY' }}
medium
A. The date pipe cannot format month and day.
B. The pipe name 'date' is misspelled.
C. The date format string uses uppercase 'YYYY' which is invalid.
D. The variable 'today' is not defined.

Solution

  1. Step 1: Check the date format string correctness

    Angular date pipe requires lowercase 'yyyy' for year, not uppercase 'YYYY'.
  2. Step 2: Verify other parts of the code

    The pipe name 'date' is correct, 'today' is assumed defined, and date pipe can format month and day.
  3. Final Answer:

    The date format string uses uppercase 'YYYY' which is invalid. -> Option C
  4. Quick Check:

    Date pipe year format = 'yyyy' lowercase [OK]
Hint: Use lowercase 'yyyy' in date pipe format strings [OK]
Common Mistakes:
  • Using uppercase 'YYYY' instead of 'yyyy'
  • Assuming pipe name is wrong
  • Ignoring variable definition issues
5. You want to display a product price in Euros with the currency symbol and exactly 3 decimal places in Angular. Which pipe usage is correct?
hard
A. {{ price | currency:'EUR':'code':'1.2-2' }}
B. {{ price | currency:'EUR':'symbol':'1.3-3' }}
C. {{ price | currency:'EUR':'symbol':'1.0-2' }}
D. {{ price | currency:'USD':'symbol':'1.3-3' }}

Solution

  1. Step 1: Identify the currency code and symbol usage

    To show Euros with symbol €, use currency code 'EUR' and display 'symbol'.
  2. Step 2: Set decimal places to exactly 3

    The digit info '1.3-3' means minimum 1 digit before decimal, exactly 3 decimals.
  3. Step 3: Check other options for correctness

    {{ price | currency:'EUR':'code':'1.2-2' }} uses 'code' display and 2 decimals; C uses 2 decimals; D uses USD instead of EUR.
  4. Final Answer:

    {{ price | currency:'EUR':'symbol':'1.3-3' }} -> Option B
  5. Quick Check:

    Currency EUR with 3 decimals = {{ price | currency:'EUR':'symbol':'1.3-3' }} [OK]
Hint: Use '1.3-3' for exactly 3 decimals in currency pipe [OK]
Common Mistakes:
  • Using wrong currency code or symbol
  • Setting wrong decimal places
  • Mixing currency codes (USD instead of EUR)
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