• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ESTK error "Can not assign value"

Community Expert ,
Apr 07, 2016 Apr 07, 2016

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?

TOPICS
Scripting

Views

494

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Apr 07, 2016 Apr 07, 2016

Hi Klaus,

just change your line 12 to

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

That should work.

Votes

Translate

Translate
Enthusiast ,
Apr 07, 2016 Apr 07, 2016

Copy link to clipboard

Copied

Hi Klaus,

just change your line 12 to

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

That should work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2016 Apr 08, 2016

Copy link to clipboard

Copied

LATEST

Au weia,

such simple syntactic error not spotted - shame on me!

Klaus

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines