These are chat archives for FreeCodeCamp/Help

14th
Jan 2015
James McShane
@jmcshane
Jan 14 2015 00:00
oh, it should be request.num_found, not JSON.num_found
here, try executing this in a console:
jQuery(['war', 'peace']).each(function(ix, word){

  var query_params = { apikey: 'f6ab5f2e4f69444b9f2c0a44d9a5223d',
                       phrase: word
                     };

  var endpoint = 'http://capitolwords.org/api/text.json'

  var options = {
    data: query_params,
    type: 'GET',
    dataType: 'jsonp'      
  };

    var request = jQuery.ajax(endpoint, options)
                        .done(function(response) { console.log(response.num_found)});

});
Suzanne Atkinson
@AdventureBear
Jan 14 2015 00:01
thanks for that correction, I still get undefined. :(
Oh cool, that worked!
James McShane
@jmcshane
Jan 14 2015 00:02
yep, now replace the console.log statements with variable assignment, like that if/else above
Suzanne Atkinson
@AdventureBear
Jan 14 2015 00:02
if I use "return" instaed of "var" fro that last line will hte variables be persistent?
Hmm, OK. Really helpful, thank you!
James McShane
@jmcshane
Jan 14 2015 00:02
glad to help!
Suzanne Atkinson
@AdventureBear
Jan 14 2015 00:03
unlike some of those folks at stackoverflow, lol
someone downvoted my question, and answered "you can't".
James McShane
@jmcshane
Jan 14 2015 00:04
hmm, well if you want to look at the documentation, these are the two things going on in the first line: http://api.jquery.com/jquery/#jQuery-elementArray and http://api.jquery.com/each/
Suzanne Atkinson
@AdventureBear
Jan 14 2015 00:04
Thank you. I think I need to take a break
let this all sink in. I've learned a lot today!
James McShane
@jmcshane
Jan 14 2015 00:05
good stuff! keep doing that every day and you will know a ton
Suzanne Atkinson
@AdventureBear
Jan 14 2015 00:06
:)
iknow more than I knew yesterday. Thanks again.
Dominic Jones
@towwiow
Jan 14 2015 00:08
:)
Suzanne Atkinson
@AdventureBear
Jan 14 2015 00:15
@jmcshane Thank you SO MUCH!!!
just moved it over so I can play with it. Things are slowly making sense.
I even moved a function over to the javascript window and added back a call in. will take a break and continue to play.
Bill Maca
@bmaca
Jan 14 2015 03:00
Can anyone take a second look at this
// When color button is clicked...
$(".color").click(function() {
  // assign each named color a random number 0-255
  var red = Math.floor(Math.random() * 255);
  var green = Math.floor(Math.random() * 255);
  var blue = Math.floor(Math.random() * 255);

  // Generate an RGBA value from red, green, and blue
  var randomRGBA = 'rgba('+red+','+green+', '+blue+', 1')';

  // Display the RGBA value in an alert window
  alert(randomRGBA);
});
telling me to copy out the variable that generates randomRGBA when color button is clicked
Ben Clist
@BenClist
Jan 14 2015 03:17
can't see anything obvious wrong
are you sure alerting the result is what it wants you to do, and not console log it?
Bin Ury
@teddy-error
Jan 14 2015 03:18

Using jQuery attr method on a selected object as in the 1st jQuery exercise:

$("#next-exercise").attr("disabled", false);

will set disabled to false
However, the jquery code:

$("#next-exercise").attr("disabled", "false");

Will not.

Looking at the jquery documentation for attr, the method is supposed to only take a number or string for the value parameter. How are we supposed to know to pass false as a keyword in this instance?

I shared a screenshot
Bin Ury
@teddy-error
Jan 14 2015 03:19
var randomRGBA = 'rgba('+red+','+green+', '+blue+', 1')'; looks wrong
too many apostrophes
Ben Clist
@BenClist
Jan 14 2015 03:20
good spot, lose the apostrophe after the 1
Bill Maca
@bmaca
Jan 14 2015 03:21
Ahh shikes
Good catch guys
I should of tossed that into a text editor
James McShane
@jmcshane
Jan 14 2015 03:35
Has anyone successfully installed the mongodb instance they offer through cloud 9 and connected via a node.js mongo driver?
James McShane
@jmcshane
Jan 14 2015 03:48
nvm, wrong port
Dominic Jones
@towwiow
Jan 14 2015 04:29
Glad you figured it out!
Evan Davis
@davisec52
Jan 14 2015 16:19

Good morning everybody! And again, I am still working on the coderbyte LetterChanges problem.

At this point, the code I'm working with produces a string with characters promoted and spacing intact.

The main problems are these: the function ignores the second elseif statement intended to allow non alpha characters and the else if statment to change vowels to upper case throws a TypeError on "match".

I'd appreciate any advice :)

function dev(str) {
    phraseArr = str.split("");
    var alphabet = ("abcdefghijklmnopqrstuvwxyz").split("");
    var count = [];
    count.length = str.length;
    for(var i = 0; i < alphabet.length; i++) {
        for(var j = 0; j < str.length; j++) {
            if(str[j] === alphabet[i]) {
              count[j] = alphabet[(i + 1) % 26];
            }
            else if(str[j] >= String.fromCharCode(32) && phraseArr[j] <= String.fromCharCode(47)) {
               count[j] = phraseArr[j];
            }
            else if(str[j] >= String.fromCharCode(58) && phraseArr <= String.fromCharCode(64)) {
               count[j] = phraseArr[j];
            }
            else if(count[j].match(/[aeiou]/g)) {
                count[j] = count[j].toUpperCase();
            }
        }

    }
    return count.join("");
}
dev("hello worldz ##@?");
Evan Davis
@davisec52
Jan 14 2015 17:05
I fixed the upper case change issue but the second elseif statement still does not work. Anyone have any suggestions?
function dev(str) {
    phraseArr = str.split("");
    var alphabet = ("abcdefghijklmnopqrstuvwxyz").split("");
    var count = [];
    count.length = str.length;
    for(var i = 0; i < alphabet.length; i++) {
        for(var j = 0; j < str.length; j++) {
            if(str[j] === alphabet[i]) {
              count[j] = alphabet[(i + 1) % 26];
                if(count[j].match(/[aeiou]/g)) {
                count[j] = count[j].toUpperCase();
            }
                }

            else if(str[j] >= String.fromCharCode(32) && phraseArr[j] <= String.fromCharCode(68)) {
               count[j] = phraseArr[j];
            }
            else if(str[j] >= String.fromCharCode(91) && phraseArr <= String.fromCharCode(96)) {
               count[j] = phraseArr[j];
            }

        }

    }
    return count.join("");
}
dev("hello worldz! [##@?}");
Justin Rogers
@yaskyj
Jan 14 2015 17:14
@davisec52 Why did you decide to create an alphabet variable instead of using the ASCII table?
Evan Davis
@davisec52
Jan 14 2015 17:20
@yaskyj I was running with code I started working with. Wanted to see if I could get it to work. Almost there.
Also, I can't get modulo to work if I start from the ascii table. I just don't see how to do it.
Justin Rogers
@yaskyj
Jan 14 2015 17:27
From your code, it looks like you're beginning your str[j] comparison against the Left Square Bracket instead of "a" which begins the lowercase alphabet at 97.
For some reason I can't see the rest of your code.
To the right.
I can see it now.
Evan Davis
@davisec52
Jan 14 2015 17:32
@yaskyj I'm not sure I see what you are referring to. Could tell me the line number where the comparison is off?
Justin Rogers
@yaskyj
Jan 14 2015 17:33
Well, in your second else if after the && you're comparison is to your entire phaseArr.
Evan Davis
@davisec52
Jan 14 2015 17:39
@yaskyj Yow! Shot down by a typo! You have no idea how long I've stared at that segment! Many thanks!!
Justin Rogers
@yaskyj
Jan 14 2015 17:42
Np. Sometimes you've just looked at your own code too long to see things.
This was my solution. I just did two separate for loops.
function LetterChanges(str) { 

  var output = "";
  for (var i = 0; i < str.length; i++) {
      var c = str.charCodeAt(i);
      if (c >= 97 && c <= 122) {
          output += String.fromCharCode((c - 97 + 1) % 26 + 97);
      } else {
          output += str.charAt(i);
      }
  }
  var output2 = "";
  for (var i = 0; i < output.length; i++) {
      var c = output.charCodeAt(i);
      if (c == 97 || c == 101 || c == 105 || c == 111|| c == 117) {
          output2 += String.fromCharCode(c - 32);
      } else {
          output2 += output.charAt(i);
      }
  }
  return output2;         
}
Evan Davis
@davisec52
Jan 14 2015 17:53
@yaskyj Thank you. This is a much more elegant solution. As I continue, I hope to move in the direction of simplicity and elegance.
Justin Rogers
@yaskyj
Jan 14 2015 17:55
And even now, I look at it and think, why did I do it that way?
And thanks.
Evan Davis
@davisec52
Jan 14 2015 18:06

@yaskyj Here is a solution I found on coderbyte using very few lines of code.

I was wondering if you could explain the return statement to me (sorry, I am very, very new at this). I know what it does, but I don't understand the syntax.


function LetterChanges(str) { 
  return str.replace(/[a-z]/ig,function(c){
    var next = String.fromCharCode(c.charCodeAt() + 1);
    if(/[aeiou]/g.test(next)){
      next = next.toUpperCase(); 
    }
    return c == 'z' ? 'A' : c == 'Z' ? 'A' : next;
  });    
}
Evan Davis
@davisec52
Jan 14 2015 18:15

Also, in your code, is the statment:

c = str.charCodeAt(i)

the same as:


c = str[i].charCodeAt(0)
Justin Rogers
@yaskyj
Jan 14 2015 18:16
@davisec52 It's called a ternary operator. That one is like a nested if else. The question mark is checking the first statement. If true, it returns what is in front of the colon. Otherwise it goes to the next statement. Here's some more documentation on it from the MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
Evan Davis
@davisec52
Jan 14 2015 18:21
@yaskyj Thank you. I'm looking at it right now.
Justin Rogers
@yaskyj
Jan 14 2015 18:22
Those two should be equivalent.
Evan Davis
@davisec52
Jan 14 2015 18:27
Thank you--what I thought.
Suzanne Atkinson
@AdventureBear
Jan 14 2015 19:01
question on JS functions & HTML... I am following another API tutorial, this one on Youtube calls. I finished the tutorial, then wanted to move it over to coderbyte to play more. It won't run in coderbyte when I just move the code directly into the HTML & JS blocks.
I think I know why..the JS is just a bunch of functions, with no "calls" anywhere. But it worked in the codecademy tutorial. I'm wondering if the codecacemy contains some calls that we never see for the sake of getting the tutorial to run?
here is my codepen
Justin Rogers
@yaskyj
Jan 14 2015 19:04
Did you add jQuery to the JS panel?
Nvm you did
Suzanne Atkinson
@AdventureBear
Jan 14 2015 19:04
yes, it's there
lol. Do I need to add a "document ready" call?
or somehow hook up a button or action to get things rolling?
Harry Karapetyan
@hk99
Jan 14 2015 19:16
@AdventureBear open up your console log, getting a 404 on the search call. I don't think that api key will work outside of their lesson.
Suzanne Atkinson
@AdventureBear
Jan 14 2015 19:17
OH!!! cool thank you. I wasn't sure.
that's why they must have said to be logged in while doing it.
Harry Karapetyan
@hk99
Jan 14 2015 19:21
Yeah, either login or sign up for a api key.