Question Relates Javascript Wrote Code Meant Change Background Colour Webpage Random Colou Q43806244
This question relates to Javascript.
I wrote a code below that is meant to change the backgroundcolour of my webpage to a random colour in the colArray. Could youplease show me how I can fix it because it does not work. Pleasekeep it simple as I am new to Javascript. Please keep itsimple.
Thank you
<html>
<head>
<title></title>
<script>
var colRef;
var randNum;
var randCol;
var flag = true;
var colArray =[“navy”,”gold”,”pink”,”green”,”blue”,”teal”,”purple”,”cyan”,”indigo”,”yellow”];
randomCol();
while(flag==true){
randomCol();
functionrandomCol(){
randNum = Math.floor(Math.random()*10);
randCol = colArray[randNum];
changeCol();
}
//document.writeln(randCol);
functionchangeCol(){
colRef =document.getElentById(‘bgCol’).style.background = randCol;
}
}
</script>
</head>
<body id=’bgCol’style=”background-color:colChange;”>
<h1>Colourful World</h1>
</body>
</html>
Expert Answer
Answer to This question relates to Javascript. I wrote a code below that is meant to change the background colour of my webpage to…
OR