# The problem with the JS: Maximum call stack size exceeded

I am trying to program a calculator for my blog. I have 2 input fields [X1] and [X2] and the result field [Y1], I used if else if but since the test run is long I get “Maximum call stack size exceeded” error, how can I solve this problem?

if(x[1]>=0 && x[1]<=1409.99 && x[2]>=0 && x[2]<=5) {y[1]=0;}
else if((x[1]>=1410.00 && x[1]<=1939.99 && x[2]>=1 && x[2]<=5) ||
(x[1]>=1940.00 && x[1]<=2229.99 && x[2]>=2 && x[2]<=5) ||
(x[1]>=2230.00 && x[1]<=2519.99 && x[2]>=3 && x[2]<=5) ||
(x[1]>=2520.00 && x[1]<=2819.99 && x[2]>=4 && x[2]<=5) ||
(x[1]>=2820.00 && x[1]<=3109.99 && x[2]==5)) {y[1]=0;}

else if(x[1]>=1410.00 && x[1]<=1419.99 && x[2]==0) {y[1]=5.4;}
else if(x[1]>=1420.00 && x[1]<=1429.99 && x[2]==0) {y[1]=12.4;}
else if(x[1]>=1430.00 && x[1]<=1439.99 && x[2]==0) {y[1]=19.4;}
else if(x[1]>=1440.00 && x[1]<=1449.99 && x[2]==0) {y[1]=26.4;}
else if(x[1]>=1450.00 && x[1]<=1459.99 && x[2]==0) {y[1]=33.4;}
else if(x[1]>=1460.00 && x[1]<=1469.99 && x[2]==0) {y[1]=40.4;}
else if(x[1]>=1470.00 && x[1]<=1479.99 && x[2]==0) {y[1]=47.4;}
else if(x[1]>=1480.00 && x[1]<=1489.99 && x[2]==0) {y[1]=54.4;}
else if(x[1]>=1490.00 && x[1]<=1499.99 && x[2]==0) {y[1]=61.4;}
else if(x[1]>=1500.00 && x[1]<=1509.99 && x[2]==0) {y[1]=68.4;}
else if(x[1]>=1510.00 && x[1]<=1519.99 && x[2]==0) {y[1]=75.4;}
else if(x[1]>=1520.00 && x[1]<=1529.99 && x[2]==0) {y[1]=82.4;}
else if(x[1]>=1530.00 && x[1]<=1539.99 && x[2]==0) {y[1]=89.4;}
.
.
.
.
.else if(x[1]>=4190.00 && x[1]<=4199.99 && x[2]==0) {y[1]=1951.4;}
else if(x[1]>=4190.00 && x[1]<=4199.99 && x[2]==1) {y[1]=1129.98;}
else if(x[1]>=4190.00 && x[1]<=4199.99 && x[2]==2) {y[1]=786.38;}
else if(x[1]>=4190.00 && x[1]<=4199.99 && x[2]==3) {y[1]=501.58;}
else if(x[1]>=4190.00 && x[1]<=4199.99 && x[2]==4) {y[1]=275.58;}
else if(x[1]>=4190.00 && x[1]<=4199.99 && x[2]==5) {y[1]=108.39;}

else {y[1]=7777;}

I have to ask. What type of calculator are you trying to program?

1 Like

it is not a real calculator in the sense that it is just a check input that calculates the seized amount. the user enters how much he earns in [X1] and how many people live in his household and appends a table “seizure table” which gives the user the result of how much is seized.

And how many `else/if` statements do you have? Seems like there should be a formula you can use to calculate this, which would allow you to get rid of most of those `else/if`s.

Regarding the call stack issue, you’ll probably need to give us all of your code. While having all those `else/if` statements is not ideal, I don’t think they are the cause. Are you using a recursive function call anywhere? Are you looping and the loop doesn’t stop? You haven’t given us enough information to help with this problem.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.