# My Random Number Generator now handles weird decimal edge cases

/Alright. I think I maybe got this silly thing working as it should. I looked up `isNumber`

and it seems like it basically does an upgraded version of what the conditional in my first `while`

loop does. The thing is, I actually understand what my conditional does (filters out all falsey values except for 0) because I wrote it, and I'm fine with it for now. I might upgrade later once I fully understand `isNumber`

. (As a rule, I don't like writing code that I don't 100 percent understand.)

Anyway, I then tackled the edge cases that have been irking me. Specifically, what if a user inputs something like (3.1, 3.9) as their values? In my previous version, the RNG returns 3 because it applies `Math.floor`

to the max and min, which in this case amounts to (3, 3). But 3.0 is not within the user-defined parameter of (3.1, 3.9). So fooey.

In my newest iteration, I added a new `while`

loop that tests if `Math.floor`

of the min and max are equivalent, and demands a new WHOLE number while this condition is true. I then stored this new value into one of the original nums, and reassigned max and min based on the new value pair.

Finally, I generate a random number, and added new bits of code to the variable that is returned to the user. I rounded-up the min and rounded-down the max to ensure that whatever integer is returned falls within a safe range. OK, this is too many words now. Here is my code.

// collect num1 from user do { // Use parseFloat bc parseInt evaluates non-zero values under 1 as NaN var num1 = parseFloat(prompt("Give me a number!")); } while (num1 !== 0 && !num1); // do not accept falsy values except for 0 // collect num2 from user do { var num2 = parseFloat(prompt("Give me a different number!")); } while (num2 !== 0 && !num2); // do not accept num2 if it is equal to num1 while (num2 === num1){ num2 = parseInt(prompt("Give me a DIFFERENT number!")); } // find and store the min and max var min = Math.min(num1, num2); var max = Math.max(num1, num2); // if the Math.floor values are the same, ask for a diff whole number // accounts for edge cases where user inputs something like (5.4, 5.3) and gets 5 [5.0 falls outside 5.3 - 5.4] while (Math.floor(min) === Math.floor(max)) { // reassign num2 (could also reassign num1), and set new min and max num2 = parseInt(prompt("Give me a different WHOLE number!")); min = Math.min(num1, num2); max = Math.max(num1, num2); } // store random whole number in variable to return to user // round up the min value and round down the max value, so you can return inclusive min/max integers var randomNum = Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + Math.ceil(min); alert("Your random whole number is " + randomNum); document.write();