Javascript Code : Change body Background onload using Random Values and Switch Case
html>
<head>Javascript Events</head>
</br>
<body id="bodybg" onload="window.alert('Page successfully loaded');">
<script>
<!--
n=Math.floor(Math.random()*10);
document.write("The page is loaded successfully" +n);
switch(Number(n))
{
case 1:document.body.style.background="pink"; break;
case 2:document.body.style.background="red"; break;
case 3:document.body.style.background="maroon"; break;
case 4:document.body.style.background="brown"; break;
case 5:document.body.style.background="yellow"; break;
case 6:document.body.style.background="orange"; break;
case 7:document.body.style.background="green"; break;
case 8:document.body.style.background="blue"; break;
case 9:document.body.style.background="gray"; break;
default:document.body.style.background="aqua"; break;
}
//-->
</script>
</body>
</html>
Output of the Code :
Comments
Post a Comment