Copy link to clipboard
Copied
Dear friends, a new project has started - and of course new problems arise:.
The function SumOf (list of values) works perfectly,
but an equivalent function VsumOf (list of variables) stops at line 16 in the first iteration of the loop: Can not assign value.
At this point the variable result is just -132.09 - way out of some sort of numeric problem.
var z = SumOf (11.1, -11.9, 12345679.0, -12345679.0, 124.5, -17, 18.9, 2.2, 2.5, 2.5, 2.5, 31.31, 312345679, -312345679);
alert ("SumOf the numbers = " + z); // giving 166.610000014305 (figures after the 000 are artifacts)var z = VsumOf (11.1, -11.9, 12345679.0, -12345679.0, 124.5, -17, 18.9, 2.2, 2.5, 2.5, 2.5, 31.31, 312345679, -312345679);
alert ("VsumOf the numbers = " + z);function VsumOf (valuePairs) {
var nArguments = arguments.length;
var j, z, result = 0;
if (Math.floor(nArguments/2) * 2 !== nArguments) {return undefined;}
for (j = 0; j < nArguments; j=++2) {
if (isNaN(arguments)) {return NaN;} // should be skipped in calling environment
if (isNaN(arguments[j+1])) {return NaN;}
z = arguments* arguments[j+1];
result = result + z; // <<== Can not assign value ???
}
return result;
}// this one works correctly
function SumOf (values) {
var nArguments = arguments.length;
var j, result= 0;
for (j = 0; j < nArguments; j++) {
if (isNaN(arguments)) {return NaN;} // should be skipped in calling environment
result = result + arguments;
}
return result;
}
Any ideas what this error message really means?
Hi Klaus,
just change your line 12 to
for (j = 0; j < nArguments; j=j+2) {
That should work.
Copy link to clipboard
Copied
Hi Klaus,
just change your line 12 to
for (j = 0; j < nArguments; j=j+2) {
That should work.
Copy link to clipboard
Copied
Au weia,
such simple syntactic error not spotted - shame on me!
Klaus