Results 1 to 5 of 5

Thread: Still Need Help With A Function

  1. #1
    Join Date
    Jun 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Still Need Help With A Function

    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

  2. #2
    Join Date
    Jul 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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=ht...line&verbose=1

  3. #3
    Join Date
    Jun 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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!

  4. #4
    Join Date
    Jul 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well It did not have an end </html> tag. or </body> even. so any weird thing could be going on.

  5. #5
    Join Date
    Jun 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •