Looking at this example.

admin

Administrator
Staff member
I'm looking at the following example code to make sure that I'm doing everything correctly.

Code from DevGuru site:
-----------------------------
function describeAge(obj)
{
if(obj.year < 1996)
return "Old-fashioned"
else
return "Good-as-new"
}

function car(make, year, description)
{this.make = make, this.year = year, this.description = describeAge(this)}

myCar = new car("Ford", "1993", describeAge(this))
-----------------------------

Just that code if I am correct would not create any visable data, to be shown on the page.

First off though in the function car, the this.description = describeAge(this), wouldn't (this), be (obj). Aren't you wanting to call upon that function to get the description?

Anyway you would create another function to actually have it display something on the screen in I am correct. Aren't I?

Also, just as a clarification.
The parameters are what I want the return values to be?
And if I want to change those parameters within a script I'd use return (Variable name) correct?

ie-

function AgeDifference(YourCarAge)
{
Age= (11 - YourCarAge);
return Age;
}

function ShowAge()
{
var YourCarAge=prompt("Your Car Age Is?","");
var myCarAge= AgeDifference(Age);

document.writeln("The Difference is " + YourCarAge + " years.");
}
 
Back
Top