I've gone from writing JavaScript code that displays results in the console to making things happen directly in the browser. ๐
Our JavaScript instructor recently introduced us to DOM and showed us how to make JavaScript interact with webpages.
Before then, all our outputs were displayed in the browser console.
For our latest assignment, we were asked to calculate the areas of different shapes. But this time, instead of displaying the answers in the console, we had to create input fields where users could enter values, click a button, and get their results directly on the webpage.
I was able to successfully calculate the areas of a triangle, square,circle and rhombus.
I also had my first proper debugging moment with this assignment.
Everything looked right, but my code wasn't working. I kept checking and checking until I eventually discovered that I'd misspelled a function name.
Imagine spending all that time debugging because of one misspelled word. ๐
I also ran into an issue with calculating the area of a quadrilateral. I discovered that even when an input field is set to accept numbers, JavaScript's .value property retrieves the user's input as a string rather than a number.
So, when I tried adding two values, instead of getting their sum, JavaScript joined them together. I'll be exploring how to handle this as we progress with our JavaScript classes.
I actually planned to finish the entire assignment tonight and even design the interface. Unfortunately, I forgot the cable I use to charge my laptop with my friend. The power bank is here, but the cable isn't. ๐ญ
So, I'm calling it a day.