5. Beyond the Fundamentals
Activity 5.01: Simple Number Comparison
Solution
- Create the function signature:
function average_grade() {
- Copy the function arguments to a variable. This should be a new Array instance:
var args = Array.prototype.slice.call(arguments);
- Sum all the values of the arguments and store them in a variable:
var sum = 0; for (let i=0; i<args.length; i++) { sum += Number(args[i]); }
Remember to convert the grade values into a Number instance so that they can be correctly added together.
- Get the average of the sum and store it in a variable:
var average = sum / args.length;
- Using the average, calculate the student's grade and return it. This can simply be a list of conditionals:
if (average < 35) { return "...