(read how to properly format code here)
The syntax of “for of” is
for (variable of iterable) statement-to-execute;
statement-to-execute can be a single statement or a codeblock in curly braces that can contain multiple statements.
So the first version is executed as your indentation suggests: for every mark
in marks
mark
is added to sum
and afterwards the average
is calculated and the respective grade is returned.
With the curly braces in the second example you say that you want the whole code block in braces to be executed for each iteration. So in the first iteration you add 80 to sum
calculate an average
of 80 / 3 (a little less than 27) and return the respective grade of “F”. And since you already return
ed a value there will be no second and third iteration.