Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

How to translate indexOf in pseudo code?

I am unable to understand how Dave uses indexOf(), in pseudo code how can we write it or better how to understand it while writing?

Kenichi is correct. The key to remember is that indexOf() is a method of an already defined array (list) used to search for a specific item (element value / list item) and print out or return that item's index number / place on list .

Psuedo Code could look something like:

Create list (insert array declaration here) Ask user to enter an item ( prompt()) Check list for user entered item ( search list items (indexOf()) ....(more code if needed)

1 Answer

Kenichi Beveridge
Kenichi Beveridge
8,734 Points

Hi,

I think I understand you question.

According to W3 Schools definition "The indexOf() method returns the position of the first occurrence of a specified value in a string." So essentially the method takes what you have entered into the search variable and compares it with what is in the inStock array and return the first instance it appears.

Hope this helps.