I am trying to pull student scores from a sheet, average them for each student then output them to a new tab in the same sheet. Each student is scored by eight teachers on their character and leadership.
I am not a programer by trade so I'm learning as I go. I have figured out using the Google sheet scripting tool how to add the student and their scores into an array and output them to a new tab in sheets. I have found examples of code on how to average the numbers in an array but I haven't been able to get any of them to work. I'm assuming I need to add the code to average the values before doing the output, but all the examples I find seem to be in different programming languages than what sheets uses as I get errors when I put an any of the code I find. This is what I have working to get the students and the scores into a new tab.
function CharAvg(){
var app = SpreadsheetApp;
var sheet = app.getActiveSpreadsheet().getSheetByName("Sheet1");
var map = {};
for(var row = 3; row <=297; row++)
{
var studentname = sheet.getRange(row, 2).getValues();
if(studentname != " " && studentname != null && studentname != "")
{
if(!(studentname in map))
{
map[studentname] = [];
}
var character = sheet.getRange(row, 3).getValue();
if(character != " " && character != null)
{
map[studentname].push(character);
}
var leadership = sheet.getRange(row, 5).getValue();
if(leadership != " " && leadership != null)
{
map[studentname].push(leadership);
}
}
else
{
Browser.msgBox(studentname);
}
}
var outputsheet = app.getActiveSpreadsheet().insertSheet("OutPut");
outputsheet.getRange(1, 1).setValue("Student Name");
outputsheet.getRange(1, 2).setValue("Character Avg.");
outputsheet.getRange(1, 3).setValue("Leadership Avg.");
var row = 2;
for (var studentname in map)
{
outputsheet.getRange(row, 1).setValue(studentname);
for(var character in map[studentname])
{
outputsheet.getRange(row, 2).setValue(map[studentname][character]);
for(var leadership in map[studentname])
{
outputsheet.getRange(row, 3).setValue(map[studentname][leadership]);
}
row ++
}
row ++
}
}
If anyone could help me figure out how to do this in a Google sheet script it would make our lives easier. Otherwise we can get by writing a formula in the sheet manually to get the averages, but we would like to automate the process as much as possible. Thank you.



