<script>
function getRandomColor(){
let letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function changeColor(){
let newColor = getRandomColor();
document.body.style.backgroundColor = newColor;
}
</script>
In this HTML assignment, I’m wondering how can I get to show what color it is on the webpage as well after it generates the color.? what would I add to the code to achieve that?
That did seem to work, but when applied it gets rid of the random color button making you need to restart the program, is there a way to have it display in the middle of the screen but also keep the button to generate the next color
when you say “now change the above line” what do you mean?
because I can add it into the script and paste the text but the text does not turn into the color code
In the olden days I used to deploy this code to the home page of sites at the opening stage of the domain. It was far more entertaining than an, “Under Construction” page that the search engines so loved (not). For me it was confirmation that the home page was reachable and everything in place to go forward with the site. A day or two later, the site emerged.
It wasn’t originally in jQuery, but is now. If you can glean anything from it, then we’re in plus territory. It was a fun experiment from ages ago that I’ve just kept around for the sheer novelty of it.