Skip to main content
K.Daube
Community Expert
Community Expert
April 7, 2016
Answered

ESTK error "Can not assign value"

  • April 7, 2016
  • 1 reply
  • 659 views

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?

This topic has been closed for replies.
Correct answer Klaus Göbel

Hi Klaus,

just change your line 12 to

  for (j = 0; j < nArguments; j=j+2) {

That should work.

1 reply

Klaus Göbel
Klaus GöbelCorrect answer
Legend
April 7, 2016

Hi Klaus,

just change your line 12 to

  for (j = 0; j < nArguments; j=j+2) {

That should work.

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
April 8, 2016

Au weia,

such simple syntactic error not spotted - shame on me!

Klaus