I m trying to create a simple calculator in Javascript. I have an array named expression
chunk[0] = 12
chunk[1] = +
(the "+" sign)
chunk[1] = 5
我曾用 lo子(草) lo,然后加入如下单一表述:
equation = ""; // To make var equation a string
for(i = 0; i <= length; i++)
{
equation = equation + expression[i];
alert(expression[i]);
}
alert(equation);
alert(expression[i])
showed values 12, + and 5.
But alert(equation) showed 125 (instead of "12+5"). I need the variable equation to be "12+5" so that I can later call eval(equation) and get the value of 12+5.
我在这里做了什么错误?