+3

Can you help me with binomial distribution formula code? I don't know what I did wrong!

Here is the code: <html> <script> var sucess = tacpo/pokusaji var failure = 1 - sucess var pokusaji = prompt("Koliko ukupno ima pokusaja(max tries)?"); var tacpo = prompt("Koliko ima tacnih pokusaja(success tries)?"); var numberOfTries = prompt("Koliko rundi(n)?!"); var successtries = prompt("Koliko uspesnih rundi(X)?"); var failuretries = numberOfTries-successtries var success1 = Math.pow(parseInt(sucess),parseInt(successtries)); var fail1 = Math.pow(parseInt(failure),parseInt(failuretries)) var result = (parseInt(numberOfTries)/parseInt(successtries))success1fail1 var perc = result * 100 alert("Percentange is " + perc) </script> </html> Also binomial distribution formula is: (n/X) * success^X * failure^n-X

10/21/2019 1:37:07 AM

Stefan

8 Answers

New Answer

+9

Stefan remove the "success one fail" It should work. If you want it to alert that , then wrap your code in a condition statement (if else). #BestOfLucks

+4

Try to link a code from Code Playground into your question. Not only does this improve neatness, but it also helps us to debug it.

+4

It's hard reading a code with no identation, please write it in code playground then share it here. I didn't read the code yet, but I see missing semi-colons ';' at the end of decalation of many variable, try adding semi-colons and run it again. Also, in line twelve, you wrote success1fail1 directly after parenthese ')', you forgot to put an operator there.

+3

Try fixing it and test it, I don't know what the code does so I couldn't test

+2

Ah,ok

+1

Here is the written code in here https://code.sololearn.com/WjxDvzSsG6Mx/?ref=app

+1

Done! It is now available in code playground

+1

Stefan Change line 12 to var result = (parseInt(numberOfTries)/parseInt(successtries)) * success1 * fail1;