You never return
a value from myDays
. So days = myDays(date2,date1);
will result in days
being undefined
.
When we look further gradient = followers / days;
will result in gradient
always being NaN
(not a number). Since something divided by undefined
will always yield NaN
.
To solve the issue add a return
statement.
function myDays(date1 , date2 , followers1 , followers2) {
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
const firstDate = new Date(2008, 1, 12);
const secondDate = new Date(2008, 1, 22);
const diffDays = Math.round(Math.abs((firstDate - secondDate) / oneDay));
return diffDays; // <- return the difference in days
}
CLICK HERE to find out more related problems solutions.