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

Javascript Foundations - Please Fix This

I've plowed my way through this course thus far but I now feel I must comment. This needs attention from Treehouse. In the section on arrays we are first expected to solve a routine challenge, fine. But in order to pass it you have to identify and resolve a further problem with no indication from the course content.

The problem is then repeated later on when a video shows the most basic use of numerical array sorting and then expects the student, with no prior indication or discussion of approppriate method, to sort a string array.using an entirely unnassociated property. Yes, we can look elsewhere for answers or have the forum answer it for us but I don't feel that's acceptable frankly. We are supposed to be learning, not copy/pasting. These 'continuity errors' have a major impact on enjoyment of and enthusiasm for the material and dirupt the learning process.

Can you be specific about what the questions were and what it was you had to figure out on your own? I get what you are saying, but without the specifics it's difficult to evaluate the issue.

I took the course and don't remember running into this issue, but it may have changed so I'm curious.

3 Answers

I can't replicate the first error having done it again. I think it may have come about because i ended up deleting the line and retyping it. I can't explain that one other than 'random glitch'. At the time I had to delete the 'saying;' lines at the bottom to get a pass.

Edit: i thought about this and it was because the title said 'about line 19' rather than on line 19. This prompted me to start on the line after so as not to affect the existing code. If it had said on line 1x, which it does in the previous task, it would have worked first time. This happens fairly frequently in this section where it switches from 'about' to on. Javascript Foundations, Methods 1, Challenges 1 - 4.

The second point is still valid in my opinion. Stage 4 Arrays, Methods part 2,. Challenge task 2. The video deals entirely in numerical arrays but the challenge deals with strings. Whilst the principles involved are similar they're not the same and the resulting function is quite different.

There;s a similar comment on the issue here https://teamtreehouse.com/forum/javascript-foundations-stage-4-arrays-methods-2-challenge-task-2-not-sure-how-to-approach-this

The section is entitled methods but the method in this case is not clear. The sections after this one deal with strings fairly comprehensively and make it very clear what's required.

Jason, I understand that it's a bit abstract and a little frustrating.

The video shows you how to sort numbers in an array according to number values:

var my_array = [10, 33, 300, 32, 100, 0, 32, 44, 3, 4];

my_array.sort(function (a, b) {
    return a - b;
 });
//output --> [0, 3, 4, 10, 32, 32, 33, 44, 100, 300]

And the code challenge is asking you to sort strings according to their length values, shortest first:

var saying2 = ["The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog's", "back"];

At first glance this seems different, because this array is full of strings, and the array in the video is full of numbers, right?

But it's not different. They are asking you to sort numbers in both the video and the challenge.

You are tasked with sorting the "saying2" array by the length of the strings inside the array, shortest (read: smallest) first. That means they are asking you to sort by number values of the string lengths.

The answer is almost identical, except you have to compare the length number of the strings, instead of number values of the numbers. See how similar the answers are?

 saying2.sort(function (a, b) {
    return a.length - b.length;
 });
//output --> ["The", "fox", "the", "over", "lazy", "back", "quick", "brown", "dog's", "jumped"]

Again, it's abstract, but this is the nature of programming. You'll get used to dealing with objects in various ways, and looking at them in different ways. One person may see the word "quick" and think of a fox with fast reflexes. A programmer looks at the word "quick" and might think that it's 5 characters in length.

These tests are designed to get you thinking in these kinds of abstractions, but only just slightly differently than in the videos. You can do it!

Sorry Alex but I disagree. I looked at the video and I had no idea what method to use, despite having taken other units and being able to think in the abstract to an extent. You either know it or you don't and at that point I didn't. Testing based on some level of familiarity is fine, I've seen plenty of units where they are clear about the method but then switch the required outcome or context, which is a challenge but at least you have a method to work with. At that point you can abstract. I still don't feel that was the case here.