This forum is now read-only. Please use our new forums! Go to forums
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
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!
Answer 553c7291937676990a0001e6
you need an _ between all the arraypush, should be array_push.
1 comments
That’s Markdown removing the underscore. He actually does have an underscore there.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
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.