JavaScript Program to Display HTML Heading in Different Colors

Write a JavaScript program to display HTML heading in different colors.



Source Code
<html>
<head>
    <title>Display Heading in Different Colors</title>
</head>
<body>
<script>
    var colors = ['red', 'blue', 'cyan', 'yellow', 'brown'];
    var i;
    for(i = 0; i < colors.length; i++)
    {
        document.write("<h1 style=\"color:" + colors[i] + "\";>Hello</h1>");
    }
</script>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store