/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title> Assert </title> <style> .pass:before { content: 'PASS: '; color: blue; font-weight: bold; } .fail:before { content: 'FAIL: '; color: red; font-weight: bold; } </style> </head> <body> <ul id="output"></ul> <script> var output = document.getElementById('output'); // Via Resig function assert( outcome, explanation ) { var li = document.createElement('li'); li.className = outcome ? 'pass' : 'fail'; li.appendChild( document.createTextNode( explanation ) ); output.appendChild(li); } assert( Array.prototype.each, 'Checking if the each method of the Array object is available, as an example.' ); </script>