我正在制作一个基于文本的RPG,我决定使用函数而不是为了方便而重复所有内容。到目前为止,我已经制作了3个,一个用于介绍,一个用于结束,一个用于挑选你将要穿的鞋子(包含结尾)。开始和结束工作,鞋本身也是如此,但是一旦我把它与我的游戏的其余部分一起使用,鞋功能就不起作用了。它说“TypeError:鞋子不是一个功能”。我确保它的格式与我的其他功能相同,但它仍然不起作用。在这里,我提供了到目前为止谷歌文档中的链接。鞋子功能是列出的第三个功能。这也仅适用于代码学院,因为我正在使用他们的控制台。运行它去第二个链接并点击保存并提交。当被问到一个问题时,只输入//中列出的第一个选项,因为我尚未完成其他选项。 https://docs.google.com/document/d/1pGQNFNCxsNGxKP43mUloZH3w2xeDLD8nq-knluHsQ_8/edit?pli=1
var opening = function (opening) {
console.log ("You are looking up at your ceiling.");
console.log ("You feel the sun shining on you through your bedroom window.");
console.log ("You look over at your clock. It is 10:37am.");
console.log ("You contemplate getting out of bed.");
var wakeUp = prompt ("Get out of bed? /yes/ or /no/?");
if (wakeUp == "yes") {
//1
alert ("You decide to get out of bed.");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("You get up and look at yourself in the mirror.");
var userSex = prompt ("Are you male or female?");
var userHairColor = prompt ("What color is your hair?");
var userHairLength = prompt ("How long is your hair?");
var userEyeColor = prompt ("What color are your eyes?");
var userSkinTone = prompt ("What is your skin tone?");
var userGlasses = prompt ("Do you wear glasses?");
console.log ("Before you head out you want to check your computer and freshen up."); } }
////////////////////////////////////////////
var ending = function (ending) {
var endingAction = prompt ("Are you ready to go outside? /yes/ or /no/?");
if (endingAction == "yes") {
//15
alert ("You open the door and walk outside and go about your day.");
} else if (endingAction == "no") {
alert ("You remember you are a lazy couch potato and go back inside and watch T.V.."); } }
////////////////////////////////////////////////
var shoes = function (shoes) {
var shoeChoice = prompt ("What shoes will you wear? /sneakers/ or /sandals/?")
if (shoeChoice == "sneakers") {
//14
console.log ("You grab some socks and your pair of Nike sneakers and put them on.");
console.log ("You get up, make sure you are all ready, and put your hand on the door handle.");
ending("ending")
} else if (shoeChoice == "sandals") {
console.log ("You slip on your pair of blue sandals and walk up to the door.");
ending("ending") } }
//////////////////////////////////////////////////
/ /////////////////////////////////////////////////
alert ("Begin?");
opening("opening")
var beforeHeadingOutAction = prompt ("Do you want to /check your computer/ or /freshen up/ first?")
if (beforeHeadingOutAction == "check your computer") {
//2
alert ("You decide to check your computer.");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("You head over to your desk.");
var userComputer = prompt ("Do you have a /desktop/ or a /laptop/?");
if (userComputer == "desktop") {
//3
alert ("You sit down at your desk and boot up your computer.");
console.log ("The computer logo pops up and after a few seconds and the login screen appears.");
console.log ("You enter your password and login.");
console.log ("You notice that you have two facebook notifications");
var checkFacebook = prompt ("Do you want to check Facebook? /yes/ or /no/?");
if (checkFacebook == "yes"); {
//4
alert ("You click on the tab with Facebook open.");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("……………………………………………………………………………………………………");
console.log ("You see that you have one message and that you were tagged in one photo.");
var firstFacebookAction = prompt ("Do you want to /check your message/ or /check the photo/ first?");
if (firstFacebookAction == "check your message") {
//5
alert ("You open up your messages.");
console.log ("You see the message is from your friend who you met with the other day.");
console.log ("He asked you if you wanted to get lunch with him on monday.");
console.log ("'Hey I had fun hanging out the other day and I wanted to know what your favorite food was?'");
var favFood = prompt ("What is your favorite food? (Plural)");
console.log ("'My favorite food are " + favFood +".'");
var favFoodPlace = prompt ("Where do you like to get " + favFood + "?");
var lunchPlans = prompt ("Do you want to go get " + favFood + " at" + " " + favFoodPlace + " sometime next week? /yes/ or /no/?");
if (lunchPlans == "yes") {
//6
console.log ("'Cool, I'll call you later when I find a time that works.'");
alert ("You respond yes with a smiley emoji.");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("You say bye and you close out of the chat.");
var afterMessageAction = prompt ("Do you want to /check your other notification/, or /log off/ your computer?");
if (afterMessageAction == "check your other notification"); {
//7
alert ("You check your other notifications.");
console.log ("You click on 'notifications' and see that you were tagged in a photo with your friends at the local pizza place you all hangout at.");
console.log ("You chuckle to yourself remembering when your friend tried to eat a whole pizza in under five minutes.");
alert ("You like the photo and close out of Facebook.");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("You glance down at the time and you see it is now 10:59.");
alert ("You decide to log off your computer and head to the bathroom to get ready for the day.");
console.log ("You get into the bathroom and you immediately feel the difference in temperature from your warm sunbathed room to the cold bathroom");
console.log ("You quickly shuffle over to the corner where the bath and shower are located.");
var bathOrShower = prompt ("Do you want to take a /shower/ or a /bath/?");
if (bathOrShower == "shower") {
//8
alert ("You opt for a shower instead of a bath.");
console.log ("You hop into the shower and turn on the water.");
console.log ("You immediately feel refreshed and glad that you started taking two showers a day.");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
console.log ("…………………………………………………………………………………………………");
alert ("After about fifteen minutes you get out of the shower");
console.log ("You step out and wrap up in a towel after drying yourself off.");
console.log ("You relax for a minute or two before getting dressed.");
console.log ("Today is August 23 and the weather is temprate with a cool breeze you see after you check your weather app.");
console.log ("You decide to wear a T-shirt because you just bought a bunch of new ones online.");
var TshirtStyle = prompt ("Do you want to wear a /graphic/ or a /plain/ shirt?");
if (TshirtStyle == "graphic") {
//9
var graphicTshirtDesign = prompt ("What is on your shirt?");
console.log ("You put on your shirt with the " + graphicTshirtDesign + " design.");
console.log ("It is not yet cold outside, but it is not too warm that you cannot wear something over your shirt.");
var overShirt = prompt ("Do you want to wear a something over your shirt? /yes/ or /no/?");
if (overShirt == "yes") {
//10
var overShirtChoice = prompt ("Do you want to wear your grey /sweater/, your blue /hoodie/, or your black /jacket/? Or did you /change your mind/?");
if (overShirtChoice == "sweater") {
//11
console.log ("You take your sweater off the hanger and put it on.");
console.log ("You open the part of your wardrobe with shorts and pants.");
var bottomWear = prompt ("Do you want to wear /pants/ or /shorts/?");
if (bottomWear == "pants") {
//12
var pantsType = prompt ("What type of pants do you want to wear? /sweatpants/ or /jeans/?");
if (pantsType == "sweatpants") {
//13
console.log ("You grab your pair of white sweatpants and put then on as you decide you should buy another pair or two.");
console.log ("You don't feel like wearing anything else so you head over to your front door.");
console.log ("You open the shoe closet and ponder your footwear options.");
shoes("shoes")
} } } } } } } } } } } }
答案 0 :(得分:1)
我的代码没有出错。
此外,您应该更好地格式化代码以获得清晰的视图并找到可能的错误。
我建议尝试在代码学院之外运行代码(JSFiddle可能?)以避免干扰。尝试一下,向我们介绍发生的事情(以及指向你的小提琴的链接)。
无论如何,您可以在代码中修复两件事:
这一行:
//////////////////////////////////////////////////
/ /////////////////////////////////////////////////
如果您真的想要这个,请将其调整为:
//////////////////////////////////////////////////
//////////////////////////////////////////////////
缺少一些;
(可能不是错误的原因,但调整代码会很好)