Seksjon 3. Kapittel 4
single
Challenge: Apply Safe Execution Patterns
Sveip for å vise menyen
Oppgave
Swipe to start coding
Refactor the divideNumbers function to use safe execution patterns for division in PHP.
- Validate that both
numeratoranddenominatorare numbers. - If either argument is not a number, throw an
InvalidArgumentException. - If
denominatoris zero, throw aDivisionByZeroError. - If validation passes, return the result of dividing
numeratorbydenominator.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 4
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår