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
2
Answers
console.log won’t be printed after return statement. Change the function as follow
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