As you build more complicated projects you need get better at troubleshooting.
When you troubleshoot you try to elminate parts of the project in order to find out where the problem is.
Check each component separately
Check the power source
Check the wiring
Check the code
You will get better at troubleshooting with practice. It is no good throwing up your arms and giving up. Slowing go through the steps of where the problem might be, and try to isolate that step, to see if it works.