NAN- practice create task

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level:
**What I expect to happen:**in lines 80-86 the student is trying to calculate the average test score
What actually happens: it gets the answer of NAN for the calculation
What I’ve tried: We tried to console log the different variables and they all are numbers, but it doesn’t calculate to a number. Why?

You are looping through the array Assignmentsoutput summing that into finalgrademultiplier. Like this:

You problem is <=. Arrays are zero indexed so you go one element too far. That adds undefined to your calculation which makes is NaN.

You are also filtering out input that can’t be a number.

You compare the input to "NaN" and display an error if it is equal. That is a problem. NaN is a value, "NaN" is a string. You need to compare to NaN. You also don’t need to compare it to an empty string. getNumber never returns a string.

That little mistake lets NaN get into the calculation and that causes the entire calculation to be NaN.

Your nested if-else doesn’t have a default value.

Screenshot 2020-11-20 at 2.25.44 PM

What is the final grade if the average is less than 50?

finalgrademultiplier is used to sum up the grades. Where is it reset to zero?

Screenshot 2020-11-20 at 2.29.02 PM

This only sets it to zero the first time it is run.

1 Like