Martin46766474
05-09-2003, 11:46 PM
I've searched for an hour and can't find the answer to this (no doubt simple) question so can someone put me on the right track?
In my script there is a section of code that is used twice, similar to this example:
var x = 3
var y = x + 4
var z= y * 2
var zz= y * 5
alert ("First - "+z+" - "+zz);
var x = 6
var y = x + 4
var z= y * 2
var zz= y * 5
alert ("Second - "+z+" - "+zz);
What I want to do is create a function:
function calculate () {
var y = x + 4
var z= y * 2
var zz= y * 5
}
So altogether I'd have something like this:
function calculate () {
var y = x + 4
var z= y * 2
var zz= y * 5
}
var x = 3
calculate();
alert ("First - "+z+" - "+zz);
var x = 6
calculate();
alert ("Second - "+z+" - "+zz);
How do I return z and zz so that they can be used?
In my script there is a section of code that is used twice, similar to this example:
var x = 3
var y = x + 4
var z= y * 2
var zz= y * 5
alert ("First - "+z+" - "+zz);
var x = 6
var y = x + 4
var z= y * 2
var zz= y * 5
alert ("Second - "+z+" - "+zz);
What I want to do is create a function:
function calculate () {
var y = x + 4
var z= y * 2
var zz= y * 5
}
So altogether I'd have something like this:
function calculate () {
var y = x + 4
var z= y * 2
var zz= y * 5
}
var x = 3
calculate();
alert ("First - "+z+" - "+zz);
var x = 6
calculate();
alert ("Second - "+z+" - "+zz);
How do I return z and zz so that they can be used?