Challenge - 5 Problems
Pipe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this custom pipe usage?
Given the Angular pipe below and its usage in a template, what will be displayed?
Angular
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'reverse' }) export class ReversePipe implements PipeTransform { transform(value: string): string { return value.split('').reverse().join(''); } } // Template usage: // {{ 'hello' | reverse }}
Attempts:
2 left
💡 Hint
Think about what the pipe does to the input string.
✗ Incorrect
The custom pipe named 'reverse' takes the input string and reverses its characters. So 'hello' becomes 'olleh'.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a pure custom pipe?
Select the correct Angular pipe definition that creates a pure pipe named 'capitalize'.
Attempts:
2 left
💡 Hint
Pure pipes have pure: true and implement PipeTransform interface.
✗ Incorrect
Option A correctly sets pure: true (boolean) and implements PipeTransform. Option A sets pure: false (impure pipe). Option A misses implementing PipeTransform. Option A uses a string 'true' instead of boolean true.
🔧 Debug
advanced2:00remaining
Why does this custom pipe cause a runtime error?
Examine the pipe code below. What causes the runtime error when used in a template?
Angular
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'double' }) export class DoublePipe implements PipeTransform { transform(value: number): number { return value * 2; } } // Template usage: // {{ '5' | double }}
Attempts:
2 left
💡 Hint
Check the input type and what the template passes.
✗ Incorrect
The pipe expects a number input but the template passes a string '5'. Multiplying a string by 2 results in NaN in JavaScript/TypeScript.
❓ state_output
advanced2:00remaining
What is the output when using this impure pipe with changing input?
Consider the impure pipe below and its usage in a component template. What will be the displayed output after the component's 'counter' property increments?
Angular
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'addRandom', pure: false }) export class AddRandomPipe implements PipeTransform { transform(value: number): number { return value + Math.floor(Math.random() * 10); } } // Component template: // {{ counter | addRandom }} // Initial counter = 5 // After increment, counter = 6
Attempts:
2 left
💡 Hint
Impure pipes run on every change detection cycle.
✗ Incorrect
Impure pipes run every time Angular detects changes, so the random addition recalculates and changes output when 'counter' changes.
🧠 Conceptual
expert2:00remaining
Which statement about Angular custom pipes is TRUE?
Select the only true statement about Angular custom pipes.
Attempts:
2 left
💡 Hint
Think about the pipe interface and lifecycle.
✗ Incorrect
Custom pipes must implement PipeTransform interface and define a transform method. Impure pipes run on every change detection, pure pipes run only when inputs change. Pipes cannot modify component properties directly.