And I mean the last solution. 

I have no idea how to write promise in JavaScript.