Don't know how to output this array

LOL! I thought there was just one!

I’m not getting the results I expected. For instance, if the array contained spurs of 72, 75, 78, 81, 84, then I would expect the results to give me the same spur range, but different pinions, for example, 87/26 = 3.346, 87/27 = 3.222. The floor and ceiling was supposed to apply to the pinion tooth amount, rounding up and rounding down, but still keeping the same spurs.

Instead I am getting 720/23, 751/24, 782/25 – no one uses spur gears containing 720 teeth! Somewhere our approach went off, although the ratio numbers are very similar to the original ratio, which is good.

Among the results are good numbers, like 78/24, 81/25, and 84/26, in which the first number is the same as the number in the array, and the divided/by results with numbers similar to the ratio numbers – which is the useful numbers we want. Numbers outside the array are not acceptable because spur gears are not available or appropriate for that application.

If I choose SC8: 50, 52, 54, then none of the numbers are appropriate, since none are numbers found in the array (720/36, 72/36, etc.)

Look at this part of the code;

spurs[i] + i + '/' + pinionUp

That + i part should not be there.

If you type in 50 for Spur then 17 for rPinion, you get a ratio of 2.94117.
Then you choose “SC8: 50, 52, 54” because that has a spur the same as the one you put in the top Spur box. However, none of the results give me a spur found in that array. It gives me the default spur array.

Currently your gearSpurs function is called using the calculated ratio.


spurs = gearSpurs(ratio),


That’s no good - as you need to pass the ratio range from the selection box instead.


spurs = gearSpurs(form.elements.ratio.value),

THOSE are the results I expected! Now I’ll do some homework and see how to limit the decimals to 2 places. Thanks for your help!

You can use .toFixed(2) to limit numbers to two decimal places.

OK, I figured out where to put your 2-place code. One final thing – I should be able to enter a number in the ratio box without adding any numbers in the Spur and Pinion boxes at top. But the code won’t execute. Any reason why it won’t read the top form?

Your attached code from earlier plus the fixes seems to work fine in that regrad.

Show us what you are using now, and we’ll find the problem.

Zipped HTML. Thanks for your time!

I won’t at this station tomorrow. I’ll be back in on Friday.

I am using this on the iPhone only, so it only needs to work in Safari. If there’s no workaround, then we can consider this finished. The people will be very happy to have it as is!

I really appreciate all your hard work. You are truly a Javascript Guru!

The Windows version of the Safari web browser doesn’t seem to have any trouble either. I’ll see if I can find an iphone simulator. Ahh, here’s one.
iBBDemo2 - Cross Platform iPad and iPhone Simulator

That seems to work too, with your test code that I have up at:
Gear Ratio

You’re very welcome. Thanks.

I just tried it in Safari on the Mac. Typing a number in either of the top boxes generates “not valid.”

Strange!