<script>function Calculate (a,c,b) {if (c== ' + ') {var d=a+b;} if (c== '-') {var d=a-b;} if (c== ' * ') {var d=a*b;} if (c== '/') {var d=a/b;} return D;} Calculate (2, ' * ', 6); Cannot output result//alert (d); Alert (Calculate (2, ' * ', 6)); Can output normally </script>
The problem is listed, why?
OK, is the scope of the problem, is the scope of the problem, the function is declared with Var, is a local variable ~ ~ ~ minus the var can be normal output, but it is best not to do so, you can not assign the result to another variable:
<Script> functionCalculate (a,c,b) {if(c=='+'){returna+b;} if(c=='-'){returna-b;} if(c=='*'){returna*b;} if(c=='/'){returna/b;}} alert (Calculate (2,'*',6)); </Script>
I know this mistake is too low, but, I really did not find it at the beginning! Remember to remember!
JS Note 2--Amount, is the scope of the pit ~