Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two questions about the code #11

Open
juanchi opened this issue Oct 4, 2023 · 3 comments
Open

Two questions about the code #11

juanchi opened this issue Oct 4, 2023 · 3 comments
Labels
enquiry Questions about this app

Comments

@juanchi
Copy link

juanchi commented Oct 4, 2023

This is definitely an awesome piece of code. I have two questions, not issues. I understand that the animation only displays a maximum of 40 numbers, which are taken randomly from the entered list, but the final result isn't necessarily one of those 40 numbers displayed in the animation; it's taken from the complete list, right? Also, could you please guide me to the part of the code that calculates the winner randomly? Thanks.

@icelam
Copy link
Owner

icelam commented Oct 7, 2023

Hi @juanchi, this is part of code that generates the items displayed in the reel.

// Shuffle names and create reel items
let randomNames = Slot.shuffleNames<string>(this.nameList);
while (randomNames.length && randomNames.length < this.maxReelItems) {
randomNames = [...randomNames, ...randomNames];
}
randomNames = randomNames.slice(0, this.maxReelItems - Number(this.havePreviousWinner));
const fragment = document.createDocumentFragment();
randomNames.forEach((name) => {
const newReelItem = document.createElement('div');
newReelItem.innerHTML = name;
fragment.appendChild(newReelItem);
});
reelContainer.appendChild(fragment);
console.log('Displayed items: ', randomNames);
console.log('Winner: ', randomNames[randomNames.length - 1]);

It works by taking the first N (default is 40) items from the shuffled name list to form an sublist, then treat the last item in the sublist as the winner. If the renaming names in the name list is less than the number of items to display, it concats the list again until it has enough item.

@juanchi
Copy link
Author

juanchi commented Oct 7, 2023

Thank you so much for your response, @icelam . I may not have explained myself clearly. If I have a list of names comprising, let's say, 500 names, will the code account for all 500 names? Or will I have to change it from 40 to 500?

@icelam
Copy link
Owner

icelam commented Oct 10, 2023

@juanchi, the code will always account for the 500 names provided. Every time "Draw" button is pressed, the whole 500 items shuffle and form a subarray of display items.

@icelam icelam added the enquiry Questions about this app label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enquiry Questions about this app
Projects
None yet
Development

No branches or pull requests

2 participants