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 The Solution

michael edmondson
michael edmondson
4,511 Points

Practice Basic Variables, Input & Output in JavaScript

var FirstName = prompt('What is your name '); var Why = prompt('Why are you here'); var TwoQuestions = FirstName.toUpperCase()+' '+Why.toUpperCase(); var Characters = (TwoQuestions.length); alert("The string \""+ TwoQuestions +\""is"+ Characters"); could you help me with whats wrong with my alert?

Christopher Flores
Christopher Flores
6,898 Points

it's kind of tough to see with the code in this format. I'm not sure how to properly post screenshots either from courses instead of objectives either BUT from what I could read, possibly the problem could be with your string and how you wrote it for your alert

alert("The string \" + TwoQuestions + "\ is " + Characters); -------> try something along these lines. As far as I know you don't need to put quote marks around variables.

Is your alert not coming up at all, or just not putting up the string exactly the way you want it to?

teresemartyn
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
teresemartyn
Front End Web Development Techdegree Graduate 21,880 Points

first, I would get those variables to start with a lowercase letter. Also use camelcase syntax. I removed those "\" from your alert("...");

var firstName = prompt('What is your name '); var why = prompt('Why are you here'); var twoQuestions = firstName.toUpperCase() +' ' + why.toUpperCase(); var characterLength = (twoQuestions.length);

alert("The string is " + characterLength + " characters long");

2 Answers

Looks like the problem is in your alert syntax. After playing around with it, in an online Javascript editor, I came up with the following (seems to work, hope this helps):

var FirstName = prompt('What is your name '); var Why = prompt('Why are you here'); var TwoQuestions = FirstName.toUpperCase()+' '+Why.toUpperCase(); var Characters = (TwoQuestions.length); alert("The string " + TwoQuestions +" is " + Characters +" characters");

On a side note, I had the code nicely spaced out and easy to read, but when I replied it just lumped it all together. How can we do line breaks and spacing between the code. Do we need to use HTML formatting like <br> or <p>?

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

To post properly formatted and viewable code snippets in the Community, you'll need to use Markdown.

There is a Markdown Cheatsheet that can be referenced using the link that is above the Post button in the Community. The better other option would be to take the Markdown Basics course available here on Treehouse.

Notably, if you are posting directly from a challenge page, just click the Get Help button, follow the prompts, but make sure "include code" is checked. This will automatically format the code with Markdown before posting.

Keep Coding! :) :dizzy:

Thanks Jason for the answer, will look at the Markdown Basics course. Really appreciate the help !!