I'm a beginner with node.js and I have a problem after evaluating evalMath() function. Especially, assigning the value of Math2 to yScale.
Math2 is an input box of a web page, which is introduced a simple equation like 'Ir = Vr/R'. This string value is passed from the web page to the web server implemented on node.js. In there, the function evalMath() is executed, which replaces Vr (with a string) and R with a respective integer value. After executing this function is obtained something like this 'ANI0[i]-ANI5[i]/10', which is stored in the variable Math2. The function works perfectly. However, when Math2 is assign to yScale only saves 'Ir = Vr/R' and not the string obtained after executing the evalMath() --> 'ANI0[i]-ANI5[i]/10'. I don't know exactly why.
if (yScale == 'Math2') {
console.log('Math2 selected');
evalMath(textAD0,textAD1,textAD2,textAD3,textAD4,Math2,Rb,Rc,R,yScale);
yScale = Math2;
console.log ("yScale: "+ yScale);
} else {
console.log("Nothing to change :) - No eqn");
}
function evalMath(labelAD0, labelAD1, labelAD2, labelAD3,
labelAD4, entry, entry1, entry2, entry3, entry4) {
iAD0="",iAD1="",iAD2="",iAD3="",iAD4="",iR="",iRb="", iRc="", iEq="";
var iAD0 = entry.search(labelAD0);
var iAD1 = entry.search(labelAD1);
var iAD2 = entry.search(labelAD2);
var iAD3 = entry.search(labelAD3);
var iAD4 = entry.search(labelAD4);
var iR = entry.search('R');
var iRb = entry.search('Rb');
var iRc = entry.search('Rc');
var iEq = entry.search('=');
if (iAD0 > "0"){ entry = entry.replace(labelAD0,'(ANI0[i]-ANI5[i])'); }
else{console.log("Nothing to change AD0")}
if (iAD1 > "0"){ entry = entry.replace(labelAD1,'(ANI1[i]-ANI5[i])'); }
else{console.log("Nothing to change AD1")}
if (iAD2 > "0"){ entry = entry.replace(labelAD2,'(ANI2[i]-ANI5[i])'); }
else{console.log("Nothing to change AD2")}
if (iAD3 > "0"){ entry = entry.replace(labelAD3,'(ANI3[i]-ANI5[i])'); }
else{console.log("Nothing to change AD3")}
if (iAD4 > "0"){ entry = entry.replace(labelAD4,'(ANI4[i]-ANI5[i])'); }
else{console.log("Nothing to change AD4")}
if (iRb > "0"){ entry = entry.replace('Rb',entry1); }
else{console.log("Nothing to change Rb")}
if (iRc > "0"){ entry = entry.replace('Rc',entry2); }
else{console.log("Nothing to change Rc")}
if (iR > "0"){ entry = entry.replace('R',entry3); }
else{console.log("Nothing to change R")}
if (iEq > "0"){ entry = entry.slice(iEq+1,entry.length); }
else{console.log("Nothing to change iEq")}
console.log("entry: " + entry);
return entry;
}