-
Practice Help....
I'm bored at work, so I pull out my laptop to get some practice coding done. In class at the moment, we're working on arrays, so I thought I'd practice a bit. This isn't homework. I created a string array listing various movies I enjoy. I've also created a txtbox and a button. I'd like to know how to have an int that the user enters into the txtbox be equal (minus 1) to the index of a particular element, without having to write 10 different IF statements. Any help at all would be well appreciated.
-
Re: Practice Help....
In an array, you access the array element by its index.
So you already know that you need to subtract one from what the user gives you.
All you need to do is pass that value (let's call it _index) to the movies array to retrieve the item.
Code:
var movie = _movies[_index];