SOURCE

console 命令行工具 X clear

                    
>
console
var words = [
	//"javascript",
	//"python",
	//"fortran",
	//"cplusplus"
	"ok"	
];

var word = words[Math.floor(Math.random() * words.length)];

var answerArray = [];
for (var i = 0; i<word.length;i++){
	answerArray[i] = "_"
}

var remianingLetters = word.length;

while (remianingLetters > 0){
	alert(answerArray.join(" "));

	var guess = prompt("Guess a letter, or click Cancel to stop playing");	

	if(guess == null){
		break;
	}else if(guess.length !== 1){
		alert("Please enter a single letter.");
	}else{
		for (var j = 0; j<word.length;j++){
			if(word[j]==guess){
				if(answerArray[j] =="_"){
					answerArray[j] = guess;
					remianingLetters--;
				}
				
			}
		}
	}

}

alert(answerArray.join(" "));
alert("Good job! The answer was "+word);
Guess what is the hidden words!