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
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