Week 3: Dancing Cat | Jonathon Haley

One of these is the LINK.

Same as everyone else, I made a simple webpage with Javascript functionality that makes a cat “dance” to the left and right upon clicking one of two buttons, as well as changing the caption by pushing another button. I built the main page as index.html, added some styling in css/style.css, and defined a few basic functions in js/script.js. As this is the first time I’ve used Javascript, I ran into an unexpected problem: the index.html page could not read the functions from the js file. Instead, whenever I clicked a button (which called one of three functions from the js file), I received the following error in the console: ReferenceError: <function name> is not defined. This was very odd. I checked the js file, and it seemed that I had defined the functions correctly, without syntax errors. I then checked the areas of the html file where I load the script and call the functions, but also couldn’t find anything to explain the error. In the end I directly copy-pasted the js functions inside the <script> section of index.html, and now the page works as intended. Since the functions themselves work, the error must have been in the way I loaded and/or called the functions in the html page, however I’m not sure exactly what the problem was.

Leave a Reply