Code One
09-12-2003, 11:18 AM
<script>
var syllables = new Array( "ay", "bay", "bih" );
var phrase = new Array;
var typed = " ";
document.onkeypress = function ( evt ) {
var c = document.layers ? evt.which
: document.all ? event.keyCode
: evt.which;
typed += String.fromCharCode( c );
for( i=syllables.length; i > -1 ; i-- ) {
if ( typed.indexOf( syllables[i]) != -1 ) {
phrase.push(syllables[i]);
typed = " ";
}
}
}
function playPhrase() {
if( phrase.length > 0 )
//alert(phrase.join( " - "));
phrase.reverse();
playSound();
}
function playSound() {
soundfile = document.getElementById(phrase.pop());
soundfile.play()
if( phrase.length > 0 ) { playSound() }
{
setTimeout("playSound();", 1500);
}
}
</script>
============================================================
Please notice above the scripts which are bold. I believe these two are at fault for the error. It seems shortly after you have typed your input and have pushed play the document shows an error. So I assume it is due to the settimeout. Please feel free to explore the rest of this script, for the error may lye some where in the non-bold script as well.
All help is appreciated.
Code One
var syllables = new Array( "ay", "bay", "bih" );
var phrase = new Array;
var typed = " ";
document.onkeypress = function ( evt ) {
var c = document.layers ? evt.which
: document.all ? event.keyCode
: evt.which;
typed += String.fromCharCode( c );
for( i=syllables.length; i > -1 ; i-- ) {
if ( typed.indexOf( syllables[i]) != -1 ) {
phrase.push(syllables[i]);
typed = " ";
}
}
}
function playPhrase() {
if( phrase.length > 0 )
//alert(phrase.join( " - "));
phrase.reverse();
playSound();
}
function playSound() {
soundfile = document.getElementById(phrase.pop());
soundfile.play()
if( phrase.length > 0 ) { playSound() }
{
setTimeout("playSound();", 1500);
}
}
</script>
============================================================
Please notice above the scripts which are bold. I believe these two are at fault for the error. It seems shortly after you have typed your input and have pushed play the document shows an error. So I assume it is due to the settimeout. Please feel free to explore the rest of this script, for the error may lye some where in the non-bold script as well.
All help is appreciated.
Code One