If you're looking for a quick and easy solution, try this approach:
document.write( "text" ) //de ...or:
document.writeln( "text" )
For a more sophisticated method, consider creating a DOM element to write your text into. Here's an example:
Start by adding an element like
<div id="console"></div>
in your HTML (you can also do this with JavaScript), then:
function debug_output( text ) {
document.getElementById( "#console" )
.insertAdjacentHTML(
'beforeend',
'<span class="debug_output">' + text + '</span><br/>'
);
//de thanks to @cookiemonster for the .appendChild fix
}
If your aim is to display plain text in the browser, I'll show you how to bypass using console.log
and instead write directly to the browser.
The second code snippet provided allows you to achieve that, giving you the flexibility to style or position your debug output as needed.
Here's the full solution implementing the "more elegant" way mentioned above:
if ( 11 > 10 ) {
debug_output("You made it!")
} else {
debug_output("You have just died!")
}