Most importantly take a look at the style. I’m using globals since the it seems more clear this way, but I am aware it is considered bad practice.

when I run it I get an error in the console “error: cannot read property ‘done’ of undefined.” I guess the function should return a value which is a promise. But how do I do that? Looking for best practices.