You could use a Promise which is a technique to manage long-term asynchronous events and avoid callback-hell. In regular Opal you would do for example: HTTP.get("url") do |response| puts "got response" end With promises, this becomes: HTTP.get("url").then do |response| puts "got response" end The difference lies in the then which...
The Math module is in Opal's stdlib and isn't included in the default runtime (as far as I can tell). Depending on your deployment context, it might be easiest to build the Math module (Opal::Builder.build('math')) into a file. For your specific example, though, you can just use the JS PI...