www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Can't Average to work from an Array

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    44

    resolved [RESOLVED] Can't Average to work from an Array

    So, I've got my code to take in a number of student names and their respective marks. So far so good. But, when it gets to the end, it should put together the marks and find an average, then alert the average to the user. But, as it stands, I get no alert. Here's the code:

    PHP Code:
    var sQuantity parseInt(prompt("Let's begin compiling our student database. How many students would you like to enter?""Number of Students"));

    var 
    sList = new Array();
    var 
    sMarks = new Array();

    for (var 
    count 0count sQuantitycount++) {
        
    sList.push(prompt("Please enter the Student's Name""Students Name"));
    }

    var 
    0;

    for (var 
    count 0count sQuantitycount++) {
        
    sMarks.push(parseInt(prompt("Please enter " sList[i] + "'s average grade for this course.""Enter Average Grade")));
        var 
    i=(i+1);
    }


    var 
    sum 0;
    var 
    cAverage 0;

    for (
    0sMarks.lengthi++) {
        
    sum = (sum sMarks[i]);
    }

    cAverage = (Sum/sMarks.length);

    alert(cAverage); 
    Thanks for any help!

  2. #2
    Join Date
    Apr 2014
    Posts
    44
    Aaaand after taking a break from staring at the code for an hour, I discovered I had a "Sum" instead of "sum". Problem solved!

  3. #3
    Join Date
    Aug 2008
    Posts
    40
    It happens all the time. . .

Thread Information

Users Browsing this Thread

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

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