Sorry but no, the extra stuff you added is completely the wrong approach.
I know that you’re keen to make progress on this, as are we all, but attempting to go fast doesn’t actually achieve that, and instead only slows everything down instead.
Robert C. Martin wrote about this recently in his book The Clean Coder where in one part he talks about problem of coding to a deadline and rushing things, and the fallacy of working overtime.
“There is no way to rush. You can’t make yourself code faster. You can’t make yourself solve problems faster. If you try, you’ll just slow yourself down and make a mess that slows everything else down too.”
You now need to remove all that you did as none of it is usable.
Let me know when you have done what has been asked of you in post #47 and further progress can then be made from there.
Yes, that is wrong. You have created an object there. An object is not an array. You create an array using []’instead.
You hav3 placed it in the wrong place. I think that I said that it goes at the top of the function. You have placed it above the function instead.
Above, top, bottom, and below all have different meanings when it comes to functions. The top of a function means inside of the function, above all of the other things inside of that function.
Imagine that a function already exists called findPlayers. At the top of the init function (not above it) invoke that findPlayers function, as you would when using any other function.
When you have done that and you are getting a suitable error that the function doesn’t exist, we can then create the findPlayers function above the other functions in the manageUI code.
The findPlayers function shouldn’t be above the definition of the players variable. The findPlayers function should be below it instead.
You have added a reference to findPlayers in the manageUI return object. That is not suitable because there is no good reason to make it available to anything outside of the manageUI code. Remove findPlayers from that return object.
Lastly, the init function is still failing to invoke the findPlayers function.
Get all of those issues dealt with and we will be back on track.
At a guess I’m thinking that it might be terminology that you are stuck on when it comes to the meaning of invoke, so let’s use an example by comparison.
Somewhere above the init function is another function called exitClickHandler.
function exitClickHandler() {
resetPage();
}
That exitClickHandler function invokes the resetPage function.
Good one. We can now move on to populating the players array, after which getWrapper can then be updated to search for that cover in the players array and return the appropriate wrapper instead.
The findPlayers function will populated the players array. How that is done is by making a list of covers, a list of wrappers, and then combining each of them in a loop into an object, which we add to the players array.
So first, in the findPlayers function use document.querySelectorAll to search for “.thePlay” and assign them to a variable called allCovers. That is done because all of your elements that are covers have a consistent classname called thePlay.
This is a good time to think about renaming thePlay in your HTML and CSS to be cover instead.
Then, also in the findPlayers function, use document.querySelectorAll to search for “.wrap” which are your wrappers, and assign them to a variable called allWrappers.
You should then have two variables, one called allCovers and another called allWrappers, that each contain an array-like list of all matching HTML elements.
When you’ve achieved that I’ll take you through how to appropriately combine them together.
Good one. We can now use forEach to loop over each of the elements in allCovers, where the looping function is called addToPlayers. The function parameters of the loop are cover and index.
We need that index reference because we are going to use it to get the same indexed item from the allWrappers array too.
Inside of the addToPlayers loop, push to the players array an object. That object consists of a property called cover, and a property called wrapper.
For the cover property you can use the index to reference an item from the allCovers array.
For the wrapper property you can use the index to reference an item from the allWrappers array.