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 trialtoniclawson
Courses Plus Student 459 PointsNeed assistance in helping me to understand the 3rd question in the Method's exercise.
I've reviewed the entire Methods 1 video and followed sections 6:16 through 7:08 exactly. Somehow I'm getting the formula wrong. Passed the first two questions with success and ease.
Here's 3rd Original Question: Update the variable of 'tenthCharacter' on about line 20, to get the tenth character of the string 'quick'.
var quick = "The quick brown fox jumps over the lazy dog";
var quickLength = quick.length;
console.log(quickLength);
var indexOfBrown = quick.indexOf("brown");
console.log(indexOfBrown);
var tenthCharacter = quick;
Here's my answer to get to the 10th character per following Methods 1 video. I counted the character spaces in var βquickβ to locate which word will add up to the 10th character. If I put the "quick" word into the first console log statement below, it would create an syntax error message. Therefore, I followed the example of βindex 2β from the video for locating a certain number of character. I thought I was following the correct method, but apparently my statements are still incorrect. Please advise me the correct method and what I'm doing wrong.
P.S. I'm a beginner in JavaScript coding. Therefore; I don't know what to leave out when it comes to video demo, and I tend to do exactly what's in the video.
var tenthCharacter = quick.indexOf("brown");
console.log(tenthCharacter);
console.log(quick.charAt(9));
2 Answers
Denisse Cabieses
6,411 PointsHi Toni- You have to use the charAt() and do not need to use the console.log for this exercise. Sometimes we over think the question and end up doing way more work than what is need it (Trust me this happens to me all the time with JavaScript).
The answer would be:
var tenthCharacter = quick.charAt(9);
toniclawson
Courses Plus Student 459 PointsExcellent and thanks.
toniclawson
Courses Plus Student 459 Pointstoniclawson
Courses Plus Student 459 PointsDenisse, Thank you! The video demos are great, but a bit misleading in how to answer some of the questions. Honestly, I'm not trying to over think but when one is not given the proper method from the beginning in the video. Therefore; one is lead to believe to follow the video demos method ...thinking it's the best practices or proper method to follow by. I didn't know the "charAt "could be included in the var statement directly, because per seeing the video the presenter only added it the console.log.
I was trying to get ahead of the game in Java Script before going back to college a few months from now. Should I go ahead and get a Java Script book, so I can enhance my understanding before doing anymore exercises.
Denisse Cabieses
6,411 PointsDenisse Cabieses
6,411 PointsToni- In the videos they use an external file for the JavaScript and that is why they use console.log, however on the case of this exercise problem they embedded the JavaScript code into the html file so that is why the console.log was not need it. I guess they just try to show different ways the code can be displayed. Anyhow, "Eloquent JavaScript" is a pretty good book and it's available online as well for free. Best of luck on your JavaScript journey, Denisse