These are chat archives for FreeCodeCamp/Help

29th
Jan 2015
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:19
hello codecamp helpers
Nathan
@terakilobyte
Jan 29 2015 04:20
hey there Suzanne
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:20
@terakilobyte good evening!
Nathan
@terakilobyte
Jan 29 2015 04:20
how's it going?
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:20
How are you tonight?
good, I"m pluging away with express.js
Nathan
@terakilobyte
Jan 29 2015 04:20
doing ok
nice
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:20
I have a basic question that's bugging me about it
Nathan
@terakilobyte
Jan 29 2015 04:20
did you see my new blog?
shoot
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:20
Yes I only read the first paragraph this afternoon, decided I wanted to save my fun reading for tonight!
so I haven't finsihed it yet.
Nathan
@terakilobyte
Jan 29 2015 04:21
ah ok
layout looks good though?
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:21
I'm excited that bonfire is running though!
Nathan
@terakilobyte
Jan 29 2015 04:21
yeah me too :)
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:21
oh yeah, the layout is ncie and clean...I like that.
here's my express q
var cities = {
  'Lotopia': 'Rough and mountainous',
  'Caspiana': 'Sky-top island',
  'Indigo': 'Vibrant and thriving',
  'Paradise': 'Lush, green plantation',
  'Flotilla': 'Bustling urban oasis'
};


app.get('/cities/:name', function(request,response) {
    var description = cities[request.params.name];
    if (!description) {
        response.status(404).json('No description found for ' + request.params.name);
    }else {
        response.json(description);
    }  
});
I think the cities object is called a hash, or should I just refer to it as an object? In either case, how does the get route know that city = name and description = description? Couldn't I call those anything, or is 'Name' : 'Description' standard reference?
like what if they were dog: black, cat: orange. it would be animal: color, or would it still be name: description?
Cristián Berríos
@crisberrios
Jan 29 2015 04:38
@AdventureBear description is a variable (var = description) and name comes from the route (/cities/:name)
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:39
Oh. Well that makes sense.
how does it know name is the first part of the key: value pair, or is that just the way it works?
Julie Myers
@BlueOceanView
Jan 29 2015 04:40
@AdventureBear I just finished the node.js class earlier today. Pretty cool stuff.
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:41
good I'm glad to hear that. This section (express module 3) is the first time I've started to feel in over my head. I'm sure more examples will clear it up
Cristián Berríos
@crisberrios
Jan 29 2015 04:41
@AdventureBear you can use name anyway you want. let's say you have a variable request.params.name = "value" (string)
if :name is "010101010" you could use it to parse a binary value and return an integer
Nathan
@terakilobyte
Jan 29 2015 04:43
you can call it a hash
in the sense of the way a hash table operates
but it's still an object
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:43
crazy stuff.
I need to let it sink in.
Julie Myers
@BlueOceanView
Jan 29 2015 04:44
@AdventureBear I'll learn node.js much better later. I've got to much practice coding and building to do with HTML, CSS and JavaScript...then jQuery.
Suzanne Atkinson
@AdventureBear
Jan 29 2015 04:48
will the FCC material include more info on learing node.js as part of the remaining challenges?
The curriculum is feeling "thin" right now compared to the front end HTML/CSS portion, but that might be because I have no prior experience with node.js/express.js stuff.
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:05
How about multiple search parameters? In module two, they showed an example of using ?limit=1 to slice the returned dataset...that worked fine when I tried it. Then they also used a ?search= example in the challenges section. in my app.js both of those worked independantly in my app.get('/cities') route, but how do I get both to work at the same time? Or should I not worry about it right now?
Cristián Berríos
@crisberrios
Jan 29 2015 05:06
those are queries, so you can chain them
?search=example&limit=1
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:07
right I've seen that...but what would my app.get route look like? Nested if's? Serial ifs?
Cristián Berríos
@crisberrios
Jan 29 2015 05:07
then you call by req.param.search and req.param.limit
no
sorry
req.query
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:08
both inside the route? Sorry if it's a basic question. I'm coding a live app.js as I follow along and don't want to end up with Spagetti when I'm done. but I"m also willing to skip it if it will keep me from advancing
Cristián Berríos
@crisberrios
Jan 29 2015 05:08
you can use only one :name since you use that in the route
but if you want multiple parameters, you can use either a JSON object
or multiple queries
like &city2=xx&city3=xx
queries (after ?) are called by request.query.parameterName
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:10
so query.request.limit and query.request.search for example
Cristián Berríos
@crisberrios
Jan 29 2015 05:10
yep
no
request.query
not query.request
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:11
lol.
Cristián Berríos
@crisberrios
Jan 29 2015 05:11
sorry
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:11
right got it
that's what I meant.
I'm looking at my code and typing
and reading and listenign to music and my cat...
maybe time for a break!
or plow through parts 4 & 5?
Nathan
@terakilobyte
Jan 29 2015 05:20
@BlueOceanView you'll do things with angular in two lines that would take 20 in jquery
embrace the mean stack (Mongo, Express, Angular, Node) :P
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:23
I"m done for the night. Brain fried, lol.
this is dense material!
thanks for the /help
Nathan
@terakilobyte
Jan 29 2015 05:24
g'night!
and it gets easier
good books help too
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:24
thanks nathan! What's a good book, or did you already send me a link to one?
Branden Byers
@brandenbyers
Jan 29 2015 05:25
"and it gets easier" says that man that whipped up a bonfire from scratch as a starter project!
Nathan
@terakilobyte
Jan 29 2015 05:25
Mean Web Developmet
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:26
@brndnb haha!
right. the man is on fire!
Nathan
@terakilobyte
Jan 29 2015 05:26
lol @brndnb I had help
and I might have a natural talent for it
who knows
also Getting MEAN with Mongo, Express, Angular, and Node
it's in the mannin early access program atm
MEAP
highly worth it for the design considerations the author writes about
Suzanne Atkinson
@AdventureBear
Jan 29 2015 05:30
thanks!
I'm so close to the end I really want to skip ahead
var isEven = function(number) {
  // Your code goes here!
  if(number % 2)
  {
      return true;
  }
  else{
      return false;
  }
};

The error:

Looks like your function returns false when number = 2. Check whether your code inside the if/else statement correctly returns true if the number it receives is even.

Darryl Dixon - Piece Digital
@piecedigital
Jan 29 2015 07:27
if(number % 2 === 0)
Ammar Ali Shah
@AmmarAliShah
Jan 29 2015 08:47
@piecedigital thanks - that works
Darryl Dixon - Piece Digital
@piecedigital
Jan 29 2015 08:49
Great :) :+1:
Cristián Berríos
@crisberrios
Jan 29 2015 15:11
it should work without === 0 because of type coercion from 0 to false
is 2 being passed as string or number?
lol... 8 hours ago
Nathan
@terakilobyte
Jan 29 2015 15:12
you can always do the much more cryptic if (!number % 2)
Cristián Berríos
@crisberrios
Jan 29 2015 15:15
or number%2? return false: return true;
Nathan
@terakilobyte
Jan 29 2015 15:16
or even better return !(number % 2)
Cristián Berríos
@crisberrios
Jan 29 2015 15:31
or even shorter !(num%2) (without using a function) in most cases)
and even faster (I think) !(2&1);
Ammar Ali Shah
@AmmarAliShah
Jan 29 2015 17:50
var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
for(i = 0; i <  languages.length; i++ )
{
    console.log(languages);
}
Problem?
surikmeetr
@surikmeetr
Jan 29 2015 17:54
you are always printing the whole array
Ammar Ali Shah
@AmmarAliShah
Jan 29 2015 17:58
@surikmeetr problem fixed
Sang Wook Bok
@Sambok
Jan 29 2015 22:31
Did anyone have problem with submitting code to coderbyte challenges??
Cristián Berríos
@crisberrios
Jan 29 2015 22:31
it's not 100% stable
I always copy the code to clipboard before submitting
Sang Wook Bok
@Sambok
Jan 29 2015 22:32
Okay
Should i try to submit some other time?
Cristián Berríos
@crisberrios
Jan 29 2015 22:35
dunno, just keep trying
Sang Wook Bok
@Sambok
Jan 29 2015 22:36
Okay Thanks!