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
>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