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 trialFarney Paixao
7,812 PointsFeedback please?
I tried the length method as the professor did, but it didn't work. Then I did it this way and it works:
var firstName = prompt('What is your first name?');
var lastName = prompt('What is your last name?');
var fullName = firstName + ' ' + lastName;
var sentence = 'The string \'' + fullName.toUpperCase();
sentence += '\' is ' + fullName.length + ' characters long.';
alert (sentence);
Any thoughts?
Farney Paixao
7,812 PointsIt was pretty much the same, insted fullName.length in the sentence var, I created a var with a fullName.length and it didn't worked
Steven Parker
231,269 PointsIf you show the exact code we can probably help find the cause.
1 Answer
Christian Fynbo
Full Stack JavaScript Techdegree Student 2,910 PointsAs mentioned, without seeing the complete faulty code it's impossible to troubleshoot accurately. That said, from your code I'm guessing your placement of the toUpperCase() method could have been the culprit.
Ideally you want to complete your "fullName" variable, uppercasing and all, on the same line. That way you avoid both calling on a variable and acting on it at the same time while also defining your "sentence" variable — all on the same line.
Lastly, I would ditch your "sentence" variable as it's a bit redundant in this example — simply type out your alert using the relevant strings and variables. In its place, reapply the characterCount variable with its .length data property.
I would reformat as such, using your own approach:
var firstName = prompt('What is your first name?');
var lastName = prompt('What is your last name?');
var fullName = (firstName + ' ' + lastName).toUpperCase();
var characterCount = fullName.length;
alert ('The string \'' + fullName + '\' is ' + characterCount + ' characters long.');
Otherwise you logic is sound and you did well, especially coming from the very early stages of the course — coming up with alternative solutions already! You will improve your code's readability by a lot as you gain more experience, keep at it!
Documentation on string length: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
Documentation on the toUpperCase() method: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
Steven Parker
231,269 PointsSteven Parker
231,269 PointsShow the code that didn't work (formatted with Markdown or by a link to a snapshot) and we can help you spot the issue.