Pārlūkot izejas kodu

Correct random number generation formula

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 gadi atpakaļ
vecāks
revīzija
3941a81fa1
1 mainītis faili ar 4 papildinājumiem un 2 dzēšanām
  1. 4 2
      numbers-methods.js

+ 4 - 2
numbers-methods.js

@@ -11,7 +11,7 @@ console.log(Math.ceil(num)) //round up
 
 // let min = 10
 // let max = 20
-// let randomNum = Math.floor(Math.random() * (max - min + 1)) // floor( 10 to 10.999 )
+// let randomNum = Math.floor(Math.random() * (max - min + 1)) + min// floor( 10 to 10.999 )
 // //0 to 10
 // console.log(randomNum)
 
@@ -19,7 +19,9 @@ console.log(Math.ceil(num)) //round up
 // 1 - 5 - true if correct - false if not correct
 
 let makeGuess = function (guess) {
-    let randomNum = Math.ceil(Math.random()* (4 + 1))
+    let min = 1
+    let max = 5
+    let randomNum = Math.floor(Math.random() * (max - min + 1)) + min
     console.log(randomNum)
     return guess === randomNum
 }