Learn basic debugging by building a random background color changer - Step 3

I’ve actually solved this one without too much trouble however, I’m a little curious about the chosen solution…

Without giving spoilers or depriving the other campers of the satisfaction and sense of accomplishment for solving it our/themselves; I’m wondering why it isn’t using Math.trunc() as the solution? I understand why it chose the solution it did but, if rounding it down to the nearest whole number would be just the same as removing the decimal? If the instructions were to round it to the nearest whole number, then I would understand why not to use trunc().

Again, I’m just curious if it’s a performance reason, just preference of the course developer, or another reason I haven’t even considered yet! I’m just trying to deepen my understanding of the language/concepts.

Thanks!

The step is asking the camper to recall a method that rounds a number down. The only method that was discussed before is used in the solution. Math.trunc was not discussed earlier so that is why it is not in the solution. But it could have been if the developers wanted to make it so.

1 Like