PDA

View Full Version : Still Need Help With A Function



7079
07-05-2006, 04:01 PM
I am sorry to keep bugging everyone for help with this function, but it is driving me up the wall. I made some corrections based on some help I recieved from Twey(A member of this forum) which is semi-working, there is an apparent problem with my loop.

You can view the code online here:

http://7079.net/cars_objects_ara.html

Invoking the below function with the word "Ford" should bring back 2 results, and populate the new array, models3[] with "Crown Victoria" and "Taurus". For some reason it is only populating it with the first element and not the second. I think the code is close enough to being complete, it does require experienced Javascript Eyes to see my mistake(s). I have only been working with JS for a few weeks and I am working on this project for a class that I am taking. I really need some help!

[code]
getModelsByMake("Ford");
[code]

[code]
var models3 = new Array(); //to be global scope
function getModelsByMake(mType){
this.mType = mType;
for(var i = 0;i<myAutos.length;i++){
if(myAutos[i].make === mType){
var md = myAutos[0].model;
models3[0] = md;
mdIndex = 0;
for(var j = 0;j<myAutos.length; j++){
if(myAutos[j].model === md){
continue;
}
else{
md = myAutos[j].model;
models2[++mdIndex] = md;
}
}
}
}

}
[code]

Thank you so much in advance, I look forward to any response from anyone!

7079

tim.thelion
07-05-2006, 06:32 PM
I am not just biching at you in saying your code is discusting and you need to make it more complient.
http://validator.w3.org/check?uri=http%3A%2F%2F7079.net%2Fcars_objects_ara.html&charset=%28detect+automatically%29&doctype=Inline&verbose=1

7079
07-06-2006, 12:06 AM
If that is the help that you are offering, I could have done without it. BTW, the class is not a HTML class, it's a JavaScript Class.

Thanks for nothing!

tim.thelion
07-06-2006, 12:09 AM
well It did not have an end </html> tag. or </body> even. so any weird thing could be going on.

7079
07-06-2006, 02:24 PM
I have updated the code, if anyone is interested in helping please look at the following link:

http://7079.net/cars_objects_ara.html

I have the code functioning much better, the only problem is that I am not getting the exact results I need. If you notice in the code, I am invoking the method with the word "Ford", the output is the 2 "Ford" vehicles and the rest of the vehicles. I want to exclude anything that is not "Ford".

Here is the code for the function:

[code]
var models3 = new Array(); //to be global scope
function getModelsByMake(mType){
this.mType = mType;
var md = myAutos[0].model;
models3[0] = md;
mdIndex = 0;
for(var i = 0;i<myAutos.length;i++){
if(myAutos[i].model === md && myAutos[i].make === mType){
continue;
}
else{
md = myAutos[i].model;
models3[++mdIndex] = md;
}
}

}
[code]

Thanks for the help!