2 Replies Latest reply on Apr 8, 2016 4:14 AM by K.Daube

    ESTK error "Can not assign value"

    K.Daube Level 1

      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[j])) {return NaN;}        // should be skipped in calling environment
          if (isNaN(arguments[j+1])) {return NaN;}
          z = arguments[j] * 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[j])) {return NaN;}        // should be skipped in calling environment
          result = result + arguments[j];
        }
        return result;
      }
      

      Any ideas what this error message really means?