Random number generator in JavaScript ⁉

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

КОМЕНТАРІ • 38

  • @BroCodez
    @BroCodez  Рік тому +6

    // RANDOM NUMBER GENERATOR
    const myButton = document.getElementById("myButton");
    const label1 = document.getElementById("label1");
    const label2 = document.getElementById("label2");
    const label3 = document.getElementById("label3");
    const min = 1;
    const max = 6;
    let randomNum1;
    let randomNum2;
    let randomNum3;
    myButton.onclick = function(){
    randomNum1 = Math.floor(Math.random() * max) + min;
    randomNum2 = Math.floor(Math.random() * max) + min;
    randomNum3 = Math.floor(Math.random() * max) + min;
    label1.textContent = randomNum1;
    label2.textContent = randomNum2;
    label3.textContent = randomNum3;
    }


    My website

    roll




    body{
    font-family: Verdana;
    text-align: center;
    }
    #myButton{
    font-size: 3em;
    padding: 5px 25px;
    border-radius: 5px;
    }
    .myLabels{
    font-size: 3em;
    }

  • @Oloche-zr8id
    @Oloche-zr8id 7 місяців тому +15

    Thank you, bro. I have learned in 2 days, more than I have understood in months, because of your unique style of teaching and then applying it in real work exercises immediately, this, is indeed, very very effective.

  • @Calculususs
    @Calculususs 3 місяці тому +2

    I think the thing multiplied to the floor function must be max - min + 1

  • @Yahye_Aydh_Hassan
    @Yahye_Aydh_Hassan 10 місяців тому +6

    Iam waiting for the React js series bro

  • @marcogarcia9118
    @marcogarcia9118 10 місяців тому +2

    Do you know lua? Would love to see a full lua course in the future. Also your videos are awesome!

    • @l-fitness3590
      @l-fitness3590 7 місяців тому

      Did you find something that teaches lua effectively

    • @helioobianchi
      @helioobianchi 5 місяців тому

      There's a CS50 focused on game development that uses lua as the main language

  • @brenmaxhow
    @brenmaxhow 4 дні тому

    Bro teaches it so well. I turned pro overnight!

  • @shreehari2589
    @shreehari2589 10 місяців тому +2

    Hey bro since you have lot of videos on JavaScript already can you release more react videos, I think most of the people are waiting for react videos

  • @name_yug
    @name_yug 10 місяців тому

    Day 1 of asking for react.js course:- Can you pls make a react.js course pls I learned java, js, py, html and css all from you because your course is best so can you pls make a react.js course?

  • @BowzaaComedy
    @BowzaaComedy 10 місяців тому +1

    Hey I’ve got a question about deserialization I’m hoping you can help me with. I have a couple an object that implements serializable and fields in there if custom classes that are also serializable. I have a UID for each class too. Now I want to update the structure by adding a field in one of the classes that is a JPanel. How do I update the deserialize method (loadGame) to handle the addition of this field? I’m having trouble finding my answer elsewhere figured I’d come to the Bro. Thx

  • @dirtyconsole2247
    @dirtyconsole2247 2 місяці тому

    So it's not apparent to me how you get this code to work in the first place. For reference, I'm in eclipse, started a new java project and typed char for char what you did and it just doesn't work. I see you're doing a js project in visual studio I think. How can I make this work in eclipse?

  • @hunin27
    @hunin27 10 місяців тому +1

    please keep doing the react tutorials ❤

  • @dilip_s
    @dilip_s Місяць тому

    Can we use trunc() instead of floor() to eliminate decimal portion?

  • @ritushetty1425
    @ritushetty1425 15 днів тому

    Here:)
    This works the same.
    document.getElementById("button").onclick=function(){
    document.getElementById("dice1").textContent=Math.floor(Math.random()*6+1);
    document.getElementById("dice2").textContent=Math.floor(Math.random()*6+1);
    document.getElementById("dice3").textContent=Math.floor(Math.random()*6+1);
    }

  • @piotrmazgaj
    @piotrmazgaj Місяць тому

    This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.

  • @kitarikitsuga
    @kitarikitsuga 10 місяців тому

    Hey i know this has nothing to do with the Random Number Generator, but Im following your C++ Tutorial, and when I open a C++ File on Vscode, I get about 20 little command windows that pop up and close down. They all say MSYS2 MINGW32 Shell. Is this normal, or did something mess up?. When I run the code it appears to work just fine, but im not sure if those 20 or so windows are supposed to pop up and then close down

  • @avishekchakrabarty2560
    @avishekchakrabarty2560 10 місяців тому

    I have completed your 8 hr js video, please make some videos on fetch api like get post, delete and create

  • @MrPvssy
    @MrPvssy 10 місяців тому +1

    Daddy Brocode teaches me lots

    • @natnaelabayneh7664
      @natnaelabayneh7664 10 місяців тому

      how did u comment 5 days ago but the vid got posted an hour ago? is this a glitch?

    • @MrPvssy
      @MrPvssy 10 місяців тому

      @@natnaelabayneh7664 I watch his tutorials daily and keep a close eye on his channel, I saw the playlist release.

  • @ngehbrandon9491
    @ngehbrandon9491 10 місяців тому

    ❤❤ Awesome, please more react videos

  • @SAJIDFOYSAL-zo1lq
    @SAJIDFOYSAL-zo1lq 11 днів тому

    you should accecpt islam bro your talent is a gift from Allah

  • @capslock3250
    @capslock3250 10 місяців тому

    He is a real king.
    Full Kotlin course?

  • @navyadesai67
    @navyadesai67 10 місяців тому +1

    First! But thanks for the tutorials.

  • @helioobianchi
    @helioobianchi 5 місяців тому

    Thanks, bro. You're a real bro 💪

  • @Chill_Mode_23
    @Chill_Mode_23 10 місяців тому +1

    Bro code can you work in problem solving by java

  • @JorielTejada-te4dd
    @JorielTejada-te4dd 10 місяців тому

    Hey Broo!! Teach us Node JS Please?

  • @hangupmyheart
    @hangupmyheart 27 днів тому

    1:13 oops !

  • @ShabbyVelarde
    @ShabbyVelarde Місяць тому

    Im very grateful to u bro

  • @Ma7hiu5
    @Ma7hiu5 6 місяців тому

    is there a specific reason why Math.floor........... +1 is used for RNG, instead of Math.ceil ???

    • @sundarreddy1078
      @sundarreddy1078 5 місяців тому

      simple math.floor....+1 every outcome will have equal probability while in Math.ceil there will be a exception(the min number)
      example math.floor(math.random()*10)+1 implies values between 0 to

    • @helioobianchi
      @helioobianchi 5 місяців тому

      I've been asking myself if the video algorithm is right, and I'm gonna generate a lot of numbers, send to excel and make graphs to see the result by myself.
      And I suspect the right formula is the following:
      Math.floor( Math.random() * (max - min + 1) + min);
      This produces the same result as in the video because min is 1, but if min was another number the maximum roll would never happen

    • @helioobianchi
      @helioobianchi 5 місяців тому

      ceil works when min is 1 and you multiply the random number by max. but you'll realize that to make the formula more generic you'd have to use -1 😅

  • @bonbonbonbons
    @bonbonbonbons 10 місяців тому

    Cool channel.