+ 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

6th Sep 2018, 12:55 PM
Abdelrahman Amr Mohammed
Abdelrahman Amr Mohammed - avatar
3 odpowiedzi
+ 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
6th Sep 2018, 1:26 PM
Calviղ
Calviղ - avatar
+ 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]; }
6th Sep 2018, 1:19 PM
PandaThePumpkin
PandaThePumpkin - avatar
+ 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; }
6th Sep 2018, 11:48 PM
Fikadey Abegaz
Fikadey Abegaz - avatar