Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOzgur Parlakkilic
8,399 Pointsprompt isnt showing
this is a childs story in another language. its like a fill in the blank everything looks good tried forever to find the mistake, the question prompt isnt showing . pls help
var answer1 = prompt("Isminiz Ne?"); var answer2 = prompt("Kizmisin yoksa Erkek?"); var answer3 = prompt("En Sevdiniz Renk Nedir?"); var answer4 = prompt("En cok Sevdiniz hayvan Nedir?"); var answer5 = prompt("Annenin Adi Ne?"); var answer6 = prompt("Yasiniz Kac?"); var answer7 = prompt("Babanin Adi Ne?"); var answer8 = prompt("Gozlerin Rengi Ne");
alert("Sorunuz Bitti, Bakalim Sizin Hikayenize!!");
var answer = "Bir Varmis Bir Yokmus, Cok onceden Bir " + answer2 + " varmis, ve onun adi " + answer1 + ". " + answer1 + "'nin en sevdi Renk" + answer3 + "'di, ve hep" + answer3 + "seyler giyerdi, elbeseleri, ve odasi hep " + answer3 + "'di." + answer1 ="'nin bir" + answer4 + "'i vardi, onu cok sever ve her yere onu getirirdi" + "ama bir gun annesi ve babasi " + answer5 + answer7 + answer1+ "'ya dediki sen hayvanini getiremesin parka, belki insanlar korkar ve " + answer1 + "'nin" + answer8 + "gozlerinden okadar gos yasi ciktiki, annesi ve babasi tamam getirebilirsin dedi ama sadece bu kez ve " + answer1 + "cok mutlu oldu, ve bu hikaye burda bitti"; document.write(answer);
Ozgur Parlakkilic
8,399 Pointsthank you so much but i am still not getting the prompt for the questions? i dunno why. I made all the correct changes. i deleting the whole storyline just kept the prompt questions but they still wont show up on my browser,
6 Answers
Erik Nuber
20,629 Pointsvar answer1 = prompt("Isminiz Ne?"),
answer2 = prompt("Kizmisin yoksa Erkek?"),
answer3 = prompt("En Sevdiniz Renk Nedir?"),
answer4 = prompt("En cok Sevdiniz hayvan Nedir?"),
answer5 = prompt("Annenin Adi Ne?"),
answer6 = prompt("Yasiniz Kac?"),
answer7 = prompt("Babanin Adi Ne?"),
answer8 = prompt("Gozlerin Rengi Ne");
alert("Sorunuz Bitti, Bakalim Sizin Hikayenize!!");
var answer = "Bir Varmis Bir Yokmus, Cok onceden Bir " + answer2 + " varmis, ve onun adi " + answer1 + ". "
answer += answer1 + "'nin en sevdi Renk" + answer3 + "'di, ve hep" + answer3
answer += "seyler giyerdi, elbeseleri, ve odasi hep " + answer3 + "'di." + answer1
answer +="'nin bir" + answer4 + "'i vardi, onu cok sever ve her yere onu getirirdi" + "ama bir gun annesi ve babasi "
answer+= answer5 + answer7 + answer1 + "'ya dediki sen hayvanini getiremesin parka, belki insanlar korkar ve "
answer += answer1 + "'nin" + answer8 + "gozlerinden okadar gos yasi ciktiki, annesi ve babasi tamam getirebilirsin dedi ama sadece bu kez ve "
answer += answer1 + "cok mutlu oldu, ve bu hikaye burda bitti";
document.write(answer);
I cleaned up your code. I apologize if I messed any of the dialog up. The issue I found is that in the middle of your building the answer, you had an = sign. So it was trying to compare the left and right side instead of building up the story.
Just in case, I noticed several single quote marks in the text. If they are not being read properly, you may need to escape them.
To do so you have to insert a \ before them.
example
answer += "\'nin bir"
Ozgur Parlakkilic
8,399 PointsThank you so much Erik
Steven Parker
231,271 Points
It looks like you have a typo where a "=
" replaced a "+
".
In the very long concatenation line, about 1/3 of the way in, this can be seen:
... + "'di." + answer1 ="'nin bir" + ...
That equal sign (=
) was probably intended to be another plus sign (+
) in the concatenation chain.
The apostrophes ("single quotes") do not need escaping, since they are enclosed in double quotes. I assume they are intentional, and part of the Turkish language.
Erik's "declaration chain" is functional but not a best programming practice. Your original declarations were better.
Erik Nuber
20,629 Points@steven — I love reading your comments because you remind me of some people I know that are exactly the same. They think they know everything and can tell you why you are wrong no matter what you have to say. You like to belittle other people that are here to help; it's like cyber-bully answering and you do it all the time. You may know a lot which is great but, you are sorely lacking in communication skills. I have no problem being called out if I have a wrong answer but, calling someone out with your foot in your mouth just makes it stink that much worse.
That said...How one declares variables is a matter of personal choice and not a "best practice".
JSLint forces you to use a one var statement and, there is nothing wrong with that. In fact if you look around enough this is fairly common usage.
That said, when using the debugger, variable definitions chained with comma are a single statement, while multiple var statements are multiple statements at which the debugger can stop. Since you may define a variable when it is declared you may actually want to stop in a variable declaration.
So either way there are pluses and minuses with neither being a "best practice".
To bring an "Authoritative" opinion into the discussion, this is what Douglas Crockford says on the website of the popular JSLint tool: But because JavaScript does not have block scope, it is wiser to declare all of a function's variables at the top of the function. It is recommended that a single var statement be used per function. This can be enforced with the onevar option.
Ozgur Parlakkilic
8,399 Pointsthank you so much but i am still not getting the prompt for the questions? i dunno why. I made all the correct changes. i deleting the whole storyline just kept the prompt questions but they still wont show up on my browser,
Erik Nuber
20,629 Pointscopying and pasting the code into the console that I cleaned up, everything works fine. Though I can't read any of it. I am prompted over and over, get the alert and then the story on screen. Maybe a screen refresh, or close and reopen your browser?
Steven Parker
231,271 PointsTry using your original code, and changing just that one "=
" to a "+
".
It ran for me after doing that.
Ozgur Parlakkilic
8,399 Pointsi tried just the one line of code
var answer1 = prompt("Isminiz Ne?"); document.write(answer1);
and still wont prompt me with anything, for some reason my prompt wont pop up
Ozgur Parlakkilic
8,399 Pointsok i found out why my prompt was not showing my bad guys its bc my dumbass added a different name to my .js file then what was in my html. i had script.js instead of story.js my bad thank you so much thu you guys r the best
Erik Nuber
20,629 Pointsglad you figured it out.
Steven Parker
231,271 PointsSteven Parker
231,271 PointsSee the Markdown Cheatsheet pop-up below the answer section for info on how to present code.