javascript, figuring out what's wrong

Fayd

Diamond Member
Jun 28, 2001
7,970
2
76
www.manwhoring.com
I'm trying to code up a power and sample size calculator to put on a website, and I don't really have access to the backend of the website. So i'm limited to the things I can do with html and on-PC rendering, rather than making calls to some sort of backend language.

So i'm pretty much stuck with javascript. I don't know my ass from a hot rock with javascript.

I realize I could just find another PSS calc and copy the source code, but if it isn't public domain code, that's not really a good move. I did find a public domain Z calculator, and from there the actual calculation to move it into sample size is just simple algebra.

but when i try to merge the public domain Z calculator into

How it works:

user enters desired alpha, beta.
user enters mu0,mu1,sigma

calculate cumulative p value, power associated. (1-alpha, 1-beta...sticking with 1 sided test for now. will add radio button to select 1-sided vs 2-sided after i get it working)
calculate critical Z values associated with the p-value, power. <-- get stuck here. values not being calculated, not sure why

simple math calculation, spit out n.


The problem is I can't figure out how to trace what's happening through the program, or see if anything is happening at all. it took awhile to get to this point until I realized that the text inputs are entered as strings and javascript doesn't do on the fly retyping.


So...does anyone know of a user friendly debugging tool that will allow me to track the value of items as they change through functions?
 

Fayd

Diamond Member
Jun 28, 2001
7,970
2
76
www.manwhoring.com

I tried firebug, but I wasn't making progress.

edit:

hmm... found the firebug console, but now i'm even more confused. when i try everything i do on the page in the console, it works just fine. this is messed up.

edit2:

now i figure out what's wrong. the Z calculator is returning the Z value as a string instead of a number. *sigh*
 
Last edited:

smackababy

Lifer
Oct 30, 2008
27,024
79
86
Your main problem is you're using Javascript and Javascript is stupid. Have an error or using a function not supported by your browser? No problem! Javascript will kind of run on it anyway!

Can you post the snip of code you're having an issue with? It might not be Javascript released and a formula problem. That is just a guess though, it could be entirely Javascript related.
 

Train

Lifer
Jun 22, 2000
13,599
90
91
www.bing.com
Best thing to do if you want help, is to put your prototype in jsFiddle, then you can share what you've done here. Then others can see what you are doing, as well as fork it to suggest modifications.

http://jsfiddle.net
 

Fayd

Diamond Member
Jun 28, 2001
7,970
2
76
www.manwhoring.com
Your main problem is you're using Javascript and Javascript is stupid. Have an error or using a function not supported by your browser? No problem! Javascript will kind of run on it anyway!

Can you post the snip of code you're having an issue with? It might not be Javascript released and a formula problem. That is just a guess though, it could be entirely Javascript related.

No, it was definitely a javascript problem.

I finally got it working. even found the math.ceil() function to make the req sample size work properly.

now I just have to implement the radio buttons to make it one-sided vs two sided, and it'll be good.
 

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
You can get a long way with two pieces of information for chrome.
1) F12 to bring up the dev tools, there is a console tab, use it.
2) console.log(something) will print something to the console.

The combination of which is a crude but capable debugging system that you can use until you get your bearings a bit better. Any exceptions will also show up there allowing you at least to work out what line went wrong and maybe the reason why.
 

smackababy

Lifer
Oct 30, 2008
27,024
79
86
You can get a long way with two pieces of information for chrome.
1) F12 to bring up the dev tools, there is a console tab, use it.
2) console.log(something) will print something to the console.

The combination of which is a crude but capable debugging system that you can use until you get your bearings a bit better. Any exceptions will also show up there allowing you at least to work out what line went wrong and maybe the reason why.

I don't even go that far. I simply use the alert() function to give me an idea at what is being spit out. It is incredibly crude, but it gets the job done. I try and do as little in JS as possibly though.
 

purbeast0

No Lifer
Sep 13, 2001
53,764
6,645
126
google chrome is by far the best browser to develop in due to their developer tools. their tools are superior to shitty firebug in every single way possible.

I don't even go that far. I simply use the alert() function to give me an idea at what is being spit out. It is incredibly crude, but it gets the job done. I try and do as little in JS as possibly though.

that is 100% nub tactics that i would never recommend. good luck trying to display the data in an alert of an actual object in javascript. throwing up alerts is also bad due to the async aspect of javascript, and that anything else being held up on the "alert" thread won't execute until you press OK, and it can throw off the timing of execution. console.logs you don't have that problem though, which can be very useful if you just want to see if a certain piece of code has been hit or just want to see a string variable.

just toss a break point in there and look at the data in the debugger.

again, STRONGLY recommend chrome for devving.
 
Last edited: