math.random Javascript
Every time I do the function it always results in a chickenCount = 0. I've tried multiple ways to fix this but can't pinpoint it. Help would be greatly appreciated.
gamble.onclick = function() { if (chickenCount >= 1) { gamble = (Math.random()); console.log(gamble) if (gamble >= 0.5); (chickenCount = chickenCount * 2); if (gamble < 0.5); (chickenCount = 0); counter.innerHTML = chickenCount; gambled++; gamble.innerHTML = gamble;
SPQR
I'm not entirely familiar with JS, but the problem that stands out to me is that you don't have the chickenCount = 0
inside curly braces {}
. So, the program isn't actually doing chickenCount = 0
only if gamble < 0.5
, it's multiplying it by 2 and then setting it to zero every time regardless of gamble
's value.
JackFly26
I think I fixed it at https://repl.it/@ThatSmart/click
JackFly26
It looks like you are using 2 different variables called gamble. Did you mean to make the random number gambled?
Essentially it's just going down the list, it doesn't actually associate your
if
statements with yourchickenCount
modifiers.