How to create a random color generator using javascript?
<script> // paste this code to see magic var propmt = window.prompt("Enter any number only: "); var test = isNaN(propmt); if (propmt == ""){ document.write("<h2 class='alert alert-danger'>Please enter a valid value!</h2>"); } else{ if (propmt == null){ document.write("<h2 class='alert alert-danger'>× You have cancelled the process!</h2>"); } else{ for(i=1; i<=propmt; i++){ document.write("<div id='"+i+"'>" + i + "</div>"); var randomColor = Math.floor(Math.random()*16777215).toString(16); //main function var target = document.getElementById(i); target.style.background ="#"+randomColor; } } } </script>
POST COMMENTS