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 trial
Noel Hale
1,715 PointsJavascript not working
I have went over this code so many times....I even delete all lines except the first one but my prompt will not come up.
Would really appreciate any advice on this. I was going so well but this has just stopped me. Here is the code, it wont even bring up a prompt.:
var name = prompt("What is your name"); var team = prompt("What is your favourite Football Team"); var wish = prompt("Type in a wish"); alert("All done. Are you ready for your story?")
var sentence = "There is a little boy called " + name + ".";
sentence += "All he ever wanted to do was to play for " + team ".";
sentence += "Then one day a genie appeared and granted him his wish!"
sentence += " The little boy thought long and hard and then said to the genie for my wish I would like to " + wish;
document.write(sentence)
The prompt will not even come up???
Really stuck on this one.
Cheers
For any help
5 Answers
Devin Scheu
66,191 PointsI came up with this code:
var name = prompt("What is your name?");
var team = prompt("What is your favourite Football Team");
var wish = prompt("Type in a wish");
alert("All done. Are you ready for your story?");
var sentence = "There is a little boy called " + name + ". ";
sentence += "All he ever wanted to do was to play for " + team + ". ";
sentence += "Then one day a genie appeared and granted him a wish!";
sentence += " The little boy hought long and hard and then said to the genie for my wish I would like to " + wish;
document.write(sentence);
Devin Scheu
66,191 PointsLooks like you forgot a semi-colon after your second prompt and your third sentence, maybe that is your issue?
Noel Hale
1,715 PointsHi Devin, I cant see what i am missing. All semi-colons are where they are supposed to be??
var name = prompt("What is your name"); var team = prompt("What is your favourite Football Team"); var wish = prompt("Type in a wish"); alert("All done. Are you ready for your story?");
var sentence = "There is a little boy called " + name + ".";
sentence += "All he ever wanted to do was to play for " + team ".";
sentence += "Then one day a genie appeared and granted him he a wish!"
sentence += " The little boy hought long and hard and then said to the genie for my wish I would like to " + wish;
document.write(sentence)
Devin Scheu
66,191 PointsLike this
var name = prompt("What is your name");
var team = prompt("What is your favourite Football Team");
var wish = prompt("Type in a wish");
alert("All done. Are you ready for your story?"); <------ Here
var sentence = "There is a little boy called " + name + ".";
sentence += "All he ever wanted to do was to play for " + team ".";
sentence += "Then one day a genie appeared and granted him he a wish!"; <-------Right Here
sentence += " The little boy hought long and hard and then said to the genie for my wish I would like to " + wish;
document.write(sentence); <---- And Here
Noel Hale
1,715 PointsDevin,
I copied and pasted your code and delete <--------- comments but it still does bring up a prompt.
I tested it line by line and go as far as the line below before the prompt stopped working:
sentence += "All he ever wanted to do was to play for " + team ".";
Is it something to do with this line?/
Noel Hale
1,715 PointsHey Devin,
Unrelated to the question but wow man you have some point achieved on treehouse. Can i just ask when did you start studying. I really enjoy coding but at times struggle with the thought that I am so far behind everyone that sometimes I feel like I am forever going to be playing catch up and I am never going to get there......as in getting a proper job in the internet industry. Just with bills n all to pay my wife say that I am wasting my always being on the computer!!
Have you found much work with the skills you have learned??? I am just learning these new skills because I enjoying learning about them. I am an accountant by trade but i just dont enjoy it!
Thanks again for your help
Noel
Devin Scheu
66,191 PointsHey, I actually have not found a job yet, this is not because coders are not needed, it's just that I have not been really looking yet. I have about 3 courses left on this website, once I finish them I plan on developing my own app and putting out for sale. You do not have to wait as long as I am now. Simply work hard on one programming language and master it. There are tons of job opportunities from selling apps on Google play to becoming a freelancer. As for how I started study, I actually found out from a math website that my school made me took called Kahn Academy. It had a free programming section where I did all of the courses. Later on we saw Treehouse on the bloomburg show, which is a tech talk show. I started on the course here of how to build a website with Nick Pettet. I spent a few hours everyday learning new stuff about code, and eventually got where I am at. Now I help people with their code because it also strengthens my knowledge. It's funny, even with as much coding iv'e done, I still never feel like iv'e learned enough. But that is how I started.
Hope this helps you Noel!
Marcus Parsons
15,719 PointsDevin, semi-colons are only relevant if the code is on the same line, although it is a best practice to use them for readability. If they are on different lines, you do not have to have a semi-colon:
//Valid code:
var name = "Marcus"; var favColor = "green";
//Also Valid, missing semicolon on end
var name = "Marcus"; var favColor = "green"
//Also Valid, no semicolons, on different lines
var name = "Marcus"
var favColor = "green"
//Also Valid, semicolons on both statements
var name = "Marcus";
var favColor = "green";
//Invalid code, no semicolons, on same line
var name = "Marcus" var favColor = "green"
Devin Scheu
66,191 PointsYes your very right Marcus, thanks for reminding me! I get so used to putting one it's like putting a period on the end of sentence.
Marcus Parsons
15,719 PointsIt is definitely a best practice to keep the semi-colons on the end, but I just wanted to remind you that this is not an issue :P
Devin Scheu
66,191 PointsYes, it ended up being that he did not properly concatenate the team variable with the second sentence variable set.
Marcus Parsons
15,719 PointsJust addressing something so that students can continue to learn about valid and invalid statements. I saw that. Good find, Devin. Happy Coding!
Devin Scheu
66,191 PointsYes, thanks for the assisted help!
jason phillips
18,131 PointsDo you have this in a script block on the html page or is it in a separate file? If it is separate, do you have a script block with the source pointing to that file?
Noel Hale
1,715 PointsHi Jason,
Thanks for coming back. I am using the workspace provided by treehouse. my js file is called story.js
I was testing it line by line as i went through and when it stopped working I started deleting lines to test but just stopped working. Checked the html and the script block is where it suppoed to be an refenced in the right way too. Here is the HTML code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/main.css"> <title>The Story Maker</title> </head> <body> <div class="container"> <h1>The Story Maker</h1> <script src="story.js"></script> </div> </body> </html>
jason phillips
18,131 PointsI think you are missing a plus sign after team:
sentence += "All he ever wanted to do was to play for " + team ".";
needs to be:
sentence += "All he ever wanted to do was to play for " + team + ".";
Noel Hale
1,715 PointsYour cracked it jason and so did Devin.....gurus the both of uz thanks. That was driving me nuts how it can all break down over one semi colon!!
Noel Hale
1,715 PointsHI Devin,
Thanks for the advice much appreciated. Could I just ask a couple more questions:
1) When did you start learning from treehouse? It just seems that you have accomplished so much on here and it seems that it would take years to get to your level!
2) How do I stay in touch with you...can i add you to my account almost like a treehosue network?
Devin Scheu
66,191 PointsI joined June 11th of last year, you can contact me at devinwscheu@gmail.com.
Devin Scheu
66,191 PointsDevin Scheu
66,191 PointsThis is the full code I got to work.