These are chat archives for FreeCodeCamp/HelpJavaScript

7th
Mar 2016
Richard Corbett
@reacorbett
Mar 07 2016 00:00
function rot13(str) { // LBH QVQ VG!

  var numArr = [];
  var decode = [];
//turns string into char. number array, and subtracts 13 from the value

  for(var i = 0; i < str.length; i++){
    numArr.push(str.charCodeAt(i)); 
    if(numArr[i] >= 78 && numArr[i] <= 90){
      numArr[i] = numArr[i] - 13;

    }


    else if(numArr[i] > 64 && numArr[i] < 78 ){
      numArr[i] = numArr[i] + 13;

    }

//Leaves the spaces as their char. number value
    else{
      numArr[i] = numArr[i];

    }
  }
for(var j = 0; j < numArr.length; j++){
  decode.push(String.fromCharCode(numArr[j]));
}
  return decode.join(" ");
}   



// Change the inputs below to test
rot13("SERR PBQR PNZC");
I dont understand why this is not passing. It does what it is supposed to. the only thing i can think of is that it doesnt have the quotes.
bitgrower
@bitgrower
Mar 07 2016 00:00
also -- you need to review how .filter works ... filter works by keeping or not a value in the array depending upon whether the callback function returns true or false ... returning either an empty string OR arr[i] will be interpreted as "true", and therefore none of your values will be removed from the array ... you may also want to look at the .slice & .splice functions as well as reviewing how .filter works
^^^ @adamboyer
Richard Corbett
@reacorbett
Mar 07 2016 00:02
NM i figured it out.
bitgrower
@bitgrower
Mar 07 2016 00:02
:) ... okay ... one of the more elegant ways of handling this challenge @reacorbett is to use the .map function ...
Suprith Aireddy
@sup-rith
Mar 07 2016 00:02

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

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

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

Richard Corbett
@reacorbett
Mar 07 2016 00:02
FINALLY PASSED THIS THING @bitgrower thanks
CamperBot
@camperbot
Mar 07 2016 00:02
reacorbett sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: reacorbett already gave bitgrower points
Suprith Aireddy
@sup-rith
Mar 07 2016 00:02
anyone know what is wrong with my code
bitgrower
@bitgrower
Mar 07 2016 00:02
woot!!! WTG @reacorbett !!!
Suprith Aireddy
@sup-rith
Mar 07 2016 00:03
return myObj.checkProp; never returns a value
Nick Robson
@nickrobson
Mar 07 2016 00:03
@bestkid74 Post what code you have.
bitgrower
@bitgrower
Mar 07 2016 00:03
@sup-rith -- you can't use dot notation there, use brackets ...
Richard Corbett
@reacorbett
Mar 07 2016 00:03
@bitgrower that is what i heard. I wasn't able to figure it out, so i went the only way i knew how.
Nick Robson
@nickrobson
Mar 07 2016 00:04
my bad.. gitter is laggy today for me :(
Suprith Aireddy
@sup-rith
Mar 07 2016 00:04
Thank you @bitgrower
CamperBot
@camperbot
Mar 07 2016 00:04
sup-rith sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 759 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Mar 07 2016 00:04
well ... now that you see @reacorbett -- see if you can get at least a couple of pieces to work with .map -- like the parts using charCodeAt() and fromCharCode ... it will help you get more familiar with using .map
yw @sup-rith
LOL yeah, @nickrobson -- he just wanted a solution ... not the benefits of figuring out a solution ...
Richard Corbett
@reacorbett
Mar 07 2016 00:05
Will do. @bitgrower this was my last Algo challenge so i will spend the rest of the day working on that.
bitgrower
@bitgrower
Mar 07 2016 00:06
....I think you'll be well-pleased when you do ... :) more tools (powerful tools) in your toolchest -- ones which will make your code more elegant & easier to understand ... :)
@nickrobson -- I tried to sell him @SteveCarroll 's solution -- who had just spent some hours figuring it out ...
let me know how it goes, @reacorbett ... :)
you can always poke your head over in the codereview room, too ... :)
Richard Corbett
@reacorbett
Mar 07 2016 00:08
@bitgrower for sure.
Denis
@bestkid74
Mar 07 2016 00:08
function lookUp(firstName, prop){
// Only change code below this line
  var property=[];
  var rez="";
  for(i=0; i<contacts.length; i++){

   if(contacts[i].firstName==firstName){
     if(contacts[i][prop]){
       for(j=0; j<contacts[i][prop]; j++){
       property.push(contacts[i][prop]);
       }
       rez="";
     } else {rez="No such property";}
   }else {rez="No such contact";}
  }

  if(rez===""){
    return property;
  } else {
    return rez;
  }
// Only change code above this line
}
bitgrower
@bitgrower
Mar 07 2016 00:09
aren't you being handed 3 parameters, @bestkid74 ? either that, or what challenge (name) is this ?
Nick Robson
@nickrobson
Mar 07 2016 00:09
profile lookup ^
Denis
@bestkid74
Mar 07 2016 00:09
@nickrobson yes
bitgrower
@bitgrower
Mar 07 2016 00:10
okay ... getting mixed up with record collection...my bad ... sorry ...
Nick Robson
@nickrobson
Mar 07 2016 00:10
For starters, you only need one for loop, and your "No such contact" should be outside it.
bitgrower
@bitgrower
Mar 07 2016 00:10
@SteveCarroll -- you want to help out here ?
apklip
@apklip
Mar 07 2016 00:10
This message was deleted
This message was deleted
This message was deleted
This message was deleted
This message was deleted
This message was deleted
Steve Carroll
@SteveCarroll
Mar 07 2016 00:12
@bitgrower I could try but I' the guy that added all that 'hosOwnProperty' crap ;)
greg
@wearenotgroot
Mar 07 2016 00:13
wiki format
CamperBot
@camperbot
Mar 07 2016 00:13

: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

bitgrower
@bitgrower
Mar 07 2016 00:13
ahh ... right ... sorry ... I'm getting my campers & challenges mixed up ... sorry!
@wearenotgroot ... I've started using the direct link ... https://github.com/freecodecamp/freecodecamp/wiki/code-formatting - cleans up the chat a bit
greg
@wearenotgroot
Mar 07 2016 00:14
@bitgrower ok :smile:
apklip
@apklip
Mar 07 2016 00:14
function destroyer(arr) {

  for(var b = 1; b < arguments.length; b++) {
    for(var i = 0; i < arr.length; i++) {
      if(arr[i] === arguments[b]) {
        arr.splice(i, 1);
      }

    }
  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3, 1);
My code doesn't work when arguments is greater than 2.
Steve Carroll
@SteveCarroll
Mar 07 2016 00:15
@bestkid74 I just used a for loop with a series of 3 'if - else if' statements and one of them had a nested loop to catch the "likes" array. As mentioned, catching "Bob" should be done out of the loop
adamboyer
@adamboyer
Mar 07 2016 00:16
this is what I did but I don't think this is how the wanted it done...
```
function destroyer(arr, destroy, destroy2, destroy3) {
  // Remove all the values
  console.log(destroy);
  console.log(destroy2);
  function dontDestroy (arr) {
    return arr !== destroy && arr !== destroy2 && arr !== destroy3;
  }
  for(var i = 0; i<arr.length; i++){
    console.log(arr[i]);
  }
  return arr.filter(dontDestroy);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
bitgrower
@bitgrower
Mar 07 2016 00:17
@adamboyer -- yeah, you need to have a general solution, so you can be handed any number of additional values after the target array (arguments[0])
greg
@wearenotgroot
Mar 07 2016 00:17
@adamboyer you can copy the arguments on to an array
bitgrower
@bitgrower
Mar 07 2016 00:18
^^^ !!!
@DarkPigeons -- just curious -- do you have a problem using .filter ? it's such a great method for this challenge ...
adamboyer
@adamboyer
Mar 07 2016 00:23
@wearenotgroot I don't understand what you mean.
bitgrower
@bitgrower
Mar 07 2016 00:24
@adamboyer -- read the arguments object page ... :) the arguments object is not an array ... only array-like .. so it can be very handy to transfer the arguments to an array ...
bitgrower
@bitgrower
Mar 07 2016 00:25
I think I may have found the problem, though, @adamboyer ... you are using arguments.length in your first for loop -- see what happens if you use arguments.length-1
Collin
@collinferry
Mar 07 2016 00:28
I'm wrapping up No Repeats Please (http://www.freecodecamp.com/challenges/no-repeats-please) and and two of the checked returns are giving a number 1 less than the correct result. I'm having trouble locating where these values are getting skewed. Anyone remember encountering a similar issue here?
bitgrower
@bitgrower
Mar 07 2016 00:29
@DarkPigeons -- one of the things you are doing is looking at arr.length in your 2nd loop -- that value gets re-evaluated every time thru the loop -- so you may not be iterating thru the loop enough times ... not sure if that clears up your problem, though ...
@collinferry -- sorry -- haven't done no repeats .. :(
apklip
@apklip
Mar 07 2016 00:32
@bitgrower I'll try filter and thanks.
CamperBot
@camperbot
Mar 07 2016 00:32
darkpigeons sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 760 | @bitgrower | http://www.freecodecamp.com/bitgrower
Richard Corbett
@reacorbett
Mar 07 2016 00:33
i dont understand the map method. MDN is no help either.
bitgrower
@bitgrower
Mar 07 2016 00:35
@reacorbett ... it simply takes each element of an array and does something to it ... to transform it into a new value ... ...
Daniel Bashir
@db7894
Mar 07 2016 00:35

This is probably really basic but I'm on the Using Objects for Lookups challenge and can't seem to figure out the problem with my code. I was supposed to convert a switch statement into a lookup table to lookup val (from a function that it's inside) and assign the string to a result variable
I had this:
// 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("foxtrot");

bitgrower
@bitgrower
Mar 07 2016 00:35
@reacorbett -- it performs the same operation on each and every element of the array ...
scnetsec
@ni234
Mar 07 2016 00:35
'''
'''
CamperBot
@camperbot
Mar 07 2016 00:35
:bulb: to format code use backticks! ``` more info
Daniel Bashir
@db7894
Mar 07 2016 00:35
Actually I got it never mind
bitgrower
@bitgrower
Mar 07 2016 00:36
love it when that happens ... @db7894 .... congrats !!!
scnetsec
@ni234
Mar 07 2016 00:37

'''
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];

'''

CamperBot
@camperbot
Mar 07 2016 00:37
:bulb: to format code use backticks! ``` more info
bitgrower
@bitgrower
Mar 07 2016 00:37
@DarkPigeons -- .filter takes care of making sure you iterate thru the whole array, so you don't have to worry about what's happening to the length of the array ...
apklip
@apklip
Mar 07 2016 00:37
This message was deleted
bitgrower
@bitgrower
Mar 07 2016 00:37
@ni234 -- what is the challenge, please ?
apklip
@apklip
Mar 07 2016 00:37
function destroyer(arr) {
  function des(val, index, array) {
    var counter = 0;
    for(var i = 0; i < arguments.length; i++) {
      if(val !== arguments[i]) {
        return val;
      }
    }

  }

  return arr.filter(des);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
This also doesn't work.
Ignore the counter variable.
scnetsec
@ni234
Mar 07 2016 00:38
Can some help explain this to me!
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];
bitgrower
@bitgrower
Mar 07 2016 00:38
@reacorbett -- reviewing the functional program section of FCC, too -- there is at least one challenge which uses .map
scnetsec
@ni234
Mar 07 2016 00:38
Access MultiDimensional Arrays With Indexes
Richard Corbett
@reacorbett
Mar 07 2016 00:38
@ni234 whatis the challenge name?
bitgrower
@bitgrower
Mar 07 2016 00:38
@DarkPigeons -- when you create a new function, you create a new arguments object ...
Bob
@henryberry1992
Mar 07 2016 00:39
Challege = Record Collection
apklip
@apklip
Mar 07 2016 00:39
@bitgrower Nevermind. I won't create a new function then.
scnetsec
@ni234
Mar 07 2016 00:39
I have to Read from myArray using bracket notation so that myData is equal to 8
bitgrower
@bitgrower
Mar 07 2016 00:39
so ... the value of the arguments object on entry to destroyer is NOT the same as what it is when you enter the des function
scnetsec
@ni234
Mar 07 2016 00:40
@reacorbett Read from myArray using bracket notation so that myData is equal to 8
bitgrower
@bitgrower
Mar 07 2016 00:40
ooooh ... reduce -- thanks @SteveCarroll -- I need some help with that ...
CamperBot
@camperbot
Mar 07 2016 00:40
bitgrower sends brownie points to @stevecarroll :sparkles: :thumbsup: :sparkles:
:star: 275 | @stevecarroll | http://www.freecodecamp.com/stevecarroll
Steve Carroll
@SteveCarroll
Mar 07 2016 00:40
@bitgrower I think it's the daddy of the rest of them
Bob
@henryberry1992
Mar 07 2016 00:41

Challenge = Record Collection
Website says my solution is right however I don't see "Addicted to Love" being pushed into array (test 3) in the console. Can someone take a look at my code?
// 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!=="")
{
if(collection[id].hasOwnProperty(prop))
{
collection[id][prop].push(value);
}
else
{
collection[id][prop] = value;
}
}
else
{
delete collection[id][prop];
}
return collection;
}

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

bitgrower
@bitgrower
Mar 07 2016 00:41
@ni234 -- do you know how to index into an array ? just a 1-d array ... if I asked you how to address 8 in this array, could you ? myArr= [6,7,8.9]; ?
Victor
@victoriousj
Mar 07 2016 00:42
@ni234 You'll have to use two sets of brackets to access the that array
bitgrower
@bitgrower
Mar 07 2016 00:42
looked like he was, from what I saw, @victoriousj ...
Christopher Aguilar
@chrisaguilar
Mar 07 2016 00:42

(Sorry if my formatting is off, I'm new to this)
Hey everybody, I just completed the Falsy Bouncer challenge, and it worked fine, but I don't know why. Here's my solution:

function bouncer(arr) {
  finalArr = arr.filter(function isFalsy(value){
    return Boolean(value);
  });
  return finalArr;
}

bouncer([7, "ate", "", false, 9]);

I'm confused, because I don't really know how the object.filter() method works. Why does it do what I wanted it to? I wrote the code myself, but I just went off of instinct, I didn't even think about it.

bitgrower
@bitgrower
Mar 07 2016 00:42
@henryberry1992 -- please post using these formatting instructions ... https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
apklip
@apklip
Mar 07 2016 00:43
function destroyer(arr) {
  var newArr = [];

  return arr.filter(function(val) {
    for(var i = 1; i < arguments.length; i++) {
      if(val !== arguments[i]) {
        return val;
      } else {
        return '';
      }
    }
  })
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I tried again.
I connected the filter to the arr.
Steve Carroll
@SteveCarroll
Mar 07 2016 00:43
Also, Mattias Petter Johansson has a series on You tube entitled: "Functional programming in JavaScript"
bitgrower
@bitgrower
Mar 07 2016 00:43
@christopher-m-aguilar -- falsy bouncer is an EXTREMELY easy challenge to solve ... once you know the secret -- I spent HOURS pulling my hair out until I found the secret -- the secret can be found in the helpful hints page ... on Booleans, I think ...
Bob
@henryberry1992
Mar 07 2016 00:44
This message was deleted
im sorry misclick
bitgrower
@bitgrower
Mar 07 2016 00:44
@DarkPigeons -- unfortunately, since you have a callback function within filter, you have the same problem with the arguments object... you need to capture the arguments into a different variable so you can use it in the filter callback ...
apklip
@apklip
Mar 07 2016 00:44
Okay @bitgrower .
Bob
@henryberry1992
Mar 07 2016 00:44
This message was deleted
bitgrower
@bitgrower
Mar 07 2016 00:45
@DarkPigeons --- it's always something, isn't it ?!? :)
apklip
@apklip
Mar 07 2016 00:46
function destroyer(arr) {
  var arg = arguments;

  return arr.filter(function(val) {
    for(var i = 1; i < arg.length; i++) {
      if(val !== arg[i]) {
        return val;
      } else {
        return '';
      }
    }
  })
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@bitgrower Haha, yeah. Thanks for the help thus far bitgrower.
CamperBot
@camperbot
Mar 07 2016 00:46
darkpigeons sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: darkpigeons already gave bitgrower points
apklip
@apklip
Mar 07 2016 00:47
This returns 1, 3, 1, 3. Not 1, 1
Daniel Bashir
@db7894
Mar 07 2016 00:47
Haven't been able to figure this one out... I'm supposed to modify a function called checkObj to test myObj for checkProp and return the value of that property's found (and return "Not Found" if not)
This is what I have:
```
Bob
@henryberry1992
Mar 07 2016 00:47
This message was deleted
bitgrower
@bitgrower
Mar 07 2016 00:48
okay ... next step you can't just set arg to arguments, @DarkPigeons -- that assignment simply sets arg to point to the same place arguments is (I think?) whatever that might be ... look on the arguments object MDN page for a line of code you can use (although some in FCC hate that line of code .. but it does the trick for now)
Daniel Bashir
@db7894
Mar 07 2016 00:48
// 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";
  }
}

// Test your code by modifying these values
checkObj("bed");
apklip
@apklip
Mar 07 2016 00:49
Okay @bitgrower
bitgrower
@bitgrower
Mar 07 2016 00:49
@db7894 -- you can't use dot notation there ... change it to brackets ...
Suprith Aireddy
@sup-rith
Mar 07 2016 00:49
@DarkPigeons do myObj[checkProp];
bitgrower
@bitgrower
Mar 07 2016 00:49
LOL @sup-rith -- wrong camper
Suprith Aireddy
@sup-rith
Mar 07 2016 00:50
hahaha whoops @bitgrower
@db7894 do myObj[checkProp];
Bob
@henryberry1992
Mar 07 2016 00:50
@bitgrower how do u code format? ```js <code> is that it
bitgrower
@bitgrower
Mar 07 2016 00:50
yeah -- the auto-complete in gitter sucks ...
@henryberry1992 -- follow the instructions on the page I provided ... EXPLICITLY ... step by tiny step ... and then you'll get it ...
Daniel Bashir
@db7894
Mar 07 2016 00:50
@bitgrower I see... What's the reason for that?
bitgrower
@bitgrower
Mar 07 2016 00:51
@db7894 -- you can only use dot notation when you are using the actual NAME of a property -- doesn't work with variables
Suprith Aireddy
@sup-rith
Mar 07 2016 00:51
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
how do i access pine?
bitgrower
@bitgrower
Mar 07 2016 00:51
@sup-rith -- describe your data structure ...
Daniel Bashir
@db7894
Mar 07 2016 00:51
@bitgrower That makes sense, thanks
CamperBot
@camperbot
Mar 07 2016 00:51
db7894 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 761 | @bitgrower | http://www.freecodecamp.com/bitgrower
Steve Carroll
@SteveCarroll
Mar 07 2016 00:52
Suprith Aireddy
@sup-rith
Mar 07 2016 00:52
its a json object
bitgrower
@bitgrower
Mar 07 2016 00:52
@sup-rith not quite ... what's the name of the challenge ...
Suprith Aireddy
@sup-rith
Mar 07 2016 00:52
Accessing Nested Arrays in Json
bitgrower
@bitgrower
Mar 07 2016 00:53
so ... if you look at the first character after the = sign, what is it ?
Suprith Aireddy
@sup-rith
Mar 07 2016 00:53
an array @bitgrower
dposse
@dposse
Mar 07 2016 00:53
@SteveCarroll you should show this over at helpfrontend or freecodecamp general, doesn't have any javascript in it!
bitgrower @bitgrower thinks they should change the name of the challenge ... it's a bit deceptivce
Bob
@henryberry1992
Mar 07 2016 00:53
This message was deleted
Steve Carroll
@SteveCarroll
Mar 07 2016 00:54
@dposse Oh, is that the place for it? SOrry.
bitgrower
@bitgrower
Mar 07 2016 00:54
okay ... so, you first have to index into the array ...
Suprith Aireddy
@sup-rith
Mar 07 2016 00:54
wait its a [ @bitgrower
bitgrower
@bitgrower
Mar 07 2016 00:54
yes -- it's a [ -- meaning, array ... at the topmost level ...
Suprith Aireddy
@sup-rith
Mar 07 2016 00:54
so I would do myPlants.
bitgrower
@bitgrower
Mar 07 2016 00:54
so myPlants is an array containing objects ...
so ... how do you select the particular element (object) of the array ?
Suprith Aireddy
@sup-rith
Mar 07 2016 00:55
myPlants1.trees1
Bob
@henryberry1992
Mar 07 2016 00:55
Challenge = Record Collection
Website says I passed all tests, however "Addicted to Love" isn't pushed into the array(test 3) in console. Can someone take a look at my solution? Thanks.
// 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!=="")
    {
     if(collection[id].hasOwnProperty(prop))
        {
          collection[id][prop].push(value);
        }
      else
        {
          collection[id][prop] = value;
        }
    }
   else
     {
       delete collection[id][prop];
     }
  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
bitgrower
@bitgrower
Mar 07 2016 00:55
looks good to me ... does that take care of it ?
Suprith Aireddy
@sup-rith
Mar 07 2016 00:55
no
bitgrower
@bitgrower
Mar 07 2016 00:56
no ? hmmm ...
Suprith Aireddy
@sup-rith
Mar 07 2016 00:57
yea I have no Idea @bitgrower
bitgrower
@bitgrower
Mar 07 2016 00:57
This message was deleted
Victor
@victoriousj
Mar 07 2016 00:57
@sup-rith you will use both bracket and dot notation to access the propety
bitgrower
@bitgrower
Mar 07 2016 00:58
^^^!!!!
Suprith Aireddy
@sup-rith
Mar 07 2016 00:58
@victoriousj i understand but i dont know the syntax of it
bitgrower
@bitgrower
Mar 07 2016 00:58
he was doing that ... just wrong property ...
@sup-rith -- you have pretty much the right syntax, just the wrong property ...
you need to use the property of the array
(the inner array)
Victor
@victoriousj
Mar 07 2016 00:58
^yeap, wrong property. the property is in list and not trees
Suprith Aireddy
@sup-rith
Mar 07 2016 00:58
okay let me try that
oh okay thanks guys @victoriousj @bitgrower
bitgrower
@bitgrower
Mar 07 2016 00:59
hey @henryberry1992 -- congrats on getting the formatting nailed .. :)
Victor
@victoriousj
Mar 07 2016 00:59
@sup-rith that one can be misleading
Bob
@henryberry1992
Mar 07 2016 01:00
@bitgrower hey thanks. would u be so kind to look over my solution
CamperBot
@camperbot
Mar 07 2016 01:00
henryberry1992 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 762 | @bitgrower | http://www.freecodecamp.com/bitgrower
Bob
@henryberry1992
Mar 07 2016 01:00
@bitgrower challenged passed however tracks remains an empty array in console for me
bitgrower
@bitgrower
Mar 07 2016 01:01
@henryberry1992 -- I would double check the command you are using to show the object in the console ... and also make sure you understand how to look at objects in the console ...it can be a bit tricky ...
Mahfouzer
@Mahfouzer
Mar 07 2016 01:01
hint
CamperBot
@camperbot
Mar 07 2016 01:01
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
Richard Corbett
@reacorbett
Mar 07 2016 01:03
@bitgrower so i can use split to turn my string into an array. then use map to pass charCodeAt() to each of its objects. and the samething for fromCharCode(). Is that correct?
bitgrower
@bitgrower
Mar 07 2016 01:11
sounds about right, @reacorbett ... good job!
Daniel Bashir
@db7894
Mar 07 2016 01:13
I'm trying to figure out how to access something from a nested array like this from a challenge, can anyone help out? (I'm trying to access "pine")
```
// Setup
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = myPlants.trees[1]; // Change this line
The bottom code is my attempt to access it but it's not working
bitgrower
@bitgrower
Mar 07 2016 01:14
dang ... where's @victoriousj -- and @sup-rith ...
@db7894 -- can you describe what kind of data structure myPlants is ?
Kristian Sigston
@nexatris
Mar 07 2016 01:15
This message was deleted
Daniel Bashir
@db7894
Mar 07 2016 01:15
It's a JSON object
It's from the "Accessing Nested Arrays in JSON" challenge
Kristian Sigston
@nexatris
Mar 07 2016 01:16
How do i post my code like the above?
bitgrower
@bitgrower
Mar 07 2016 01:16
@db7894 -- look again ... what's the character after the = sign?
Daniel Bashir
@db7894
Mar 07 2016 01:17
@bitgrower I guess that just makes it an array
bitgrower
@bitgrower
Mar 07 2016 01:17
yup ...
an array of ... .?
Daniel Bashir
@db7894
Mar 07 2016 01:17
Of objects
bitgrower @bitgrower 's lesson here is to always look and describe the data structure you've been handed ... :)
Kristian Sigston
@nexatris
Mar 07 2016 01:17
This message was deleted
Mahfouzer
@Mahfouzer
Mar 07 2016 01:17
hint
CamperBot
@camperbot
Mar 07 2016 01:17
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
bitgrower
@bitgrower
Mar 07 2016 01:18
awesome sauce, @db7894 -- so how do you index into an array ?
Kristian Sigston
@nexatris
Mar 07 2016 01:18
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:18
:bulb: to format code use backticks! ``` more info
Daniel Bashir
@db7894
Mar 07 2016 01:18
@bitgrower Bracket notation..?
Kristian Sigston
@nexatris
Mar 07 2016 01:18
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:18
:bulb: to format code use backticks! ``` more info
Kristian Sigston
@nexatris
Mar 07 2016 01:19
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:19
:bulb: to format code use backticks! ``` more info
Daniel Bashir
@db7894
Mar 07 2016 01:19
@nexatris do the three backticks then press enter before putting in your code
It should automatically insert three more on the bottom line
bitgrower
@bitgrower
Mar 07 2016 01:19
@db7894 -- sounds good to me ... so which element of the myPlant array do you want to access ?
Daniel Bashir
@db7894
Mar 07 2016 01:20
The "pine" element from "trees"
Kristian Sigston
@nexatris
Mar 07 2016 01:20
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:20
:bulb: to format code use backticks! ``` more info
Mahfouzer
@Mahfouzer
Mar 07 2016 01:20
// Example
var ourStr = "I come first. ";
ourStr += "I come second.";

// Only change code below this line

var myStr = ourStr;
myStr = myStr+="";
Kristian Sigston
@nexatris
Mar 07 2016 01:20
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:20
:bulb: to format code use backticks! ``` more info
Kristian Sigston
@nexatris
Mar 07 2016 01:20
This message was deleted
'''
CamperBot
@camperbot
Mar 07 2016 01:21
:bulb: to format code use backticks! ``` more info
Mahfouzer
@Mahfouzer
Mar 07 2016 01:21
it does exactly as it says
but it doesn't work
bitgrower
@bitgrower
Mar 07 2016 01:21
@db7894 -- you're getting ahead of yourself ... all you need to do is select an element in the top level array ...
Bob
@henryberry1992
Mar 07 2016 01:21
@bitgrower hey i copy pasted my code in jsfiddle and it gave me push is not a function error . I don't know whats wrong with the push method though? I tried both .prop and [prop]
Daniel Bashir
@db7894
Mar 07 2016 01:21
@bitgrower it says "retrieve the second tree from the variable myPlants"
greg
@wearenotgroot
Mar 07 2016 01:22
@henryberry1992 push are for arrays
bitgrower
@bitgrower
Mar 07 2016 01:22
sorry @henryberry1992 -- I dunno -- try here: pythontutor.com/javascript.html
Kristian Sigston
@nexatris
Mar 07 2016 01:22
@db7894 Didn't work? What is the procedure. Idiot proof.
?
Bob
@henryberry1992
Mar 07 2016 01:22
@wearenotgroot yea but for my question i was pushing into an array of object
Daniel Bashir
@db7894
Mar 07 2016 01:23
It's using object dot and array bracket notation.
I tried using
var secondTree = myPlants.trees[1];
greg
@wearenotgroot
Mar 07 2016 01:23
@henryberry1992 did you access it correctly though?
Daniel Bashir
@db7894
Mar 07 2016 01:23
But that didn't work
Bob
@henryberry1992
Mar 07 2016 01:24
it worked when i tried it in console manually
greg
@wearenotgroot
Mar 07 2016 01:24
@henryberry1992 collection[id][prop].push(value); ?
Bob
@henryberry1992
Mar 07 2016 01:24
yes
greg
@wearenotgroot
Mar 07 2016 01:26
@henryberry1992 link the fiddle?
Kristian Sigston
@nexatris
Mar 07 2016 01:26
'''
CamperBot
@camperbot
Mar 07 2016 01:26
:bulb: to format code use backticks! ``` more info
Kristian Sigston
@nexatris
Mar 07 2016 01:26
This message was deleted
Daniel Bashir
@db7894
Mar 07 2016 01:26
Still can't figure out how to access this...
Bob
@henryberry1992
Mar 07 2016 01:27
Kristian Sigston
@nexatris
Mar 07 2016 01:27
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:27
:bulb: to format code use backticks! ``` more info
Kristian Sigston
@nexatris
Mar 07 2016 01:27
This message was deleted
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:28
:bulb: to format code use backticks! ``` more info
Bob
@henryberry1992
Mar 07 2016 01:28
@db7894 hint: myPLnats is an array
Kristian Sigston
@nexatris
Mar 07 2016 01:28
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:28
:bulb: to format code use backticks! ``` more info
Bob
@henryberry1992
Mar 07 2016 01:28
an array of objects
Kristian Sigston
@nexatris
Mar 07 2016 01:28
Someone? I'm missing something obvious.
Daniel Bashir
@db7894
Mar 07 2016 01:28
@henryberry1992 I see that arrays have bracket notation but when I access tree with that it says it would be better accessed with dot notation
Richard Corbett
@reacorbett
Mar 07 2016 01:28
function rot13(str) { // LBH QVQ VG!
  var arr = str.split('');
  arr.map(function(value){

  });

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
@bitgrower am i heading in the right direction here?
greg
@wearenotgroot
Mar 07 2016 01:29
@henryberry1992 oh you were doing it twice
Kristian Sigston
@nexatris
Mar 07 2016 01:29
This message was deleted
CamperBot
@camperbot
Mar 07 2016 01:29
:bulb: to format code use backticks! ``` more info
Bob
@henryberry1992
Mar 07 2016 01:30
@wearenotgroot whatdo u mean?
Kristian Sigston
@nexatris
Mar 07 2016 01:30

var longestLength = 0;
function findLongestWord(str) {
var res = str.split(" ");
var arrayLength = res.length;
for (var i = 0; i < arrayLength; i++) {
if (res[i].length > longestLength){
longestLength = res[i].length;
}
}
return longestLength;

//Do something

}

findLongestWord("May the force be with you");

'''
CamperBot
@camperbot
Mar 07 2016 01:30
:bulb: to format code use backticks! ``` more info
greg
@wearenotgroot
Mar 07 2016 01:30
@henryberry1992 if you remove the update on the console.log and just log the collection instead
Kristian Sigston
@nexatris
Mar 07 2016 01:30
This message was deleted
greg
@wearenotgroot
Mar 07 2016 01:30
@henryberry1992
update(5439, "artist", "ABBA");
console.log(collection);
Kristian Sigston
@nexatris
Mar 07 2016 01:30
This message was deleted
```
Bob
@henryberry1992
Mar 07 2016 01:31
@wearenotgroot yes i know but if u remove that line and put the code in, you'll see that test 3 isn't correct even though it's passed
Kristian Sigston
@nexatris
Mar 07 2016 01:31
This message was deleted
```
bigbeno37
@bigbeno37
Mar 07 2016 01:31
Hey guys, why am I getting an error here:
function largestOfFour(arr) {

  var arrayOfLargestNumbers = [];

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

    var tempNumberStorage = 0;
    var tempArrayStorage = arr[i];

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

      if (tempNumberStorage < arr[i][j]){

        tempNumberStorage = arr[i][j];

      }

    }

    arrayOfLargestNumbers.push(tempNumberStorage);

  }

  return arrayOfLargestNumbers;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Kristian Sigston
@nexatris
Mar 07 2016 01:32
```
This message was deleted
Bob
@henryberry1992
Mar 07 2016 01:32
@db7894 look at the brackets closely
bigbeno37
@bigbeno37
Mar 07 2016 01:32
The error is TypeError: Cannot read property of '0' of undefined
Kristian Sigston
@nexatris
Mar 07 2016 01:32
```
This message was deleted
var longestLength = 0;
function findLongestWord(str) {
    var res = str.split(" ");
  var arrayLength = res.length;
for (var i = 0; i < arrayLength; i++) {
    if (res[i].length > longestLength){
          longestLength = res[i].length;
    }
}
return longestLength;



    //Do something
} 


findLongestWord("May the force be with you");
Daniel Bashir
@db7894
Mar 07 2016 01:32
@henryberry1992 I'm not sure what you mean. I have a 1 in the brackets to access the second tree but that's it
It's this:
var secondTree = myPlants.trees[1];
greg
@wearenotgroot
Mar 07 2016 01:33
@henryberry1992 it should add artist property with value "ABBA"
Kristian Sigston
@nexatris
Mar 07 2016 01:33
Finally did it. I would like some help please. This is not passing for the "may the force be with you string" except that it is giving me the correct result when i put it in as a test.
Bob
@henryberry1992
Mar 07 2016 01:33
@db7894 trees is a value not a key
Daniel Bashir
@db7894
Mar 07 2016 01:34
@henryberry1992 Yes but when I access it with brackets the website tells me to use dot notation
greg
@wearenotgroot
Mar 07 2016 01:34
@henryberry1992 should only push a value if the property is equal "tracks"
Daniel Bashir
@db7894
Mar 07 2016 01:34
@henryberry1992 And I don't know how to access the actual "pine" element if I put "trees" it in brackets
Bob
@henryberry1992
Mar 07 2016 01:35
@wearenotgroot I'm talking about After update(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element. if you copy pasta my code into the question you'd see that collection[1245][tracks] is empty
Daniel Bashir
@db7894
Mar 07 2016 01:35

@henryberry1992 This is what I would have with brackets:

var secondTree = myPlants["trees"];

But it says "trees is better written in dot notation" on the side

And I don't know how to access "pine" from the list thing below it with that notation
bitgrower
@bitgrower
Mar 07 2016 01:37
@db7894 -- you need to index into the array first ... with a number ...
there are only 2 elements in the myPlants array ... so it's gonna be either myPlants[0] or myPlants[1]
Daniel Bashir
@db7894
Mar 07 2016 01:39
@bitgrower Got it. Thanks.
CamperBot
@camperbot
Mar 07 2016 01:39
db7894 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: db7894 already gave bitgrower points
greg
@wearenotgroot
Mar 07 2016 01:39
@henryberry1992 not empty here
Bob
@henryberry1992
Mar 07 2016 01:40
@wearenotgroot really? It is on mine. Weird.
bitgrower
@bitgrower
Mar 07 2016 01:41
@db7894 -- so, now you've selected an object, (it's "name" if you will) ... then you use object notation to select the "key" (aka "property") of the array where pine is an element ...
greg
@wearenotgroot
Mar 07 2016 01:41
@henryberry1992 what you can do is add an extra check if the prop is equal tracks together with .hasOwnProperty to push values
@henryberry1992 to make sure to only push values into tracks
if(prop === "tracks" && collection[id].hasOwnProperty(prop))
Richard Corbett
@reacorbett
Mar 07 2016 01:43
I need charCodeAt to iterate through the array. How can I combine map with charCode at to acheive this?
Bob
@henryberry1992
Mar 07 2016 01:45
@wearenotgroot yea i did that earlier but i wanted to write it in a more generalized way. thanks anyway.
CamperBot
@camperbot
Mar 07 2016 01:45
henryberry1992 sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 953 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
Nick Robson
@nickrobson
Mar 07 2016 01:48
@bitgrower is your job to be on Gitter 24/7 ???
Lana K.
@luckieblinkie
Mar 07 2016 01:48
Hello everyone. I am feeling a bit stuck with javascript, and have just hit the "Assignment with a Returned Value" section. The instructions are a bit unclear. Any ideas where to go for some more info?
bitgrower
@bitgrower
Mar 07 2016 01:48
no .. is it yours ? :)
Nick Robson
@nickrobson
Mar 07 2016 01:49
nah.. but you seem to be on all the time :P
bitgrower
@bitgrower
Mar 07 2016 01:49
it's a weekend, @nickrobson ...
Nick Robson
@nickrobson
Mar 07 2016 01:49
it's monday here in Aus.. that'd be why :P
bitgrower
@bitgrower
Mar 07 2016 01:50
lol, well there ya go ...
Nick Robson
@nickrobson
Mar 07 2016 01:50
I've been at uni for the past 4 hrs lol
that makes sense why you've been on the whole time
greg
@wearenotgroot
Mar 07 2016 01:51
@bigbeno37 the second for loop
@bigbeno37 should be j++
@bigbeno37 also you can pretty much do this
unction largestOfFour(arr) {

  var arrayOfLargestNumbers = [];

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

    var tempNumberStorage = 0;
    //var tempArrayStorage = arr[i]; //<-------no need for this

    for (var j = 0; j < arr[i].length; j++){  //<-----------just use the inner array length, also use j++ not i++

      if (tempNumberStorage < arr[i][j]){

        tempNumberStorage = arr[i][j];

      }

    }

    arrayOfLargestNumbers.push(tempNumberStorage);

  }

  return arrayOfLargestNumbers;
}
@luckieblinkie what you got so far?
Robert Richey
@0x0936
Mar 07 2016 02:02

@luckieblinkie call process with 7 as the argument

  • process(7);

process() does something with that input and returns a new output, assigned to the variable processed. All together, it should look like this:

  • processed = process(7);

It's not important to understand what process() does. The bigger picture here is to pass a value into a function call and get a new value back from it.

Lana K.
@luckieblinkie
Mar 07 2016 02:03
Thanks @0x0936 , sorry for the delay in responding.
CamperBot
@camperbot
Mar 07 2016 02:03
luckieblinkie sends brownie points to @0x0936 :sparkles: :thumbsup: :sparkles:
:star: 1221 | @0x0936 | http://www.freecodecamp.com/0x0936
Robert Richey
@0x0936
Mar 07 2016 02:04
:+1: :)
Lana K.
@luckieblinkie
Mar 07 2016 02:04
I was able to get the result, but didn't really understand the solution. Now I'm at "Stand In Line." I'd say that Javascript is a bit beyond me at times. Any advice on how to understand the meaning behind the code?
greg
@wearenotgroot
Mar 07 2016 02:05
@luckieblinkie reading documentation might help
@luckieblinkie just search for "any method name" + js + mdn
Steve Carroll
@SteveCarroll
Mar 07 2016 02:06
Must be a way to use this in a function...
str = "SERR PBQR PNZC";

  str.split('').map(function (char) {
     convert = char.charCodeAt(0) - 13;

     return convert;
  });
This is for Caesars Cipher
I tried returning "convert" in an object inside of the function, to no avail.
Nitin Nayyar
@nayyarnitin09
Mar 07 2016 02:08
Hi do anyone has a solution for javascript problem:Escaping Literal Quotes in Strings
Steve Carroll
@SteveCarroll
Mar 07 2016 02:08
Anyone use the map method on Caesars Cipher?
Nitin Nayyar
@nayyarnitin09
Mar 07 2016 02:09
need to print his:Escaping Literal Quotes in Strings
greg
@wearenotgroot
Mar 07 2016 02:09
@SteveCarroll did you catch/store the result of the into a variable
Steve Carroll
@SteveCarroll
Mar 07 2016 02:09
@wearenotgroot Hmmm... maybe not ;)
greg
@wearenotgroot
Mar 07 2016 02:09

@SteveCarroll

str = "SERR PBQR PNZC";

  var result  = str.split('').map(function (char) {
     convert = char.charCodeAt(0) - 13;

     return convert;
  });

result will be an array of numbers/charcodes

Steve Carroll
@SteveCarroll
Mar 07 2016 02:10
But can't i just convert back to text and back to a string from here?
greg
@wearenotgroot
Mar 07 2016 02:10
@SteveCarroll use String.fromCharCode("some charcode")
@nayyarnitin09 what you got so far?
Steve Carroll
@SteveCarroll
Mar 07 2016 02:11
I know, I can't figur out how to do it, or even return it inside of a function
Which is what is called for.
greg
@wearenotgroot
Mar 07 2016 02:12
@SteveCarroll you can do this
str = "SERR PBQR PNZC";

  var result  = str.split('').map(function (char) {
     convert = char.charCodeAt(0) - 13;

     return String.fromCharCode(convert);
  });
Richard Corbett
@reacorbett
Mar 07 2016 02:14
function rot13(str) { // LBH QVQ VG!
  var  arr = str.split('');
  arr.map(function(value){
    return value.charCodeAt(0) + 13;
  });

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
im having a hard time combining the charCodeAt() and map() method. Am I even getting close? I am trying to iterate the objects of my array through charCodeAt().
Steve Carroll
@SteveCarroll
Mar 07 2016 02:14
@reacorbett Me, too... about the combining
greg
@wearenotgroot
Mar 07 2016 02:15
@reacorbett remember .map will create/return a new array with the result from the function you feed it
@reacorbett so you need to catch/store/capture it into a variable
Steve Carroll
@SteveCarroll
Mar 07 2016 02:16
Which his example isn't doing
At least, I dont think it is :smile:
greg
@wearenotgroot
Mar 07 2016 02:16
@SteveCarroll correct
@reacorbett
function rot13(str) { // LBH QVQ VG!
  var  arr = str.split('');
  var result = arr.map(function(value){ //<-------------store the array on result variable 
    return value.charCodeAt(0) + 13;
  });
console.log(result); //<------------to see what you are getting
}
Steve Carroll
@SteveCarroll
Mar 07 2016 02:18
I can log it from the funtion just not return it
jonny8887
@jonny8887
Mar 07 2016 02:20

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
result = wordBlanks;

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

Richard Corbett
@reacorbett
Mar 07 2016 02:20
@wearenotgroot result is not defined
jonny8887
@jonny8887
Mar 07 2016 02:20
ehy not working
greg
@wearenotgroot
Mar 07 2016 02:21
@SteveCarroll
function rot13(str) { // LBH QVQ VG!
  var result  = str.split('').map(function (char) {
     convert = char.charCodeAt(0) - 13;

     return String.fromCharCode(convert);
  });
return result.join(''); //<-----------convert result from array  to string
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
@reacorbett did you call the function?
@reacorbett --------->rot13("SERR PBQR PNZC");
Richard Corbett
@reacorbett
Mar 07 2016 02:23
@wearenotgroot Ahh, I figured it out.
mstankey
@mstankey
Mar 07 2016 02:27
What's wrong with my increment code?

var myVar = 87;

// Only change code below this line
myVar = myVar++;

Robert Richey
@0x0936
Mar 07 2016 02:27
@luckieblinkie the purpose of JS, as part of HTML / CSS / JS, is to handle the behavior or action of a Web app. It's all about receiving inputs and giving outputs - transforming data in some way, and often involves looping over data to find the one element you need and then either returning it or transforming it. You can do this.
mstankey
@mstankey
Mar 07 2016 02:27
It keeps saying myVar does not equal 88
greg
@wearenotgroot
Mar 07 2016 02:31
@mstankey remove the myVar = myVar++; and just do myVar++ <---------this give the original value then increments it afterwards
mstankey
@mstankey
Mar 07 2016 02:31
There we go, thank you
greg
@wearenotgroot
Mar 07 2016 02:32
@mstankey now if you do this---------> myVar = ++myVar; <------------------this will increment the value then give the result. will give you 88
apklip
@apklip
Mar 07 2016 02:37
Hi, I'm at Caesers Cipher. Can someone explain .charCode to me?
What is unicode?
Richard Corbett
@reacorbett
Mar 07 2016 02:43
@wearenotgroot Thank you sooo much!!! can I pm you my final code so you can look it over? I dont want to post the answer in chat.
CamperBot
@camperbot
Mar 07 2016 02:43
reacorbett sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 956 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Mar 07 2016 02:44
@reacorbett sure
Steve Carroll
@SteveCarroll
Mar 07 2016 02:44
@wearenotgroot @reacorbett Wish I could see it...
The thing eludes me... had to take a break.
greg
@wearenotgroot
Mar 07 2016 02:45
@SteveCarroll tips you can check the range of the code and shift them accordingly(plu 13 or -13)
@SteveCarroll --->http://www.asciitable.com/
Sidharth Kriplani
@sidkrip
Mar 07 2016 02:47
wiki Sum All Primes
CamperBot
@camperbot
Mar 07 2016 02:47

:point_right: algorithm sum all primes [wiki]

Explanation:

The explanation for this problem is very simple. You will generate a list of prime numbers up to the number you are given as a parameter. Then you need to add them all up and return that value. The tricky part is on generating the list of prime numbers. I suggest you find a code or a good math algorithm that you can turn into code.

:pencil: read more about algorithm sum all primes on the FCC Wiki

Richard Corbett
@reacorbett
Mar 07 2016 02:48
@SteveCarroll I worked on it until 5 am this morning and got no where. this evening I finished it and decided to rewrite the code using the map method.
Steve Carroll
@SteveCarroll
Mar 07 2016 02:51
@reacorbett I know the feeling with these reduction methods.
@wearenotgroot One thing that gets me is why the spaces don't transfer, too
Steve Carroll
@SteveCarroll
Mar 07 2016 02:57
Well, I guess I'll go cry myself to sleep again :smile:
Or at least lay face down on the bed...
greg
@wearenotgroot
Mar 07 2016 02:59
@SteveCarroll well the code for space is 32
@SteveCarroll so when you subtracted 13 it became 19
Steve Carroll
@SteveCarroll
Mar 07 2016 03:00
LOL!
Like I said, I'm a lamebrain
greg
@wearenotgroot
Mar 07 2016 03:00
@SteveCarroll and 19 is code for some device control
Steve Carroll
@SteveCarroll
Mar 07 2016 03:00
That'd do it.
IT's funny how wishful your thinking can be when you're doing this stuff ;)
greg
@wearenotgroot
Mar 07 2016 03:01
@SteveCarroll just do a check for the code that are within a certain range and ignore or dont change the other code
Steve Carroll
@SteveCarroll
Mar 07 2016 03:02
I was gonna do that but I wanted to see if I could make it more expansive using map
But not without consideration for the spaces, ovbiously
Charles
@GUITARPLRC
Mar 07 2016 03:07
help where art thou
CamperBot
@camperbot
Mar 07 2016 03:07

:point_right: algorithm where art thou [wiki]

Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

:pencil: read more about algorithm where art thou on the FCC Wiki

Kyle Morton
@kmorton1988
Mar 07 2016 03:11
how do I check to see if a property exists?
inside an opject
help profile lookup
CamperBot
@camperbot
Mar 07 2016 03:13

:point_right: checkpoint profile lookup [wiki]

Checkpoint: Profile Lookup

Instructions

We have an array of objects representing different people in our contacts lists.

A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

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

:pencil: read more about checkpoint profile lookup on the FCC Wiki

Sidharth Kriplani
@sidkrip
Mar 07 2016 03:14
isnt this code correct to find a prime?
function isPrime(number) {
  for(var i=number-1; i>1; i--) {
    if(number%i!==0) {
      return number;
    }
  }
}
Richard Corbett
@reacorbett
Mar 07 2016 03:17
I am finally finished with the Basic Algo Challenges!!!!!!!!!!! It feels good.....yeah.
apklip
@apklip
Mar 07 2016 03:18
function rot13(str) { // LBH QVQ VG!
  str.toUpperCase();

  var arr = str.split('');
  var orgLen = str.length;
  for(var i = 0; i < orgLen; i++) {
    if(str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {

      arr[i] = str.charCodeAt(i); 

      if(isNaN(arr[i])) {} else {
        arr[i] = arr[i] - 13;
      }

      if(arr[i] < 65) {
        arr[i] = 90 - (65 - arr[i]);
      }

    } 

    str = arr.join('');

  }
  return arr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Can someone help me with Caesers Cipher?
It works fine until the .join();
Steve Carroll
@SteveCarroll
Mar 07 2016 03:19
@reacorbett Ah... shaddup! ;)
Richard Corbett
@reacorbett
Mar 07 2016 03:19
what happends at join?
apklip
@apklip
Mar 07 2016 03:19
Somehow, random alphabetical characters are added to the str.
Before that, it is just uni numbers
I'm still testing and am not completely done with my code.
Steve Carroll
@SteveCarroll
Mar 07 2016 03:20
I was finished with a lot of this stuff... until they added a ton more.
But I;'m glad they did.
apklip
@apklip
Mar 07 2016 03:20
This is what was returns
Richard Corbett
@reacorbett
Mar 07 2016 03:21
@DarkPigeons I think one problem you are having is that when you subtract 13 you end up outside the alpha code. it might help to look up char codes and figure out where all the alphas fall.
bitgrower
@bitgrower
Mar 07 2016 03:22
hahahahahaha ... learned your lesson, eh @reacorbett :)
apklip
@apklip
Mar 07 2016 03:22
        [70, 'E', 81,  'R', ' ', 69, 'B', 'Q', 'R', 78, 68,  69, 'Z', 'C']
Richard Corbett
@reacorbett
Mar 07 2016 03:23
lol yes i did.
@bitgrower
apklip
@apklip
Mar 07 2016 03:23
@reacorbett I have an if statement for that.
bitgrower @bitgrower will give the advice she likes to give -- try seeing how you would do this if you weren't using code ... write down exactly what you would need to do, step by step ... pencil & paper ...
golfguy1984
@golfguy1984
Mar 07 2016 03:24
so im looking for some real life examples/scenarios using JS anyone have any resources?
bitgrower
@bitgrower
Mar 07 2016 03:26
go to just about any website ... "view source" ... :)
Steve Carroll
@SteveCarroll
Mar 07 2016 03:27
@golfguy1984 Just JS? Here's a crappy example I wrote awhile ago: http://boomersbanddenver.com/schedule.html (I did not make that website).
Richard Corbett
@reacorbett
Mar 07 2016 03:28
@DarkPigeons str = arr.join(''): why do you have that? have you thought about putting the join() directly on return arr.join('');
also fromCharCode will convert it back into alpha code.
@bitgrower I rewrote my code using the map method and it works great.
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:30
anyone help with the Sum All Primes bonfire?
CamperBot
@camperbot
Mar 07 2016 03:30
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:31
@bitgrower help?
bitgrower
@bitgrower
Mar 07 2016 03:31
@reacorbett -- worth doing, eh ? :)
@sidkrip -- can't right now ... doing my "day job" ... just taking a brain cell break ... :)
Richard Corbett
@reacorbett
Mar 07 2016 03:32
@bit yeah. learned a lot. i was thinking about getting rid of the if statements using ternary operator.
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:32
@reacorbett can you help?
Richard Corbett
@reacorbett
Mar 07 2016 03:32
sure what do you have @sidkrip
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:32
@bitgrower goodluck, man.
@reacorbett
this is my code for the bonfire Sum All Primes
function sumPrimes(num) {

  var p=2;
  var sum=0;
  for(var i=p; i<=num; i++) {
    if (isPrime(i)) {
    sum+=i; 
    }
  }
  sum+=num;
  return sum;
}

function isPrime(number) {
  for(var i=2; i<number; i++) {
    if(number%i===0) {
      return false;
    }
    else return true;
  }
}

sumPrimes(10);
bitgrower This message was deleted
Richard Corbett
@reacorbett
Mar 07 2016 03:36
what is your question?
Devlin S Healy
@soaren
Mar 07 2016 03:39

"Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable."

// 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");

What am I doing wrong here?

this is the example given
var alpha = {
  1:"Z",
  2:"Y",
  3:"X",
  4:"W",
  ...
  24:"C",
  25:"B",
  26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"

var value = 2;
alpha[value]; // "Y"
Richard Corbett
@reacorbett
Mar 07 2016 03:40
echo i think is part of javascript. I would change those to Capital letters.
CamperBot
@camperbot
Mar 07 2016 03:40
@reacorbett said: echo i think is part of javascript. I would change those to Capital letters.
Devlin S Healy
@soaren
Mar 07 2016 03:41
@camperbot what is the purpose of life?
Richard Corbett
@reacorbett
Mar 07 2016 03:42
nevermind maybe not
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:42
@reacorbett so sorry. The task is to find all the primes upto a given number and then sum them up and include the entered number as well. and return the sum
Maddah Anass
@unlimiworks
Mar 07 2016 03:42
@soaren you should search in lookup for the variable that val holds, and put it in result
Devlin S Healy
@soaren
Mar 07 2016 03:44
val = result; Does nothing
Maddah Anass
@unlimiworks
Mar 07 2016 03:45
@soaren I think you misunderstood the assignment :)
Devlin S Healy
@soaren
Mar 07 2016 03:46
they did a pretty bad job explaining it
I've seen a few other people having issues with it, not just me
Richard Corbett
@reacorbett
Mar 07 2016 03:47
@sidkrip ok. hold on let me take a look.
bitgrower
@bitgrower
Mar 07 2016 03:47
such is the programming life ... not everything is as well explained as we might like ... hence the RSAP recommendations: read, search, ask, post ... :) I feel ya, @soaren
Maddah Anass
@unlimiworks
Mar 07 2016 03:47
the assignment, in other words, is :
"assign the value of the lookup object's property that val holds to result "
Does it click ?
Richard Corbett
@reacorbett
Mar 07 2016 03:48
you should be getting 18 but you are getting 34?
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:49
17
yes
I have no idea why. isPrime code is right.
wiki Sum All Odd Fibonacci Numbers
CamperBot
@camperbot
Mar 07 2016 03:53

:point_right: algorithm sum all odd fibonacci numbers [wiki]

Explanation:

You will need to gather all the Fibonacci numbers and then check for the odd ones. Once you get the odd ones then you will add them all. The last number should be the number given as a parameter if it actually happens to be an off Fibonacci number.

:pencil: read more about algorithm sum all odd fibonacci numbers on the FCC Wiki

Maddah Anass
@unlimiworks
Mar 07 2016 03:53
@sidkrip What can we help with ?
bitgrower
@bitgrower
Mar 07 2016 03:53
@sidkrip -- your prime routine isn't doing anything when the the prime number you are checking for is 2 ...
Richard Corbett
@reacorbett
Mar 07 2016 03:55
@sidkrip no i dont think so. what bitgrower said.
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:56
@bitgrower but I cant initialize i with 2 or else the code will not work. But I know that 2 is the prime right so I included it.
Devlin S Healy
@soaren
Mar 07 2016 03:56

I'm going over all the lessons I couldn't get earlier, which is why I'm constantly moaning on here.

Anyways, this one asks:

"Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found"."

Example code:

var myObj = {
  top: "hat",
  bottom: "pants"
};
myObj.hasOwnProperty("top");    // true
myObj.hasOwnProperty("middle"); // false
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:56
@UnlimiWorks yes, please figure out why my code is not working? I tried.
Devlin S Healy
@soaren
Mar 07 2016 03:57
I could rig the system to work with if statements, but I don't think that's the right way to do it, so I'm trying to figure out what I am suppose to do
Maddah Anass
@unlimiworks
Mar 07 2016 03:57
@sidkrip Do you understand what is a prime number ?
bitgrower
@bitgrower
Mar 07 2016 03:57
okay ... the piece of code I saw didn't include it in the isPrime routine ...
Sidharth Kriplani
@sidkrip
Mar 07 2016 03:57
ofcourse I do.
Maddah Anass
@unlimiworks
Mar 07 2016 03:57
Alright then, quick glance at your code, give me a minute :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 03:58
Hi everybody
Maddah Anass
@unlimiworks
Mar 07 2016 03:58
you have a sum += num that shouldn't be there
Richard Corbett
@reacorbett
Mar 07 2016 03:58
your first if statement, look at it and think about what is is doing if it returns false. @sidkrip
bitgrower
@bitgrower
Mar 07 2016 03:59
@sidkrip -- I looked at your most recent code posted here ... where are you explicitly checking for 2 ?
Amir Eskandari
@AmirEskandari87
Mar 07 2016 03:59
I'm totally stumped on a lesson and I don't know what's wrong - should I just copy and paste my attempt here or is there a better method?
bitgrower
@bitgrower
Mar 07 2016 04:00
@AmirEskandari87 -- paste your code in here ... following these instructions: https://github.com/freecodecamp/freecodecamp/wiki/code-formatting -- please provide us with the name of the challenge while you're at it ... :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:00
OK - thank you.
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:02

@UnlimiWorks but we have to include the entered number as well in the sum to be returned.
@reacorbett oh yes! okay I will change the isPrime function to

function isPrime(number) {
  for(var i=2; i<number; i++) {
    return number%i===0;
  }
}

@bitgrower I am not checking for 2 because i already know it is prime. So I am including it by default

Maddah Anass
@unlimiworks
Mar 07 2016 04:03
@sidkrip you're also not treating the number '2' as stated above.
One way you could do that is by adding a separate condition check for 2
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:03
@reacorbett no even that one is wrong.
Okay folks, thanks, I will check it again.
CamperBot
@camperbot
Mar 07 2016 04:03
sidkrip sends brownie points to @reacorbett :sparkles: :thumbsup: :sparkles:
bitgrower
@bitgrower
Mar 07 2016 04:03
@sidkrip -- you are returning at the first test in your isPrime routine instead of iterating thru the loop, too ..
CamperBot
@camperbot
Mar 07 2016 04:03
:star: 288 | @reacorbett | http://www.freecodecamp.com/reacorbett
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:03
thanks @UnlimiWorks @bitgrower
I will get back to you with some modifications
CamperBot
@camperbot
Mar 07 2016 04:03
sidkrip sends brownie points to @unlimiworks and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 319 | @unlimiworks | http://www.freecodecamp.com/unlimiworks
:star: 763 | @bitgrower | http://www.freecodecamp.com/bitgrower
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:03
maybe try sieve of eratosthenes
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:03
```
Maddah Anass
@unlimiworks
Mar 07 2016 04:03
Supposedly, the number you're given for the function is 1. the sum will then return 2 which is false
Sorry. let me do the bonfire, i didn't do it yet
bitgrower
@bitgrower
Mar 07 2016 04:05
make a general purpose isPrime routine ... (including checking for input you don't expect, like 0,1 ... etc ... and handle them appropriately ... an isPrime routine is a handy routine to have around, you can use it in other places ... :)
@sidkrip -- the one number you might want to check especially with your current isPrime routine is the number 9 ... :)
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:07
thank you guys :) I have done the isPrime routine a million times before but I dunno why I cant remember it now
Richard Corbett
@reacorbett
Mar 07 2016 04:08
@sidkrip I havn't even got that far yet.
Sorry bud. I did the best i could.
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:09
thanks @reacorbett it was enough help to make me realize what I did wrong so it mattered :D
CamperBot
@camperbot
Mar 07 2016 04:09
:warning: sidkrip already gave reacorbett points
sidkrip sends brownie points to @reacorbett :sparkles: :thumbsup: :sparkles:
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:11
function lookUp(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++){
  if (contacts[i].firstName === firstName) {
    if (contacts[i][prop] !== undefined) {
      return contacts[i][prop];
    } else {
      return "No such property";
    }   
  } else {
    return "No such contact";
  }
}
Stumped on Profile Lookup
bitgrower
@bitgrower
Mar 07 2016 04:11
wtg @AmirEskandari87 !!!! getting the format down ...
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:11
I'm not sure what's wrong..
haha thanks.
Weird thing is when I remove the final else piece I hit 4/5 conditions, but bringing that in throws everything off.
bitgrower
@bitgrower
Mar 07 2016 04:12
So ... ... first ... take a look at the data structure and describe it to me ... is it an object? a number? an array ?
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:13
it looks like an array of objects
bitgrower
@bitgrower
Mar 07 2016 04:13
excellent !!!!
okay ... are you familiar with the hasOwnProperty() method ?
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:14
I'm not, let me google it..
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:14
@bitgrower
got the isPrime right
bitgrower
@bitgrower
Mar 07 2016 04:14
YAY!!!
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:14
unction isPrime(number) {
  for(var i=2; i<number; i++) {
    if(number%i===0) {
    return false;
    }
    else return true;
  }
  if(number===2) {
    return true;
  }
}
bitgrower
@bitgrower
Mar 07 2016 04:14
ummmmm ...
greg
@wearenotgroot
Mar 07 2016 04:15
@sidkrip do the if number === 2 on top
bitgrower
@bitgrower
Mar 07 2016 04:15
you're still returning after your first loop iteration ... seems to me ?
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:15
I commented out the above sumPrimes code. Will work on it now
greg
@wearenotgroot
Mar 07 2016 04:16

@sidkrip something like

if(number === 2) return true;
if(number === 3) return true;
...

if number is divisible by 2 or 3 return false

bitgrower
@bitgrower
Mar 07 2016 04:16
I just ran it with the number 9, and it says 9 is a prime number ...
you.are.not.listening ...
I'm talking about the first loop iteration in isPrime ...
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:17
umm I dont know why it is doing that
okay, yes, what about it?
bitgrower
@bitgrower
Mar 07 2016 04:18
because you have an if/else within your loop and each of them does a RETURN ... so no matter what happens, the first time you run thru the loop, it returns before it iterates over another number ...
go throw your code in pythontutor.com/javascript.html and watch it ...
just the isPrime code
Maddah Anass
@unlimiworks
Mar 07 2016 04:19
@sidkrip There is a much cleaner way though, your loop has a problem
Talking about the isPrime(num) function
bitgrower @bitgrower listens attentively to @UnlimiWorks
Maddah Anass
@unlimiworks
Mar 07 2016 04:20
THe way it's written, it will return something at the first iteration of the loop no matter what
bitgrower
@bitgrower
Mar 07 2016 04:20
3rd time the charm, @UnlimiWorks ?
Maddah Anass
@unlimiworks
Mar 07 2016 04:21
In other words, you're always checking against 2, then leaving the loop
@bitgrower Ain't it right :) I actually went and did the challenge XD
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:22
@UnlimiWorks I am checking against all the number in the loop right starting from one less than the number and upto 2.
Maddah Anass
@unlimiworks
Mar 07 2016 04:22
unction isPrime(number) {
  for(var i=2; i<number; i++) {
    if(number%i===0) {
    return false;
    }
    else return true;
  }
  if(number===2) {
    return true;
  }
}
Look closer at your else return true though
bitgrower @bitgrower knows there's a facepalm icon ... where's the "drop forehead to desktop" icon ...
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:24
now I feel dazed
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:24
haha
bitgrower
@bitgrower
Mar 07 2016 04:24
take your isPrime code and use pythontutor.com/javascript.html to step thru the code and see what it does ... use the number 9 as the value to pass
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:24
i know that feel :]
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:24
did that @bitgrower
bitgrower
@bitgrower
Mar 07 2016 04:24
...and ?
Maddah Anass
@unlimiworks
Mar 07 2016 04:24
Sorry, i'm trying not to spoon feed you :)
bitgrower
@bitgrower
Mar 07 2016 04:25
did you see how it says 9 is a prime ?
it's going to pass for all numbers 3-8 ... because all odd numbers are prime up until 9
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:26
I will recover from this dazed feeling soon enough and get back to this one afterwards I guess. But thanks guys, really. @UnlimiWorks that is how one should help and thanks a lot for not telling me anything which wouldnt force me to think
CamperBot
@camperbot
Mar 07 2016 04:26
sidkrip sends brownie points to @unlimiworks :sparkles: :thumbsup: :sparkles:
:warning: sidkrip already gave unlimiworks points
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:26
OK so the hasOwnProperty() method is the best way to check if an object has a specific property yeah? I'm going to change my code to use that.
Maddah Anass
@unlimiworks
Mar 07 2016 04:26
@sidkrip Good luck on the assignment ! You're not far from it, the general logic is there :)
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:27
wait a second @bitgrower
the visualization says that it is testing against 2, but I am incremeneting the loop right, then why is it happening?
@UnlimiWorks
bitgrower
@bitgrower
Mar 07 2016 04:29
@AmirEskandari87 -- yes ...
there are some really good reasons for doing so beyond this challenge, as well ...
function isPrime(number) {
  for(var i=2; i<number; i++) {
    if(number%i===0) {
    return false;
    }
    else return true;
  }
  if(number===2) {
    return true;
  }
}

isPrime(9);
@sidkrip -- run ^^^^^ this code in pythontutor
Maddah Anass
@unlimiworks
Mar 07 2016 04:30
@sidkrip You're getting closer. You are incrementing it right, but are you returning a value the right way ?
bitgrower
@bitgrower
Mar 07 2016 04:31
you aren't incrementing because your if/else returns before it gets a chance to go to the top of the loop again ...
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:31
so I have to reposition the return statement
bitgrower
@bitgrower
Mar 07 2016 04:32
yeah ... after the loop terminates ... :)
Maddah Anass
@unlimiworks
Mar 07 2016 04:32
Try to simulate the loop in your head, or in a paper
bitgrower
@bitgrower
Mar 07 2016 04:33
go thru the loop, check the numbers ... if you get thru the all the numbers and none of the preceding numbers divide evenly, then it's prime ...
you can return if a number DOES divide evenly, because you know it's not a prime number ... but to determine IF it IS a prime number, you have to check the rest of the numbers
(you actuallly don't have to check all of them .... only up to the sqrt(num) ...
Richard Corbett
@reacorbett
Mar 07 2016 04:35
@bitgrower If you dont mind me asking, how long have you been coding?
bitgrower
@bitgrower
Mar 07 2016 04:35
LOL .. .not quite sure how to answer it ... I wrote my first programs on punch cards ...
KaiserBakunawa
@KaiserBakunawa
Mar 07 2016 04:35
Roman Numeral Converter
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:36
@PhilipBalbas write wiki before the bonfire name to get help with it
Richard Corbett
@reacorbett
Mar 07 2016 04:36
oh wow. ok that sums it up.
bitgrower
@bitgrower
Mar 07 2016 04:36
or help, I think ...
KaiserBakunawa
@KaiserBakunawa
Mar 07 2016 04:36
wiki Roman Numeral Converter
CamperBot
@camperbot
Mar 07 2016 04:36

:point_right: algorithm roman numeral converter [wiki]

Problem Explanation:

  • You will create a program that converts an integer to a roman numeral.
:pencil: read more about algorithm roman numeral converter on the FCC Wiki
greg
@wearenotgroot
Mar 07 2016 04:36
@bitgrower since the beginning of the universe ? :smile:
bitgrower
@bitgrower
Mar 07 2016 04:37
@wearenotgroot -- well, I didn't help Grace Murray Hopper find the first bug ... if that's what you mean .... :)
KaiserBakunawa
@KaiserBakunawa
Mar 07 2016 04:37
I already figured out the solution for this function but I never got to use the suggested methods.
Here's my code:
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:38

@bitgrower

function isPrime(number) {
  var result;
  if(number===2) return true;
  for(var i=2; i<=Math.sqrt(number); i++) {
    if(number%i===0) {
    result=false;
    }
    return result;
  }
}

result is global but still nothing is being returned

greg
@wearenotgroot
Mar 07 2016 04:38
@PhilipBalbas suggestions are just suggestion :smile:
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:38
@PhilipBalbas its not necessary to use the provided suggestions
bitgrower
@bitgrower
Mar 07 2016 04:38
that's because you're not returning after the loop finishes ...
you should also initialize result if you're going to use it that way ...
KaiserBakunawa
@KaiserBakunawa
Mar 07 2016 04:39
I was just wondering what solutions other people are doing using the suggested functions
bitgrower
@bitgrower
Mar 07 2016 04:39
help rooms
CamperBot
@camperbot
Mar 07 2016 04:39
bitgrower
@bitgrower
Mar 07 2016 04:39
@PhilipBalbas -- there's a great room called CodeReview which you can use for that ... :)
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:39
@bitgrower thanks! i think it works now
CamperBot
@camperbot
Mar 07 2016 04:39
sidkrip sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: sidkrip already gave bitgrower points
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:39
oh damn camperbot, send the points again na
bitgrower
@bitgrower
Mar 07 2016 04:40
come back in a bit -- it only allows you to give points to a person once an hour ... thanks for the thought, though @sidkrip
CamperBot
@camperbot
Mar 07 2016 04:40
bitgrower sends brownie points to @sidkrip :sparkles: :thumbsup: :sparkles:
:star: 293 | @sidkrip | http://www.freecodecamp.com/sidkrip
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:40
and the challenge has been solved, though I still feel dazed
KaiserBakunawa
@KaiserBakunawa
Mar 07 2016 04:40
@bitgrower thanks for suggesting that
bitgrower
@bitgrower
Mar 07 2016 04:41
it happens ... @sidkrip -- but, a word about mind set ...
you were SO confident your isPrime worked, it blinded you to seeing how it didn't work ...
Maddah Anass
@unlimiworks
Mar 07 2016 04:41
@sidkrip Can i see your answer ?
Oh, i see that nvm :)
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:42
I guess there is something about returning from inside the loops that I dont understand yet.
@bitgrower
bitgrower
@bitgrower
Mar 07 2016 04:42
I like to say ... humility is a great trait for programmers ... :) and part of the reason it's actually more efficient ...
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:42

@UnlimiWorks

function isPrime(number) {
  var result=true;
  if(number===2) return true;
  for(var i=2; i<=Math.sqrt(number); i++) {
    if(number%i===0) {
    result=false;
    }
  }
      return result;

}

the isPrime() code

bitgrower
@bitgrower
Mar 07 2016 04:43
@sidkrip -- if you return from a loop -- just say to yourself (or ask yourself) ... I'm about to exit this function ... is that what I want to do ? Am I ready to exit the function ?
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:43
that would have worked for me
bitgrower
@bitgrower
Mar 07 2016 04:43
return is not continue, and it's not break....
awesome ... keep it in mind in the future :) just think ... return === exit function
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:44
sure I will from now on hehe :D
bitgrower
@bitgrower
Mar 07 2016 04:45
awesome ... have you done Profile Lookup yet ?
it's another challenge where folks famously return too early for part of the solution ...
Maddah Anass
@unlimiworks
Mar 07 2016 04:46
@sidkrip Btw, now that you've completed the challenge, don't you think the condition of number === 2 is being checked 2 times ? :)
bitgrower
@bitgrower
Mar 07 2016 04:46
good catch, @UnlimiWorks ...
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:46
@bitgrower I think I must have left it for later and then forgotten about it :|
bitgrower
@bitgrower
Mar 07 2016 04:47
no sweat ... but ... maybe, when you attack it ... you'll remember ... :) it's actually a bit less obvious where the early return happens, because there are places in the solution where you want to return within the loop ...
Maddah Anass
@unlimiworks
Mar 07 2016 04:48
@bitgrower Thanks, I'm blushing :blush:
CamperBot
@camperbot
Mar 07 2016 04:48
unlimiworks sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 764 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Mar 07 2016 04:49
and to everyone ... pythontutor.com/javascript.html is your friend ... it will help you from growing bald prematurely ....
Maddah Anass
@unlimiworks
Mar 07 2016 04:50
@bitgrower First time checking that out, seems interesting
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:50
yeah I bookmarked it already @bitgrower :)
bitgrower
@bitgrower
Mar 07 2016 04:50
I had someone come in one night and said pythontutor had an error ... I think it was on Seek and Destroy ... I'm going ... ahhhhhhh ....
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:51
@UnlimiWorks I will go through it again, just too dazed for now
but thanks for pointing that out
bitgrower
@bitgrower
Mar 07 2016 04:51
@sidkrip -- sounds like you've been at it too long ... time to take a break ... get some refreshment, exercise ... oxygenate the brain cells ... :)
Maddah Anass
@unlimiworks
Mar 07 2016 04:52
@sidkrip Alright then. Good job on that one
bitgrower
@bitgrower
Mar 07 2016 04:52
indeed ... congrats!!!
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:52
wouldnt have completed without your help @bitgrower @UnlimiWorks @reacorbett :)
bitgrower
@bitgrower
Mar 07 2016 04:52
how long HAVE you been at it today, @sidkrip ?
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:53
I guess just half an hour for this problem but then I was thinking about other ones before it as well
Richard Corbett
@reacorbett
Mar 07 2016 04:53
@bitgrower Not a bad idea at all. :smile: IDK if i was much help but thanks
CamperBot
@camperbot
Mar 07 2016 04:53
reacorbett sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 765 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Mar 07 2016 04:53
hey, thanks @reacorbett ... what's that for ?
CamperBot
@camperbot
Mar 07 2016 04:53
bitgrower sends brownie points to @reacorbett :sparkles: :thumbsup: :sparkles:
:star: 293 | @reacorbett | http://www.freecodecamp.com/reacorbett
Richard Corbett
@reacorbett
Mar 07 2016 04:53
@sidkrip the second part
bitgrower
@bitgrower
Mar 07 2016 04:54
awww ... well thank you ... :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:54
function lookUp(firstName, prop){
// Only change code below this line
var i = 0;
 while ( i < 4) {
 if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)){    
      return contacts[i][prop];
    } else if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop) === false) {
      return "No such property";
    } else if (contacts[i].firstName !== firstName && i == 3) {
      return "No such contact";
    }  
  i++;  
  }
// Only change code above this line
}
I got it
Thanks for the tip about hasOwnMethod() bud
Richard Corbett
@reacorbett
Mar 07 2016 04:54
@bitgrower lol I was reading and typing at the same time. I combined your nessage and @sidkrip message
bitgrower
@bitgrower
Mar 07 2016 04:54
hahahaha speaking of Profile Lookup ...
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:54
@bitgrower
Maddah Anass
@unlimiworks
Mar 07 2016 04:54
That makes me happy :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:54
much better than the way I was trying to do it before I knew about that..
bitgrower
@bitgrower
Mar 07 2016 04:55
@AmirEskandari87 -- try not to hardcode numbers into your programs ... you want to make them as general as possible ...
Sidharth Kriplani
@sidkrip
Mar 07 2016 04:55
@bitgrower another challenge now. Spinal Tap Case one this time. Dont know what to for one of the inputs
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:55
I thought that was weird
OK
bitgrower
@bitgrower
Mar 07 2016 04:56
and your i == 3 check is using too much knowledge of the data structure ...
but it's got the right spirit ... :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 04:57
I can't figure out where the "no such contact" return needs to go so I don't need that check
Richard Corbett
@reacorbett
Mar 07 2016 04:57
function rot13(str) { // LBH QVQ VG!
  var result  = str.split('').map(function (char) { // turns string into an array and iterates throught the array objects
    var convert = char.charCodeAt(0);

    if(convert >=78 && convert <= 90){              // converts half the alpha codes by subtracting 13 
      convert = convert - 13;
    }

    else if(convert > 64 && convert < 78){          // converts other half of alpha codes by adding 13
      convert = convert + 13;
    }

     return String.fromCharCode(convert);           
  });
return result.join(''); 
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Does that look a lot cleaner?
@bitgrower
bitgrower
@bitgrower
Mar 07 2016 04:57
if you use a for loop, @AmirEskandari87 -- you would return "no such contact" after you iterated thru all of the objects in the array -- because if you'd found one, you'd already have returned ...
@reacorbett -- MUCH !!!
nice ... one map function ... very cool ... :)
Richard Corbett
@reacorbett
Mar 07 2016 04:59
@bitgrower would a ternary operator work for my if/else statement?
bitgrower
@bitgrower
Mar 07 2016 04:59
your js code is starting to look like you've got real js skillz ... :)
@reacorbett -- a ternary operator is a substitute for if/else ... directly ...
Richard Corbett
@reacorbett
Mar 07 2016 04:59
lol. IDK about all that. I am still a wet fish out of water @bitgrower
so it wouldnt work with else if
bitgrower
@bitgrower
Mar 07 2016 05:00
(and your ternary code can get just as messy as a string of nested if/else)
Richard Corbett
@reacorbett
Mar 07 2016 05:00
good to know.
bitgrower
@bitgrower
Mar 07 2016 05:00
@reacorbett -- it would work ... as far as I know, anywhere you can use if/else, you can use a ternary ... it's just a more terse way of writing if/else
Sidharth Kriplani
@sidkrip
Mar 07 2016 05:01

@bitgrower

function spinalCase(str) {
   var newStr;
  newStr=str.replace(/\s/g, '-');
  //\s is used for spaces
  newStr=newStr.replace(/_/g, '-');
  newStr=newStr.toLowerCase();
  return newStr;
}

this is my code for the bonfire Spinal tap Case

bitgrower
@bitgrower
Mar 07 2016 05:01
I'm guessing it doesn't pass all of the test cases, @sidkrip ?
Sidharth Kriplani
@sidkrip
Mar 07 2016 05:02
no it doesnt
I dont know what to do for "thisIsSpinalTap"
bitgrower
@bitgrower
Mar 07 2016 05:02
I don't remember what I did either ... undoubtedly some kludge ...
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:03
function lookUp(firstName, prop){
// Only change code below this line
for (var i = 0; i < 4; i++) {
 if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)){    
      return contacts[i][prop];
    } else if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop) === false) {
      return "No such property";
    } else if (contacts[i].firstName !== firstName && i === contacts.length-1) {
      return "No such contact";
    }  
  }
// Only change code above this line
}
@bitgrower Is that what you mean?
Or this still too specific of a condition?
Richard Corbett
@reacorbett
Mar 07 2016 05:04
Turn it up to ELEVEN!!!
bitgrower
@bitgrower
Mar 07 2016 05:04
yes, still too specific ... for (var i = 0; i < contacts.length; i++) <-- use that
eh @reacorbett ?
Richard Corbett
@reacorbett
Mar 07 2016 05:05
it is a spinal tap reference. Spinal Tap is a movie.
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:05
oh whoops yes that was an oversight.. is the condition i === contacts.length-1 on the final else if ok though?
bitgrower
@bitgrower
Mar 07 2016 05:05
ahhh ... okay ... I know Spinal Tap is a movie ... just don't know any of the movie memes ... :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:05
Even though I passed the lesson I want to make sure I've done it the best way..
bitgrower
@bitgrower
Mar 07 2016 05:06
@AmirEskandari87 -- not really ....
well there's "best" -- I dunno if I'm giving you the "best" solution ... but I am giving you advice based on good programming practice ...
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:07
Is there a way that I can make it return something once it iterates through the entire loop and nothing else is returned?
Right
Much appreciated by the way..
bitgrower
@bitgrower
Mar 07 2016 05:07
sure ... return AFTER the loop terminates ... go scroll up and see @sidkrip's revised isPrime routine .. :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:08
OK will do!
bitgrower
@bitgrower
Mar 07 2016 05:08
return "no such contact" ...
not just return, return with something ... :)
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:09
hmmmm.. return with something? So this isn't quite what you meant then:
function lookUp(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
 if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)){    
      return contacts[i][prop];
    } else if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop) === false) {
      return "No such property";
    } 
  } return "No such contact";

// Only change code above this line
}
Sidharth Kriplani
@sidkrip
Mar 07 2016 05:11
@UnlimiWorks help me out with Spinal tap Case?
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:12
Oh I think I misunderstood, that's exactly what you meant!
This solution makes more sense to me..
If after going through the entire array and none of the elements fit the required return criteria, then return that there is no such contact.
Maddah Anass
@unlimiworks
Mar 07 2016 05:12
@sidkrip I didn't get to it yet, sorry ^^
Can't look at the code :) Would have done it if i had more time
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:13
If there's anything else I've missed here let me know, but this problem is a lot more clear to me than it was when I started.. a long time ago.. lol
Maddah Anass
@unlimiworks
Mar 07 2016 05:13
It's 5 AM. Time to call it a night
It has been a pleasure everybody
Sidharth Kriplani
@sidkrip
Mar 07 2016 05:13
I will get back to it later then @UnlimiWorks
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:13
Thanks for your help @UnlimiWorks
CamperBot
@camperbot
Mar 07 2016 05:13
amireskandari87 sends brownie points to @unlimiworks :sparkles: :thumbsup: :sparkles:
:star: 320 | @unlimiworks | http://www.freecodecamp.com/unlimiworks
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:14
Thanks for your help too @bitgrower - this was extremely helpful for me.
CamperBot
@camperbot
Mar 07 2016 05:14
amireskandari87 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 766 | @bitgrower | http://www.freecodecamp.com/bitgrower
Richard Corbett
@reacorbett
Mar 07 2016 05:14
good night @UnlimiWorks
Sidharth Kriplani
@sidkrip
Mar 07 2016 05:15
night @UnlimiWorks
greg
@wearenotgroot
Mar 07 2016 05:15
@sidkrip look at the examples specially with custom function on replace-------->https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
bitgrower
@bitgrower
Mar 07 2016 05:15
bingo @AmirEskandari87 ... you got it ...
David Jones
@Finesse-One
Mar 07 2016 05:16

I guess this must be one those brain teaser because every time I about to post my question for help the same problem seems to be everybody nemesis. Ahy how, I would like some help with same problems as well. I am not sure where in my logic statement where I am going wrong so if someone could please help me out I would appreciate it thanks. Here is link reference to challenge: http://tinyurl.com/prop-func

```

greg
@wearenotgroot
Mar 07 2016 05:17
@Finesse-One you have to test for the property
@Finesse-One use .hasOwnProperty method to check if a given property exist or not
Very helpful link.
David Jones
@Finesse-One
Mar 07 2016 05:18
where both if statements or just one @wearenotgroot
?
greg
@wearenotgroot
Mar 07 2016 05:19
@Finesse-One depends on your if structure
@Finesse-One you can either test for firstname first
@Finesse-One then nest an if statement to test for the property
@Finesse-One or you can use && to combine the test and so on
David Jones
@Finesse-One
Mar 07 2016 05:21
well I give it a try again.
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:22
@Finesse-One It took me a while too dude. You'll get it.
@Finesse-One It's a tough one.
greg
@wearenotgroot
Mar 07 2016 05:23
@Finesse-One btw you need to check if the property exist before returning the result of prop(collection[id][prop])
HaiderJaan
@HaiderJaan
Mar 07 2016 05:24

// 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"
};
var value = lookup;
var result = lookup[value];
// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("charlie");
<!--Guys whats the problem in my above code -->

Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:27
@HaiderJaan Is "value" set to what you intended?
bitgrower
@bitgrower
Mar 07 2016 05:27
please post your code with the formatting instructions found here: https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
HaiderJaan
@HaiderJaan
Mar 07 2016 05:27
@AmirEskandari87 for undefined
bitgrower
@bitgrower
Mar 07 2016 05:27
@HaiderJaan -- you don't seem to use the "val" parameter ?
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:28
@HaiderJaan what bitgrower said..
bitgrower
@bitgrower
Mar 07 2016 05:28
swap out val for value ... you might have better results ....
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:28
@HaiderJaan yep :)
HaiderJaan
@HaiderJaan
Mar 07 2016 05:29
@bitgrower nop
bitgrower
@bitgrower
Mar 07 2016 05:29
remove the var value = lookup; line
HaiderJaan
@HaiderJaan
Mar 07 2016 05:30
@bitgrower not yet
bitgrower
@bitgrower
Mar 07 2016 05:30
let's see what you have now ?
Amir Eskandari
@AmirEskandari87
Mar 07 2016 05:33
@HaiderJaan did it work..?
HaiderJaan
@HaiderJaan
Mar 07 2016 05:37
@AmirEskandari87 no
bitgrower
@bitgrower
Mar 07 2016 05:38
please post your revised code @HaiderJaan -- you are pretty close to a solution ...
David Jones
@Finesse-One
Mar 07 2016 05:42
hello @bitgrower , its me again. Here is what I came up with http://tinyurl.com/hmh452a, if there is a better solution then the one I have let me know also. Thanks
greg
@wearenotgroot
Mar 07 2016 05:44
@Finesse-One the else if condition is wrong
Richard Corbett
@reacorbett
Mar 07 2016 05:45
On to random quote machine
David Jones
@Finesse-One
Mar 07 2016 05:45
it passed for some funny reason.
greg
@wearenotgroot
Mar 07 2016 05:45
@Finesse-One should be if the prop doesnt exist then return no such property
Robert
@vLGrok
Mar 07 2016 05:47
hi, am I mistaken that palindrome("1 eye for of 1 eye.") should return true? looks like one to me.
greg
@wearenotgroot
Mar 07 2016 05:47
@Finesse-One you can use the if structure like this
for loop

     if firstName of contacts equals firstName

           if contacts at index ith has some given property (using  .hasOwnProperty(prop) to test)
                    return prop value(contacts[i][prop])
           else 
                     return "No such property";
end for loop

return "No such contact"
Robert
@vLGrok
Mar 07 2016 05:50
var isAlpha = function(c) { return /[a-z]/.test(c); };
var f = function(c) { return isAlpha(c); };

function palindrome(str) {
  var aa = str.toLowerCase().split("").filter(f);
  console.log(str.toLowerCase().split("").filter(f));
  for(var i=0; i<Math.floor((aa.length+1)/2); i++) {
    if(aa[i] !== aa[aa.length-(i+1)]) return false;
  }
  return true;
}
palindrome("1 eye for of 1 eye.");      // fcc test wants false, but returns true.
David Jones
@Finesse-One
Mar 07 2016 05:50
Are you saying that in this particular case that the if and if else statment woundn't be the proper approach or the nested if statement is the best solution.
greg
@wearenotgroot
Mar 07 2016 05:51
@Finesse-One well with your solution
@Finesse-One you just need to redo the else if statement
HaiderJaan
@HaiderJaan
Mar 07 2016 05:51

@bitgrower check this code // 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"
};

var result = lookup;
// Only change code above this line
return result;
}

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

Zach
@Moose1551
Mar 07 2016 05:51
Am I anywhere near being correct in the "Return Early Pattern for Functions" challenge in Basic JavaScript?
// Setup
function abTest(a, b) {
  // Only change code below this line
  console.log(a < 0);
  return undefined;
  console.log (b < 0);
  return undefined;


  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,2);
greg
@wearenotgroot
Mar 07 2016 05:51
@Finesse-One
else if(!contacts[i].hasOwnProperty(prop)) //<---------test if the property doesnt exist
@Moose1551 where is your if test?
Richard Corbett
@reacorbett
Mar 07 2016 05:54
@vLGrok if it was "1 eye for of eye 1" it would return true.
greg
@wearenotgroot
Mar 07 2016 05:54
@Moose1551 put what you wrote in the console log inside an if test
David Jones
@Finesse-One
Mar 07 2016 05:55
@wearenotgroot can you explain why the solution passed in the first place if it wasn't in right format in the first place. Thanks
CamperBot
@camperbot
Mar 07 2016 05:55
finesse-one sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 961 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
Richard Corbett
@reacorbett
Mar 07 2016 05:55
unless you are removing the numbers. in that case it should return true. @vLGrok
Robert
@vLGrok
Mar 07 2016 05:56
oh crud we're not supposed to remove numbers.
thanks @reacorbett
CamperBot
@camperbot
Mar 07 2016 05:56
vlgrok sends brownie points to @reacorbett :sparkles: :thumbsup: :sparkles:
:star: 297 | @reacorbett | http://www.freecodecamp.com/reacorbett
greg
@wearenotgroot
Mar 07 2016 05:56
@Finesse-One well the first if cover the situation where both the firstname and the property exist so it will give you the right result
Richard Corbett
@reacorbett
Mar 07 2016 05:56
oh i dont know. it has been a while since i have done that challeng @vLGrok
bitgrower
@bitgrower
Mar 07 2016 05:57
@HaiderJaan - think about the lookup data structure -- it's an object -- js objects consist of key:value pairs, ... index into the object with the key, and you get back the value ... so .. with that knowledge, how might you change your code ?
Zach
@Moose1551
Mar 07 2016 05:58
Beauty, @wearenotgroot . It worked. Why would free code camp even provide this as an example?
function myFun() {
  console.log("Hello");
  return "World";
  console.log("byebye")
}
myFun();
It doesn't look anything like an if test.
Richard Corbett
@reacorbett
Mar 07 2016 06:00
@vLGrok two things that might help you out are .replace() and regular expression flags.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
check out these two links for more info.
bitgrower
@bitgrower
Mar 07 2016 06:01
also
help regex
CamperBot
@camperbot
Mar 07 2016 06:01

:point_right: js regex resources [wiki]

Links to useful RegEx resources.

See also: :clipboard: Tutorials | :syringe: Testing | :soccer: Games | :newspaper: Blogs | :package: Software

:pencil: read more about js regex resources on the FCC Wiki

V Arun Kumar
@arunvkumr
Mar 07 2016 06:03
http://codepen.io/arunkumrv/pen/Vavaor
hey guys, i'm working on random quote machine. but i have a problem, in editor view i can see the quotes but not in full view or debug view. :/
why is this happening ?
Robert
@vLGrok
Mar 07 2016 06:04
@reacorbett I got it already. just hadn't noticed they wanted me to keep alphanumeric, and I had only kept alpha. after your tip, I updated the regex to
var isAlphaNumeric = function(c) { return /[a-z0-9]/.test(c); };
Richard Corbett
@reacorbett
Mar 07 2016 06:04
@vLGrok .reverse() was something that saved me a lot of time and headache.
Robert
@vLGrok
Mar 07 2016 06:04
and used .filter
Richard Corbett
@reacorbett
Mar 07 2016 06:04
oh cool. did you get it to work ? @vLGrok
Robert
@vLGrok
Mar 07 2016 06:05
yes
Nopply
@StandB
Mar 07 2016 06:05
I think u might need to import jquery in the html itself @arunkumrv not sure though.
bitgrower
@bitgrower
Mar 07 2016 06:06
@arunkumrv -- you might get more specific help for the front end projects in the front end room
help rooms
CamperBot
@camperbot
Mar 07 2016 06:07
bitgrower
@bitgrower
Mar 07 2016 06:07
@StandB -- if he set up his codepen.io correctly, he's already added it "behind the scenes" so to speak
Robert
@vLGrok
Mar 07 2016 06:08
@Moose1551 hope this helps ... without giving it away completely.
function abTest(a, b) {
  if (condition1 || condition2) return undefined;
Nopply
@StandB
Mar 07 2016 06:09
@bitgrower yeah true, but I still saw some people here having problems with it and they fixed it by adding it that way
Sidharth Kriplani
@sidkrip
Mar 07 2016 06:09
wiki Validate US Telephone Numbers
bitgrower
@bitgrower
Mar 07 2016 06:09
k
CamperBot
@camperbot
Mar 07 2016 06:09

:point_right: algorithm validate us telephone numbers [wiki]

Problem Explanation:

  • The task is not that hard to understand, implementing it is the hardest part. You have a to validate an US phone number. This means there is a certain amount of numbers required, while you don't need to put the country code, you will still need the area code and use one of the few formats allowed.
:pencil: read more about algorithm validate us telephone numbers on the FCC Wiki
Richard Corbett
@reacorbett
Mar 07 2016 06:11
@vLGrok did you get my PM?
Sidharth Kriplani
@sidkrip
Mar 07 2016 06:13
@bitgrower have you done this bonfire? ^
wiki Map The Debris
CamperBot
@camperbot
Mar 07 2016 06:16

:point_right: algorithm map the debris [wiki]

Problem Explanation:

The first thing to do is to get familiar with what the program is for, for this I would suggest you check the Wikipedia link as that is very important and from where you can also get the formula for the conversion. The hardest part are finding the formula, implementing it and for some modifying objects by the key. However, something that is not very clear is the fact that your program has to be able to check for any number of objects in the array which is what is tested on the second part.

:pencil: read more about algorithm map the debris on the FCC Wiki

Nick Robson
@nickrobson
Mar 07 2016 06:17
who was doing telephone numbers?
(and can I post my golfed solution?)
Sidharth Kriplani
@sidkrip
Mar 07 2016 06:17
@nickrobson I was trying the telephone numbers bonfire
wiki Make a Person
CamperBot
@camperbot
Mar 07 2016 06:18

:point_right: algorithm make a person [wiki]

Explanation:

When I started the program I figured I just had to create the six functions mentioned in the details. However, it was not that simple. Creating them as a function was not the right way, I had to create them in a different way to make them a key.

There is also a tricky part as you need six keys no more or less, so at first I had the variable that store the original name as a key too which was wrong.

As for the usage of array, that is optional, you could also create new variable to hold the separated string if you wish but an array is easier to deal with as strings are immutable.

Read the instructions carefully, it is always a good hint in itself to run the code and check what the test results were so you know what to expect but do not fixate yourself on that. Once you understand what you need to do, this problem is very easy and straightforward.

:pencil: read more about algorithm make a person on the FCC Wiki

Richard Corbett
@reacorbett
Mar 07 2016 06:18
@sidkrip was doing tele number
Sidharth Kriplani
@sidkrip
Mar 07 2016 06:18
@nickrobson have you done it?
Nick Robson
@nickrobson
Mar 07 2016 06:20
@sidkrip yeah.. have you finished it?
I don't wanna post code if you haven't.
monad-one
@monad-one
Mar 07 2016 06:21
function destroyer(arr) {
    arr.filter(function(val){
    for(var i=1;i<arguments.length;i++){
      if(val===arguments[i])
      return false;
    }
      return true;
  });
}

destroyer(["tree", "hamburger", 53], "tree", 53);
I need help on this one , it's output is showing blank
Richard Corbett
@reacorbett
Mar 07 2016 06:21
The Code Review room is great for posting completed challenges
@nickrobson
Nick Robson
@nickrobson
Mar 07 2016 06:22
ik. but this isn't for code review
a golfed solution will get a 0/10 for efficiency and looks lol
Nick Robson
@nickrobson
Mar 07 2016 06:30
Here it is anyway.
var telephoneCheck=s=>/^1? ?(\d{3}|\(\d{3}\))(-| )?\d{3}(-| )?\d{4}$/.test(s);
@rehlotus Remember, arr.filter will return a new array. It doesn't change the current one! You should use:
return arr.filter (etc..)
monad-one
@monad-one
Mar 07 2016 06:34
thanks @nickrobson
CamperBot
@camperbot
Mar 07 2016 06:34
rehlotus sends brownie points to @nickrobson :sparkles: :thumbsup: :sparkles:
:star: 420 | @nickrobson | http://www.freecodecamp.com/nickrobson
monad-one
@monad-one
Mar 07 2016 06:39
var temp=arguments;
    return arr.filter(function(val){
    for(var i=1;i<temp.length;i++){ ...
I changed starting lines to this , and now it works :)
Markus Kiili
@Masd925
Mar 07 2016 06:42
@rehlotus Yes, the filter callback function has its own arguments object.
Aleksander Gębicki
@Takumar
Mar 07 2016 06:42
@rehlotus that's because your anonymous function has another arguments :-)
1ety
@1ety
Mar 07 2016 06:42
Is someone can correct the following code?
Aleksander Gębicki
@Takumar
Mar 07 2016 06:43
Hi @Masd925 :-)
1ety
@1ety
Mar 07 2016 06:43
var Bike = function() {

  // Only change code below this line.
  var gear;
  this.getgear=function(){
    return gear;
  };
  this.setgear=function(gear){
    gear=gear;
  };    

};
Aleksander Gębicki
@Takumar
Mar 07 2016 06:43
@1ety getGear() and setGear() that's correct names for the methods
Markus Kiili
@Masd925
Mar 07 2016 06:43
@Takumar Hello.
Aleksander Gębicki
@Takumar
Mar 07 2016 06:44
@1ety also try to name parameter of setGear() method as newGear or something else, to set: gear = newGear; it is more clear I think.
1ety
@1ety
Mar 07 2016 06:44
However something doesn't work correctly
Aleksander Gębicki
@Takumar
Mar 07 2016 06:47
@1ety show your code. Have you changed name of the parameter?
1ety
@1ety
Mar 07 2016 06:49
I have tried, but it doesn't make a different. It is still doesn't do the work.
var Bike = function() {

  // Only change code below this line.
  var gear;
  this.getgear=function(){
    return gear;
  };
  this.setgear=function(newGear){
    gear=newGear;
  };    

};
@Takumar , do you know what is not correct with the following code?
This message was deleted
1ety
@1ety
Mar 07 2016 06:57
This message was deleted
Aleksander Gębicki
@Takumar
Mar 07 2016 06:57
@1ety I have told you to use big letters so: getGear() and setGear those are valid names for methods - use Camel Case Style for naming methods and variables
Gaurav Prabhu
@Gauravp15
Mar 07 2016 06:57
switch(val) {
case "bob":
answer = "Marley";
break;
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
answer = "Ate Nine";
break;
default:
return answer;
}
What is wrong with this code?
Aleksander Gębicki
@Takumar
Mar 07 2016 06:59
@Gauravp15 move return answer; outside your switch() {} statement!
Otherwise it will never run!
Travis LaDuke
@laduke
Mar 07 2016 06:59
is there some reason i couldn't return false but setting like returnVal = false; return returnVal worked?
1ety
@1ety
Mar 07 2016 07:01
Thank you @Takumar . After changing to Camel Case, it works.
CamperBot
@camperbot
Mar 07 2016 07:01
1ety sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2583 | @takumar | http://www.freecodecamp.com/takumar
Gaurav Prabhu
@Gauravp15
Mar 07 2016 07:01
Oh okay. Thanks @Takumar
CamperBot
@camperbot
Mar 07 2016 07:01
gauravp15 sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2584 | @takumar | http://www.freecodecamp.com/takumar
Gaurav Prabhu
@Gauravp15
Mar 07 2016 07:03
Is it fine if we dont write default?
Aleksander Gębicki
@Takumar
Mar 07 2016 07:06
@Gauravp15 you are welcome
1ety
@1ety
Mar 07 2016 07:06
Why the the following this.setGear=function(newGear){
gear=newGear; works
Aleksander Gębicki
@Takumar
Mar 07 2016 07:07
@Gauravp15 default is equivalent of else in if () else if() else() structure.
It catches rest of cases not checked with case 1: case 2: ... cases.
1ety
@1ety
Mar 07 2016 07:07
and this.setGear=function(gear){
gear=gear;
}; doesn't wrok?
Aleksander Gębicki
@Takumar
Mar 07 2016 07:08
@1ety I guess JS cannot work out which gear is name of parameter of your method, and which gear is name of property of your object.
Gaurav Prabhu
@Gauravp15
Mar 07 2016 07:08
Alright thanks a lot for the help sir @Takumar :+1:
CamperBot
@camperbot
Mar 07 2016 07:08
gauravp15 sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:warning: gauravp15 already gave takumar points