I believe the answer is: when they work hard.
In this situation, the teacher need to realize that there is always a potential of failure when people are trying to solve challenging task.
So, the teacher need to prepare the students to stay positive under such situation as long as they've given their best effort.