Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Simple issue while trying to return random value

I’m facing the issue when trying to return random number from the function.
Can anyone explain?

const MyButton = document.querySelector(".Flipper");

    MyButton.addEventListener("click", recordLog);

    function recordLog (){

        MyButton.style.backgroundColor = 'red';
            
        let RandomNumber = Math.floor(Math.random() * 256);

            
        return RandomNumber;

        console.log(RandomNumber);

    };

I suppose to get the random number and consol log it

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Any statement after return in a function does not get executed because it marks the function as end, you would have to put all the things before return in order to some them, generally return is at the last of the function

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading