help with function and array

January 28, 2010 at 03:33:26
Specs: Windows Vista
hi all need help with this im trying to find the difference between 2 numbers in an array that conatns 4 and display the results i keep getting unidenified her is the code that i have done so far can you please help
<SCRIPT>


var numberArray = [16,14,4,5];

function difference()
{
difference = (firstNumber=[1], secondNumber=[0]);
difference = (firstNumber - secondNumber);

}


document.write( difference() + '
');
difference();
</SCRIPT>


See More: help with function and array

Report •


#1
January 28, 2010 at 04:05:54
maybe try replacing this line:
difference = (firstNumber=[1], secondNumber=[0]);

to:
firstNumber=numberArray[1] ;
secondNumber=numberArray[0] ;

then proceed with your code as written...
difference = (firstNumber - secondNumber);



Report •

#2
January 28, 2010 at 04:24:27
still comes back as undefined

Report •

#3
January 28, 2010 at 04:56:58
my C++ knowledge is very limited, hope you get good help...
but is this allowed?
var numberArray = [16,14,4,5];
(assignment of values at time of creation and if so,
syntax of expression value vs. ubound and dimensions)

what about:
int numberArray[10] ;
numberArray[1]=16 ;
numberArray[2]=14 ;
numberArray[3]=4 ;
numberArray[1]=5 ;



Report •

Related Solutions

#4
January 28, 2010 at 05:24:06
hi thanks for you help got it woking with the following;
<SCRIPT>


var numberArray = [16,14,4,5];

function difference()
{
firstNumber=numberArray[0] ;
secondNumber=numberArray[1] ;
return firstNumber-secondNumber;
}


document.write(difference() + '
');
</SCRIPT>
now do you now were i can get a copy of a programm called diffy boxes has code like i am writing so i can see how the rest of it works


Report •

Ask Question