I have following Html file with javascript. This gives me error that “testCircle is undefined.” kinldy help me resolve this.
<html>
<body>
<h1> Testing Object-based Javascipt </h1>
<script type="text/javascript">
function mycircle(x,y,r)
{
this.xcoord=x;
this.ycoord=y;
this.radius=r;
this.area = getArea;
this.getCircumference = function () { return (2 * Math.PI * this.radius ) ; };
}
function getArea()
{
return (Math.PI * this.radius * this.radius);
}
var testCircle = mycircle(3,4,5);
window.alert('The radius of my circle is ' + testCircle.radius);
</script>
</body>
</html>
Thanks in advance….
should be
Constructors are to be called with the
newkeyword. If the keyword is not used, you’re assigning the return value of themycirclefunction. And asmycirclecontains noreturnstatement, the return values isundefined– that’s what you assigned totestCirclein your code.