In Ex 18, I took this to the next level (smile) by taking integer of average grade (Math.floor(calculateAvg(Array)/10). Why 10? To return all possible scores as Avg = 0,1,2,3,4,5,6,7,8 or 9. Then I set up a const grade = [‘F’,‘F’,‘F’,‘F’,‘E’,‘D’,‘C’,‘B’,‘A’] and use the integer value to extract the grade (grade[avg]) so the function becomes …
function calculateGrade(array) {
const grade = [‘F’,‘F’,‘F’,‘F’,‘E’,‘D’,‘C’,‘B’,‘A’];
const avg = Math.floor(calculateAvg(array)/10);
return grade[avg]
}
For Ex 19, i found that you can use string.repeat(i) and then I thought why not pass another parameter being the character you want to be repeated so …
function showChar(limit,char) {
for (let i=0; i<limit; i++)
console.log( char.repeat(i) )
}
showChar(10,"*");
showChar(15,“x”);
Would be interesting to see the variations everyone comes up with!