-
March 14th, 2014, 10:52 PM
#1
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.
-
March 15th, 2014, 05:12 PM
#2
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];
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|