Get More Supplies explainer


#1

The aim of this puzzle: To update the objects values to store arrays [] rather than strings. The value 'bananas' stored inside the food property should be replaced with an array that lists two or more food items (i.e. two or more strings). The value 'map' stored inside the equipment property should be replaced with an array that lists two or more equipment items. And the value 'hat' stored inside the clothing property should be replaced with an array that lists two or more clothing items. In the end you’ll have three arrays inside the object myBackpack.
Review concepts: The achievements ‘Used a String’, ‘Created an Array’ and ‘Accessed a Property’s Value’ unlock the ability to complete this puzzle.
Review puzzles: Try taking another a look at the puzzles ‘Passphrase Generator’ and ‘Custom Colors’ to get an idea of how to replace a string and change an objects value — as well as how to create an array.
Sample code solution:
(Tap below to reveal)

Since this is part of the final topic of the fundamentals course and it is testing your knowledge, there is no sample solution code.

JavaScript Concepts: Object Expressions, Member Expressions, Calling Functions, Data Structures (arrays)
Grasshopper Concepts: print()


Get More Supplies
Get more equipment
#2

Hi i’m a bit lost in this puzzle. Can someone please explain this puzzle? Thank you in advance


#3

Hey @CluelessCoder,

Do you want to share a screenshot of they code you have so far — then I can give you some pointers on where to make changes?

H :slight_smile:


#4

Thanks btw @Grasshopper_Heather


#5

Hey @CluelessCoder,

Well you’re definitely not clueless, you’re just giving yourself extra work!

Rather than creating new variables to store arrays (like you have in var bananas = [.....], try instead to directly add the arrays inside the food, equipment and clothing properties, of the myBackpack object.

I’d suggest your reset your code (by tapping on the button with arrows in a circle). Then tap on the string in the food property (I think it’s 'bananas'), then tap on the array key. That will replace the string with an array. Inside your new array, add three new strings, so it’ll look something like food: ['bananas', 'nuts', 'energy bar'].

Then repeat that for equipment and clothing!

I hope this helps and you’re feeling a little less clueless.

H :slight_smile:


#6

This is what you should be doing

DG


#7

How do you get them the stack instead of listing? I have this…


#8

@Vivacia To allow for multiple strings spaced out on different lines, you have to first insert brackets [ ]. That lets the code know you’re using an array and an array allows you to have multiple strings as the value. So delete the string ‘apples, granola, chips’ and then look for the [ ] button to add an array. Then that will let you have them stacked like in Dennis’s screenshot.


#9

Eu fiz o código, porém parece estar incompleto, pois não apareceu a mensagem de sucesso

Meu código ficou assim:

Se alguém puder me orientar agradeço


#10

Já conseguir descobrir o erro!


#11

¡Estoy feliz de que lo hayas resuelto! El código quería que cada artículo en una línea separada


#12

Please help me what’s wrong in my code


#13

I think that there is a bug or glitch on this section. I have completed it, but it will not or doesn’t acknowledge it. Please fix. Thank you


#14

Hi @joestak,
What does your code look like? :slightly_smiling_face:


#15

Hey @Kapil_Shalgar,

As of now, you have an array with a single string in it. (‘bananas, nuts, energy bar’)
For this assignment, you want to have an array with 3 strings in it. (‘bananas’, newLine ‘nuts’, newLine ‘energy bar’)
By having 3 different elements, your array (food) can access any of the 3 individually instead of having to call all of them at once every time it wants a single element.
Your equipment and clothing arrays have the same issue. Fixing them will be the solution to this puzzle.

Hope this helps! Feel free to reply if you’d like for me to go more in-depth. :smile:


Get more equipment
#16

You just have to do like
Ex.
Arrayvalue: [
‘value1’,
‘value2’,
‘value3’,
]
This is the syntax to define array


#17

I did not use separate lines, I just separated with comma. Thank you. The output looked okay, but was not.


#18

Here your answer


#19

Just be a simpler coder don’t make it complicated


#20

Hi
Can somebody help with my code. I’m stuck