Please help for javascript

Hi, I’m trying to make a script for class, but I spend over 10 hours, but I still didn’t make it yet. So, would you give some help for me? It probably a basic script for you guys. Thank you.

Let the user type a word. Display the word in color, such that each letter’s position in the alphaabet determines its color. Try using a string containing the alphabet and indexOf to find the position of each input letter.

I tried to work… but It looks totally messed up…

<html>
<head>
<script language=“JavaScript”>
<!-- hide

colors = new Array; // "
colors[0]=“red”;
colors[1]=“blue”;
colors[2]=“green”;
colors[3]=“purple”;
colors[4]=“orange”;
colors[5]=“lime”;
colors[6]=“cyan”;

var first=window.prompt(“Please enter the “Hello world.””,“”);
var i=0;
var count=0;
var b=“d”;
document.writeln(“<font size=+3>” + “<br>”);
var str=“Hello world”
document.write(str.indexOf(“d”)+“<br />”);
document.write(str.indexOf(“United”) + “<br />”);
document.write(str.indexOf(“united”));
for(i=0;i<str.length;i++)
{
document.writeln(“<font color=”+colors[i]+“>”+ i “</font>” longdays[i].fontcolor(colors[i]) + “<br>”);

document.writeln(“Day “”<font color=”+colors[i]+“>”+ i + “</font>” +
" Long: " + longdays[i].fontcolor(colors[i]) + “<br>”);

if (str.charAt(i)==b)
	count++;

}

document.write(count );
document.writeln(“<hr>”);
document.writeln(“<br>”);
//–>
</script>
</head>
<body>
<font size=+2>
The preceding text was generated entirely by JavaScript code in this page.
<br>
</font>
</body>
</html>

<html>
<head>
<script language="JavaScript">
<!-- hide

colors = new Array(); // "
colors[0]="red";
colors[1]="blue";
colors[2]="green";
colors[3]="purple";
colors[4]="orange";
colors[5]="lime";
colors[6]="cyan";

var str= window.prompt("Please enter the \\"Hello world.\\"","Hello world") || "";
var j = 0;
for(i=0;i<str.length;i++)
{
   if(j>=colors.length)
     j=0;
   document.writeln("<font color="+colors[j]+">"+ str[i] + "</font>");
   j++
}

document.writeln("<hr>");
document.writeln("<br>");
//-->
</script>
</head>
<body>
<font size=+2>
The preceding text was generated entirely by JavaScript code in this page.
<br>
</font>
</body>
</html>

i’m not sure ,this is what you want…
But in your code , there’s so much mistake.
I’m sorry,I couldn’t read more about your code…

where is the element the user will type a word in?

and where is the element the colored word will be output to?

this is 1 way of doing it

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
 
var colorsA = ['antiquewhite','aqua','blue','blueviolet','brown','cadetblue','chartreuse','chocolate','coral','crimson','darkcyan','darkgreen','darkkhaki','darkred','darkslateblue','deeppink','dimgray','firebrick','goldenrod','hotpink','khaki','lightcoral','red','maroon','rosybrown','yellowgreen'];
var alphabetA = 'abcdefghijklmnopqrstuvwxyz';
 
window.onload=function() {
    var resultO = document.getElementById('result');
    var str = window.prompt('Enter a word','Hello');
    var chr,txtNode,pos,elem;
 
    for(var i=0; i < str.length; i++) {
        chr = str.charAt(i);
        pos = alphabetA.indexOf(chr.toLowerCase());
        elem = document.createElement('span');
        elem.setAttribute("id", 'id_' + i);
        elem.style.color = colorsA[pos];
        txtNode = document.createTextNode(chr);
        elem.appendChild(txtNode);
        resultO.appendChild(elem);
    }
} 
 
</script>
</head>
<body>
 
<div id="result"></div>
 
</body>
</html>