Control Flow Challenge One

I cannot seem to figure this out. I’ve eliminated the error, but I’m having trouble assigning the new value to lastName. Anyone know what I’m missing?

let firstName = “Matt”
var lastName = “”

if firstName == “Matt” {
let lastName = “Galloway”
} else if firstName == “Ray” {
let lastName = “Wenderlich”
}

let fullName = “(firstName) (lastName)”

print(fullName)

Just to add some context. If I print lastName at the end I just get a blank, and if I print full name I just get Matt.

Hi @matrausc and welcome to Forums!

The reason you are seeing this is because you are re-creating the lastName variable within each condition block with the keyword let prior to each assignment, try removing it:

if firstName == “Matt” {
    lastName = “Galloway”
} else if firstName == “Ray” {
    lastName = “Wenderlich”
}
1 Like

Thanks for your reply, can’t believe I missed that! I needed to modify the instance, and by declaring ‘let’ I was in effect taking an action to recreate it. I appreciate your help!