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 trialammarkhan
Front End Web Development Techdegree Student 21,661 PointsHow 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?
1 Answer
Kenichi Beveridge
8,734 PointsHi,
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.
Justin Blalock
8,206 PointsJustin Blalock
8,206 PointsKenichi 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)