Why is our conditional statement not working well?