我有这个功能可以为我一直在做的测验随机生成一个国家名称,但我不希望同一个名字出现多次。我怎么能那样做?这是我正在使用的代码。
<div style="float:left">
<h1> <span id="questionnum"></span>. Can you locate <span id="countryquestion"></span> on the map?</h1>
</div>
<script type="text/javascript">
generateCountry();
function generateCountry(){
filenames = [ "Albania", "Andorra", "Armenia", "Austria", "Azerbaijan", "Belarus", "Belgium", "Bosnia and Herzegovina", "Bulgaria", "Croatia", "Cyprus", "Czech Republic", "Denmark", "Estonia", "Finland", "France", "Georgia", "Germany", "Greece", "Hungary", "Iceland", "Ireland", "Italy", "Latvia", "Liechtenstein", "Lithuania", "Luxembourg", "Macedonia", "Malta", "Moldova", "Monaco", "Montenegro", "The Netherlands", "Norway", "Poland", "Portugal", "Romania", "Russia", "San Marino", "Serbia", "Slovakia", "Slovenia", "Spain", "Sweden", "Switzerland", "Ukraine", "United Kingdom" ];
filename = filenames[Math.floor(Math.random()*filenames.length)];
document.getElementById('countryquestion').textContent = filename;
}
</script>