JSFiddle - React, Tailwind, and code Playground

HTML

<input type="button" id="test" value="Ping these!"/>
<table>
    <tr>
        <td>US</td>
        <td><div id="statusUS" value="128.114.119.137"></div></td>
    </tr>
    <tr>
        <td>Europe</td>
        <td><div id="statusEU" value="192.38.44.238"></div></td>
    </tr>
</table>

JavaScript

$("#test").click(function(){
    //Pinger_ping("128.114.119.137"); //http://genome.ucsc.edu/
    
    $("div").each( function(){
        var msg = this.id;
        var ip = $(this).attr("value");
        var avg = 0;
        var cpt = 0;
        var i=0;
        for(i=0; i<10;i++){
            var ping = $.now();            
            $.ajax({ type: "HEAD",
                    url: "http://"+ip,
                    cache:false,
                    complete: function(output){ 
                        ping = $.now() - ping;
                        //alert("#"+ip+" Response "+ping);
                        
                        if (ping < 1000) { // 1 times out of 2, the diff is not computed
                            cpt++;
                            avg+= ping/cpt - avg/cpt; //update average val
                            $("#"+msg).text(avg+" ms (on "+cpt+"tests)");
                            if(avg < 200) {
                                $("#"+msg).css({"color": "green"});
                            } else if (avg < 500) {
                                $("#"+msg).css({"color": "orange"});
                            } else {
                                $("#"+msg).css({"color": "red"});
                            }                                
                        }
                    }
              });
        }        
    });
});