Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.