- console.log(Math.ceil(Math.random() * 1000) / 10);
- console.log(Math.ceil(Math.random() * 100));
- console.log(Math.ceil(Math.random() * 10) * 10);
- console.log(Math.ceil(Math.random() * 5) * 20);
I had assumed that, by doing Math.random, multiplying by 1000 in Math.ceil, and then diving that total by ten, I’d get what could be a percentage of 100 with one float point, and I was right.
My next one, I had assumed that I could get an accurate rounded percentage to have no float point by doing Math.random times 100 in a Math.ceil, and I was also right.
Now, my third one was a bit tricky. I wanted to count by 10s, but still have a percentage. It worked somewhat as expected, but it only seemed to return 10, 20, or 30, even after refreshing the console many times by clicking “Run”. Not sure of why that occured.
My fourth and final one was one where I wanted to get an accurate percentage counting up by fives. I’d get a random number between 1 and 100 every time, but it would never end with a 5, just a 0. Again, not sure of why that occured.
I understand that the console in the course might not be perfect, but if I am going about it wrong, I’d really appreciate someone telling me the proper way to type it, as well as explaining what each part of the equation would do in that case. It would be easiest for me to understand if you limited it to Math.ceil and Math.random like I did for this description, as I’m still on the end of the first lesson, which is around 7% of the actual course.