1

can anyone help me understand why this code doesn't work? Don't know where I'm going wrong.

let ratings = ["8.8", "8.6", "9.0", "8.3"];

ratings.forEach(rating => {
return parseFloat(rating)}
);

I just get undefined.

Lauren
  • 109
  • 2
  • 11

1 Answers1

5

Your program is not working since your forEach() is not storing the result anywhere. And it would be better to use Array.map() in this case :

:

let ratings = ["8.8", "8.6", "9.0", "8.3"];

ratings = ratings.map(a=> parseFloat(a));

console.log(ratings);
amrender singh
  • 7,949
  • 3
  • 22
  • 28