Challenge: Guard Clauses in User Registration
Taak
Swipe to start coding
Write a method to register a user that uses guard clauses to validate the provided username and password.
- If
usernameis null or empty, immediately throw anArgumentExceptionwith the message "Username cannot be null or empty.". - If
passwordis null or empty, immediately throw anArgumentExceptionwith the message "Password cannot be null or empty.". - If both inputs are valid, return a string in the format "User '
' registered successfully.".
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 4
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Geweldig!
Completion tarief verbeterd naar 4.17
Challenge: Guard Clauses in User Registration
Veeg om het menu te tonen
Taak
Swipe to start coding
Write a method to register a user that uses guard clauses to validate the provided username and password.
- If
usernameis null or empty, immediately throw anArgumentExceptionwith the message "Username cannot be null or empty.". - If
passwordis null or empty, immediately throw anArgumentExceptionwith the message "Password cannot be null or empty.". - If both inputs are valid, return a string in the format "User '
' registered successfully.".
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 4
single