Tip of the day never displays the first tip from array

I thought something looked fishy about this during the stream. Is there a category for future bugs? :wink:

random will never be 0. That means the first tip in your array will never display.

Try it:

Gives 1, 2, 3 as possible values (what your code is doing)
Math.ceil(Math.random() * (['a','b','c','d'].length - 1));

Gives 0, 1, 2, 3 as possible values (use floor and remove the -1)
Math.floor(Math.random() * (['a','b','c','d'].length));

Merry Christmas, @Tom!


Good catch! Those pesky indexing errors!

nice work @jonzoid! I’ve embedded your feedback directly into his post, as he will likely not see @ references to his forum name… :wink:

1 Like