Reputation:
I am trying to translate this statement into Actionscript:
"Sally is 5 years old. Jenny is 4 years old. The combined age of Sally and Jenny is 9 years."
This is what I have so far:
function getAges (sallyAge:Number,jennyAge:Number,combinedAge:Strin g)
{
trace("Sally's Age:" + sallyAge);
trace("Jenny's Age:" + jennyAge);
trace("Combined Age:" + combinedAge);
}
getAges (5,4,"9");
It works - but I would like to have it so that the Actionscript is actually doing the math. Would I declare a variable like
var combinedAge = sallyAge + jennyAge;
? And where would I put it? Thanks in advance for any assistance, I am really new to this.
Upvotes: 1
Views: 1590
Reputation: 245489
A simple way would be:
trace("Combined Age: " + (sallyAge + jennyAge));
or if you wanted to store the result and then print it:
var combinedAge:Number = sallyAge + jennyAge;
trace("Combined Age: " + combinedAge);
(both of those would replace the line that currently outputs the combined age)
Upvotes: 0
Reputation:
trace("Combined Age:" + (sallyAge + jennyAge));
This usually works in all languages. Put math between a '(' and a ')'
Upvotes: 1