我現在試了一下,並得到它的完美。我試圖簡化這個for循環我創建並使它實際上工作,沒有任何數組,只有最基本的基本JavaScript。如何簡化Javascript中的簡單循環?
for (var x=0;x<=1;x++) {
if (secondInput == luckyNumber || secondInput == luckyNumber2 || secondInput == luckyNumber3) {
if (thirdInput == luckyNumber || thirdInput == luckyNumber2 || thirdInput == luckyNumber3) {
if (firstInput == luckyNumber || firstInput == luckyNumber2 || firstInput == luckyNumber3) {
while (firstInput !== secondInput){
while(firstInput !== thirdInput){while(secondInput !== thirdInput) {
alert('Congratulations! You got all 3 numbers correct. You\'ve won £1,000!');
}
}
}
}
}
}
此代碼是否有意義或我做錯了什麼?我覺得我甚至可以離開這個循環,但這是我認爲這是正確的唯一方式。
你如何從內部'while()'循環中斷? – SparKot