2016-04-04 20 views
0

Tamam Koduma chrome ile çalışırken yasadışı bir şekilde girmeye devam ediyorum.loop illegal mola

//village 
var village = function() { 
    document.write("<p>You come to a small village with a Smiths shop, a bakery, a guards Tower, and a bank. If you follow thst path some more you'll wind up going into the forrest.</p>") 
    window.scrollTo(0, document.body.scrollHeight) 
    while (choice != "bakery" || "tower" || "bank" || "forrest" || "smith") { 
     var choice = prompt("bakery,tower,smith,bank,forrest") 
     if (choice = "bakery") { 

      villageBakery(); // its this line getting flagged, not even the bellow it. only this line. 

      break; 
     } else if ("tower") { 
      document.write("<p>You walk up and knock on the door. No one came.</p>") 
     } else if ("smith") { 
      villageSmith() 
      break 
     } else if ("bank") { 
      villageBank() 
      break 
     } else if (choice == "forrest") { 
      forrest() 
      break 
     } else { 
      document.write("<p>Please type the choices as shown</p>"); 
      window.scrollTo(0, document.body.scrollHeight) 
     }; 
    }; 
}; 

Sorunu araştırmayı denedim ancak kısa sürmeye devam ediyorum. Diğer işlevlerimin aynı şekilde ayarlandığını biliyorum, ancak bunun sadece bir tanesi bozulduğunu söylüyor. Fren tabloların arkasında

+0

'if (choice ==" unlu mamul ") {'; atama yerine karşılaştırmanız gerekir. – dandavis

+0

"while" durum karşılaştırmanız yanlış; '' 'JavaScript’de bu şekilde çalışmıyor. Sadece bir dize ('if (" banka ")') bahseden tüm “eğer” karşılaştırmalarınız yanlıştır; 'eğer (true)' okuyabilirler. Ve, yukarıda belirtildiği gibi, eğer (seçim == "fırın") olmalıdır. – Pointy

cevap

-1

koyun noktalı virgül: Sen koşullarını değiştirmek gerekir break;

+0

Bu hiçbir şeyi değiştirmeyecek; dil, bu noktalı virgüllerin var olduğunu varsayacaktır. – Pointy

0

, sizin süre koşullar böyle olursa alışkanlık cüceye içeride ne olursa olsun demektir koşulları, yapabileceğiniz eğer bir şeye karşı şunlardır:

(choice === "unlu mamuller" || choice === "tower" || choice === "bank" || choice === "forrest" || "choice === smith") {

var choice = prompt("bakery,tower,smith,bank,forrest") 
    if (choice === "bakery") { 

     villageBakery(); // its this line getting flagged, not even the bellow it. only this line. 

     break; 
    } else if (choice ==="tower") { 

umuyoruz ki bu yardımcı olabilir