www.webdeveloper.com
Results 1 to 5 of 5

Thread: Functions and placements of {

  1. #1
    Join Date
    Nov 2010
    Posts
    21

    Functions and placements of {

    I just did this function in my program

    I am wondering if i wrote it right?

    such as the placements of my { and }

    did i put them in the correct spots?

    thanks

    here is my code
    Code:
    function totalVotes(votes){ // script element that will calculate the array
         var total = 0;
         for (var i = 0; i < votes.length; i++);
              {
                 total = total + votes[i];
              }
         return total;

  2. #2
    Join Date
    Dec 2009
    Location
    Shropshire UK
    Posts
    153
    Not being funny, but did you read any of those links I posted for you on functions?

    Your code.
    PHP Code:
    function totalVotes(votes){ // script element that will calculate the array
         
    var total 0;
         for (var 
    0votes.lengthi++);
              {
                 
    total total votes[i];
              }
         return 
    total
    Well for starters

    Code:
    for (var i = 0; i < votes.length; i++);
    Note the semi-colon at the end. You don't want this as your following block {....} will never be executed.

    If you're going for a....

    Code:
    blah blah(){
      .....
      .....
    {
    format then I'd say keep the rest of your code in the same format.

    You're missing a closing brace at the end.

    Are you using an editor like notepad++ ?

    If you click on an opening brace or curly bracket { it will highlite in red where the closing one } is.

    So it should be
    PHP Code:
    function totalVotes(votes){
      var 
    total 0;
      for (var 
    0votes.lengthi++){ // removed semicolon
        
    total total votes[i];
      } 
    // note lines up with 'for'
      
    return total;
    // added the closing brace. Note lines up with the 'function' 
    RPG
    Last edited by rpg2009; 11-22-2010 at 06:01 PM.

  3. #3
    Join Date
    Nov 2010
    Posts
    21
    Thank you so much

  4. #4
    Join Date
    Dec 2009
    Location
    Shropshire UK
    Posts
    153
    You're welcome

  5. #5
    Join Date
    Nov 2010
    Posts
    21
    now i have to figure how to make rest of the program to work!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles