Math Methods and How to Generate a Random Number with JavaScript | JavaScript Tutorial for Beginners

Поділитися
Вставка
  • Опубліковано 29 жов 2024

КОМЕНТАРІ • 24

  • @Grihlo
    @Grihlo 2 роки тому

    4:30 - Haha... Your videos are SO interactive!! I was just about to ask this question in comments. Before I've seen your explanation I paused the video and played with Math.ceil() in the VSC - couldn't get 0 in practice but I figured that theoretically it's possible. And here you go confirming my thoughts. Just amazing! :))

  • @sasindudilshan6679
    @sasindudilshan6679 Рік тому

    you are a god to me sir !!!. I learnt lot from your free courses. 💗❤

    • @xerxes1321
      @xerxes1321 7 місяців тому

      he is a "kind man" not god.

  • @GoGetSP
    @GoGetSP 2 роки тому

    console.log(Math.round("43")); // outputs 43?
    I was expecting NaN? as 43 is a string here?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Type coercion is something that is confusing in Javascript - especially if you are coming from another language like Java. Article: www.freecodecamp.org/news/js-type-coercion-explained-27ba3d9a2839/

    • @GoGetSP
      @GoGetSP 2 роки тому

      @@DaveGrayTeachesCode Wasn't aware with this concept. Thanks for introducing me to it. Will read about it now.

  • @zhala3860
    @zhala3860 2 роки тому

    Why do we say that random numbers from 1 to 10?Because we also get number 0.Then should we call it random numbers from 0 to 10?I confuse my brain maybe, but it made me think a lot)

  • @zhala3860
    @zhala3860 2 роки тому

    Hello, sorry, but I did not understand properly why Math.ceil is not a good way while generating random numbers?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      There is a graphic near the end of the video. I also suggest rewatching that part. I do not think I can explain it better in comments than I did in the video.

    • @jiweihe3413
      @jiweihe3413 2 роки тому

      is it because Math.random() samples from [0, 1) instead of (0, 1]? otherwise Math.ceil will be preferred.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      stackoverflow.com/questions/15830658/random-number-math-floor-vs-math-ceil

    • @CondeAlberto
      @CondeAlberto 2 роки тому

      ua-cam.com/video/vzLdq3b0w3Y/v-deo.html link to where it is explained.

  • @GoGetSP
    @GoGetSP 2 роки тому

    console.log(Number.isNaN(0 / 0)); //outputs true??
    console.log(Number.isNaN(42)); //outputs false??

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      From MDN: "The Number.isNaN() method determines whether the passed value is NaN and its type is Number." Link: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN

  • @Awpsun
    @Awpsun 3 місяці тому

    Amazing lecture but please reduce the intro sound omg My ears drums almost blasted 😭

  • @GoGetSP
    @GoGetSP 2 роки тому

    I was playing around with Math.min and Math.max functions and came across
    console.log(Math.min()); //infinity
    console.log(Math.max()); //-infinity
    I have been trying to understand it through various blogs but couldn't.
    Please somebody explain.
    Thankyou!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      It's built into the API itself. MDN: "The Math.min() function returns the smallest of the numbers given as input parameters, _or Infinity if there are no parameters_ ." Opposite for Math.max() Link: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min

  • @lameiraangelo
    @lameiraangelo 3 роки тому

    If only Math had 'linspace'

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 роки тому

      Sounds like you have a Python background 😀

    • @lameiraangelo
      @lameiraangelo 3 роки тому

      @@DaveGrayTeachesCode Yes. I do scientific programming with Pandas, Numpy, SymPy, SciPy, Plotly, Matplotlib etc, but not having a way to define arrays as in arange() or linspace() methods, limits the capabilities of Javascript for scientific programming.
      The random() function in Numpy has many more features, that's all.
      I'm pretty sure there is a way, but the learning curve is steep.
      You have a great tutorial though. :-)

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 роки тому +1

      Thanks KJ. I'm enrolled in a Programming for Data Analytics with Python course this semester. 🚀