Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript problem - Jedi Name

Options
  • 08-04-2009 11:55am
    #1
    Registered Users Posts: 6,207 ✭✭✭


    Hi im making a Javascript page to churn out the last three letters of your first name


    I have this so far
    for ( i == document.jedin.firstn.value.length - 3 ; i == document.jedin.firstn.value.length ; i++)
    {
      firstName = charAt[i];    
    }
    

    Where am I going wrong


Comments

  • Registered Users Posts: 12,037 ✭✭✭✭L'prof


    miralize wrote: »
    Hi im making a Javascript page to churn out the last three letters of your first name


    I have this so far
    for ( i == document.jedin.firstn.value.length - 3 ; i == document.jedin.firstn.value.length ; i++)
    {
      firstName = charAt[i];    
    }
    

    Where am I going wrong

    I don't know anything about Javascript, so the statements looks a little bit confusing, but if the for loop works correctly firstName is being overwritten and so is only one character long!


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Yup so use += instead of =

    RD


  • Registered Users Posts: 12,037 ✭✭✭✭L'prof


    Yup so use += instead of =

    RD

    Yeah, also in the for statement (I don't know if it's the same for Javascript to be honest) you have ==, I think that should be = instead?


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    == to check if variables are equivalent
    = to assign a variable/value to a variable.


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    You could try using the substr() function.

    It might accept negative numbers like substr() does in perl and php.


  • Advertisement
  • Registered Users Posts: 6,207 ✭✭✭miralize


    Oops sorry I fixed it already guys! Thanks for the help =]


  • Closed Accounts Posts: 3,285 ✭✭✭Smellyirishman


    rew? Algorithm needs some work :p


Advertisement