Skip to content

Why doesn't the name get added? #125

Answered by alwayscommit
rileymross asked this question in Q&A
Discussion options

You must be logged in to vote

The way mapping works is that you store "values" against "keys". In this case, the "key" is the name and the "value" is the favorite number.

To perform a lookup (read) operation on a map, you have to pass a "key" which in our case is the name and the map will return a "value" which in our case is the favorite number.

We can only retrieve one value based on the key, as keys are unique.

If you wish to retrieve all the entries in a map, you will have to maintain an array of keys separately and loop over it from 0 to n and perform a lookup operation on the map with each name as the key, in the code.

For now, you will see a textbox against the "nameToFavorite " button, just enter the "key" whi…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@rileymross
Comment options

Answer selected by rileymross
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants