finalGrade() exercise

function finalGrade (exam1, exam2, exam3) {
	if((exam1 < 0 || exam1 > 100) || (exam2 < 0 || exam2 > 100) || (exam3 < 0 || exam3 > 100)) {
		return 'You have entered an invalid code'
	} let average = (exam1 + exam2 + exam3) / 3
	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 {
		return 'A'
	}
}

((45 + 56 + 78)/3)

Why am I not getting anything (not even error) returned ?

where do you call the function? I don’t see a function call anywhere.

Hi @stetim94 I think this is a self calling function. @damianroiz you are not getting anything because you have not printed anything to the console. You may choose to write your code in this manner instead:

function finalGrade (exam1, exam2, exam3) {
	if((exam1 < 0 || exam1 > 100) || (exam2 < 0 || exam2 > 100) || (exam3 < 0 || exam3 > 100)) {
		return 'You have entered an invalid code'
	} let average = (exam1 + exam2 + exam3) / 3
	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 {
		return 'A'
	}
}

grade = finalGrade(45 + 56 + 78)/3
console.log(grade) //displays result calculated in function to screen

1 Like

You mean an anonymous function which is immediately invoked? It is not

Letting users getting to some insights themselves can really help them. Of course they can now study your solution, but they haven’t actually solved the problem themselves

i on purpose decided to help in smaller steps.

Thank you Ryan, you were right although I was trying the way to have the function self-called without having to console.log