DEV Community

Cover image for What I did learn from Scrimba Js Course
benoah
benoah

Posted on

What I did learn from Scrimba Js Course

After been taking some time from coding Js I needed to go back to the fundamentals.

I started to build a blackjack with help from the tutorial and did learn how to work with math.floor() and math.random().

What is The Math.floor() its a method that rounds a number down to the nearest integer, and returns the result.And Math.random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).

Both of them have a value can be important too generate Auth and also be used in Casino games and etc

Here is a code example:

function getRandomCard() {
  // if 1     -> return 11
  // if 11-13 -> return 10
  let randomNumer = Math.floor(Math.random() * 13) + 1;
  if (randomNumer > 10) {
    return 10;
  } else if (randomNumer === 1) {
    return 11;
  } else {
    return randomNumer;
  }
}
    ```

Enter fullscreen mode Exit fullscreen mode

Top comments (0)