HI everyone
i can't figure out what's wrong with this one code
[CODE=javascript]var a=[1,2,3,4,5,6];
var len=a.length;
var med=len/2;
if (len%2==0)
median=(a[med]+a[med-1])/2;
else
median=a[Math.floor(med)];
alert(median); [/CODE]
and the right answer is 3.5 but why is it when i put it into my code and enter the same number it ends up being 22.5
here my code
[CODE=javascript]var med= len/2; // length divided by 2
if (len%2==0)
median=(new_arr ay[med]+ new_array[med-1])/2;
else
median=new_arra y[Math.floor(med)];[/CODE]
can someone help me? I can pm the whole code if needed thanks
i can't figure out what's wrong with this one code
[CODE=javascript]var a=[1,2,3,4,5,6];
var len=a.length;
var med=len/2;
if (len%2==0)
median=(a[med]+a[med-1])/2;
else
median=a[Math.floor(med)];
alert(median); [/CODE]
and the right answer is 3.5 but why is it when i put it into my code and enter the same number it ends up being 22.5
here my code
[CODE=javascript]var med= len/2; // length divided by 2
if (len%2==0)
median=(new_arr ay[med]+ new_array[med-1])/2;
else
median=new_arra y[Math.floor(med)];[/CODE]
can someone help me? I can pm the whole code if needed thanks
Comment