I completed the entire basic javascript and working on the smaller sections now.
And isnât my code similar to the profile lookup challenge in basic java
The players array, sure. The object
array, not really. Iâm not sure what it is for.
I thought calling an object you have to say players. and actual name of sport so I created an array where the i var call the items in the array so players[object[i]] would call the players and sport
Your array called objects
(syntax highlighting doesnât like that variable name) doesnât hold objects though, only strings.
Also, you should be able to directly index into players
without an extra array of strings.
What do you think I should do if I already went through the basic java course and still my code looks like the way it does?
Practice more, read the articles in freecodecamp.org/news about JavaScript concepts, etc
Also note that Java is not JavaScript
What is your goal for this code?
Yeah no, you cannot just throw a string at an object an assume JS will somehow parse it as dot-notation AND somehow know that the dot actually belongs behind the bracket.
For example, your object-array contains 'basketball.lakers'
meaning you call players['basketball.lakers']
â so JS will look for a key 'basketball.lakers'
.
It will NOT look for players['basketball']['lakers']
.
Please either go through the part of the curriculumn dealing with this kind of object again OR go to something like w3schools.com to look at the JS references for this kind of objects.
Generally what you need is the built-in method to extract keys from an object as array - then you can loop over that without having to create the array yourself.
Is there a way to write basketball.lakers in a way where js would read it as if itâs behind a beacket?
Doesnât matter. Thatâs simply not the way to deal with objects. Whatâs the point of even designing nested objects if you then have to write all key-key nesting into a separate array?
At that point you could just populate an array with all players and donât even bother with an object.
Plus you still have the problem of different depths of the object.
How could I create an array and still asign different players to different teams
By using objects⌠just look up how to do that, maybe watch a tutorial if you donât feel like using any of the resources already mentioned.
The array-thing was just to say how absurd your current approach is.
Boy, you need a book for real beginners, with LOTS of practice exercises. I donât think OO should enter your code until you know the basics REALLY well. You donât need the complexity of OO for small programs. The FCC BootCamp is great for a kick start for someone who already knows programming concepts. But the JavaScript one should be split into two bootcamps instead of one. The first one should stop on arrays or dictionaries and have at least a dozen projects. Thatâs what I suggest you do before trying complicated structures.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.