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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Javascript problem - Jedi Name

  • 08-04-2009 10:55am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 12,046 ✭✭✭✭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, Registered Users 2 Posts: 12,046 ✭✭✭✭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, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


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


  • Registered Users, Registered Users 2 Posts: 6,571 ✭✭✭daymobrew


    You could try using the substr() function.

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


  • Advertisement
  • Registered Users, Registered Users 2 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