Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript problem - Jedi Name

  • 08-04-2009 11: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,051 ✭✭✭✭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,051 ✭✭✭✭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,449 ✭✭✭✭Creamy Goodness


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


  • Registered Users, Registered Users 2 Posts: 6,652 ✭✭✭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