Let me preface this by stating that the code provided is not my own. As a novice hobbyist coder delving into the realm of Javascript, I have turned to a book in hopes of expanding my knowledge. However, a setback has emerged as the publisher's website lacks the necessary files for the exercises within the book.
The aim of the code snippet below is to display the contents of the 'str' variable upon execution. Yet, instead of the expected output, all I see is a blank screen when running it. Despite scouring for glaring typos, none have surfaced. Initially setting up an HTML document like so:
<html>
<head>
<title>Variable</title>
<script type = "text/javascript" src = "variable.js">
obj.innerHTML = str + ":" + typeof str;
</script>
<body>
<div id = "panel"> </div>
</body>
I proceeded to input the output code in Notepad and saved it in the same directory as the HTML file. Additionally, saving the code as a JavaScript file in that very location.
The aforementioned output code is as follows:
function init()
{
//STATEMENTS TO BE EXECUTED GO HERE
var str = "Text Content in Javascript";
obj.innerHTML = str + ":" + typeof str;
}
document.addEventListener( "DOMContentLoaded", init, false);
Based on my limited understanding of JavaScript, it appears that the script responsible for displaying the result remains unseen. Puzzlingly enough, the reason behind this eludes me – either due to oversight or some other blatantly obvious factor. Where exactly does the missing piece lie?