Hi Jonas!
On this lesson you're trying to generate a random number between min and max that includes both these values. However, the min value never gets generated with the code you have:
complete-javascript-course/12-Numbers-Dates-Timers-Bankist/final/script.js
Lines 427 to 430 in 4a64f00
For results to include both min and max value you should replace:
Math.floor(Math.random() * (max - min) + 1) + min;
with:
Math.floor(Math.random() * (max + 1 - min) + min);
The issue seems to be that for randomInt(10, 20)
you're multiplying the random number by 10 (max - min)
and then always adding 1 to it, ensuring that the lowest possible outcome will always be at least 1 above the min value and that the possible outcomes range from 11 to 20 (10 values).
Instead you should be multiplying the random number by 11 (max + 1 - min)
so that the range of possible outcomes ranges from 10 to 20 (11 values) and thus includes both min and max values.
Hope this helps and thanks for creating this course. I'm really enjoying it!
Owner Name | jonasschmedtmann |
Repo Name | complete-javascript-course |
Full Name | jonasschmedtmann/complete-javascript-course |
Language | JavaScript |
Created Date | 2018-06-14 |
Updated Date | 2023-03-29 |
Star Count | 12137 |
Watcher Count | 850 |
Fork Count | 14403 |
Issue Count | 153 |
Issue Title | Created Date | Updated Date |
---|