Question: Write a defining table and a function that returns the sum of the first and last values in an array. The function must have this
Write a defining table and a function that returns the sum of the first and last values in an array. The function must have this header:
function addEnds(list)
Use this code to test function:
function doCalcs()
{
var evenlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var oddlist = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var endsums = addEnds(evenlist); //This should be 1 + 10 = 11
var evenmiddle = getMiddle(evenlist); //This should be 5 + 6 / 2 = 5.5
var oddmiddle = getMiddle(oddlist); //This should be 5
document.getElementById("output").innerHTML = "endsums = " + endsums + " ";
document.getElementById("output").innerHTML += "evenmiddle = " + evenmiddle + " ";
document.getElementById("output").innerHTML += "oddmiddle = " + oddmiddle + " ";
}
function addEnds(list)
{
//Put your code here
}
function getMiddle(list)
{
//Put your code here
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
