Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

DATA AVAILABLE There is a local storage value you will need named: qualifier The

ID: 3543859 • Letter: D

Question

DATA AVAILABLE

There is a local storage value you will need named: qualifier

There is a local storage value you will need named: factor

There is an array you will need named: sales

The array and local storage exist so just use them.


WHAT TO RETURN

Return the average bonus.


HOW TO CALCULATE AVERAGE BONUS

a. Each amount in the array sales[] that is more than qualifier gets a bonus.

Remember: array means you think for() loop.

b. The bonus is calculated as that sales amount times factor.

c. If the sale is greater than qualifier add the bonus to the bonus total.

d. Calculate the average by dividing the total by the number of bonuses that qualify.


TIP Remember, you are returning the average of bonuses that qualify; not the total of bonuses.


What I've got:

function extraPay(){

     total = 0;

     bonus = 0;

     length = 0;


     sales = parseInt(document.getElementById('sales').value);

     qualifier = localStorage.qualifier;

     factor = localStorage.factor;


     for(i=0;sales.length;i++){

          if(sales[i]>qualifier){

               bonus = sales[i] * factor;

               total = total + bonus;

               length = length + 1;

          };

     };

     return total/length;

};

Explanation / Answer

your code looks fine... you will get the no of sales that qulify in the variable 'length' I can see that you have used some ; which are not required (after if condition and for loop block) but the code should work fine


are you getting any errors? If your question has not mentioned about sales array you can even hard code it as sales=Array{100,200,300,400,500}; instead of taking it from the document


----------------------------------------------------


function extraPay(){

total = 0;

bonus = 0;

length = 0;


sales = parseInt(document.getElementById('sales').value);

qualifier = localStorage.qualifier;

factor = localStorage.factor;


for(i=0;sales.length;i++){

if(sales[i]>qualifier){

bonus = sales[i] * factor;

total = total + bonus;

length = length + 1;

}

}

return total/length;

}