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 trialCarlos E. Quiroz Rojas
15,278 PointsCode Challenge Methods: Part 1: Ordering 2 of 2 Java Script
I am Stuck in this code Challenges 2 of 2 I am almos too finish PHP Developer and is few thigs missing
The Question say's: Sort the 'saying2' array, on about line 19, so that the words are listed in length order. The shortest first. Use the 'length' property on the strings in the sort function.
*//<script>
var saying1 = ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"];
var saying2 = ["The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog's", "back"];
saying1.reverse();
saying2.sort(function (a, b) {
return saying2.length(a > b);
});
</script>
*//
when I put check I get this error Bummer! The 'saying2' was 'The,quick,brown,fox,jumped,over,the,lazy,dog's,back' not 'The,fox,the,over,lazy,back,quick,brown,dog's,jumped'.?? is corret or Not?
Deepthi Yakkala
3,238 Pointsi did same as like this...but it always showing error..can you please help me.
Deepthi Yakkala
3,238 Pointssorry..i got it...thanks for the help.
6 Answers
Carlos E. Quiroz Rojas
15,278 PointsFirst I want to Thanks for your answer Andrew!!
I am glad you answer because I think you are really cool I watch some of the videos you do and I get good time watching and learning with you
I advance a lot with Java script however some things still I don't know I read and try to get some Ideas from internet to see some diferent code and learn some more but well I think is question of time
I try to make some changes to make the comparison but still I don't get it look here is my code
http://codepen.io/anon/pen/Husmw
and still the same error The 'saying2' was 'The,quick,brown,fox,jumped,over,the,lazy,dog's,back' not 'The,fox,the,over,lazy,back,quick,brown,dog's,jumped'.
I belive is because dog's
p.s.:But Well also I want to tell you I am a Mexican a few time I just Come to live in UK I understand is your birth contry Is very Nice
Kuba Tuscher
10,722 PointsHey Carlos,
I just had a problem with the same exercise and thanks to you and Andrew I have been able to solve it. I think what Andrew was meaning to explain is that you simply have to substract two values (using the .length property on the strings) from each other to receive the numerical comparison the compare function (a,b) expects. There is no need for a boolean in the 'return' line. So the only difference between the example in the video and the exercise is that the compare function does not return a - b, but returns the a.length - b.length substraction.
I hope that helps. I tried to explain the best way I could without pasting the answer:)
Regards/Pozdrawiam,
Kuba
Andrew Chalkley
Treehouse Guest TeacherHi there,
The return
expects a number not a boolean.
So in the example in the video it was a - b when a and b were numbers.
'a' and 'b' are strings so length can be called on 'a' and 'b' and that's what you need to do the comparison on.
Hope that helps.
Regards
Andrew
Carlos E. Quiroz Rojas
15,278 PointsBoyaaa!!
I did it Thanks a lot Kuba and Andrew... yesterday I was a littel bit confuse by the answer but now it make sense I pass thanks alot
Mr.Q
Kuba Tuscher
10,722 PointsYou're welcome!
Andrew Chalkley
Treehouse Guest TeacherGlad you both got there.
These are new additions to JavaScript Foundations that I added. Hopefully brain teasers like this should help you use the tools you've learnt in previous stages and you can do some interesting things.
Kuba Tuscher
10,722 PointsExercises that are not purely analogous and require a little extra bit comparing to the videos/learning material, are always a challenge for us newbies. Some might like this type of exercises, some not, but as long as it is not too complicated it provides in my opinion a really great added value to our learning process. Despite the frustration that arises when I can't solve the exercise straight away;)
So thanks for the good work and I am looking forward to your exercises and courses - so far Jim has been the tutor in the programming vids I have seen. But anyway, all you guys are doing a really great job!
Kuba Tuscher
10,722 PointsAnd just one more follow-up:
I have just started the 'Functions' stage in the 'Javasrcipt Foundations' course and I really miss any challenges here. So to sum up: the more coding challenges the better the learning experience!
Andrew Chalkley
Treehouse Guest TeacherKuba Malbek, Chris Akers one of our other developers is helping me add some more challenges to these other stages. It should be added in the coming weeks.
I'm glad you agree "the more coding challenges the better the learning experience!" that's what I was hoping for adding them in to our older content!
Carlos E. Quiroz Rojas
15,278 PointsAndrew:
So that Means more Code Challenges Nooooooo !!! well that true is the only real way too get and ,make better the skill of coding Thanks Andrew for your hard Work and the team of tree house I really Like keep lerning new stuff!!
Chears!!
James Griffith
4,751 PointsI have to say that out of all the code challenges in the Web Designer Learning Adventure, this is the only one that completely stumped me (solely-Treehouse-taught newbie here), at least so far. I'm glad this post was here (wouldn't have figured it out without leaving and coming back to it later) and I'm glad you're adding new code challenges, even if I get angry once in a while (or just once)!
I know adding code challenges is a work in progress, but what I'd really like to see is a series of harder challenges (perhaps like this one) at the end of a given stage rather than in the middle, so that I can keep watching the videos with easier coding challenges in between. Also, is there some sort of change log/alert where we can see which stages of which deep dives are getting new challenges added to them? I'd love to go back to previous stages and do them just for the extra practice. Maybe in the content roadmap? (Just a free scholarship member here, so I know I can't be making too many demands!) =P
Kuba Tuscher
10,722 PointsIf you liked this challenge you will definitely like the challenges in the Jquery course tutored by Andrew..;)
Andrew Chalkley
Treehouse Guest TeacherI'd really like to see is a series of harder challenges ... at the end
Stay tuned.
anthony de alwis
4,146 Pointsanthony de alwis
4,146 Pointsthat should do it