Why is it returning undefined

I completed the entire basic javascript and working on the smaller sections now.

1 Like

And isn’t my code similar to the profile lookup challenge in basic java

1 Like

The players array, sure. The object array, not really. I’m not sure what it is for.

1 Like

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

1 Like

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.

1 Like

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?

1 Like

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?

1 Like

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.

1 Like

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.