Incorrect JS exercise solution.
complete
V
Victory
In a workout devoted to JS Core the task to the insight "Get a random item from an Array" contains an error.
The situation in the task is absolutely equal to the explanation.
Math.random returns a random number between 0 (inclusive) and 1 (exclusive).
Multiplying by the length of the array we get the interval [0, 3).
Using Math.floor we found a number downward to its nearest integer, so we can get 0, 1, 2. It's fine.
The app indicates choosing Math.floor incorrect and accepts Math.ceil.
But it rounds a number upward to its nearest integer, sowe can get out of the required interval. E.g.: the result of Math.ceil(2.37..) will be 3, but there is no any element with such an index in the given array.
I think it's an error in the app. The answer should be "floor".
Cătălin Buruiană
Hello,
Thanks for letting us know of this mistake. We really appreciate feedback from our users and try to correct any mistakes inside the app as soon as possible.
I have updated the insight now with the appropriate answer.
V
Victory
Thanks, enki is a really great project. Success attend you!
This post was marked as
complete