Have you written code that worked, then broke it, only to not remember what the working code was?
Git, a version control application could be the solution you are looking for. Git can help you to track changes in your projects, go back to when your code is working, or even find out where it broke. You can use it in collaboration with a team or as the only developer on a project.
Learn the commands that are used every day as well as a few that can help you recover from mistakes.