I am new to web dev and recently I learning DOM. However, I have a problem that had been bugging me . I am trying out to make a simple sphere volume calculator where the user can get the volume of sphere by inputting the radius.
Here is the code.
HTML
Enter the sphere radius : <input type="number" id="radius">
<button id=>Calculate !</button>
<p>Therefore, the volume of sphere are: <span id="volsphere"></span> </p>
JS
var radius = document.querySelector("#radius");
var volsphere = document.querySelector("#volsphere");
volsphere.addEventListener("click",function(){
//calculate the sphere volume
var spherevolume = (4/3) * Math.PI * Math.pow(radius,3);
//put the text content into sphere volume
volsphere.textContent = spherevolume ;
});
I try working it out by troubleshooting the console log radius.value and spherevolume.value.
Radius appeared to be fine and giving me "3" but sphere volume have this error message of
VM97:1 Uncaught ReferenceError: spherevolume is not defined at :1:1
So, which part of the code is giving out this error ? Thank you to those who helps
<button id=>Calculate !</button>You should fill in a value for the button's id attribute or remove the attribute altogether.