This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Joel.Macke
almost 9 years

I've passed technically but testing the code proves something is wrong

I’ve technically passed as in my code works. But I kept noticing that the same name would pop up as the “winner” I tested it by replacing the name and the name would switch to the top name. I’m thinking something happens when I sort it and then randomize it. Would it change if I increased the number of people?

Answer 552203e095e3782c9c00048e

2 votes

Permalink

hi joel-

your issue is coming from this line: $lotteryS = sort($lottery);

the sort() function does not return the sorted array, it sorts the one you pass it; it returns 1. this means that your count($lotteryS) is always returning 1 and giving you the same winner each time.

take out $lotteryS = and just leave sort($lottery);, replace $lotteryS in your count() call and see what happens!

points
Submitted by David Fudge
almost 9 years

1 comments

Joel.Macke almost 9 years

Hi David,

Thanks for responding. If I understand you correctly, by putting $lotteryS=sort($lottery); it will always return the first input of the sorted array. But, if I just have sort($lottery); it passes $lottery, which has been sorted, right into rand(0,count($lottery));. This allows it to be sorted differently with each submission. Please let me know if I’m understanding you correctly. Thanks again for your help.

Answer 553c7291937676990a0001e6

-3 votes

Permalink

you need an _ between all the arraypush, should be array_push.

points
Submitted by jaredbenskins
almost 9 years

1 comments

Zeke Y almost 9 years

That’s Markdown removing the underscore. He actually does have an underscore there.