猿问

系统提示break非法 为什么啊

  <script>

    var words=[

      "javascript",

      "monkey",

      "amazing",

      "pancake"

    ];

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

    var answerArray=[];

    for(var i=0;i<word.length;i++){

      answerArray[i]="_";

      }

    var remainingLetters=word.length;

    while(remainingLetters>0){


    };


    alert(answerArray,join(" "));

    var guess=prompt("Guess a letter,or click cancle 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) {

        answerArray[j]=guess;

        remainingLetters--;

        }

      }

    }

  }

    alert(answerArray.join(""));

    alert("Good job! The answer was "+word);


  </script> 


qq呵呵_0
浏览 1633回答 4
4回答

cnyballk

break 是跳出循环  你自己看看你写的

慕粉3835723

一般在js里面,中断方法用return

李晓健

break应该是用在for循环里的吧!
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答