+ 6
Help please .. how to change font weight randomly using js ?? As in my code attached
I created code to change bg color randomly by clicking on the page .. how I can change font of the paragraph randomly also using js ?? https://code.sololearn.com/Wih2O7L8jfWh/?ref=app
3 ответов
+ 7
function change(){
var font = ["monospace", "cursive","fantasy","system-ui"];
var el = document.getElementById('color');
el.style.backgroundColor="#"+Math.random().toString (16).substr(-6);
// change font randomly
while(rand1==rand) rand = Math.floor(Math.random()*font.length);
el.style.fontFamily = font[rand];
rand1 = rand;
}
https://code.sololearn.com/WDFd7g6SAwML/?ref=app
+ 4
function change(){
var el = document.getElementById('color');
el.style.backgroundColor="#"+Math.random().toString (16).substr(-6);
// change font randomly
var fonts = ["Courier New" , "Didot" , "Georgia", "Helvetica"]
var number = Math.floor(Math.random() * 3);
el.style.fontFamily = fonts[number];
}
+ 4
unction change(){ var font = ["monospace", "cursive","fantasy","system-ui"]; var el = document.getElementById('color'); el.style.backgroundColor="#"+Math.random().toString (16).substr(-6); // change font randomly while(rand1==rand) rand = Math.floor(Math.random()*font.length); el.style.fontFamily = font[rand]; rand1 = rand; }