Ver código fonte

Finish numbers methods

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 anos atrás
pai
commit
934c8426c6
1 arquivos alterados com 27 adições e 0 exclusões
  1. 27 0
      numbers-methods.js

+ 27 - 0
numbers-methods.js

@@ -0,0 +1,27 @@
+let num = 103.941
+
+console.log(num.toFixed(2))
+
+console.log(Math.round(num))
+console.log(Math.floor(num)) //round down to nearest integer
+console.log(Math.ceil(num)) //round up
+
+//let randomNum = Math.random()
+//console.log(randomNum) // between 0 and 0.999
+
+// let min = 10
+// let max = 20
+// let randomNum = Math.floor(Math.random() * (max - min + 1)) // floor( 10 to 10.999 )
+// //0 to 10
+// console.log(randomNum)
+
+// Challenge area
+// 1 - 5 - true if correct - false if not correct
+
+let makeGuess = function (guess) {
+    let randomNum = Math.ceil(Math.random()* (4 + 1))
+    console.log(randomNum)
+    return guess === randomNum
+}
+
+console.log(makeGuess(1))