Background: I was an intern at my current place of work for a year, until May when I was hired in full time. I am a programmer and I develop mostly mobile apps, but some web apps as well. Since then, we've hired several interns, and 2 of them are under my command. The reasoning here being that my boss wants me to learn to delegate and to solidify what I've learned by teaching it to another person.
So, the context is I gave my intern an important, but small task. He was to program something in the project I'm working on. Either he misunderstood the task or I did not do a well enough job explaining it, but he did it wrong. His work is so far incomplete, but I can tell from what he has written that it wont work and that he misinterpreted the task (or, it was not explained well enough) and the way he went about completing the incorrect task is not good. In his defense, he's in his second year of college and I am graduated, so I've a few years of education and a whole year of work experience ahead of him. I want to scrap his code, write my own, and explain to him how and why I coded it that way, but I don't want him to feel dumb or feel defeated about the failure. The reason I am worried he may feel dumb is because I have no idea how he intended it to work and also because to me it feels like a dumb way to do it, but I am acutely aware of the fact that I also wrote dumb stuff during my internship and I am still writing dumb stuff compared to many many other people. Yet, he failed. We all fail at some time or another.
So, how do I take over his task and explain how to do it right without him feeling defeated about the failure?