JSFiddle - React, Tailwind, and code Playground

by Weston Ruter

HTML

<ol></ol>

CSS

li {
    white-space: pre;
    list-style: decimal;
    font-family: monospace;
    display:list-item;
    margin-left:2em;
}

JavaScript

function log(msg, assertion){
    var li = document.createElement('li');
    li.appendChild(document.createTextNode(msg));
    document.querySelector('ol').appendChild(li);
    if(typeof assertion != 'undefined'){
        li.style.color = assertion ? 'green' : 'red';
    }
}

try {
    var url = 'http://localhost:3131/example.com.js';
    log("Attempting to access " + url);
    
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.setRequestHeader('Pragma', 'no-cache');
    xhr.onreadystatechange = function(){
        log('readyState = ' + xhr.readyState);
        if(xhr.readyState == 4){
            isSuccess = xhr.status == 200 || xhr.status == 304;
            log('status = ' + xhr.status, isSuccess);
            if(isSuccess){
                log(xhr.responseText, true);
            }
        }
    };
    xhr.send(null);
}
catch(e){
    log(e.message, false);
}