I have a javascript object which describes the radius of a hemisphere and the volume. I'd like to be able to change the radius and then access the volume with hemisphere.volume
and it would return the volume for the current radius. I thought something like this would be possible but I'm getting NaN
back from it when I call hemisphere.volume
from the console.
var hemisphere ={radius:6,volume:Math.pow(this.radius,3)*4*Math.PI/6};
Then I thought I could do this as a function like:
var hemisphere ={radius:6,volume:function({Math.pow(this.radius,3)*4*Math.PI/6}};
This gives me 'undefined' when I call problem.answer()
from the console.
Any ideas how I can do this?