I’m working on creating an online guide. It will survey users, and based on their answers, output a list that best suits their needs.
I’m about to assemble a large list of objects and properties, but before I spend too much time on it, I’d like to address some concerns:
To give you an idea of what I’m going for, here’s an example using an interactive guide to finding a travel destination:
Questions for the user:
<form name="equator" action="">
<p>What side of the equator do you want to visit?</p>
<input type="radio" name="equator" value="north">North<br />
<input type="radio" name="equator" value="south">South<br />
</form>
<br />
<form name="english" action="">
<p>Does English need to be the first language?</p>
<input type="radio" name="english" value="yes">Yes<br />
<input type="radio" name="english" value="no">No<br />
</form>
<br />
<form name="beach" action="">
<p>Do you want a nearby beach?</p>
<input type="radio" name="beach" value="yes">Yes<br />
<input type="radio" name="beach" value="maybe">Maybe<br />
<input type="radio" name="beach" value="no">No<br />
</form>
The following is the way I plan to create the object list:
destinations = [
{
name: "Moscow", equator: "north", english: "no", beach: "no"
},
{
name: "Lima", equator: "south", english: "no", beach: "no"
},
{
name: "Nantucket", equator: "north", english: "yes", beach: "yes"
},
]
In the project I’m working on, the object list will actually number in the hundreds, with up-to two dozen properties. That said, here are my concerns (in case it affects your answers, I should note that my experience with Javascript only dates back about two weeks):
- Is my example above an efficient way to store an object list, considering it’s potential size? If not, can you suggest something better?
- My experience with Javascript so far has consisted of slogging through “w3schools” tutorials and creating mini projects to get a feel for the language…so far every script I’ve created has processed instantaneously. Taking my project–as outlined–into consideration, should I be concerned about any performance hits?
Thanks for your time.
Arrays and Objects are good at storing data like this. In JavaScript, an Array is just a specific type of Object.
What you should think about is how can you make the data as “basic” as possible; i.e. if an answer has only two answers, consider using the Boolean
trueorfalse. If it is more, then the next stop should be integers0,1, .. In some cases in JavaScript integers work more efficiently than Boolean values. The idea I’m trying to convey is it’s normally more efficient to only use a string when you actually need a string, e.g. for a name.One of the best resources to learn JavaScript is probably Codecademy, w3schools is not a good resource.