Challenge Shopping List

🚩 Remember to use Read-Search-Ask if you get stuck. Try to pair program πŸ‘₯ and write your own code πŸ“

🏁 Problem Explanation:

Create a shopping list in the variable myList. The list should be a multi-dimensional array containing several sub-arrays.

The first element in each sub-array should contain a string with the name of the item. The second element should be a number representing the quantity i.e. ["Chocolate Bar", 15].

There should be at least 5 sub-arrays in the list.

  • myList should be an array.
  • The first elements in each of your sub-arrays must all be strings.
  • The second elements in each of your sub-arrays must all be numbers.
  • You must have at least 5 items in your list.

Relevant Links

πŸ’¬ Hint: 1

A multi-dimensional array would have the following outline [[]].

try to solve the problem now

πŸ’¬ Hint: 2

Each sub-array should be separated by , as would any item in an array.

try to solve the problem now

πŸ’¬ Hint: 3

Don’t forget the ; at the end of your declaration.

try to solve the problem now

Spoiler Alert!

687474703a2f2f7777772e796f75726472756d2e636f6d2f796f75726472756d2f696d616765732f323030372f31302f31302f7265645f7761726e696e675f7369676e5f322e676966.gif

Solution ahead!

πŸ”° Basic Code Solution:

var myList = [["Canned Beans", 3],["Milk Galon", 1],["Cereal", 2],["Toilet Paper", 12],["Sack of Rice", 1]];

Code Explanation:

  • A multi-dimensional array is created.
  • The array consists five arrays inside, each composed of a string and an integer, in the same order.

πŸ† Credits:

If you found this page useful, you may say thanks to the contributors by copying and pasting the following line in the main chat:

Thanks @Rafase282 for your help with Checkpoint: Shopping List

πŸ“‹ NOTES FOR CONTRIBUTIONS:

  • ⚠ DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution.
  • Add an explanation of your solution.
  • Categorize the solution in one of the following categories β€” Basic, Intermediate and Advanced. πŸš₯
  • Please add your username only if you have added any relevant main contents. (⚠ DO NOT remove any existing usernames)

See πŸ‘‰ Wiki Challenge Solution Template for reference.