 # Function challenge

I was on this passage about creating a function for average of three numbers. it involved using an if/else statement to return just the grade(A,B,C,D,F) of the average. i wanted to go further by returning the value of the average aswell. but when i return the average it omits the grade returning only the average.

this below is my code:
const finalGrade=function(number, numero, numeral){let average=number+numero+numeral; average/=3; return average;// when i return the average here it displays but omits the code below.
if((number<0 || number>100) || (numero<0 || numero>100) || (numeral<0 || numeral>100)){return ‘You have entered an invalid grade.’} if (average<60){return ‘F’}
else if (average<70){return ‘D’}
else if (average<80){return ‘C’} else if (average<90){return ‘B’} else if (average<100){return ‘A’}
else if(average<0 || average >100){return ‘null’};};

console.log(finalGrade(93, 92, 95)) // Should print ‘A’

When using return, it acts like a break.
This can be used to exit loops for example.

Any code in a function after return/break will not execute.

1 Like