My code explains pretty much everything in comments and my failed solutions are here too. Let me know if you need clarification. Good luck!
function getAngle(