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

JavaScript

Can someone tell me why my code wont run? Not even the first prompt will show up.

I tried to get creative with this one, but it wouldn't run at all. So i copied the syntax exactly as the instructor in the lesson. It still wont run and not even the first prompt will show up. I get a "Uncaught Syntax error" on line 31. It says "Unexpected end of input." I have no idea what's wrong with my code. Help?

Not sure how to add code in the neat black box looking thing. If someone can instruct me that would also be helpful so i can get rid of this sloppy copy paste.

var correct = 0; var answer1 = prompt( "What is Brads middle name?" ); if ( answer1.toUpperCase() === 'IKAIKA' ) { correct += 1; } var answer2 = prompt( "What is Brads favorite tv show?" ); if ( answer2.toUpperCase() === 'THE OFFICE' ) { correct += 1; } var answer3 = prompt( "What is Brads first sons first name going to be?" ); if ( answer3.toUpperCase() === 'RAD' ) { correct += 1; } var answer4 = prompt( "What hospital was Brad born at?" ); if ( answer4.toUpperCase() === 'TRIPLER' ) { correct += 1; } var answer5 = prompt( "How many times has Brad been to Japan? Spell out the number." ); if ( answer5.toUpperCase() === 'THREE' ) { correct += 1;

document.write("<p>You got " + correct + " out of 5 questions correct.</p>"); if ( correct === 5 ) { document.write( "<p><strong>You earned a gold star!</strong></p>" ); } else if ( correct >= 3 ) { document.write( "<p><strong>You earned a silver star!</strong></p>" ); } else if ( correct >= 1 ) { document.write( "<p><strong>You earned a bronze star!</strong></p>" ); } else { document.write( "<p><strong>Wow, you get no crown. You don't know Brad at all.</strong></p>" ); }

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! It looks like these two got you sorted with an answer to your question. about the code and also with a tip to look at the Markdown Cheatsheet. This is likely not on your track anywhere, but might I suggest taking the Markdown Basics course? Markdown is used here on the forums to format our answers and questions. But aside from it being used here it is also used in blog posts, commenting on other sites, and most importantly while you're studying... GitHub. You can make some really snazzy README.md files for your repositories later :smiley:

The course is only about an hour long and it's actually pretty fun! :sparkles:

Thanks Joel Bardsley , I can't believe it was such a small error. I dont know if I ever would have caught that. lol. And thanks for the replies Jennifer Nordell & Neil McPartlin . I appreciate not being treated like a total noob, even though my questions are formatted like a total noob hahah. Lovin' the community on here. Much Mahalo, guys!

1 Answer

Joel Bardsley
Joel Bardsley
31,258 Points

Hi Brad, you're just missing a closing curly brace, looks like it goes at the end of the if statement for answer5. Here's the formatted version of the code you've pasted, with an additional comment for the missing brace:

var correct = 0;

var answer1 = prompt( "What is Brads middle name?" );
if ( answer1.toUpperCase() === 'IKAIKA' ) {
    correct += 1;
}

var answer2 = prompt( "What is Brads favorite tv show?" );
if ( answer2.toUpperCase() === 'THE OFFICE' ) {
    correct += 1;
}

var answer3 = prompt( "What is Brads first sons first name going to be?" );
if ( answer3.toUpperCase() === 'RAD' ) {
    correct += 1;
}

var answer4 = prompt( "What hospital was Brad born at?" );
if ( answer4.toUpperCase() === 'TRIPLER' ) {
  correct += 1;
}

var answer5 = prompt( "How many times has Brad been to Japan? Spell out the number." );
if ( answer5.toUpperCase() === 'THREE' ) {
    correct += 1;
    // Missing closing brace.

document.write("<p>You got " + correct + " out of 5 questions correct.</p>");

if ( correct === 5 ) {
    document.write( "<p><strong>You earned a gold star!</strong></p>" );
} else if ( correct >= 3 ) {
    document.write( "<p><strong>You earned a silver star!</strong></p>" );
} else if ( correct >= 1 ) {
    document.write( "<p><strong>You earned a bronze star!</strong></p>" );
} else {
    document.write( "<p><strong>Wow, you get no crown. You don't know Brad at all.</strong></p>" );
}

Hi Brad. Yep, Joel called it correctly about the missing curly brace.

To answer your second question, you just need to type 3 backticks followed by the language name, then paste in your code and finish with 3 more backticks.

```JavaScript

PASTE CODE HERE

```

If you scroll down to the bottom of this post, follow the link to Markdown Cheatsheet for additional options.