JavaScript Program to Display HTML Heading in Different Colors

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

Source Code
    <title>Display Heading in Different Colors</title>
    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>");

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