Coding without losing motivation

How can I learn coding at home without losing motivation ? Everyone needs to motivation to do something. If he will not confident and motivate then he will degrade. So to be motivate is really important for us.