1

配列からランダムな名前を生成し、それらを削除して重複がないようにするこの機能があります。生成された名前に従ってロケーション名で別の変数を更新できるように、if ステートメントを追加したいと考えています。if ステートメントを追加すると、名前がスパンに読み込まれることはなく、それがなくても正常に動作します。私は何を間違っていますか?助けてくれてありがとう。

<h1> <span id="questionnum"></span>. Where was <span id="namequestion"></span> born?</h1>


<script type="text/javascript">


filenames = [ "Isaak Newton", "Johannes Gutenberg", "Christopher Columbus"];


generateName();
function generateName(){
filename = filenames.splice(Math.floor(Math.random()*filenames.length), 1);
document.getElementById('namequestion').textContent = filename;

 if (filename == "Isaak Newton"){
     placeofbirth = "United Kingdom"; 
 }
 else if (filename == "Johannes Gutenberg"){
     placeofbirth = "Germany"; 
 }
 else  (filename == "Christopher Columbus"){
     placeofbirth = "Italy"; 
 }

</script>
4

0 に答える 0