Challenge: Guard Clauses in User Registration
Tarea
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.".
Solución
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 2. Capítulo 4
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Suggested prompts:
Can you explain this in simpler terms?
What are some examples related to this topic?
How does this information apply to real-world situations?
Genial!
Completion tasa mejorada a 4.17
Challenge: Guard Clauses in User Registration
Desliza para mostrar el menú
Tarea
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.".
Solución
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 2. Capítulo 4
single