johnnybutler
09-20-2005, 12:56 PM
I have manged to create a circle object but when i call the getArea() function i get an alert box with "Undefined" as the error message. I tried to pass back a number to test but i got the same "Undefined Message". Any Ideas?
Exercise8.html
<head>
<script type="text/javascript" src="Circle.js"></script>
<script type="text/javascript">
function disp_alert(){
bigCircle = new Circle(100);
alert(bigCircle.getArea);
}
</script>
</head>
<body>
<form>
<input type="button" onclick="disp_alert()" value="Display alert box">
</form>
</body>
</html>
Circle.js
function Circle(radius){
this.radius = radius;
}
function getArea(){
return this.radius;
}
function getCircumference(){
var diameter = this.radius*2;
var circumference = diameter*3.14;
return circumference;
}
Exercise8.html
<head>
<script type="text/javascript" src="Circle.js"></script>
<script type="text/javascript">
function disp_alert(){
bigCircle = new Circle(100);
alert(bigCircle.getArea);
}
</script>
</head>
<body>
<form>
<input type="button" onclick="disp_alert()" value="Display alert box">
</form>
</body>
</html>
Circle.js
function Circle(radius){
this.radius = radius;
}
function getArea(){
return this.radius;
}
function getCircumference(){
var diameter = this.radius*2;
var circumference = diameter*3.14;
return circumference;
}