These are chat archives for FreeCodeCamp/HelpJavaScript

25th
Mar 2016
scharla
@scharla
Mar 25 2016 00:00
@SuziexD You're on the right track. getGear is fine. The only issue with setGear is the addition - you're telling it to add your neGear to the existing gear instead of setting (e.g if gear = 2 and newGear = 3, you would get gear 5)
take out the +
Suzie
@SuziexD
Mar 25 2016 00:01
@scharla Thanks!! I just got the eureka moment hahaha
CamperBot
@camperbot
Mar 25 2016 00:01
suziexd sends brownie points to @scharla :sparkles: :thumbsup: :sparkles:
:star: 311 | @scharla | http://www.freecodecamp.com/scharla
scharla
@scharla
Mar 25 2016 00:02
@SuziexD :)
uriznik
@uriznik
Mar 25 2016 00:03
@ChristianRosa are you using wikipedia.com or wikipedia.org?
Jalon Dodson
@JEDodson
Mar 25 2016 00:10
what's the point of a constructor function??
devonwilson1
@devonwilson1
Mar 25 2016 00:20
whats wrong with this code? assignment "multiple identical options in switch statements"

function myTest(val) {
var answer = "";
// Only change code below this line
Switch(val);
case 1:
case 2:
case 3:
result = "1, 2, or 3";
answer: "Low";
break;
case 4:
case 5:
case 6:
result = "4, 5, 6";
answer: "Mid";
break;
case 7:
case 8:
case 9:
result = "7, 8, 9";
answer: "High";
break;

// Only change code above this line
return answer;
}

// Change this value to test
myTest(1);

scharla
@scharla
Mar 25 2016 00:24
@devonwilson1 You should use "=" with your answers!
devonwilson1
@devonwilson1
Mar 25 2016 00:24
changed that still not working and i replaced the missing bracket
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:25
Can anyone help me with the Falsy Bouncer algorithm?
devonwilson1
@devonwilson1
Mar 25 2016 00:25
for some reason the first case of case 1 has error stating "expected brackets and didn't expect expression and missing colon unrecoverable syntax error 15% scanned blah blah
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:26
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var filtered = [];
  filtered = arr.filter(valid);
  return filtered;
}
function valid(value) {

  var test = 0;
  switch(value) {
    case false:
    case null:
    case 0:
    case '':
    case undefined:
    case NaN:
      test = false;
      break;
    default:
      test = value;

    return test !== false;
  }
}
bouncer([false, null, 0, NaN, undefined, ""]);
The 'null' keeps coming through.
Jalon Dodson
@JEDodson
Mar 25 2016 00:28
NaN means Not a Number right?
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:28
Yeah.
Jalon Dodson
@JEDodson
Mar 25 2016 00:28
that beard doe
@jwhisnant97
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:28
The expected answer is '[]'
devonwilson1
@devonwilson1
Mar 25 2016 00:29
anyone?
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:29
I keep getting '[null]'
uriznik
@uriznik
Mar 25 2016 00:30
@devonwilson1 you need to remove the semicolon from the switch line and make sure you have brackets around the case statements
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:30
really? I keep getting [NaN] with that code @jwhisnant97
scharla
@scharla
Mar 25 2016 00:31
@devonwilson1 Your first switch line should end with { not ;
@devonwilson1 you also don't need the result bits
Jalon Dodson
@JEDodson
Mar 25 2016 00:32
you're over complicating it jwhisant
Andrew Charlebois
@andrewchar
Mar 25 2016 00:32
Just finished intermediate algorithms!!!!!!!!!! the last one just took me all day omg
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:32
@JEDodson How so?
devonwilson1
@devonwilson1
Mar 25 2016 00:32
thank you @uriznik
CamperBot
@camperbot
Mar 25 2016 00:32
devonwilson1 sends brownie points to @uriznik :sparkles: :thumbsup: :sparkles:
:star: 360 | @uriznik | http://www.freecodecamp.com/uriznik
devonwilson1
@devonwilson1
Mar 25 2016 00:32
thank you @scharla
CamperBot
@camperbot
Mar 25 2016 00:32
devonwilson1 sends brownie points to @scharla :sparkles: :thumbsup: :sparkles:
:star: 312 | @scharla | http://www.freecodecamp.com/scharla
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:33
@JEDodson if you could just give me a direction that I could read up on.
Jalon Dodson
@JEDodson
Mar 25 2016 00:33
Falsy is something which evaluates to FALSE. There are only six falsy values in JavaScript: undefined, null, NaN, 0, “” (empty string), and false. We need to make sure we have all the falsy values to compare, we can know it, maybe with a function with all the falsy values… Then we need to add a filter() with the falsy values function…
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:33
@jwhisnant97 btw the reason your code doesn't work is because NaN can't equal anything, not even NaN, so it doesn't end up in its case
Jalon Dodson
@JEDodson
Mar 25 2016 00:33
help Falsy Bouncer
CamperBot
@camperbot
Mar 25 2016 00:33

:point_right: algorithm falsy bouncer [wiki]

Problem Explanation:

Remove all falsy values from an array.

:pencil: read more about algorithm falsy bouncer on the FCC Wiki

Jalon Dodson
@JEDodson
Mar 25 2016 00:33
that was a copule hints from the wiki.
take a look there.
scharla
@scharla
Mar 25 2016 00:33
@andrewchar congratz!
Jason Whisnant
@jwhisnant97
Mar 25 2016 00:33
Thanks @JEDodson
CamperBot
@camperbot
Mar 25 2016 00:34
jwhisnant97 sends brownie points to @jedodson :sparkles: :thumbsup: :sparkles:
:star: 250 | @jedodson | http://www.freecodecamp.com/jedodson
devonwilson1
@devonwilson1
Mar 25 2016 00:34
@scharla what do you mean result bits?
scharla
@scharla
Mar 25 2016 00:34
@devonwilson1 result = etc
devonwilson1
@devonwilson1
Mar 25 2016 00:34
i don't need that?
where would i put 1 2 or 3 at?
scharla
@scharla
Mar 25 2016 00:34
@devonwilson1 nope, your var answer fulcills the same function
EternityElephant
@EternityElephant
Mar 25 2016 00:34
function lookUp(firstName, prop){
// Only change code below this line
  var i = 0;

  while(i < contacts.length)
      {
        if(firstName == contacts[i].firstName)
          {
            for (var j = 0; j < contacts[i].length; j++)
              {
                if(prop == contacts[i][j]){
                  return;
                  }else{
                    return "No such property";
                  }
              }
            return contacts[i][prop];
          }
        i++;

      }
  return "No such contact";
// Only change code above this line
}
I cant get my "no such property" to work for the challenge profile lookup. could someone help me out?
scharla
@scharla
Mar 25 2016 00:35
@devonwilson1 it's already in your case
EternityElephant
@EternityElephant
Mar 25 2016 00:35
i think i' going about it in the wrong way
devonwilson1
@devonwilson1
Mar 25 2016 00:36
ok what about the ending first line in "not" I'm not understanding that
Jalon Dodson
@JEDodson
Mar 25 2016 00:36
for (var x = 0; x < contacts.length; x++){
    if (contacts[x].firstName === firstName) {
        if (contacts[x][prop]) {
            return contacts[x][prop];
        } else {
            return "No such property";
        }
    }
}
return "No such contact";
Andrew Charlebois
@andrewchar
Mar 25 2016 00:37
how much of a jump in difficulty is going from intermediate algorithms to the advance?
EternityElephant
@EternityElephant
Mar 25 2016 00:37
would that get nested in the while loop?
Jalon Dodson
@JEDodson
Mar 25 2016 00:38
This is Profile Lookup right?
EternityElephant
@EternityElephant
Mar 25 2016 00:38
yes
bitgrower
@bitgrower
Mar 25 2016 00:38

@bitgrower is awesome, but she can't be everywhere ;)

yeah, sometimes I have to work for a living ... :) Thanks, @SaintPeter

CamperBot
@camperbot
Mar 25 2016 00:38
bitgrower sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2702 | @saintpeter | http://www.freecodecamp.com/saintpeter
Jalon Dodson
@JEDodson
Mar 25 2016 00:38
ayyy @bitgrower is back wb!
Andrew Charlebois
@andrewchar
Mar 25 2016 00:38
@bitgrower you not getting my pm's?
bitgrower
@bitgrower
Mar 25 2016 00:39
@JEDodson -- thanks for jumping in there and helping folks ... helps, doesn't it ?
CamperBot
@camperbot
Mar 25 2016 00:39
bitgrower sends brownie points to @jedodson :sparkles: :thumbsup: :sparkles:
:star: 251 | @jedodson | http://www.freecodecamp.com/jedodson
bitgrower
@bitgrower
Mar 25 2016 00:39
hey, @andrewchar ... just saw ...
lizzieshipton
@lizzieshipton
Mar 25 2016 00:39
can anyone help me with the "Using Objects for Lookups" challenge? really confused here...
devonwilson1
@devonwilson1
Mar 25 2016 00:40
@bitgrower take look please
Jalon Dodson
@JEDodson
Mar 25 2016 00:40
for (var x = 0; x < contacts.length; x++){ // main loop
    if (contacts[x].firstName === firstName) { //condition, if contacts.firstName strictly equals firstName; 
        if (contacts[x][prop]) { //same with this, if contacts/index = prop then:
            return contacts[x][prop]; // returns the correct statement
        } else {
            return "No such property";
        }
    }
}
return "No such contact";
scharla
@scharla
Mar 25 2016 00:40
@devonwilson1 The "result" they use in the example is not a part of the switch, just an example of a one. In the actual exercise, we are using "answer" as the output variable instead. You don't need both
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:40
@EternityElephant Instead of for-looping through all the properties, try using hasOwnProperty
devonwilson1
@devonwilson1
Mar 25 2016 00:41
still having issues without the result
i just have the cases and the answer followed by break
bitgrower @bitgrower volunteers @JEDodson
uriznik
@uriznik
Mar 25 2016 00:42
This message was deleted
Jalon Dodson
@JEDodson
Mar 25 2016 00:42
what's that mean @bitgrower lol
scharla
@scharla
Mar 25 2016 00:42
 switch(val) {
    case 1:
    case 2:
    case 3:

  answer = "Low";
  break;
@devonwilson1 this works just fine for me
Lauren
@LaurenDoughty
Mar 25 2016 00:43
Ok, this has taken me all day on and off and I'm stuck on the same line. I can't get the associated variables to return here. alpha is supposed to return Adams etc. I can't figure out what command to use. I have tried defining variables but they are predefined in the given code. ```
scharla
@scharla
Mar 25 2016 00:43
maybe some missing punctuation?
Lauren
@LaurenDoughty
Mar 25 2016 00:43
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line

  var lookup = {
  "alpha":"Adams",
  "bravo":"Boston",
  "charlie":"Chicago",
  "delta":"Denver",
  "echo":"Easy",
  "foxtrot":"Frank",
  };


  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
bitgrower
@bitgrower
Mar 25 2016 00:43
@JEDodson -- sorry, my internet connection only posted the 2nd message ... I was volunterring you to help someone who was asking for help with Using Objects For Lookups ...
Jalon Dodson
@JEDodson
Mar 25 2016 00:43
@codebonobo you need to make sure you have result pointing to lookup.
Lauren
@LaurenDoughty
Mar 25 2016 00:43
I know there is something at the end I need besides just the table but I don't know what to put in.
Jalon Dodson
@JEDodson
Mar 25 2016 00:44
i'll give you a hint
after }; result =
Lauren
@LaurenDoughty
Mar 25 2016 00:44
@JEDodson So how do I do that? I try to follow the example and it doesn't help
Jalon Dodson
@JEDodson
Mar 25 2016 00:45
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line

  var lookup = {
  "alpha":"Adams",
  "bravo":"Boston",
  "charlie":"Chicago",
  "delta":"Denver",
  "echo":"Easy",
  "foxtrot":"Frank",
  };

      result =

  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
lizzieshipton
@lizzieshipton
Mar 25 2016 00:45
@JEDodson @codebonobo I am stuck on the same problem. don't understand how to get the value into the result variable. also, mine seems to return "Frank" but nothing else for some reason
Lauren
@LaurenDoughty
Mar 25 2016 00:45
@lizzieshipton the example we are supposed to follow does not do that.
Jalon Dodson
@JEDodson
Mar 25 2016 00:46
now, what do we want result to point to?
to output i mean
Lauren
@LaurenDoughty
Mar 25 2016 00:46
result = lookup[val];
Jalon Dodson
@JEDodson
Mar 25 2016 00:46
perfect!
lizzieshipton
@lizzieshipton
Mar 25 2016 00:46
ah
scharla
@scharla
Mar 25 2016 00:46
@codebonobo @lizzieshipton you need to access the key in the dictionary lookup
Lauren
@LaurenDoughty
Mar 25 2016 00:46
Dear God
Sindre
@Sinder33
Mar 25 2016 00:46
How can you post your code here?
Jalon Dodson
@JEDodson
Mar 25 2016 00:46
help code formatting
CamperBot
@camperbot
Mar 25 2016 00:46

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Lauren
@LaurenDoughty
Mar 25 2016 00:47
Sorry, it's just, all day for one line, and if I hadn't asked I'd have had no idea.
I seem to get stuck on things that aren't covered anywhere in the tutorials.
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:47
That was covered though
Jalon Dodson
@JEDodson
Mar 25 2016 00:48
@codebonobo We're here to help :) everyone has questions, even me.. I have a lot of them!
lizzieshipton
@lizzieshipton
Mar 25 2016 00:48
@codebonobo @JEDodson are people more likely to help if you post a picture of your code, as @codebonobo did? Because every time I come on here for help, I get no response and it's really starting to get me down. I literally asked the same question minutes before he did and got no response. And if that is the case, how do I do that?
Jalon Dodson
@JEDodson
Mar 25 2016 00:48
I would've helped you but I wasn't looking at the chat, apologies Lizzie. Help is given regardless.
It just depends on who sees your question.
If you'd like to know though, @lizzieshipton
help code formatting
CamperBot
@camperbot
Mar 25 2016 00:49

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:49
@codebonobo Challenge: Accessing Objects Properties with Variables
scharla
@scharla
Mar 25 2016 00:49
@lizzieshipton type "```js" , then Shift+Enter, then type/copypaste your code then Cntrol+Enter
Erik Verduin
@Everduin94
Mar 25 2016 00:49
Hello! Can anyone help me with the javascript algorithms challenge 'Check for Palindrome'?
Jalon Dodson
@JEDodson
Mar 25 2016 00:50
@Everduin94 shoot
hnry
@hnry
Mar 25 2016 00:50
@lizzieshipton i think that's true, but i wouldn't take it personally
Lauren
@LaurenDoughty
Mar 25 2016 00:50
@lizzieshipton the backtick ` is just to the left of the 1 on my keyboard if that helps you
Shian Poon
@shian3n
Mar 25 2016 00:51
@Everduin94 read the string.indexOf() link, it helps a lot
Erik Verduin
@Everduin94
Mar 25 2016 00:51
@JEDodson Thanks! I'm trying to strip the original input of spaces, commas, etc... however when I use something like str.replace(/\s/g, ''); and use a console.log to display the output. It doesn't seem to have replaced the spaces.
CamperBot
@camperbot
Mar 25 2016 00:51
everduin94 sends brownie points to @jedodson :sparkles: :thumbsup: :sparkles:
:star: 252 | @jedodson | http://www.freecodecamp.com/jedodson
Erik Verduin
@Everduin94
Mar 25 2016 00:51
@shian3n Okay great thanks!
CamperBot
@camperbot
Mar 25 2016 00:51
everduin94 sends brownie points to @shian3n :sparkles: :thumbsup: :sparkles:
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:51
@lizzieshipton In general the following conditions affect possibility of answer: 1) mentioning the name of the challenge, 2) providing current code, and 3) activity of the chat (ex: lots of people asking at once, or no one being available to answer)
CamperBot
@camperbot
Mar 25 2016 00:52
:star: 276 | @shian3n | http://www.freecodecamp.com/shian3n
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:52
@Everduin94 did you assign the result back to the string you're console.logging?
Lauren
@LaurenDoughty
Mar 25 2016 00:52
@CaroleAnneHannon Thanks. It's just so much. I started Friday and I'm trying to keep on the suggested times for each section.
CamperBot
@camperbot
Mar 25 2016 00:52
codebonobo sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 799 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:52
@codebonobo don't focus on the times. Just go at the pace that's comfortable for you
Jalon Dodson
@JEDodson
Mar 25 2016 00:52
@codebonobo Best tips I can give you: don't rush it.
Work at your own pace. If you don't understand something? Re-read it. Don't try to rush through it because then you won't learn.
Erik Verduin
@Everduin94
Mar 25 2016 00:53

@CaroleAnneHannon for example ```
refactoredData = str.replace(/\s/g, '');
refactoredData = str.replace(/,/g, '');

console.log(refactoredData);
```

lizzieshipton
@lizzieshipton
Mar 25 2016 00:53
Thanks @JEDodson @codebonobo @scharla @hnry
CamperBot
@camperbot
Mar 25 2016 00:53
lizzieshipton sends brownie points to @jedodson and @codebonobo and @scharla and @hnry :sparkles: :thumbsup: :sparkles:
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:53
@codebonobo and if you completed a challenge, but didn't quite "get" it, it's best to just ask for an explanation in chat
CamperBot
@camperbot
Mar 25 2016 00:53
:star: 190 | @hnry | http://www.freecodecamp.com/hnry
:star: 313 | @scharla | http://www.freecodecamp.com/scharla
:star: 253 | @jedodson | http://www.freecodecamp.com/jedodson
:star: 220 | @codebonobo | http://www.freecodecamp.com/codebonobo
Jalon Dodson
@JEDodson
Mar 25 2016 00:54
Something I've learned while being here is that the more you actually focus, the less you worry about timing, and "oh when will I get it done", the more you'll succeed. Like @CaroleAnneHannon said you can always ask in the chat.
lizzieshipton
@lizzieshipton
Mar 25 2016 00:54
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha": result = "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };

  result = lookup[val];
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
Jalon Dodson
@JEDodson
Mar 25 2016 00:54
We're always here to help you. Even myself.
lizzieshipton
@lizzieshipton
Mar 25 2016 00:54
YAY!
Jalon Dodson
@JEDodson
Mar 25 2016 00:54
is it working lizzie?
lizzieshipton
@lizzieshipton
Mar 25 2016 00:54
got it. thanks all!
Jalon Dodson
@JEDodson
Mar 25 2016 00:54
good! :) glad it's working.
Lauren
@LaurenDoughty
Mar 25 2016 00:54
@lizzieshipton Congratulations! :)
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:55
@Everduin94 it's working, but remember str doesn't change
@Everduin94 so you're doing the replace from the original string again
@Everduin94 if you changed your 2nd replace to work from refactoredData, it'd work refactoredData = refactoredData.replace(/,/g, '');
@Everduin94 additionally, if you learn a little bit more regex, you can do that in one replace (but that's up to you)
scharla
@scharla
Mar 25 2016 00:57
@lizzieshipton congratz!
Erik Verduin
@Everduin94
Mar 25 2016 00:58
@CaroleAnneHannon Okay great thanks! I'm getting closer
CamperBot
@camperbot
Mar 25 2016 00:58
everduin94 sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 800 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 00:58
Also another tip when trying to learn: if you kind of get it but want to play with it more, then go on an editor and just try different things. You can reuse the FCC editor (I guess), or something like https://repl.it/ which will easily show anything you put in console.log
scharla
@scharla
Mar 25 2016 01:01
@Everduin94 [^a-z]
Lauren
@LaurenDoughty
Mar 25 2016 01:01
@CaroleAnneHannon Thanks, that'll help a lot I think.
CamperBot
@camperbot
Mar 25 2016 01:01
codebonobo sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:warning: codebonobo already gave caroleannehannon points
bitgrower @bitgrower recommends pythontutor.com/javascript.html <--- visualizations !!!
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:03
@scharla that's pretty neat. Too much clicking for when doing lots of changes (for my taste), but I could see that being helpful when debugging something that's been rattling the brain for a long time
scharla
@scharla
Mar 25 2016 01:04
@CaroleAnneHannon It's a bit situational
CaroleAnneHannon @CaroleAnneHannon bookmarks that link
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:05
for when the situation arises, it's definitely a good potential tool
thanks @scharla for sharing something awesome :D
CamperBot
@camperbot
Mar 25 2016 01:06
caroleannehannon sends brownie points to @scharla :sparkles: :thumbsup: :sparkles:
:star: 314 | @scharla | http://www.freecodecamp.com/scharla
Moisés Man
@moigithub
Mar 25 2016 01:06
when u write /me message..ur avatar dont show at left side
sooo.. bitgrower was who wrote that last link pythontutor
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:06
oooops
thanks @bitgrower
CamperBot
@camperbot
Mar 25 2016 01:06
caroleannehannon sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 921 | @bitgrower | http://www.freecodecamp.com/bitgrower
CaroleAnneHannon @CaroleAnneHannon needs glasses...or reading comprehension skills
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:07
not that the regex link isn't helpful either, for those who need it
Malcolm
@noinkling
Mar 25 2016 01:12

Any smart people in here? I'm trying to merge 2 arrays of objects based on some criteria:

var arr1 = [{ id: 1, option: 5 }, { id: 2, option: 3 }, { id: 3, option: null }];
var arr2 = [{ id: 2, option: null }, { id: 3, option: 17 }, { id: 5, option: null },  { id: 1000, option: 500 }];

// Wanted output:
[{ id: 1, option: 5 }, { id: 2, option: 3 }, { id: 3, option: 17 }, { id: 5, option: null },  { id: 1000, option: 500 }]

Order doesn't matter.

Moisés Man
@moigithub
Mar 25 2016 01:17
find the shortest first i suppose...
iterate. and addto largest arr.. if option is not null...
CamperBot
@camperbot
Mar 25 2016 01:17
find the shortest first i supposeiterate and addto largest arr if option is not null
nothing found
gbbrambila
@gbbrambila
Mar 25 2016 01:17

@noinkling you have tryied:

arr1.join(arr2); ?

Miguel T Rivera
@mtrivera
Mar 25 2016 01:18
function mutation(arr){
var regExp = /[arr.length - 1]/i;
var isMutation = regExp.test(arr[0]);

if(isMutation){
    console.log(true);
} else {
    console.log(false);
}
}
the first and last condition do not work but the rest work fine
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:19
@migueltrivera oh wow another person who tried a regex on that one
Jalon Dodson
@JEDodson
Mar 25 2016 01:21
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.

};

var myCar = new Car();

var myBike = new Bike();

  var gear = 10;

  // these are public methods
  this.setGear = function(change) {
    gear += change;
  };

  this.getGear = function() {
    return gear;
};
anyone know what i'm doing wrong?
gbbrambila
@gbbrambila
Mar 25 2016 01:21
@noinkling now i saw the wanted output. The join it will not work.
Tim
@codemymind
Mar 25 2016 01:22
@bitgrower Hey there :)
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:22
@migueltrivera but how come you wrote var regExp = /[arr.length - 1]/i;
gbbrambila
@gbbrambila
Mar 25 2016 01:23
@JEDodson close the end of the: this.getGear
Jalon Dodson
@JEDodson
Mar 25 2016 01:24
it says ther'es a syntax error
if i do
Miguel T Rivera
@mtrivera
Mar 25 2016 01:24
@CaroleAnneHannon to use it as the string to look for in the array
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:25
@migueltrivera you realize you didn't actually look at arr though, so you literally made a regex for [arr.length - 1]
Jalon Dodson
@JEDodson
Mar 25 2016 01:25
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.


var myCar = new Car();

var myBike = new Bike();

  var gear = 10;

  // these are public methods
  this.setGear = function(change) {
    gear += change;
  };

  this.getGear = function() {
    return gear;
   };
};
it says myBike is not defined
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:25
@migueltrivera also, using /stuffgoeshere/ is for literals. For dynamically created regex, you should use the RegExp class
gbbrambila
@gbbrambila
Mar 25 2016 01:26
@JEDodson i remember about this lesson. I think you dont need to sum the change in the gear. After create this two functions you need to use like: myBike.setGear(10); myBike.getGear(); ... I made it i think.
@JEDodson what is the name of the lesson?
Jalon Dodson
@JEDodson
Mar 25 2016 01:27
Make Object Properties Private
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:27
@migueltrivera example: var reg3 = new RegExp(arr[arr.length-1]);
gbbrambila
@gbbrambila
Mar 25 2016 01:27
@JEDodson ok just a moment.. i will see again to remember the rules.
Jalon Dodson
@JEDodson
Mar 25 2016 01:28
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.


var myCar = new Car();

var myBike = new Bike();

  myBike.setGear(10);
  myBike.getGear();

  var gear = 10;

  // these are public methods
  this.setGear = function(change) {
    gear += change;
  };

  this.getGear = function() {
    return gear;


   };
};
That's what I have and I don't really think it's right lol
EternityElephant
@EternityElephant
Mar 25 2016 01:29
could someone check the challenge "Sift through tet with regular expressions" and see if you can edit the line. Ive reloaded a few times and I cant do anything to it
Jalon Dodson
@JEDodson
Mar 25 2016 01:29
what do you mean eternity
EternityElephant
@EternityElephant
Mar 25 2016 01:29
cant edit the text
gbbrambila
@gbbrambila
Mar 25 2016 01:29
@JEDodson i code it:
var Bike = function() {

  // Only change code below this line.  
  var gear = 0;

  this.setGear = function(change){
    gear = change;
  };

  this.getGear = function(){
    return gear;
  };

};

var myBike = new Bike();

myBike.setGear(4);
myBike.getGear();
myBike.setGear(3);
myBike.getGear();
myBike.setGear(1);
Jalon Dodson
@JEDodson
Mar 25 2016 01:29
refresh
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:30
@EternityElephant I'm able to edit
Jalon Dodson
@JEDodson
Mar 25 2016 01:30
hmm.
Miguel T Rivera
@mtrivera
Mar 25 2016 01:30
@CaroleAnneHannon thanks for the help,
EternityElephant
@EternityElephant
Mar 25 2016 01:30
ill try restarting my browser
CamperBot
@camperbot
Mar 25 2016 01:30
migueltrivera sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 803 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
Jalon Dodson
@JEDodson
Mar 25 2016 01:30
thanks @gbbrambila I'll work on it a little more to understand it better.
CamperBot
@camperbot
Mar 25 2016 01:30
jedodson sends brownie points to @gbbrambila :sparkles: :thumbsup: :sparkles:
:star: 278 | @gbbrambila | http://www.freecodecamp.com/gbbrambila
EternityElephant
@EternityElephant
Mar 25 2016 01:32
still cant edit anything, i can edit on other challenges but not that one
gbbrambila
@gbbrambila
Mar 25 2016 01:33

@JEDodson nice... So read the rule: Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.

  • The end says: to get and set that value.
    -> Now if you see the tests: myBike.getGear() should return 4 after calling myBike.setGear(4).
    You just need to set and get the values to show the usage of the functions.

Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:34
@EternityElephant did you put a loop in it?
EternityElephant
@EternityElephant
Mar 25 2016 01:35
i havent dont anything it a new challenge
Carole Anne Hannon
@CaroleAnneHannon
Mar 25 2016 01:36
weird o.O
EternityElephant
@EternityElephant
Mar 25 2016 01:36
lol ok i refreshed for the 3rd time and it working
jeez
Vik
@vvang044
Mar 25 2016 01:43
Hello guys
i am stuck with title sentence need some help please.......
its actually title case a sentence
gbbrambila
@gbbrambila
Mar 25 2016 01:45
@vvang044 Hello guy.. send your code :D
Vik
@vvang044
Mar 25 2016 01:46
i managed to get the first letter to capitalize but i am having trouble joining...... couldnt figure out how to use join()
function titleCase(str) {

  var titleStr = str.split(' ');

 for (var i = 0; i < titleStr.length; i++){

   titleStr[i] = titleStr[i].charAt(0).toUpperCase();
 }

  return titleStr.join(' ');
}

titleCase("I'm a little tea pot");
gbbrambila
@gbbrambila
Mar 25 2016 01:48
@vvang044 your join are good.
Vik
@vvang044
Mar 25 2016 01:48
if i remove the return join...... it will print ILTP.....i couldnt figure how to add the rest of the words to the capitals
gbbrambila
@gbbrambila
Mar 25 2016 01:49
@vvang044 you just need get the end of the word.
Vik
@vvang044
Mar 25 2016 01:49
indeed.....question is how to
gbbrambila
@gbbrambila
Mar 25 2016 01:50
@vvang044 try it:
titleStr[i] = titleStr[i].charAt(0).toUpperCase() + "" + "" + titleStr[i].slice(1).toLowerCase();
Vik
@vvang044
Mar 25 2016 01:50
what is slice?
gbbrambila
@gbbrambila
Mar 25 2016 01:51
@vvang044 so slice has two arguments where the second is optional
@vvang044 i will find a better explanation.
Vik
@vvang044
Mar 25 2016 01:52
ok....thank you
gbbrambila
@gbbrambila
Mar 25 2016 01:53
@vvang044 look: http://www.w3schools.com/jsref/jsref_slice_array.asp
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1, 3);

result: Orange,Lemon
Vik
@vvang044
Mar 25 2016 01:54
ok let me fix my code
gbbrambila
@gbbrambila
Mar 25 2016 01:55
now if you use:
 var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
  var citrus = fruits.slice(2);

the result will be the end of elements after including the index 2

Lemon,Apple,Mango
@vvang044 you welcome. =D
Joey Cavazos
@cavascript
Mar 25 2016 01:55
// Only change code below this line
function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
brain fart help
gbbrambila
@gbbrambila
Mar 25 2016 01:56
@cavascript what is the name of this lesson?
Joey Cavazos
@cavascript
Mar 25 2016 01:57
Record collection
javascript objects
gbbrambila
@gbbrambila
Mar 25 2016 01:57
@cavascript ok let me see.
Vik
@vvang044
Mar 25 2016 01:58
@gbbrambila thank you for the help with my code......but i really i have to understand how to use slice.....let me check the link you gave
CamperBot
@camperbot
Mar 25 2016 01:58
vvang044 sends brownie points to @gbbrambila :sparkles: :thumbsup: :sparkles:
:star: 279 | @gbbrambila | http://www.freecodecamp.com/gbbrambila
gbbrambila
@gbbrambila
Mar 25 2016 01:59
@vvang044 nice.. check the link and explore others examples in google =D
@cavascript i think you dont need to reset: collection[id][prop] = [];
Vik
@vvang044
Mar 25 2016 02:00
@cavascript are you following the steps properly
if i still remember
prop === trakc and value !=== something along those lines
track
Joey Cavazos
@cavascript
Mar 25 2016 02:00
thanks @gbbrambila @vvang044 i really thought I was, been working as a server at a restaurant for 17 hours so my brains not all there right now probably making some silly mistakes
CamperBot
@camperbot
Mar 25 2016 02:00
cavascript sends brownie points to @gbbrambila and @vvang044 :sparkles: :thumbsup: :sparkles:
:star: 255 | @vvang044 | http://www.freecodecamp.com/vvang044
:star: 280 | @gbbrambila | http://www.freecodecamp.com/gbbrambila
Vik
@vvang044
Mar 25 2016 02:01
@cavascript .......i just worked a double shift today at restaurant
haha.....welcome to the club my friend
gbbrambila
@gbbrambila
Mar 25 2016 02:02
@cavascript try this:
function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
//collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
@cavascript @vvang044 keep with the good work. You too will be great developers
Vik
@vvang044
Mar 25 2016 02:03
one day gbb
Joey Cavazos
@cavascript
Mar 25 2016 02:03
ok i tried that i forgot to mention i had removed that cuz i did remember i didn't need to reset the array
push would create one for me however that doesn't seem to do it
also sorry but how do i make my code look nice like you did when i copy and paste?
gbbrambila
@gbbrambila
Mar 25 2016 02:04
help code formatted
CamperBot
@camperbot
Mar 25 2016 02:04
no wiki entry for: code formatted
Vik
@vvang044
Mar 25 2016 02:05
try pasting your code by typing three shift enter.....paste your code in the middle of those and hit enter
`
Joey Cavazos
@cavascript
Mar 25 2016 02:05
function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
//collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
//collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
gbbrambila
@gbbrambila
Mar 25 2016 02:05
look the markdown button>
try Ctrl+Shift+M
Vik
@vvang044
Mar 25 2016 02:06
you need to use this " ` ".....three of them
gbbrambila
@gbbrambila
Mar 25 2016 02:06
| (shift+enter for line break) var code = "formatted"; |
Joey Cavazos
@cavascript
Mar 25 2016 02:06
function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
//collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
gbbrambila
@gbbrambila
Mar 25 2016 02:06
lol. i cant show.
Joey Cavazos
@cavascript
Mar 25 2016 02:06
'''
CamperBot
@camperbot
Mar 25 2016 02:06
:bulb: to format code use backticks! ``` more info
Joey Cavazos
@cavascript
Mar 25 2016 02:06
function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
//collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
'''function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
//collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
CamperBot
@camperbot
Mar 25 2016 02:07
:bulb: to format code use backticks! ``` more info
Vik
@vvang044
Mar 25 2016 02:07
cava.......its more like an aphostrophy.....next to 1 key
Joey Cavazos
@cavascript
Mar 25 2016 02:07
oh god ill just stop
```function update(id, prop, value) {
if(id !== "" && prop != "tracks"){
collection[id][prop] = value;
}else if( prop == "tracks" && value !== ""){
//collection[id][prop] = [];
collection[id][prop].push(value);
}else if (value === ""){
delete collection[id][prop];
}
}
Jalon Dodson
@JEDodson
Mar 25 2016 02:07
cava
do exactly this
```
press shift+enter then put code here
Joey Cavazos
@cavascript
Mar 25 2016 02:07
```
Jalon Dodson
@JEDodson
Mar 25 2016 02:07
```
all in one line
in one message i mean
i'll use apostrophes for example
'''
CamperBot
@camperbot
Mar 25 2016 02:07
:bulb: to format code use backticks! ``` more info
gbbrambila
@gbbrambila
Mar 25 2016 02:08
``` example
Jalon Dodson
@JEDodson
Mar 25 2016 02:08
'''
code here
'''
CamperBot
@camperbot
Mar 25 2016 02:08
:bulb: to format code use backticks! ``` more info
Jalon Dodson
@JEDodson
Mar 25 2016 02:08
replace ''' with ```
CamperBot
@camperbot
Mar 25 2016 02:08
:bulb: to format code use backticks! ``` more info
gbbrambila
@gbbrambila
Mar 25 2016 02:08
camperbot help
help
CamperBot
@camperbot
Mar 25 2016 02:08

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. ex: find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

:speech_balloon: meet CamperBot in this room!

:pencil: read more about camperbot on the FCC Wiki

Jalon Dodson
@JEDodson
Mar 25 2016 02:08
help code formatting
CamperBot
@camperbot
Mar 25 2016 02:08

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Joey Cavazos
@cavascript
Mar 25 2016 02:09
function update(id, prop, value) {
  if(id !== "" && prop != "tracks"){
    collection[id][prop] = value;
  }else if( prop == "tracks" && value !== ""){
    //collection[id][prop] = [];
    collection[id][prop].push(value);
  }else if (value === ""){
    delete collection[id][prop];
  }
}
gbbrambila
@gbbrambila
Mar 25 2016 02:09
@JEDodson aeeee
Joey Cavazos
@cavascript
Mar 25 2016 02:09
yay lol thanks...
gbbrambila
@gbbrambila
Mar 25 2016 02:09
@cavascript nice!! hehe i was try to remember how show the help
Vik
@vvang044
Mar 25 2016 02:10
fianlly
Joey Cavazos
@cavascript
Mar 25 2016 02:18
ok well
Andreas Alme
@Addibro
Mar 25 2016 02:29
Hello everyone, I'm on Stand in Line and I solved it like this:
function queue(arr, item) {
  // Your code here
  testArr.push(item);
  testArr.shift();
  return arr[0] || item;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
but I'm not sure if that was the correct solution really
that return I'm not sure about
Andy Bonner
@AbdiViklas
Mar 25 2016 02:31
Hey everybody. Quick and random question (tho I don't know if it's an easy answer): I see a lot of functions listed on MDN with .prototype as part of their name--string.prototype.replace, array.prototype.map, etc., though I also see them being used without that prototype in there (e.g. string.replace()). What does the prototype mean and is it important to include?
Dylan
@dhcodes
Mar 25 2016 02:35
@AbdiViklas all JS parts are objects and thus inherit traits from a prototype object.
Andy Bonner
@AbdiViklas
Mar 25 2016 02:36
@dhcodes thanks!
CamperBot
@camperbot
Mar 25 2016 02:36
abdiviklas sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star: 472 | @dhcodes | http://www.freecodecamp.com/dhcodes
bitgrower
@bitgrower
Mar 25 2016 02:45
hi @codemymind ... welcome to HelpJavaScript ...
dkennell
@dkennell
Mar 25 2016 02:53
Hey, friends! Working on the Mutations challenge and I'm having a hard time accessing my variables inside of my for loops.
function mutation(arr) {
  var presentCount = 0;
  arr[0] = arr[0].toLowerCase;
  arr[1] = arr[1].toLowerCase;
  for (i = 0; i < arr[1].length; i++) {
    for (j = 0; j < arr[0].length; j++) {
      if (arr[1][i] == arr[0][j]) {presentCount += 1;}
    }
  }
  if (presentCount == arr[1].length) {   
  return true;
  }
  else 
  {
    return false;
  }
}

mutation(["hello", "hey"]);
Also, I think I'm somehow changing the value of arr[1].length. console.log is showing both of my test values as zero.
....By which I mean, presentCount and arr[1].length. They both just keep evaluating to zero. :worried:
hnry
@hnry
Mar 25 2016 02:59
@dkennell toLowerCase is a function, you have to call it .toLowerCase()
@dkennell also unrelated but it's good practice to declare the variable i and j with var, so for (var i = 0 and the same for j
dkennell
@dkennell
Mar 25 2016 03:01
@hnry Ah, right, thanks. I always forget that.
CamperBot
@camperbot
Mar 25 2016 03:01
dkennell sends brownie points to @hnry :sparkles: :thumbsup: :sparkles:
:star: 191 | @hnry | http://www.freecodecamp.com/hnry
hnry
@hnry
Mar 25 2016 03:03
@AbdiViklas when you see the x.prototype.y stuff, think of them as calling that function generically, and when you see x.y think of it as a function that's more specific to x
dkennell
@dkennell
Mar 25 2016 03:04
@hnry Hm... Still failing, though.
Ken Haduch
@khaduch
Mar 25 2016 03:05

@dkennell - in the exercise they suggest String.indexOf to look for letters - that could make your code a little more straightforward.

What is happening with it now - are any cases passing?

and if you find a character that is not present, you just return false immediately and don't have to look for any more.
dkennell
@dkennell
Mar 25 2016 03:08
@khaduch Ah, right. I guess I kind of got tunnel vision with my approach. I'l give it a shot and report back. : )
Huazhou Wang
@plause
Mar 25 2016 03:08
Hi, why the test case every([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex") should return true in "everything-be-true".
Ken Haduch
@khaduch
Mar 25 2016 03:09
@dkennell - it seems that what you are doing could work, I'm just having tunnel vision looking at the code... :)
@dkennell - one thing that could potentially cause your code to fail is if you have repeated letters? I'm not sure what they put in the test cases...
dkennell
@dkennell
Mar 25 2016 03:12
@khaduch Shazam! Got it, thanks!
CamperBot
@camperbot
Mar 25 2016 03:12
dkennell sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 789 | @khaduch | http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Mar 25 2016 03:13
@dkennell - great! you're welcome (if I helped that much...)
Ken Haduch
@khaduch
Mar 25 2016 03:18
@dkennell - I think that it was the strings that had repeated letters - the "hello", "Hello" case counted the l multiple times, resulting in a mismatched count, it seemed that most of the other cases passed.
dkennell
@dkennell
Mar 25 2016 03:23
RIght, I think that was the issue. I was using console.log, and seeing a bunch of mismatched counts, I think it came from that.
Ken Haduch
@khaduch
Mar 25 2016 03:26
@dkennell - yes, console.log is helpful - when I'm stumped like that I put a load of log statements in there and report what letter I'm matching, etc. It's a pain, wish there was an easier way to do that... :)
Javier Sanchez
@javiermxmd
Mar 25 2016 03:26
hi
:D
how are you doing guys
dkennell
@dkennell
Mar 25 2016 03:29
Hey, Javier, doing good
Ken Haduch
@khaduch
Mar 25 2016 03:31
@javiermxmd - hello, not too bad, getting late here. How are you doing?
Rakesh1992
@Rakesh1992
Mar 25 2016 04:19
"Selecting from many options with Switch Statements"
can anyone help me to solve this ?
Artur Sęp
@a-sep
Mar 25 2016 04:19
Hi @javiermxmd , forward :)
Rafael
@rafaelpdl
Mar 25 2016 04:20
Hello, everyone! In the following piece of code, could someone explain me what the "?" in the second line does?
arr.filter(function(val){
    return (val !=7) ? val : null;
});
Artur Sęp
@a-sep
Mar 25 2016 04:20
@rafaelpdl if true returns val, if not true returns null
Rakesh1992
@Rakesh1992
Mar 25 2016 04:21
Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - "delta" Please help
V Arun Kumar
@arunvkumr
Mar 25 2016 04:21
@rafaelpdl ?: this statement is called the ternary operator which is similar to if condition..
( conditional statement)?(if true this will execute):(if false this will execute)
Rafael
@rafaelpdl
Mar 25 2016 04:23
@arunkumrv @a-sep Thank you very much! I will sure read that up too :)
CamperBot
@camperbot
Mar 25 2016 04:23
rafaelpdl sends brownie points to @arunkumrv and @a-sep :sparkles: :thumbsup: :sparkles:
:star: 397 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
:star: 282 | @a-sep | http://www.freecodecamp.com/a-sep
Rafael
@rafaelpdl
Mar 25 2016 04:28
So, I have the following piece of code. I want to filter out of "bouncer" the 7. Can someone explain to me what is the error in my code?
var bouncer =[7, "ate", "", false, 9];

bouncer.filter(function(val){
    return (val !=7) ? val : null;
});

console.log(bouncer);
It is still returning the same bouncer array, without any changes.
Soham
@appfobia
Mar 25 2016 04:30
@rafaelpdl You have to return either true or false , in case of filter.
You are returning a vall / null
V Arun Kumar
@arunvkumr
Mar 25 2016 04:30
@rafaelpdl yup filter works with boolean values.. only true and false.
David Weedmark
@DavidWeedmark
Mar 25 2016 04:31
@rafaelpdl there's a reason they include boolean in the hints on that one *hint hint
Miguel T Rivera
@mtrivera
Mar 25 2016 04:32
wiki mutation
CamperBot
@camperbot
Mar 25 2016 04:32

:point_right: algorithm mutations [wiki]

Problem Explanation:

  • Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array..
:pencil: read more about algorithm mutations on the FCC Wiki
Rafael
@rafaelpdl
Mar 25 2016 04:32
@appfobia @arunkumrv So, from what I understand I should write it in some way like the following? But still it does not work :(
var bouncer =[7, "ate", "", false, 9];

bouncer.filter(function(val){
    return (val !=7);
});

console.log(bouncer);
Huazhou Wang
@plause
Mar 25 2016 04:32
@rafaelpdl > filter() does not mutate the array on which it is called.
Rafael
@rafaelpdl
Mar 25 2016 04:33
@DavidWeedmark I have read that a few times already. I am still not understanding how to do it. I have been trying to do something "easier" (in this case, filtering out the value 7) to try to understand it better, but I am having difficulties with it
@plause Oh, I see! So I have to create a new array then? I tried the following and indeed it worked :)

var bouncer =[7, "ate", "", false, 9];

var hola = bouncer.filter(function(val){
    return (val !=7);
});

console.log(bouncer);
console.log(hola)
The array hola is returning what I wanted. Thanks, very much @plause @appfobia @arunkumrv
CamperBot
@camperbot
Mar 25 2016 04:35
rafaelpdl sends brownie points to @plause and @appfobia and @arunkumrv :sparkles: :thumbsup: :sparkles:
:warning: rafaelpdl already gave arunkumrv points
:star: 343 | @appfobia | http://www.freecodecamp.com/appfobia
:star: 300 | @plause | http://www.freecodecamp.com/plause
V Arun Kumar
@arunvkumr
Mar 25 2016 04:36
@rafaelpdl remember that filter returns a new array with values to keep which returns false.. you are returning the original array in your code..
@rafaelpdl You're welcome. :grinning:
David Weedmark
@DavidWeedmark
Mar 25 2016 04:37
@rafaelpdl awesome
@rafaelpdl this would have worked too return arr.filter(Boolean);
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 04:38
means rather than providing a function we can also provide a condition is that?
@rafaelpdl
like array.filter()
arrray.filter(a===5)
Rafael
@rafaelpdl
Mar 25 2016 04:45
@DavidWeedmark Could you please explain a bit more the return arr.filter(Boolean)? I do not understand it.
Shivaji
@psrijan
Mar 25 2016 04:47
In Javascript profile Look up challenge what does prop refer to? Can it refer to lastname, number and individual elements of like array ?
Challenge no 221
Soham
@appfobia
Mar 25 2016 04:50
Use hasOwnProperty() to see if that property exists or not inside an object.
David Weedmark
@DavidWeedmark
Mar 25 2016 04:50
@rafaelpdl putting Boolean in the function makes it do the work automatically If the value is 0, null, false, NaN, undefined, or non-existant, the value is automatically false. Every other value automatically returns true.
Rafael
@rafaelpdl
Mar 25 2016 04:53
@DavidWeedmark So, you are saying that that previous piece of code could also look like this?:
var bouncer =[7, "ate", "", false, 9];

var hola = bouncer.filter(Boolean(val !=7);

console.log(bouncer);
console.log(hola)
Oops. Like this:
var bouncer =[7, "ate", "", false, 9];

var hola = bouncer.filter(Boolean(val !=7));

console.log(bouncer);
console.log(hola);
Shivaji
@psrijan
Mar 25 2016 04:55
@appfobia thanks that helped. I totally forgot about that function
CamperBot
@camperbot
Mar 25 2016 04:55
psrijan sends brownie points to @appfobia :sparkles: :thumbsup: :sparkles:
:star: 344 | @appfobia | http://www.freecodecamp.com/appfobia
Soham
@appfobia
Mar 25 2016 04:55
@psrijan You are welcome.
David Weedmark
@DavidWeedmark
Mar 25 2016 04:56
@rafaelpdl nope I'm saying it could look like this:
This message was deleted
Rafael
@rafaelpdl
Mar 25 2016 04:58
@DavidWeedmark Oh I see. I dont get how that tests if the value is 7 or not, though. Would you mind explaining that?
@DavidWeedmark Thanks for the help so far.
CamperBot
@camperbot
Mar 25 2016 04:58
rafaelpdl sends brownie points to @davidweedmark :sparkles: :thumbsup: :sparkles:
:star: 432 | @davidweedmark | http://www.freecodecamp.com/davidweedmark
David Weedmark
@DavidWeedmark
Mar 25 2016 04:58
@rafaelpdl I deleted that cuz I don't think I should leave it online in case others are working on it
@rafaelpdl Boolean doesn't check for 7 or not, it checks any numbers, returning false if it's zero or NaN etc. If it's 7 or any other real number, it returns true. So whatever the numbers it returns true. make sense?
Rafael
@rafaelpdl
Mar 25 2016 05:00
@DavidWeedmark Yes! Now I get it! Thanks very much :)
CamperBot
@camperbot
Mar 25 2016 05:00
rafaelpdl sends brownie points to @davidweedmark :sparkles: :thumbsup: :sparkles:
:warning: rafaelpdl already gave davidweedmark points
David Weedmark
@DavidWeedmark
Mar 25 2016 05:01
@rafaelpdl that's why it was hard to give you a decent hint earlier. it's just one line
@rafaelpdl but was glad I could share it after you solved it yourself
Rafael
@rafaelpdl
Mar 25 2016 05:03
@DavidWeedmark Yes, I wasn't understanding how exactly boolean works, but now I think I do. :)
Andrew Bales
@agbales
Mar 25 2016 05:15
Hello all, I'm working on Steamroller. Think I have this close, but it gets stuck on nested arrays. Any thoughts?
function steamroller(arr) {
  var steamArray = [];

  for (var i = 0; i < arr.length; i++) {
    if(Array.isArray(arr[i])) {
      steamArray = steamArray.concat(arr[i]);   
    } else {
      steamArray.push(arr[i]);
    }
  }

  return steamArray;
}

steamroller([1, [2], [3, [[4]]]]);   // [1,2,3,[[4]]]
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 05:19
you are only concat the array at first level while it has three levels you can try something like recursion here
@agbales
Andrew Bales
@agbales
Mar 25 2016 05:21
I suspected that's where my trouble is (because 4 is inside an array, and it is concatenating it in some way). What might recursion look like?
I'm not sure I understand yet.
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 05:23
function fx(){}
OmMinky
@OmMinky
Mar 25 2016 05:24
Hi all, reaching for record collection help
/ Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function update(id, prop, value) { //Each album is identified by a unique id number and has several properties.
// For the given id in collection.
var evalUpdate={ //(using lookupfunction)
  (value!=="") + (prop !== "tracks"): 
  collection[id][prop]= value,
  //If value is non-blank (value !== "") and prop is not "tracks" 
  //then update or set the value for the prop.
(value!=="") + (prop === "tracks"): 
  collection[id][prop].push(value), 
  //If the prop is "tracks" and value is non-blank
  //push the value onto the end of the tracks array.
  //(.push() takes one or more parameter and "pushes" it onto the end of the array.
(value.length= 0): delete collection[id][prop] };
  //If value is blank, delete that prop.

return collection(evalUpdate);
  //Always return the entire collection object.

}
// Alter values below to test your code
update(5439, "artist", "ABBA");



var code = "formatted";
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 05:24
hold on i am writing
fx(a){
if a is array
return fx(a)
else
return a;
}
Andrew Bales
@agbales
Mar 25 2016 05:27
Ah, so that would replace the for loop?
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 05:28
may be i can't tell you perfect but this coukd be a path you can look firward
Andrew Bales
@agbales
Mar 25 2016 05:30
I'll give it a try, thanks @yashdeeph709 yashdeeph
CamperBot
@camperbot
Mar 25 2016 05:30
agbales sends brownie points to @yashdeeph709 :sparkles: :thumbsup: :sparkles:
:star: 345 | @yashdeeph709 | http://www.freecodecamp.com/yashdeeph709
Og-Morrow
@Og-Morrow
Mar 25 2016 05:33
Please help with Using Objects for Lookups
var lookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank",
};
rphares
@rphares
Mar 25 2016 05:35
Ooh, good, you've gotten he first half of the instructions done, @Og-Morrow !
Og-Morrow
@Og-Morrow
Mar 25 2016 05:35
Ive created an object but i dont understand the calling method
rphares
@rphares
Mar 25 2016 05:35
Now, you need to "use it to look up val and return the associated string"
Shivaji
@psrijan
Mar 25 2016 05:35

Challenge 221:
I tried using this. But Only two of the test cases pass. Can anyone tell why? Also in the console values logged is printed 6 times. If only 4 test cases were passed then why 6 values are logged ?
function update(id, prop, value) {
if(value === ""){
console.log("A");
delete collection[id].prop;

}
else if(value!=="" && prop!="tracks") {
collection[id][prop]= value;
console.log("B");
}
else if(prop==="tracks" && value!==""){
collection[id].tracks.push(value);
console.log("C");
}

return collection;
}

rphares
@rphares
Mar 25 2016 05:35
yep-- lets check the example,
see their table, the one called var alpha?
Og-Morrow
@Og-Morrow
Mar 25 2016 05:35
yes
rphares
@rphares
Mar 25 2016 05:36
they write alpha[2] to get what is associated with 2
you want to get, from our table, what is associated with val, so you could write that...?
(there is another step after that, dont be concerned when that alone doesn't work :blush: )
Og-Morrow
@Og-Morrow
Mar 25 2016 05:36
alrighty give me a sec
rphares
@rphares
Mar 25 2016 05:37
:plus1:
Og-Morrow
@Og-Morrow
Mar 25 2016 05:39
sorry i just cant make the snap, lol its quite frustrating.
@rphares
rphares
@rphares
Mar 25 2016 05:39
its okay-- can you paste what you just tried (to follow the example?)
Og-Morrow
@Og-Morrow
Mar 25 2016 05:41
well everything i try just throws errors
rphares
@rphares
Mar 25 2016 05:41
thats okay-- if you can show me what you are trying, it'll help me see what you are/arent getting
hnry
@hnry
Mar 25 2016 05:41
@rphares see i knew you knew your stuff!
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 05:41
pls man give a link to problem i am working on smartphone

// Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank",
};
lookup['alpha';]
// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("bravo");

rphares
@rphares
Mar 25 2016 05:42
@Og-Morrow , the last thing (that likely made it throw errors) is that the part i talked about using doesn't stand alone--
okay, cool!
Jalon Dodson
@JEDodson
Mar 25 2016 05:43
@Og-Morrow you need to have result output lookup
rphares
@rphares
Mar 25 2016 05:43
so, two things--
Og-Morrow
@Og-Morrow
Mar 25 2016 05:43
lol it made a smiley
whats up
Jalon Dodson
@JEDodson
Mar 25 2016 05:43
after the first };
put result = x[x]
the first x would be...
rphares
@rphares
Mar 25 2016 05:43
as @JEDodson is saying, you need to store that line (what is currently lookup['alpha'] in your code, in result
Jalon Dodson
@JEDodson
Mar 25 2016 05:43
what you want to point result to.
rphares
@rphares
Mar 25 2016 05:44
second, you dont want to look up 'alpha' specifically. look at the example again, the way they used 2 to get y....
alpha is from the test, i would guess, but--
Jalon Dodson
@JEDodson
Mar 25 2016 05:44
So, it'd equal result = lookup(val) because we're wanting to obtain the lookup var, and the val param.
rphares
@rphares
Mar 25 2016 05:44
you were told "use it to lookup var and return the associated string`
oh... okay then...
Og-Morrow
@Og-Morrow
Mar 25 2016 05:45
right, alrighty so give me a second haha
Jalon Dodson
@JEDodson
Mar 25 2016 05:45
be sure to include the semi-colon
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 05:46
return lookup[val] this will work fine
Jalon Dodson
@JEDodson
Mar 25 2016 05:46
sorry @rphares
no that wouldn't work yash
you're not wanting to directly output lookup[val]
rphares
@rphares
Mar 25 2016 05:47
well, it will technically run,
but its not the point of the exercise, no
Jalon Dodson
@JEDodson
Mar 25 2016 05:47
well, yeah but that's not what they're wanting you to do
rphares
@rphares
Mar 25 2016 05:47
one of the things they want, in this, is to see that you have to connect things to what you will return
Jalon Dodson
@JEDodson
Mar 25 2016 05:47
they're wanting you to have result output the lookup var and the phoneticLookup param
Og-Morrow
@Og-Morrow
Mar 25 2016 05:47
right, did you want me to adjust the result above the table?
rphares
@rphares
Mar 25 2016 05:47
nope
not above
Jalon Dodson
@JEDodson
Mar 25 2016 05:48
result = lookup[val]
you'd add that below the first };
above return result;
Og-Morrow
@Og-Morrow
Mar 25 2016 05:49
haha i did that like ten sentences up but put parenthesis hahahaha! man i was scratching my head

// Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank",
};
result = lookup[val];
// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("bravo");

Bueno?
Jalon Dodson
@JEDodson
Mar 25 2016 05:49
bueno
Og-Morrow
@Og-Morrow
Mar 25 2016 05:49
Man you guys are awesome!
Jalon Dodson
@JEDodson
Mar 25 2016 05:49
by the way
help code formatting
CamperBot
@camperbot
Mar 25 2016 05:49

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Og-Morrow
@Og-Morrow
Mar 25 2016 05:50
thanks alot! :smile:
Jalon Dodson
@JEDodson
Mar 25 2016 05:50
@Og-Morrow you're welcome
Og-Morrow
@Og-Morrow
Mar 25 2016 05:51
can I like +1 you guys somehow? lol
Jalon Dodson
@JEDodson
Mar 25 2016 05:51
help
CamperBot
@camperbot
Mar 25 2016 05:51

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. ex: find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

:speech_balloon: meet CamperBot in this room!

:pencil: read more about camperbot on the FCC Wiki

Og-Morrow
@Og-Morrow
Mar 25 2016 05:51
thanks @rphares
CamperBot
@camperbot
Mar 25 2016 05:51
og-morrow sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
Yashdeep Hinge
@yashdeeph709
Mar 25 2016 05:51
help 221
CamperBot
@camperbot
Mar 25 2016 05:51
:star: 3521 | @rphares | http://www.freecodecamp.com/rphares
Og-Morrow
@Og-Morrow
Mar 25 2016 05:51
thanks @JEDodson
CamperBot
@camperbot
Mar 25 2016 05:51
og-morrow sends brownie points to @jedodson :sparkles: :thumbsup: :sparkles:
:star: 260 | @jedodson | http://www.freecodecamp.com/jedodson
Jalon Dodson
@JEDodson
Mar 25 2016 05:51
@yashdeeph709 It doesn't accept specific course numbers
rphares
@rphares
Mar 25 2016 05:51
Anytime~
Jalon Dodson
@JEDodson
Mar 25 2016 05:52
@yashdeeph709 You'll have to type help [Course Name]
So, for example:
uh
forgot what that one was
Olawale Akinseye
@brainyfarm
Mar 25 2016 05:52
@yashdeeph709, what challenge are you on? The title
Jalon Dodson
@JEDodson
Mar 25 2016 05:52
help Use Responsive Design with Bootstrap Fluid Containers
CamperBot
@camperbot
Mar 25 2016 05:52

:point_right: challenge use responsive design with bootstrap fluid containers [wiki]

Use Responsive Design with Bootstrap Fluid Containers

Bootstrap will figure out how wide your screen is and respond by resizing your HTML elements - hence the name Responsive Design.

With responsive design, there is no need to design a mobile version of your website. It will look good on devices with screens of any width.

You can add Bootstrap to any app just by including it with <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/> at the top of your HTML.

:pencil: read more about challenge use responsive design with bootstrap fluid containers on the FCC Wiki

Jalon Dodson
@JEDodson
Mar 25 2016 05:53
Type: help [Course Name] like that.
Olawale Akinseye
@brainyfarm
Mar 25 2016 05:54
Nice one @JEDodson :+1:
Jalon Dodson
@JEDodson
Mar 25 2016 05:54
Thanks @brainyfarm Lol
CamperBot
@camperbot
Mar 25 2016 05:54
jedodson sends brownie points to @brainyfarm :sparkles: :thumbsup: :sparkles:
:star: 1673 | @brainyfarm | http://www.freecodecamp.com/brainyfarm
Jalon Dodson
@JEDodson
Mar 25 2016 05:55
yo, is this right?
var oldArray = [1,2,3];
var newArray = [];

var concatMe = [4,5,6];

// Only change code below this line.

newArray = oldArray.concat(concatMe);
Darrel Adams
@dadams-510
Mar 25 2016 05:56
function where(arr, num) {
  // Find my place in this sorted array.
  var arrayContainer = arr.push(num);
  arrayContainer = arr.sort();


  return arrayContainer.indexOf(num);
}

where([40, 60], 50);
Olawale Akinseye
@brainyfarm
Mar 25 2016 05:57
Looks good @JEDodson.
Jalon Dodson
@JEDodson
Mar 25 2016 05:57
what's the issue @dadams-510
Darrel Adams
@dadams-510
Mar 25 2016 05:57
Can anyone help with "Where do I belong?
where([10, 20, 30, 40, 50], 35) should return 3. - check
where([10, 20, 30, 40, 50], 30) should return 2. - check
where([40, 60], 50) should return 1. - check
where([3, 10, 5], 3) should return 0. - wrong
where([5, 3, 20, 3], 5) should return 2. - wrong
where([2, 20, 10], 19) should return 2. - wrong
where([2, 5, 10], 15) should return 3. - wrong
Jalon Dodson
@JEDodson
Mar 25 2016 05:59
first insert the number into the array using the Array.push() method..
yo ucould use just arr.push(num); at the top line for that, you don't need the arrayContainer
then sort the elements of the array
Darrel Adams
@dadams-510
Mar 25 2016 06:00
@JEDodson Did both of those.
Jalon Dodson
@JEDodson
Mar 25 2016 06:00
  arr.sort(function(a, b)
           {return a-b;}
          );
j0hnnym1
@j0hnnym1
Mar 25 2016 06:00
help Record Collection
CamperBot
@camperbot
Mar 25 2016 06:00

:point_right: checkpoint record collection [wiki]

Checkpoint: Record Collection

Instructions

You are given a JSON object representing (a small part of) your record collection. Each album is identified by a unique id number and has several properties. Not all albums have complete information.

Write a function which takes an id, a property (prop), and a value.

For the given id in collection:

If value is non-blank (value !== ""), then update or set the value for the prop.

If the prop is "tracks" and value is non-blank, push the value onto the end of the tracks array.

If value is blank, delete that prop.

Always return the entire collection object.

Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

:pencil: read more about checkpoint record collection on the FCC Wiki

Jalon Dodson
@JEDodson
Mar 25 2016 06:01
so essentially you have something like
Darrel Adams
@dadams-510
Mar 25 2016 06:01
Why would that work instead of this?
function where(arr, num) {
  // Find my place in this sorted array.
  arr.push(num);
  arr.sort();
  return arr.indexOf(num);
}

where([40, 60], 50);
Jalon Dodson
@JEDodson
Mar 25 2016 06:01
that'd work
but
you need to include the params in sort
elements i mean
so,
  arr.sort(function(a, b)
           {return a-b;}
          );
Darrel Adams
@dadams-510
Mar 25 2016 06:02
I haven't written code like that before after a method.
like arr.sort and then write a function on the same line.
What does that do exactly?
Jalon Dodson
@JEDodson
Mar 25 2016 06:03
exactly what it sounds like
sorting function where's a &b
Darrel Adams
@dadams-510
Mar 25 2016 06:11
function is a - b?
OmMinky
@OmMinky
Mar 25 2016 06:11
thanks @camperbot for the link, guess it's best to stick with if/else, though i'm most likely shaky on accessing property order or parameter setting logic
CamperBot
@camperbot
Mar 25 2016 06:11
omminky sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star: 1431 | @camperbot | http://www.freecodecamp.com/camperbot
Darrel Adams
@dadams-510
Mar 25 2016 06:12
could you explain what's going on here @JEDodson ?
Jalon Dodson
@JEDodson
Mar 25 2016 06:12
omminky camperbot is a bot
Darrel Adams
@dadams-510
Mar 25 2016 06:12
Thanks by the way. @JEDodson I passed the challenge, just trying to understand what the function does.
CamperBot
@camperbot
Mar 25 2016 06:12
dadams-510 sends brownie points to @jedodson :sparkles: :thumbsup: :sparkles:
:star: 265 | @jedodson | http://www.freecodecamp.com/jedodson
kavya
@kavyask1986
Mar 25 2016 06:12
Can someone please help me with challenge 209 - link( https://www.freecodecamp.com/challenges/counting-cards)
Jalon Dodson
@JEDodson
Mar 25 2016 06:12
.sort(function(a, b))
you're sorting the a and b elements of function
kavya
@kavyask1986
Mar 25 2016 06:13

Is my code correct?
var count = 0;

function cc(card) {
// Only change code below this line
switch (card)
{
case 2:
case 3:
case 4:
case 5:
case 6: count += 1;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A': count -= 1;
break;
}
if (count > 0)
{
return count + "Bet";
}
else if (count < 0)
{
return count + "Hold";
}
else
{
return "0 Hold";
}

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Darrel Adams
@dadams-510
Mar 25 2016 06:13
sooooo, what is a - b exactly?
Jalon Dodson
@JEDodson
Mar 25 2016 06:13
values of the where function lol.
it'd be uh
whatever they were above
whatever was on the function where(a, b)
Darrel Adams
@dadams-510
Mar 25 2016 06:14
return arr - num?
Jalon Dodson
@JEDodson
Mar 25 2016 06:14
it's arr and num
Darrel Adams
@dadams-510
Mar 25 2016 06:14
could you put any variable in that function?
like x - z?
Jalon Dodson
@JEDodson
Mar 25 2016 06:14
uhhh i dont think so
it's a possibility but i dont think so
i think you can only do that for loop indexes
and vars etc
DJ
@qualitymanifest
Mar 25 2016 06:15
@dadams-510 this may be helpful reading http://www.sitepoint.com/sophisticated-sorting-in-javascript/
it's long, but that's just because it gets really in-depth
Jalon Dodson
@JEDodson
Mar 25 2016 06:17
function reverseString(str) {
  return str.split('').reverse().join('');;
}

reverseString("hello");
why isn't this righ tlol.
DJ
@qualitymanifest
Mar 25 2016 06:17
@JEDodson two semicolons?
Jalon Dodson
@JEDodson
Mar 25 2016 06:17
oh my lord
in my defense it's 1 am lol
DJ
@qualitymanifest
Mar 25 2016 06:19
@dadams-510 i just looked up and saw your code - the reason why yours didn't work is because .sort() without any arguments, sorts alphabetically. therefore 10 is less than 2
Tien Anh Nguyen
@tienanh2007
Mar 25 2016 06:19
for some reason my
collection[id][prop].push(value);
delete every element in the object's array
and add the value
instead of pushing it in
could someone tell me why
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Mar 25 2016 06:20
@tienanh2007 can you give the full code ?
Tien Anh Nguyen
@tienanh2007
Mar 25 2016 06:21
sure

// Setup
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
]
},
1245: {
artist: "Robert Palmer",
tracks: [ ]
},
5439: {
album: "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function update(id, prop, value) {
if(value !=="" && prop !=="track")
collection[id][prop] = value;
else if(prop === "track")
collection[id][prop].push(value);
else
delete collection[id][prop];

return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");

update(2468, "tracks", "Addicted to Love");

sorry Idk how to make it become code
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Mar 25 2016 06:23
you should use {} after your if/else if/else!
Tien Anh Nguyen
@tienanh2007
Mar 25 2016 06:24
nope still error
I think it's something else
Jalon Dodson
@JEDodson
Mar 25 2016 06:25
function palindrome(str) {
  // Good luck!
  return true;
}



palindrome("eye");
how would i start this out?
Darrel Adams
@dadams-510
Mar 25 2016 06:26
@qualitymanifest thanks for that.
CamperBot
@camperbot
Mar 25 2016 06:26
dadams-510 sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 1112 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Mar 25 2016 06:26
I don't think collection[id][prop
Collection[id][prop].push(value) is an error
Tien Anh Nguyen
@tienanh2007
Mar 25 2016 06:27
no I means yeah
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Mar 25 2016 06:27
It must be somethings else
Tien Anh Nguyen
@tienanh2007
Mar 25 2016 06:27
I think there some problem
but it's still does something
it delete every element in that array
and add the value in
when it should only add it to the end
like a stack
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Mar 25 2016 06:28
I know! It's tracks instead of track !
Tien Anh Nguyen
@tienanh2007
Mar 25 2016 06:29
yep
thank you
:))
@thomlom thank you
CamperBot
@camperbot
Mar 25 2016 06:29
tienanh2007 sends brownie points to @thomlom :sparkles: :thumbsup: :sparkles:
:star: 270 | @thomlom | http://www.freecodecamp.com/thomlom
Tien Anh Nguyen
@tienanh2007
Mar 25 2016 06:29
that was dumb
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Mar 25 2016 06:31
@JEDodson first modify your string (to lower case, ...) construct two arrays of that string reverse one, join them and see if they're equal
Jalon Dodson
@JEDodson
Mar 25 2016 06:38
function palindrome(str) {

    str = str.toLowerCase().replace(/[^a-z]+/ig,"");
       return str === str.split("").reverse().join("");
}




palindrome("1 eye for of 1 eye");
I got all but '1 eye for of 1 eye'
returns true
nvm i got it
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Mar 25 2016 06:43
You should not replace numbers in your regex for this problem!
rphares
@rphares
Mar 25 2016 06:53
Hi, @Og-Morrow -- could you paste your code, please? :blush:
Og-Morrow
@Og-Morrow
Mar 25 2016 06:54
ya just a sec, i gotta test something
so to paste the code in the style above its ''' then like a opening and closing tag <>?
CamperBot
@camperbot
Mar 25 2016 06:55
:bulb: to format code use backticks! ``` more info
Og-Morrow
@Og-Morrow
Mar 25 2016 06:55
``` test
rphares
@rphares
Mar 25 2016 06:55
close-- those are apostrophes, the backticks `
yes, thats better,
but you need three, then shift+enter
Og-Morrow
@Og-Morrow
Mar 25 2016 06:56
``` test
rphares
@rphares
Mar 25 2016 06:56
a second row of ``` should appear, and you paste your code in between the two rows,
Og-Morrow
@Og-Morrow
Mar 25 2016 06:56
test
rphares
@rphares
Mar 25 2016 06:56
you may need to hit command +enter or ctrl + enter to send,
OmMinky
@OmMinky
Mar 25 2016 06:56
@JEDodson , thought so, still figured I'd give props and an excuse to get pointers on logic from the group
rphares
@rphares
Mar 25 2016 06:56
thats one ` on either side,
you need three to make it black :)
Og-Morrow
@Og-Morrow
Mar 25 2016 06:57
huh i did put three, thats weird
```
rphares
@rphares
Mar 25 2016 06:57
has to be in-between the two lines of those, all one message
Og-Morrow
@Og-Morrow
Mar 25 2016 06:57
<test>
rphares
@rphares
Mar 25 2016 06:57
explain format
CamperBot
@camperbot
Mar 25 2016 06:57

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

rphares
@rphares
Mar 25 2016 06:57
YAY
thats it :)
Og-Morrow
@Og-Morrow
Mar 25 2016 06:57
woop
Jalon Dodson
@JEDodson
Mar 25 2016 06:57
one liners are `
anddd on that note, it's bed time
Og-Morrow
@Og-Morrow
Mar 25 2016 06:58
haha night
Jalon Dodson
@JEDodson
Mar 25 2016 06:58
2 am, enough JavaScript from me for the day.
I got to Chunky Monkey, not bad :D
rphares
@rphares
Mar 25 2016 06:58
g'night, @JEDodson -- rest well :blush:
Og-Morrow
@Og-Morrow
Mar 25 2016 06:58
<// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = myStorage; // Change this line
gloveBoxContents.car.inside["glove box"];
>
Jalon Dodson
@JEDodson
Mar 25 2016 06:58
night all, thanks @rphares :) sleep tight whenever you go to bed
CamperBot
@camperbot
Mar 25 2016 06:58
jedodson sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 3528 | @rphares | http://www.freecodecamp.com/rphares
Jalon Dodson
@JEDodson
Mar 25 2016 06:59
put gloveBoxContents.car.inside["glove box"];
on the actual var
rphares
@rphares
Mar 25 2016 06:59
oh, very close. yes--
Jalon Dodson
@JEDodson
Mar 25 2016 06:59
so var gloveBoxContents = myStorage.gloveBoxContents.car.inside["glove box"];
Og-Morrow
@Og-Morrow
Mar 25 2016 06:59
lol
rphares
@rphares
Mar 25 2016 06:59
in general where it says // Change this line thats where you will be putting things :)
Jalon Dodson
@JEDodson
Mar 25 2016 07:00
i dunno if i can sleep i've had too much caffeine
:(
rphares
@rphares
Mar 25 2016 07:00
we probably dont need to give the actual answer-- with some hints he could probably have figured it out from there, generally better for learning... :blush:
Jalon Dodson
@JEDodson
Mar 25 2016 07:01
well he had the answer
just put it on the wrong line
Og-Morrow
@Og-Morrow
Mar 25 2016 07:01
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = gloveBoxContents.car.inside["glove box"];// Change this line
its throwing the error cannot read property of car
Jalon Dodson
@JEDodson
Mar 25 2016 07:01
you forgot myStorage
Og-Morrow
@Og-Morrow
Mar 25 2016 07:01
lol
Jalon Dodson
@JEDodson
Mar 25 2016 07:01
you're having gloveBoxContents output myStorage
not gloveBoxContents
Og-Morrow
@Og-Morrow
Mar 25 2016 07:02
like the grinch movie in the cave
im an idiot! your an idiot!
Jalon Dodson
@JEDodson
Mar 25 2016 07:02
you dont want myStorage.gloveBoxContents lol
because there's nothing that defines that
so you'd have to use myStorage.car.inside
along with the glove box part
Og-Morrow
@Og-Morrow
Mar 25 2016 07:02
Boom!
thanks @rphares
CamperBot
@camperbot
Mar 25 2016 07:03
og-morrow sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 3529 | @rphares | http://www.freecodecamp.com/rphares
Og-Morrow
@Og-Morrow
Mar 25 2016 07:03
thanks @JEDodson
CamperBot
@camperbot
Mar 25 2016 07:03
og-morrow sends brownie points to @jedodson :sparkles: :thumbsup: :sparkles:
:star: 275 | @jedodson | http://www.freecodecamp.com/jedodson
rphares
@rphares
Mar 25 2016 07:03
Anytime, lol, didn't do much
Jalon Dodson
@JEDodson
Mar 25 2016 07:03
you always do awesome @rphares ^-^
Og-Morrow
@Og-Morrow
Mar 25 2016 07:03
you guys rock you dont give me the answer and just give me that little push lol
Jalon Dodson
@JEDodson
Mar 25 2016 07:03
push in the right direction homie
rphares
@rphares
Mar 25 2016 07:04
:blush:
Og-Morrow
@Og-Morrow
Mar 25 2016 07:04
do yall run on slack>
?
Jalon Dodson
@JEDodson
Mar 25 2016 07:04
yeah
i'm part of devchat
oh
no
this is gitter
rphares
@rphares
Mar 25 2016 07:04
i dont, sorry
Og-Morrow
@Og-Morrow
Mar 25 2016 07:04
alrighty, i was just wondering
Jalon Dodson
@JEDodson
Mar 25 2016 07:04
i thought you meant if we were apart of slack loll
i'm not affiliated with freecodecamp except for being a student
freecodecamp runs on gitter
the chat at least
rphares
@rphares
Mar 25 2016 07:05
same, just a student, and new to the unrestricted internet (just moved from china) so not on any other networks currently :blush:
Og-Morrow
@Og-Morrow
Mar 25 2016 07:05
thats crazy
Jalon Dodson
@JEDodson
Mar 25 2016 07:05
what state you move to?
that's pretty cool
rphares
@rphares
Mar 25 2016 07:06
home-- I'm american, lol, so back in portland, or
just spent the last decade abroad
shrug so... things have changed, heh
Jalon Dodson
@JEDodson
Mar 25 2016 07:06
ahhh, lol. interesting! welcome back to the usa lol
i'm in kansas. land of the tornados, yellow brick road and the occasional wildfires
i just recently learned the yellow brick road is an actual landmark in kansas
rphares
@rphares
Mar 25 2016 07:08
lol, thanks, @JEDodson
CamperBot
@camperbot
Mar 25 2016 07:08
rphares sends brownie points to @jedodson :sparkles: :thumbsup: :sparkles:
:star: 276 | @jedodson | http://www.freecodecamp.com/jedodson
rphares
@rphares
Mar 25 2016 07:09
Dunno if it'll stick this time, but I'm trying to give it chance :blush: (i had a nice, fun life over there so loads of reverse culture shock-- and sticker shock, good honk have prices changed-- atm, but hope to adjust soon :blush: )
Og-Morrow
@Og-Morrow
Mar 25 2016 07:09
hey @rphares and @JEDodson have yall tried using a game engine for javascript?
Jalon Dodson
@JEDodson
Mar 25 2016 07:10
@Og-Morrow JavaScript isn't my favorite nor preferred language
so, no lol
Og-Morrow
@Og-Morrow
Mar 25 2016 07:11
I see, well alrighty thank you for the answer
rphares
@rphares
Mar 25 2016 07:11
I have not, sorry...
Og-Morrow
@Og-Morrow
Mar 25 2016 07:11
all good lol
Jalon Dodson
@JEDodson
Mar 25 2016 07:12
ugh
i thought i was going to bed -.-
Darrel Adams
@dadams-510
Mar 25 2016 07:19
lol
Can anyone help with the caesars cipher challenge?
function rot13(str) { // LBH QVQ VG!

  str = str.toUpperCase();

  for(var i = 0; i < str.length; i++) {

  }

  return str.fromCharCode();

  //the charAt method to get the character at a particular index in the string
  //the chaAt method takes an integer number between zero and the length of the string minus one.
  //Think of the string a bit like an array, with each character at an index of the string, with the indices starting at 0 just like an array

  // 
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Markus Kiili
@Masd925
Mar 25 2016 07:30
@dadams-510 You could find out the charcode range that corresponds to A-Z, and then loop through the characters and only change those charcodes that are in the range.
ajayadav09
@ajayadav09
Mar 25 2016 07:33

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
if(myObj.hasOwnProperty(checkProp)){
return myObj.checkProp;
}else{
return "Not Found";
}
return "Change Me!";
}

// Test your code by modifying these values
checkObj("gift");

this does not return "pony"
its a testing objects for properites exercise
What is wrong in my snippet?
Darrel Adams
@dadams-510
Mar 25 2016 07:37
@ajayadav09 which challenge is it?
Markus Kiili
@Masd925
Mar 25 2016 07:39
@ajayadav09 The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
So .checkProp doesn't work there.
Darrel Adams
@dadams-510
Mar 25 2016 07:40
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if(myObj.hasOwnProperty(checkProp)){
    return myObj[checkProp];
}

else {
    return "Not Found";
    }
return "Change Me!";
}

// Test your code by modifying these values
checkObj("gift");
@ajayadav09
ajayadav09
@ajayadav09
Mar 25 2016 07:45
@dadams-510 @Masd925 - Thanks a lot mate. I didn't know about the usage of arbitary string usage. Thanks a lot :smile:
CamperBot
@camperbot
Mar 25 2016 07:45
ajayadav09 sends brownie points to @dadams-510 and @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1225 | @masd925 | http://www.freecodecamp.com/masd925
:star: 325 | @dadams-510 | http://www.freecodecamp.com/dadams-510
Markus Kiili
@Masd925
Mar 25 2016 07:46
@dadams-510 You're wellcome.
Kenni Gandira Alamsyah
@kenniga
Mar 25 2016 07:57
Hello everyone, I need help :(
Here's my code
```
$(document).ready(function() {
  $("#trigger").click(function() {
    $("#target").slideToggle("slow");
  });

  function success(pos) {
    var crd = pos.coords;
    var latitude = crd.latitude;
    var longitude = crd.longitude
    var key = "7a0fb4c75c97a2d7dc6b21e9f5953783";
    var openWeather = "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&units=metric&APPID=" + key;
    $.getJSON(openWeather, function(data) {
      var city = data.name;
      var temp = data.main.temp + "  &deg;C";
      var icon = "http://openweathermap.org/img/w/" + data.weather[0].icon + ".png";
      var status = data.weather[0].description;
      var minTemp = data.main.temp_min;
      var maxTemp = data.main.temp_max;
      var press = data.main.pressure;
      var humi = data.main.humidity;
      var windSpeed = data.wind.speed;
      var windDeg = data.wind.deg;
      var fahTemp = data.main.temp * (9 / 5) + 32 + "  &deg;F";
      $(".city").html("Hello, " + city + "!");
      $(".temp").html(temp);
      $(".wow").html("<img src ='" + icon + "'>");
      $(".status").html(status);
      $(".min-temp").html(minTemp + " &deg;C");
      $(".max-temp").html(maxTemp + " &deg;C");
      $(".pressure").html(press);
      $(".humidity").html(humi);
      $(".wind-speed").html(windSpeed);
      $(".wind-deg").html(windDeg);
      $("#to-fahrenheit").click(function() {
        $(".temp").html(fahTemp);

      });
      $("#to-fahrenheit").click(function() {
        $(".temp").html(temp);

      });
    });
  }
  navigator.geolocation.getCurrentPosition(success);

});
```
Well, the second last function look stupid...
Kenni Gandira Alamsyah
@kenniga
Mar 25 2016 08:02
So I'm planning to show the fahrenheit unit format with a single click on #to-fahrenheit, the bring back the first temp by the second click, so goes on
I've try using clickToggle, but it doesn't work :(
Justin Steele
@JustinSteele02
Mar 25 2016 08:07
Can anyone tell me why str.split('') returns an array of characters, while str.split() returns an array with the entire string as one element? I'm not quite understanding the distinction
Markus Kiili
@Masd925
Mar 25 2016 08:08
@JustinSteele02 If you don't give it a delimiter, it doesn't split the string. Just puts the string into array element.
Erik Royall
@erikroyall
Mar 25 2016 08:09
@JustinSteele02 Read the doc:
Justin Steele
@JustinSteele02
Mar 25 2016 08:10
right, I guess I'm saying when you type string.split('') with nothing between the quotes, why does it choose to separate by character? why isn't it the same as no delimiter at all?
I'm reading the docs now @erikroyall
Erik Royall
@erikroyall
Mar 25 2016 08:11
status-by-design
Justin Steele
@JustinSteele02
Mar 25 2016 08:12
ok just read "If separator is an empty string, str is converted to an array of characters." Maybe it's not too important to know why?
Kenni Gandira Alamsyah
@kenniga
Mar 25 2016 08:12
what kind of function that could bring the first result, while the first click could run the function?
Erik Royall
@erikroyall
Mar 25 2016 08:13
Justin Steele
@JustinSteele02
Mar 25 2016 08:16
@erikroyall I see, thank you. So basically I can understand it as "cause that's just how it works" unless I want to get into the inner workings of the language?
CamperBot
@camperbot
Mar 25 2016 08:16
justinsteele02 sends brownie points to @erikroyall :sparkles: :thumbsup: :sparkles:
:star: 19 | @erikroyall | http://www.freecodecamp.com/erikroyall
Erik Royall
@erikroyall
Mar 25 2016 08:18
@JustinSteele02 yes, also, other programming languages implement it this way. This is in no way a design decision taken by ES standards group or anyone. They just used the algorithm that others use for consistency.
Justin Steele
@JustinSteele02
Mar 25 2016 08:19
alright that makes sense. thanks again
Harsh Khandelwal
@harsh2602
Mar 25 2016 08:21
http://codepen.io/harsh2602/pen/oxWdxR Can someone let me know why the delete array statement does not work here
Erik Royall
@erikroyall
Mar 25 2016 08:24
you are not deleting the arrays
Harsh Khandelwal
@harsh2602
Mar 25 2016 08:25
@erikroyall delete arrays statement is the end of the click function
do you know why aren't they working?
Erik Royall
@erikroyall
Mar 25 2016 08:26
So you want to remove the previously written data?
So, you are adding <li>elements to #result-list
Harsh Khandelwal
@harsh2602
Mar 25 2016 08:28
ok, got your point
Erik Royall
@erikroyall
Mar 25 2016 08:28
You can empty the #result-list every time you perform a search operation
Deleting the arrays doesn't delete the elements from the DOM
Harsh Khandelwal
@harsh2602
Mar 25 2016 08:29
yeah...I did not pay notice to that... @erikroyall thanks a lot
CamperBot
@camperbot
Mar 25 2016 08:29
harsh2602 sends brownie points to @erikroyall :sparkles: :thumbsup: :sparkles:
:star: 20 | @erikroyall | http://www.freecodecamp.com/erikroyall
João Castanho
@joaocastanho
Mar 25 2016 08:52
hello.
how would you simplify this
function sumAll(arr) {

  arr.sort(function(a, b) {
    return a - b;
  });

  var min, max;

  var newArr = [];

  min = arr[0];
  max = arr[arr.length - 1];

  for (var i = min; i < max + 1; i++) {
    newArr.push(i);
  }



  newArr = newArr.reduce(function(previousValue, currentValue, currentIndex, newArr) {
    return previousValue + currentValue;
  });

  return newArr;

}

sumAll([10, 5]);
Dardan Demiri
@dardandemiri
Mar 25 2016 08:53
can someone help me with this algorithem
function truncateString(str, num) {
  // Clear out that junk in your trunk


  if(str.length > num ){

    return str.slice( 0, num) +"...";  

  }else if(str.length <=3){

    return str.slice(0,num) + "...";

  }else if(str.length == num || str.length < num){

    return str;

  }
  if (str.length > num && num < 3){
    return str.slice(0, 1); 
  }
}

truncateString("Absolutely Longer", 2);
Matt Green
@mattxgreen
Mar 25 2016 08:54
@joaocastanho are you just adding the passed in array?
Dardan Demiri
@dardandemiri
Mar 25 2016 08:54
Truncate String
João Castanho
@joaocastanho
Mar 25 2016 08:54
@mattxgreen where?
Matt Green
@mattxgreen
Mar 25 2016 08:55
@joaocastanho function sumAll(arr)
Manikanth
@manikanth1024
Mar 25 2016 08:55
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){
// Only change code below this line
for(var i=0;i<contacts.length;i++){
  if(contacts[i]===firstName){
    if(contacts[i].hasOwnProperty(prop)){
    return contacts[i].prop;
  }
    else 
      return "No such property";

 }
}
  return "No such contact";

// Only change code above this line

}
// Change these values to test your function
lookUp("Akira", "likes");
João Castanho
@joaocastanho
Mar 25 2016 08:55
@mattxgreen yes, that was the default
Manikanth
@manikanth1024
Mar 25 2016 08:55
what's wrong w/the above code?
Matt Green
@mattxgreen
Mar 25 2016 08:56
@joaocastanho ok, easy fix
João Castanho
@joaocastanho
Mar 25 2016 08:56
@mattxgreen the code is working. just want to know how I could simplify
I could have used min and max math functions
but dont know how
negyvenketto
@negyvenketto
Mar 25 2016 08:57
@dardandemiri what's the second if supposed to do?
Matt Green
@mattxgreen
Mar 25 2016 08:57
@joaocastanho are you summing up 10 and 5, or 5+6+7+8+9+10?
João Castanho
@joaocastanho
Mar 25 2016 08:57
5+6+7+8+9+10
Matt Green
@mattxgreen
Mar 25 2016 08:57
ah, ok
Dardan Demiri
@dardandemiri
Mar 25 2016 08:58
the same as the first
but <=3
negyvenketto
@negyvenketto
Mar 25 2016 08:58
@dardandemiri also else if(str.length == num || str.length < num) is the same as else if(str.length <= num)
Matt Green
@mattxgreen
Mar 25 2016 08:59
@joaocastanho and you want it to work sumAll([10,5]) AND sumAll([5,10])
Dardan Demiri
@dardandemiri
Mar 25 2016 09:00
@negyvenketto
i fixed that problem but the main problem is there
João Castanho
@joaocastanho
Mar 25 2016 09:00
@mattxgreen yes, it should work either way
negyvenketto
@negyvenketto
Mar 25 2016 09:00
@dardandemiri i think the problem is that you are overcomplicating it and checking the conditions in the wrong order
João Castanho
@joaocastanho
Mar 25 2016 09:00
@dardandemiri your code is too long
Dardan Demiri
@dardandemiri
Mar 25 2016 09:01
hmmm should I reset the code
and start over again
V Arun Kumar
@arunvkumr
Mar 25 2016 09:01
This message was deleted
negyvenketto
@negyvenketto
Mar 25 2016 09:01
@dardandemiri not necessarily
João Castanho
@joaocastanho
Mar 25 2016 09:01
@dardandemiri just minor changes
negyvenketto
@negyvenketto
Mar 25 2016 09:01
@dardandemiri do you want me to help with the order of conditions or do you want to figure it out for yourself?
Dardan Demiri
@dardandemiri
Mar 25 2016 09:01
where :(
Matt Green
@mattxgreen
Mar 25 2016 09:01
@joaocastanho And finally why are you returnig an array? isn't it just supposed to be the sum? (one integer)
Dardan Demiri
@dardandemiri
Mar 25 2016 09:02
wait I try
@negyvenketto @joaocastanho
negyvenketto
@negyvenketto
Mar 25 2016 09:02
@dardandemiri ok
João Castanho
@joaocastanho
Mar 25 2016 09:02
@mattxgreen yes it should
@arunkumrv that seems complicated
Miguel T Rivera
@mtrivera
Mar 25 2016 09:03
wiki destroyer
CamperBot
@camperbot
Mar 25 2016 09:03
no wiki entry for: destroyer
João Castanho
@joaocastanho
Mar 25 2016 09:03
but it's not returning the array
Miguel T Rivera
@mtrivera
Mar 25 2016 09:03
wiki seek
CamperBot
@camperbot
Mar 25 2016 09:03

:point_right: algorithm seek and destroy [wiki]

Explanation:

This problem is a bit tricky because you have to familiarize yourself with Arguments, as you will have to work with two or more but on the script you only see two. Many people hardcode this program for three arguments. You will remove any number from the first argument that is the same as any other other arguments.

:pencil: read more about algorithm seek and destroy on the FCC Wiki

João Castanho
@joaocastanho
Mar 25 2016 09:03
the final value is an integer
V Arun Kumar
@arunvkumr
Mar 25 2016 09:03
@joaocastanho i thought you already completed the challenge.. that's why i deleted it
João Castanho
@joaocastanho
Mar 25 2016 09:03
But I did
But I think it could be simplified
Brendan Kinahan
@BKinahan
Mar 25 2016 09:04
@joaocastanho a simple sum all numbers in a range? how abut sumAll = arr => Array(Math.abs(arr[0]-arr[1])+1).fill().map((_,i)=>i+Math.min(...arr)).reduce((a,b)=>a+b);? :P
Matt Green
@mattxgreen
Mar 25 2016 09:04
@joaocastanho
function sumAll(arr) {

    arr.sort(function (a, b) {
        return a - b;
    });
    var min = arr[0],
        max = arr[1],
        answer = 0;
    for (var i = min; i <= max; i++) {
        answer += i;
    }
    return answer;
}

sumAll([10, 5]);
That is simpler to me
Dardan Demiri
@dardandemiri
Mar 25 2016 09:04
@negyvenketto tell me the changes because i got frustrated
João Castanho
@joaocastanho
Mar 25 2016 09:05
@BKinahan I think that's too much for me right now :P
@mattxgreen yeah, that's simpler
negyvenketto
@negyvenketto
Mar 25 2016 09:06
@dardandemiri 1st case: your string is shorter than your number
2nd case: your string is longer than your number and your number larger than 3
3rd case: your string is longer than your number and your number is smaller or equal to three
Matt Green
@mattxgreen
Mar 25 2016 09:07
@joaocastanho you could remove min/max to save a couple lines:
function sumAll(arr) {
    arr.sort(function (a, b) {
        return a - b;
    });
    var answer = 0;
    for (var i = arr[0]; i <= arr[1]; i++) {
        answer += i;
    }
    return answer;
}
V Arun Kumar
@arunvkumr
Mar 25 2016 09:07
@joaocastanho yes it could be.. this is completely your code with simplification ofcourse
function sumAll(arr) {
  arr.sort(function(a, b) {
    return a - b;
  });
  var newArr = [];
  for (var i = arr[0]; i < arr[1] + 1; i++) 
    newArr.push(i);
    return newArr.reduce(function(a,b) {
    return a+b;
  });
}
sumAll([10, 5]);
negyvenketto
@negyvenketto
Mar 25 2016 09:07
you can swap the 2nd and 3rd, if you want to, their order doesn't matter @dardandemiri
João Castanho
@joaocastanho
Mar 25 2016 09:08
@mattxgreen cool. lot cleaner
V Arun Kumar
@arunvkumr
Mar 25 2016 09:08
@joaocastanho ya @mattxgreen looks more cleaner.
João Castanho
@joaocastanho
Mar 25 2016 09:08
function sumAll(arr) {

  arr.sort(function(a, b) {
    return a - b;
  });

  var sum = 0;

  for (var i = arr[0]; i <= arr[1]; i++) {
    sum += i;
  }

  return sum;

}

sumAll([10, 5]);
much more cleaner
I do not need an array :P
Dardan Demiri
@dardandemiri
Mar 25 2016 09:08
function truncateString(str, num) {
  // Clear out that junk in your trunk


  if(str.length > num ){

    return str.slice( 0, num) +"...";  

  }else if(str.length <= num){

    return str;

  }else if(str.length <=3){

    return str.slice(0,num) + "...";

  }
  if (str.length > num && num < 3){
    return str.slice(0, 1); 
  }
}

truncateString("Absolutely Longer", 2);
still not working
João Castanho
@joaocastanho
Mar 25 2016 09:09
@dardandemiri your first if condition is correct
negyvenketto
@negyvenketto
Mar 25 2016 09:09
@dardandemiri you still have the same basic structure
João Castanho
@joaocastanho
Mar 25 2016 09:09
but inside it, you have to check if num is less than or equal to 3
V Arun Kumar
@arunvkumr
Mar 25 2016 09:09
@joaocastanho this is not complicated.. it's really simple just some aritmetic operations going on here.. that's all.
function sumAll(arr){
    arr = arr.sort(function(a,b){ return a-b; });
    return (arr[0]+arr[1])*(arr[1]-arr[0]+1)/2;
}
sumAll([6,10]);
Traplord Ses
@TrapSes
Mar 25 2016 09:09

hey guys I'm having some trouble with queues, I cannot figure out how to write it, i get the idea just can't figure out the code

function queue(arr, item) {
// Your code here

return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

João Castanho
@joaocastanho
Mar 25 2016 09:10
"However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string." @dardandemiri
Dardan Demiri
@dardandemiri
Mar 25 2016 09:10
ahhhh
wait ill try
João Castanho
@joaocastanho
Mar 25 2016 09:10
sure

@arunkumrv
for example

5+10*(10-5+1)/2 ?

Puvendran Pillay
@puven12
Mar 25 2016 09:11
hi guys
João Castanho
@joaocastanho
Mar 25 2016 09:11
well, it works
V Arun Kumar
@arunvkumr
Mar 25 2016 09:11
yup.. that's all it returns the sum.. you can try for any numbers.. @joaocastanho
João Castanho
@joaocastanho
Mar 25 2016 09:11
but how did you figured it out?
Matt Green
@mattxgreen
Mar 25 2016 09:12
@joaocastanho The speed between the two solutions is interesting as well: http://jsperf.com/add-num-mattg
Brendan Kinahan
@BKinahan
Mar 25 2016 09:12
@TrapSes are you familiar with push() and shift()?
Puvendran Pillay
@puven12
Mar 25 2016 09:12
i dont understand what i should do for challenge #166
Dardan Demiri
@dardandemiri
Mar 25 2016 09:12
ncccc
João Castanho
@joaocastanho
Mar 25 2016 09:12
then our solution is better right, @mattxgreen ?
Brendan Kinahan
@BKinahan
Mar 25 2016 09:12
@puven12 the challenges aren't numbered; use the title
Dardan Demiri
@dardandemiri
Mar 25 2016 09:12
function truncateString(str, num) {
  // Clear out that junk in your trunk


  if(str.length > num ){
    if(num <= 3){
      return str.slice( 0, num) +"...";  
    }


  }else if(str.length <= num){

    return str;

  }else if(str.length <=3){

    return str.slice(0,num) + "...";

  }
  if (str.length > num && num < 3){
    return str.slice(0, 1); 
  }
}

truncateString("Absolutely Longer", 2);
V Arun Kumar
@arunvkumr
Mar 25 2016 09:12
@joaocastanho i just used sum of series of Aritmetic progressions...
Puvendran Pillay
@puven12
Mar 25 2016 09:13
@BKinahan the word blanks challenge
João Castanho
@joaocastanho
Mar 25 2016 09:13
  if(str.length > num ){
    if(num <= 3){
      return str.slice( 0, num) +"...";  
    } else {
 return str.slice(0, num - 3) + "...";
}
V Arun Kumar
@arunvkumr
Mar 25 2016 09:13
https://www.math10.com/en/algebra/arithmetic-progression.html
@joaocastanho you can read about them here.
Puvendran Pillay
@puven12
Mar 25 2016 09:13
i dont understand the instructions
Matt Green
@mattxgreen
Mar 25 2016 09:13
@joaocastanho The solution with the for loops is nearly 3 times the speed
Traplord Ses
@TrapSes
Mar 25 2016 09:13
@BKinahan yup
Brendan Kinahan
@BKinahan
Mar 25 2016 09:14
@puven12 use string and variable concatenation to return a phrase in the form of a Mad Lib
João Castanho
@joaocastanho
Mar 25 2016 09:14
awesome then @mattxgreen :)
@arunkumrv I'll read. Thanks :)
CamperBot
@camperbot
Mar 25 2016 09:14
joaocastanho sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 398 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
Matt Green
@mattxgreen
Mar 25 2016 09:14
@joaocastanho at least with chrome
Brendan Kinahan
@BKinahan
Mar 25 2016 09:14
@TrapSes so use push() to add item onto the end of arr, then use shift() to remove the first element of arr and return it.
João Castanho
@joaocastanho
Mar 25 2016 09:15
well, that's fine
Dardan Demiri
@dardandemiri
Mar 25 2016 09:15

function truncateString(str, num) {
// Clear out that junk in your trunk

if(str.length > num ){
if(num <= 3){
return str.slice( 0, num) +"...";
} else {
return str.slice(0, num.length - 3) + "...";
}
}

if(str.length <= num){

return str;

}
if (str.length > num && num < 3){
return str.slice(0, 1);
}
}

truncateString("Absolutely Longer", 2);

```js
Puvendran Pillay
@puven12
Mar 25 2016 09:15
so @BKinahan i have to make a sentence with blanks? e.g. i like to _[verb]?
Dardan Demiri
@dardandemiri
Mar 25 2016 09:15
function truncateString(str, num) {
  // Clear out that junk in your trunk




  if(str.length > num ){
    if(num <= 3){
      return str.slice( 0, num) +"...";  
    } else {
      return str.slice(0, num.length - 3) + "...";
    }
  }


   if(str.length <= num){

    return str;

  }
  if (str.length > num && num < 3){
    return str.slice(0, 1); 
  }
}

truncateString("Absolutely Longer", 2);
Puvendran Pillay
@puven12
Mar 25 2016 09:16
@BKinahan and that verb with a variable?
Dardan Demiri
@dardandemiri
Mar 25 2016 09:16
guys I have over complicated this challange
Brendan Kinahan
@BKinahan