1.design a dynamic webpage by changing the text and its color after every second


<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dynamic Text and Color</title> <script> let colors = ["red", "blue", "green", "orange", "purple"]; let index = 0;
    function changeTextAndColor() {
        const textElement = document.getElementById("dynamicText");
        textElement.innerText = Color: ${colors[index]};
        textElement.style.color = colors[index];
        index = (index + 1) % colors.length;
    }

    setInterval(changeTextAndColor, 1000);
</script>
</head> <body> <h1 id="dynamicText">Dynamic Text</h1> </body> </html>

No answers yet!

1 month ago by