PDA

View Full Version : Why won't this work?



thenextbesthang
10-26-2006, 03:37 AM
var sentence = "|zero|one|two|three|four|five|six|seven|eight|nin e|"
var numbers = sentence.split("|");
var input = parseInt(window.prompt("Enter a number"));

for(i=0;i<numbers.length;i++)
{
if(i==input)
{
document.write(numbers[i+1]);
}
else
{
i++;
}
}

How can I get this so that if the user type in 1, it outputs one
2 = two
3= three

so on...

codeexploiter
10-26-2006, 04:03 AM
<script type="text/javascript">

var sentence = "zero|one|two|three|four|five|six|seven|eight|nine"
var numbers = sentence.split("|");
var input = parseInt(window.prompt("Enter a number"));

for(i=0;i<numbers.length;i++)
{
if(i == input)
{
document.write(numbers[i]);
break;
}
}
</script>


Changed your sourcode a bit. This will do what you said.