In code below I'm creating a circle objects and giving it's keys some values. I'm setting the radius property of the circle object to it's diameter divided by 2. When we console.log it's value, it returns NAN. How to fix this problem?
let circle = { posX: 40, posY: 70, diameter: 30, radius: this.diameter/2 } console.log(circle.radius)
thisdoes not refer tocircle. You could callcircle.radius = circle.diameter/2after the initial assignment or add it as a function to the object.radiusand thediameterattributes, when you can easily calculate one from the other if/when you need it?