Longest Word - DON'T save my ugly code - [SOLVED]

It’s embarrassing, for two reasons:

  • My code is terribly contrived (- why, but why do I do that?)

  • I can sort of feel where it goes wrong but I can’t fix it (yes, I still want to make my ugly code work, because you see it’s all my own, and I used to have panic attacks upon seeing a mere + sign).

I get the right answer but can’t call the function twice. So there’s something in there that is stuck - but all my variables are declared inside the function.

Again, I’m this close to going for solutions seen out there - I understand them, but then I always seem to understand when I read, it’s another thing when I do it myself. That’s why I want to save my ugly code, and then one day I’ll come back and try the challenges again more efficiently.

    function sortNumber(a,b) {
return a - b;}

     function findLongestWord(str){
           var mySplit = str.split(" ");
           var newArray = [];

           for (var i=0; i<mySplit.length; i++){
           var result = newArray.splice(0,1);

           return result[0];


I’m gonna get this ! I will, maybe I’ll rewrite everything.

…Ok, now I’m going to spend the next hour comparing what I had in repl/it and what I put in FCC…

Thank you though :slight_smile:

I don’t think I’ll tell you what the mistake was (yes, found it)…
But my, my, my…I’m sooooo proud !!

Thank you P1xt !

thank you @P1xt (yeah, I’m getting the hang of it all, @, [SOLVED], …)