Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html> <head>
- <script>
- function cambiarColor() {
- //creamos un arreglo de colores
- let color = ["azul", "morado", "rojo","verde"];
- // creamos una variable entre 0 y el la longitud de arreglo
- // en este caso 0 a 3
- let random_color =Math.floor(Math.random() * color.length);
- // le asignamos y pintamos el clic la posicion resultante entre 0 y 3
- clic.innerHTML=color[radom_color];
- }
- </script>
- </head> <body>
- <p><h1 id="clic">...</h1></p>
- <button id="cambiar" onclick="cambiarColor()">
- ¡Cambiar!</button>
- </body> </html>
Add Comment
Please, Sign In to add comment