Help - Search - Members - Calendar
Full Version: Help me find bug
HTMLHelp Forums > Programming > Client-side Scripting
denmarks
I am working on a program a step at a time. A rarely do HTML and Javascript from scratch so I am always forgetting details.
So far this page should convert to binary. When the page appears just enter 6 numbers less than 64. Click enter and an alert should display the binary. I am getting an error that it can't find the function. I am sure it is something simple but Firefox is no help.

I get 2 errors
nimRoutine not found and ; missing.

I sure it is something simple but I can't find the error.

http://www.dmmarks.com/nim.html
pandy
Two things jump out. It's 'if', not 'If', lower case. You shouldn't use semicolon at the end of function braces. That's just at the end of statements.

With those changes, at least it does something and the errors go away. Alas it returns 0 for everything. But a step in the right direction anyway. wink.gif
denmarks
I found the problem. The VAR on the subtables.
pandy
That's not the only change you made.

Before
CODE
nimTable = new Array(5);
nimTable[0] = new Array(5);
nimTable[1] = new Array(5);
nimTable[2] = new Array(5);
nimTable[3] = new Array(5);
nimTable[4] = new Array(5);
nimTable[5] = new Array(5);


Now
CODE
var nimTable = new Array(5);
var nimTable[0] = new Array(5);
var nimTable[1] = new Array(5);
var nimTable[2] = new Array(5);
var nimTable[3] = new Array(5);
var nimTable[4] = new Array(5);
var nimTable[5] = new Array(5);


Using var when you declare the array is fine, but not when you set the individual values.
pandy
QUOTE(denmarks @ Jul 21 2013, 11:02 PM) *

I found the problem. The VAR on the subtables.


Now you tell me! tongue.gif
denmarks
Sorry. I'm still trying to get back into the swing of things. Now the problems are just logic.
pandy
Just joking. Happens all the time. wink.gif
denmarks
QUOTE(pandy @ Jul 21 2013, 02:49 PM) *

Just joking. Happens all the time. wink.gif


Thanks for your help. I am sure I will be back. I got the convert to binary working fine. That is all for today. I assume you know about the game of Nim. The algorithm is pretty simple. Converting it to code it what is tricky. I first programmed it for the IBM 1620 about 50 years ago. I thought I would create a Javascript. I did not like what was available.
pandy
No, I didn't. But I've read a little about it now.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.