Browse Source

<HW6>upd1 done

Mark 1 year ago
parent
commit
702c8526e1
1 changed files with 11 additions and 4 deletions
  1. 11 4
      06/main.js

+ 11 - 4
06/main.js

@@ -29,11 +29,18 @@ console.log(sum3(5, 10, 100500))
 console.log(sum3(5, 10))
 
 // intRandom
+// function intRandom(min, max) {
+//    min = min || 0;
+//    max = max || 0;
+//    let result = Math.random() * (max - min) + min;
+//    return Math.round(result)
+// }
 function intRandom(min, max) {
-   min = min || 0;
-   max = max || 0;
-   let result = Math.random() * (max - min) + min;
-   return Math.round(result)
+   if (max === undefined) {
+      max = min
+      min = 0
+   }
+   return Math.floor(Math.random() * (max - min + 1) + min)
 }
 console.log(intRandom(2, 15))
 console.log(intRandom(-1, -1))