Homework Lesson 14: Email to NetID

I’m not sure what I’m doing wrong here, but something seems to be wrong as the solution is encountering its own assertion error.

fun emailToNetID(email: String): String {
	var emailSender = email.split("@")

if (emailSender[1] == "illinois.edu") {
    println("The NetID is " + emailSender[0])
    return emailSender[0]
} else {
    throw Exception("$email is not a valid email address.")

return "No NetID Found!"


Hi, it’s been a while since I’ve completed this one, but it might be because the assignment is asking you to use require instead of throwing a custom exception.

Try using require to verify the argument you’re passing. Then you can return the [0] portion as you’ve done. I think having the require to verify your argument at the the beginning ensures you can always just return [0] as well, and nothing else would be needed. I think that should take care of it.

One other thing I noticed is that I’m not sure if your code would ever reach the return "No NetID found!" portion with how the current if-else statement is constructed.

I hope this helps.

Not sure how I missed the require piece.
Adding this made things pass → require(emailSender[1] == "illinois.edu

1 Like