Javascript String Length Property Bug

MisterZuidema shared this problem 2 years ago
Not a Problem

When I run Javascript while I am editing using the offline version of Geogebra 5.0, the string length property requires the () at the end in order to (incorrectly) function properly, but when you upload the file to Geogebratube, it will only work when the () are removed. See code and comments below.


function ggbNoSpaces (s) {

snew = "";

slen = s.length(); // this code must be run when editing offline in Geogebra 5.0

// slen = s.length; // this code must be run when uploaded into GeogebraTube

for (i = 0; i < slen; i++) {

if (s.substr(i, 1) != " ") {

snew += s.substr(i, 1);

}

}

return snew;

}

Best Answer
photo

I don't think it's a bug.

that because all the variable will be treat as an "Object", not a "String。

so, you need add this statement at the beginning of the function "ggbNoSpaces":

s = ""+s

Comments (6)

photo
1

here, in ggb5 is ok.

please post your file to check the problem.

photo
1

File attached.

photo
photo
2

What version of GeoGebra 5 are you using?

photo
1

9398f36657287b6a6f21eab09371f1f3

photo
photo
1

I don't think it's a bug.

that because all the variable will be treat as an "Object", not a "String。

so, you need add this statement at the beginning of the function "ggbNoSpaces":

s = ""+s

photo
1

Thank you! That solved the issue, and I learned something new!

photo
© 2020 International GeoGebra Institute