These are chat archives for FreeCodeCamp/HelpJavaScript

7th
Jun 2016
Marco Mazzeo
@Doko85
Jun 07 2016 00:00
try to move no such contact out of the for loop
Stephen James
@sjames1958gm
Jun 07 2016 00:00
@Cameron-Burkholder Reason about this if it were a stack of business cards you were looking for Bob's email address, when would you decide you don't have Bob's card, after the first firstname mismatch?
matthew3454
@matthew3454
Jun 07 2016 00:02
I can't seem to figure out what could be wrong with this Weather App Code Pen. I have corrected it several times and there is no errors, but only the h1 and h2 elements and some dots appear. Does it look like an easy fix and if so in what way? Thank you very much for your hypothetical assistance. Here is my code:https://codepen.io/codeabode20/pen/XKWqRp
Stephen James
@sjames1958gm
Jun 07 2016 00:02
@thisgirlcodes Manipulating the array that you on filtering on inside the filter function is not recommended. Also, return true/false from the filter fucntion if val should be kept or thrown away respectively
@matthew3454 Because of the asynchronous nature of getJSON, you should nest your second getJSON inside the first callback. When you call your second getJSON, the data from the first one has not returned.
Lauren Adam
@laurenamy
Jun 07 2016 00:05
hey everyone, stuck on "Iterate over Arrays with map". this is what I've got but it's not changing anything. totally unfamiliar with this concept

var oldArray = [1,2,3,4,5];

// Only change code below this line.

var plusThree = oldArray.map(function(val){
return (val + 3);
});

var newArray = oldArray;

Cameron Burkholder
@Cameron-Burkholder
Jun 07 2016 00:06
I don't think my code does that, does it ? @sjames1958gm
Stephen James
@sjames1958gm
Jun 07 2016 00:06
@matthew3454 Also, you are connecting to codepen over https:// and the trying to get to the other sites over http:// this is not allowed. connection to codepen over http://
these errors can be seen if you look at the devtools console (f12 on chrome)
@Cameron-Burkholder No, you close off your first getJson and then call the second - the reason no data shows up is the https:// vs. http:// issue
matthew3454
@matthew3454
Jun 07 2016 00:07
@sjames1958gm Thank you for your help. It helps
CamperBot
@camperbot
Jun 07 2016 00:07
matthew3454 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1467 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
matthew3454
@matthew3454
Jun 07 2016 00:07
@sjames1958gm thanks
CamperBot
@camperbot
Jun 07 2016 00:07
matthew3454 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: matthew3454 already gave sjames1958gm points
Stephen James
@sjames1958gm
Jun 07 2016 00:07
@laurenamy you want newArray to be the result of the call to oldArray.map
@matthew3454 :+1:
Nando Delgado
@nandod1707
Jun 07 2016 00:10
This message was deleted
Devin C
@Dev-C94
Jun 07 2016 00:14
can anybody help me understand why my enter button is not working?
Nando Delgado
@nandod1707
Jun 07 2016 00:14
hey everyone, im trying to find the longest word in a string, can anyone help with telling me why this isn't working?

function findLongestWord(str) {
  var arr = str.split(" ");
  var longestWord = arr.sort(function (a, b) { 
    return b.length - a.length; 
  });
  return longestWord.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Stephen James
@sjames1958gm
Jun 07 2016 00:15
@Dev-C94 Enter button? you mean pressing the enter key?
Cameron Burkholder
@Cameron-Burkholder
Jun 07 2016 00:15
@sjames1958gm I see what you are saying now, so I fixed that (I think), but the stuff inside the for loop still isn't doing what I think it's supposed to. function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if (contacts[i][firstName] !== undefined) {
if (contacts[i][prop] === undefined) {
return "No such property";
} else {
return contacts[i][prop];
}
}
}
return "No such contact";
// Only change code above this line
}
Devin C
@Dev-C94
Jun 07 2016 00:15
@sjames1958gm yes sorry for the lack of clarification
Diego Mayer
@Chrono79
Jun 07 2016 00:15
@nandod1707 try: return longestWord[0].length;
You were rearranging your words, and at the end returning the words count
Stephen James
@sjames1958gm
Jun 07 2016 00:16
@Cameron-Burkholder The instructions say nothing about comparing firstName to undefined. Reread that
Cameron Burkholder
@Cameron-Burkholder
Jun 07 2016 00:17
Got it. Thanks so much. @sjames1958gm
CamperBot
@camperbot
Jun 07 2016 00:17
cameron-burkholder sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1468 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jun 07 2016 00:17
@Cameron-Burkholder :+1:
@Dev-C94 Looks like for keypress event the key is in e.which
Nando Delgado
@nandod1707
Jun 07 2016 00:20
Thanks @Chrono79 ! I can't believe i didn't see that, that explains why i was getting a 9 when no words were that long hahah
CamperBot
@camperbot
Jun 07 2016 00:21
nandod1707 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1058 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jun 07 2016 00:24
no problem :+1:
Devin C
@Dev-C94
Jun 07 2016 00:24
@sjames1958gm that worked thank you!
CamperBot
@camperbot
Jun 07 2016 00:24
dev-c94 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1469 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
thisgirlcodes
@thisgirlcodes
Jun 07 2016 00:24
@sjames1958gm I guess this means I should do more reading on the filter function. Thanks!
CamperBot
@camperbot
Jun 07 2016 00:24
thisgirlcodes sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1470 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Emmanuel Obogbaimhe
@EmmanuelObo
Jun 07 2016 00:29
hey guys im trying to do the palindrome problem and im having a problem removing the chosen characters
function palindrome(str) {
var spaces = /\s+/g;
var checkPal = str.replace(spaces, "").replace(/[.,-_!?():]/g,"").replace(/\W+/g ,"");
checkPal = checkPal.toLowerCase();
var dup = checkPal.split("");
dup.reverse();
dup = dup.join("");
console.log(checkPal);
if(dup === checkPal)
return true;
return false;
}
It removes all the numbers for some reason
Stephen James
@sjames1958gm
Jun 07 2016 00:29
@thisgirlcodes Once you get filter, map and reduce, they will come in handy
Emmanuel Obogbaimhe
@EmmanuelObo
Jun 07 2016 00:30
and it removes the letter 'a' from one of the sentences
Stephen James
@sjames1958gm
Jun 07 2016 00:30
@MannyOh \W should remove almost all the characters from the previous two replaces.
Sage Searwar
@Acer12
Jun 07 2016 00:31
I finally figured out the code to use for the algorithm Check for Palindromes yaaaayyy(the trouble was really finding the right code and understanding it)!!!
Ian Arsenault
@ianarsenault
Jun 07 2016 00:33
Can anyone give me some pointers as to what I'm supposed to do for the "Stand in Line" problem? I'm completely lost
function nextInLine(arr, item) {
  // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Stephen James
@sjames1958gm
Jun 07 2016 00:33
@Acer12 :+1:
Brendan Kinahan
@BKinahan
Jun 07 2016 00:36
@GorgonsMaze are you familiar with the push() and shift() methods?
Ian Arsenault
@ianarsenault
Jun 07 2016 00:36
yeah
ok i see where this is going
Brendan Kinahan
@BKinahan
Jun 07 2016 00:36
@GorgonsMaze push item onto the end of arr, then remove the first element of arr and return it.
Rafael J. Rodriguez
@Rafase282
Jun 07 2016 00:44
Does anyone knows of a way to simplyfy this as in less line of code or/and more efficient?
function truncateString(str, num) {
  // Clear out that junk in your trunk
    if (str.length > num && num > 3) {
    return str.slice(0, (num - 3)) + '...';
  } else if (str.length > num && num <= 3) {
    return str.slice(0, num) + '...';
  } else {
    return str;
  }


}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
eeflores
@eeflores
Jun 07 2016 00:46
@Rafase282 want me to PM you my solution?
Rafael J. Rodriguez
@Rafase282
Jun 07 2016 00:46
well my solution wors, I just want to see how it can be improved
I was tryign to nexted ternary operators, and simply breaking down the chain if or using a switch is not pleasing to me
eeflores
@eeflores
Jun 07 2016 00:47
This message was deleted
n0ep14
@n0ep14
Jun 07 2016 00:48
How can I make this return a string?    function reverseString(str) {

return str;
}

var reverseString = ["hello"];

str = reverseString.join("").split("").reverse().join("");

Rafael J. Rodriguez
@Rafase282
Jun 07 2016 00:48
@eeflores no really.
n0ep14
@n0ep14
Jun 07 2016 00:48
wtf
eeflores
@eeflores
Jun 07 2016 00:49
I say go for readability
Rafael J. Rodriguez
@Rafase282
Jun 07 2016 00:49
@eeflores I think my current solution meets that end.
Diego Mayer
@Chrono79
Jun 07 2016 00:49
@n0ep14 delete the first .join
and you have to write your code inside your function
eeflores
@eeflores
Jun 07 2016 00:50
@Rafase282 I usually don't like repeating a condition over multiple ifs eg. if(str.length > num
it becomes a type of code duplication ... that I don't really like
can introduce errors if it becomes habit
Emmanuel Obogbaimhe
@EmmanuelObo
Jun 07 2016 00:53
@sjames1958gm yea I originally used \W but it is also removing numbers
Rafael J. Rodriguez
@Rafase282
Jun 07 2016 00:53
I see your point.
I just didn't bother with it as I'm looking for a better way altogether.
n0ep14
@n0ep14
Jun 07 2016 00:54
@Chrono79 now the console is blank
Moisés Man
@moigithub
Jun 07 2016 00:55
if str.len < num return str
if num>3 num-=3
return slice(0,num) +...
@Rafase282
i think
Diego Mayer
@Chrono79
Jun 07 2016 00:56
@n0ep14
function reverseString(str) {
  return str.split("").reverse().join("");
}
Rafael J. Rodriguez
@Rafase282
Jun 07 2016 00:56
@eeflores meanwhile I'll switch to this to avoid repeating.
function truncateString(str, num) {
  // Clear out that junk in your trunk

  if (str.length > num) {
    return num > 3 ? str.slice(0, (num - 3)) + '...' : str.slice(0, num) + '...';
  } else {
    return str;
  }


}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Emmanuel Obogbaimhe
@EmmanuelObo
Jun 07 2016 00:57
Actually check that it's removing everything except the underscore
eeflores
@eeflores
Jun 07 2016 00:57
@Rafase282 it is smaller ... fewer lines ...
Ian Arsenault
@ianarsenault
Jun 07 2016 00:58

@BKinahan


function nextInLine(arr, item) {
  // Your code here
arr.push(item);
arr.shift(item);

}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

returns to the console

Before: [1,2,3,4,5]

After: [2,3,4,5,1]
Moisés Man
@moigithub
Jun 07 2016 00:58
@Rafase282 u repeating the slice 2 times
Emmanuel Obogbaimhe
@EmmanuelObo
Jun 07 2016 00:58
Got it
eeflores
@eeflores
Jun 07 2016 00:58
nah it's in a ternary
Moisés Man
@moigithub
Jun 07 2016 00:58
u can apply that to num only...
since both slices doing the same
eeflores
@eeflores
Jun 07 2016 00:59
@moigithub it's ok it's in a ternary
Moisés Man
@moigithub
Jun 07 2016 00:59
less characters to type
Rafael J. Rodriguez
@Rafase282
Jun 07 2016 00:59
they are doing the same, jus tnot by the same amount.
Diego Mayer
@Chrono79
Jun 07 2016 00:59
return str.slice(0, num > 3 ? num - 3 : num) + '...'; like this @moigithub ?
eeflores
@eeflores
Jun 07 2016 01:00
heh
Moisés Man
@moigithub
Jun 07 2016 01:00
:+1:
also u could remove the else part.. inverting ur if condition and return sooner
Rafael J. Rodriguez
@Rafase282
Jun 07 2016 01:02
That works thanks @moigithub & @Chrono79
CamperBot
@camperbot
Jun 07 2016 01:02
rafase282 sends brownie points to @moigithub and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1059 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 1367 | @moigithub |http://www.freecodecamp.com/moigithub
Diego Mayer
@Chrono79
Jun 07 2016 01:03
:+1:
n0ep14
@n0ep14
Jun 07 2016 01:04
@Chrono79 Ty! that fixed :) now on to the next one :D
CamperBot
@camperbot
Jun 07 2016 01:04
n0ep14 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1060 | @chrono79 |http://www.freecodecamp.com/chrono79
Ian Arsenault
@ianarsenault
Jun 07 2016 01:06

can anyone explain the 'Stand in Line' and why I'm able to get 2 out of 4 task correct with this?


function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  arr.shift();
  return item;  // Change this line
}

// Test Setup
var testArr = [];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

what i'm missing is nextInLine([2], 1) should return 2 and

nextInLine([5,6,7,8,9], 1) should return 5

Coy Sanders
@coymeetsworld
Jun 07 2016 01:07
@GorgonsMaze you don't want to return item
you want to return the first item of the array that you removed with arr.shift();
bitgrower
@bitgrower
Jun 07 2016 01:08
item is pushed onto one end, the number you are to remove is that which is on the opposite end ... you also need to capture the number which is shifted out of arr ... using something like item = arr.shift();
Ian Arsenault
@ianarsenault
Jun 07 2016 01:08
ok i'll try that out
@bitgrower Thank you!
CamperBot
@camperbot
Jun 07 2016 01:10
gorgonsmaze sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1086 | @bitgrower |http://www.freecodecamp.com/bitgrower
Ken Haduch
@khaduch
Jun 07 2016 01:11
@GorgonsMaze - the reason why you got two of the cases to pass is that in one case you would end up returning 1, which is the value of "item", and in the other case they are reading from the array, which after you shift off the first element, you'd have the correct information in the array, even if you don't return the correct item.
Ian Arsenault
@ianarsenault
Jun 07 2016 01:14
@khaduch Alright, I see what you're saying. That definitely clears things up for me, as to why I got hung up on there.
@khaduch Thank you!
CamperBot
@camperbot
Jun 07 2016 01:14
gorgonsmaze sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1271 | @khaduch |http://www.freecodecamp.com/khaduch
Andrew
@AjSchaff
Jun 07 2016 01:15

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(product += product * arr[i][j]);
}
}
// Only change code above this line
return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

this works in codepen, but not in the challenge
Diego Mayer
@Chrono79
Jun 07 2016 01:16
@AjSchaff why this: product += ?
n0ep14
@n0ep14
Jun 07 2016 01:16
Am I supposed to use a for loop on Factorialize a Number?
bitgrower
@bitgrower
Jun 07 2016 01:17
@khaduch -- good point ... @GorgonsMaze it can be useful, once you have all test cases passing, to see if you can understand why some of them passed previously ... not necessary, of course ... but it's a useful exercise and will expand your knowledge ... :)
Andrew
@AjSchaff
Jun 07 2016 01:17
so as it iterates over the loop, it continues to multiply the next value in the multi-dimensional array
bitgrower
@bitgrower
Jun 07 2016 01:19
the line where you multiply the product looks a bit strange, you may want to look at it more closely and make sure it's doing what you want ... (and/or expect)
Andrew
@AjSchaff
Jun 07 2016 01:21
got it
ty @bitgrower
CamperBot
@camperbot
Jun 07 2016 01:21
ajschaff sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1087 | @bitgrower |http://www.freecodecamp.com/bitgrower
Diego Mayer
@Chrono79
Jun 07 2016 01:22
@n0ep14 you can use it, yes
Tyson G
@Thaisuhn
Jun 07 2016 01:27
Escape Sequences in Strings exercise I put on the correct input and I expected it to work, but now I am not sure what I did wrong. May you help me?
Alexander Køpke
@alexanderkopke
Jun 07 2016 01:29
@Thaisuhn can you share what you wrote?
Tyson G
@Thaisuhn
Jun 07 2016 01:30
var myStr= "\ \t \t \r \n"
bitgrower
@bitgrower
Jun 07 2016 01:31
@Thaisuhn --- so, a literal backslash is something you have to escape with another backslash to get it interpreted as an actual backslash instead of an "escape" as it is used with \t, \r, etc ...
Diego Mayer
@Chrono79
Jun 07 2016 01:31
use `to paste the code, the first \ is double?
Tyson G
@Thaisuhn
Jun 07 2016 01:32
Oh okay it seems to work now
bitgrower
@bitgrower
Jun 07 2016 01:33
coolness, @Thaisuhn
Tyson G
@Thaisuhn
Jun 07 2016 01:33
is React.js better than Jquery??
Amit Patel
@AmitP88
Jun 07 2016 01:35
hey everyone
I need a little help with a project- it's a neighborhood map project using google maps and foursquare api. I'm nearly done with it, but I'm having a lot of trouble trying to get the infowindows to display the location info from the Foursquare API
Angelo Ryndon
@AIRyndon
Jun 07 2016 01:36
Hello Guys! I'm at the Roman numeral conversion. The plan I have is multiple switch cases depending on the length of the array of numbers. I'm guessing it will look so bad and so long, how did you go about this Roman numeral challenge? Any insight is much appreciated :)
Seth
@xboudsady
Jun 07 2016 01:46
Hey guys, I'm having trouble trying to figure out what the instruction is asking in the "Local Scope and Functions" challenge.
Stephen
@stephepush
Jun 07 2016 01:46
anyone want to partner up? I'm working on the return largest number in arrays algo
Amit Patel
@AmitP88
Jun 07 2016 01:47
here's a link to my project: https://github.com/AmitP88/map-project
Seth
@xboudsady
Jun 07 2016 01:47

function myLocalScope() {
myVar = 'use strict';

console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope

// Now remove the console log line to pass the test

Amit Patel
@AmitP88
Jun 07 2016 01:48
I think i'm having some scoping issues, but I've inspected my code and for the life of me I can't see why my infowindows won't display the foursquare content
I feel like i'm pulling my hair out trying to figure this out =(
lorenalugo
@lorenalugo
Jun 07 2016 01:51
hi, I need some help, i'm making the mutation challenge. I'm checking if a string contains another substring, my code doesn't work.
function mutation(arr) {
var firstStr = arr[0].toLowerCase();
var secondStr = arr1.toLowerCase();
if (firstStr.indexOf(secondStr) !== -1) {
return true;
}
else {
return false;
}
}
mutation(["floor", "for"]);
bitgrower
@bitgrower
Jun 07 2016 01:53
@lorenalugo you need to iterate thru all the letters in the 2nd array member and see if they are found in the first array member ...
Diego Mayer
@Chrono79
Jun 07 2016 01:53
@lorenalugo you're searching for the literal "for" like that
ALMY91
@ALMY91
Jun 07 2016 01:54
can i have an argument for reverse() ?
bitgrower
@bitgrower
Jun 07 2016 01:54
yeah -- you're trying to use indexOf like substring()
ALMY91
@ALMY91
Jun 07 2016 01:55
are u reverting back to me? @bitgrower
bitgrower
@bitgrower
Jun 07 2016 01:55
eh @ALMY91 ?
lorenalugo
@lorenalugo
Jun 07 2016 01:56
@bitgrower i used indexOf but it doesn't work when i have random characters
bitgrower
@bitgrower
Jun 07 2016 01:57
yeah, I actually didn't use indexOf, I think I used substring ... it's been a while ... I'm gettin' rusty ...
lorenalugo
@lorenalugo
Jun 07 2016 01:59
@bitgrower i don't know, i read about indexOf, includes, search...
@bitgrower i'm going to read about substring
ALMY91
@ALMY91
Jun 07 2016 02:05
hello guys im not so sure about this
for example
var a = [33, 4, 1111, 222];
console.log(a.sort()); // Alphabetical order: 1111, 222, 33, 4
im not so sure how did this come about?
Ken Haduch
@khaduch
Jun 07 2016 02:09
@ALMY91 - alphabetical sort (the default) does not know the value of the numbers. It is sorting strictly based on the numeric code value of the numbers, so it would sort "a, b, c" alphabetically based on the character code of those letters, and "1, 2, 3" based on the character code of the letters, in the same way. So "1111" comes before "2", etc.
read about the sort function in MDN - they explain it all more clearly that I did, I'm sure.
ALMY91
@ALMY91
Jun 07 2016 02:11
@khaduch okay thanks!
CamperBot
@camperbot
Jun 07 2016 02:11
almy91 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1273 | @khaduch |http://www.freecodecamp.com/khaduch
Gaston Lenotre
@GLenotre
Jun 07 2016 02:12
// Only change code below this line
function updateRecords(id, prop, value) {

    if (collection.hasOwnProperty(id.tracks) === false){
        collection[id].tracks[value] = prop;
    }

      if (value !== "" && prop === "tracks") {
        collection[id][prop].push(value);
      }

      else if (value !== "" && prop !== "tracks") {
        collection[id][prop] = value;
      }

      else if (value === "") {
        delete collection[id][prop];
      }

    return collection;

  }
Record Collection ^
Advice?
It's a "TypeError: Cannot set a property 'ABBA' of undefined"
Kevin Holmes
@codersc
Jun 07 2016 02:16
var game = {

  count: 1,
  turn: 0,
  compSeq: [],
  userSeq: [],
  mode: 'normal',
  pads: ['1', '2', '3', '4'],
  sound1: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3'),
  sound2: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3'),
  sound3: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3'),
  sound4: new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3'),

  genCompSeq: function() {

    for (var i = 0; i < this.count; i++) {

      this.compSeq.push( this.pads[Math.floor(Math.random() * this.pads.length)] ); 
    }    

    this.compSeq.push('1');       // animate function does not seem to play first animation so that's why this line is here
  },

  playSound: function(i) {            

    var sound = this['sound' + i];    

    sound.currentTime=0;

    sound.play();
  },
my sound object plays a sound but the console displays "typeerror: sound is underfined." I've been stuck on this for like two days any help is appreciated.
help record collection
CamperBot
@camperbot
Jun 07 2016 02:17

:point_right: challenge record collection [wiki]

Challenge Record Collection

Instructions

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

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

For the given id in collection:

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

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

If value is blank, delete that prop.

Always return the entire collection object.

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

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

Kevin Holmes
@codersc
Jun 07 2016 02:21
@GLenotre have u got it yet. i'll take a look at my code if you havent so i can see where u may be wrong
yet?*
Sean DiSanti
@badc0ded
Jun 07 2016 02:23
one sec codersc, taking a look at something but i think i see your issue
just want to test before i speak up
Kevin Holmes
@codersc
Jun 07 2016 02:24
thanks so much @badc0ded i've been mesing with this bug forever it seems like
CamperBot
@camperbot
Jun 07 2016 02:24
codersc sends brownie points to @badc0ded :sparkles: :thumbsup: :sparkles:
:cookie: 374 | @badc0ded |http://www.freecodecamp.com/badc0ded
max77p
@max77p
Jun 07 2016 02:24
can someone help me figure out how to pass a success function from json to external function?
Sean DiSanti
@badc0ded
Jun 07 2016 02:24
do you have the full code up in a pen?
Sean DiSanti
@badc0ded
Jun 07 2016 02:25
no problem, i'm happy to help
max77p
@max77p
Jun 07 2016 02:25
soo something like this
success: function(data) { };
i need to pass data into an external function sitting outside the json call
Seth
@xboudsady
Jun 07 2016 02:25
need help with the "Stand in Line" mini challenge
Sean DiSanti
@badc0ded
Jun 07 2016 02:25
cool, one sec
Seth
@xboudsady
Jun 07 2016 02:25

function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift(item);

return item; // Change this line
}

Kevin Holmes
@codersc
Jun 07 2016 02:26
@max77p i think if you declare outside of the fnction then you will be able to use it outside of there
declare var data*
max77p
@max77p
Jun 07 2016 02:27
@codersc possbile to get a quick example?
Kevin Holmes
@codersc
Jun 07 2016 02:27
yeah one sec ill try @max77p
max77p
@max77p
Jun 07 2016 02:27
what i am trying to do is create a function outside the main json call and success
so that I can then do a for loop to cycle through the result
i want to keep it separate from the json call
Kevin Holmes
@codersc
Jun 07 2016 02:28
ok i will try not sure if i know but hold on a sec
max77p
@max77p
Jun 07 2016 02:29
@codersc ohhh i think i got it lolll
this works just to pull the "data" outside of the json function
Sean DiSanti
@badc0ded
Jun 07 2016 02:30
the first thing that jumps out at me @codersc is your iterator starts at 0 but you don't have a sound0
Kevin Holmes
@codersc
Jun 07 2016 02:30
ok cool @max77p
Sean DiSanti
@badc0ded
Jun 07 2016 02:30
that's not the only issue just the first thing
Kevin Holmes
@codersc
Jun 07 2016 02:31
cool not sure how i missed that but we all gotta start out somewhere lol @badc0ded
Sean DiSanti
@badc0ded
Jun 07 2016 02:31
you should also avoid declaring functions inside of a for loop
Kevin Holmes
@codersc
Jun 07 2016 02:31
anything else that jumps out at you at the moment?
Sean DiSanti
@badc0ded
Jun 07 2016 02:32
definitely not knocking your effort, just trying to help you track down the source of that bug
Kevin Holmes
@codersc
Jun 07 2016 02:32
believe me i appreciate your time a lot man. this thing has been giving me hell
Ken Haduch
@khaduch
Jun 07 2016 02:32
@GLenotre - your very first test for id.tracks is not correct. At that point, you don't know if the property is tracks, and I don't really know what collection.hasOwnProperty(id.tracks) would get you - probably some unpredictable result? So then whatever you are doing there is not correct after that, within that if block. The other tests look okay to me?
Sean DiSanti
@badc0ded
Jun 07 2016 02:32
no worries
disregard on the functions in loop
you're just using i as variable name in and outside of the loop
which invalidates the first comment too
about starting at 0
CamperBot
@camperbot
Jun 07 2016 02:35
you need to ask about @someone!
Sean DiSanti
@badc0ded
Jun 07 2016 02:35
oops
Gaston Lenotre
@GLenotre
Jun 07 2016 02:36
@codersc not yet
Kevin Holmes
@codersc
Jun 07 2016 02:37
yeah i was having some trouble using jquery so the way i'm targeting is prbly kinda hacky, and i've just been changing so many different things as i try to debug that i'm introducing new bugs from careless mistakes @badc0ded
Sean DiSanti
@badc0ded
Jun 07 2016 02:37
we have ALL been there, no worries
max77p
@max77p
Jun 07 2016 02:37
@codersc what are you working on?
Kevin Holmes
@codersc
Jun 07 2016 02:38
@max77p simon game
max77p
@max77p
Jun 07 2016 02:38
ahh damn you are way ahead of me lol, i need to stop slacking so much @codersc
Kevin Holmes
@codersc
Jun 07 2016 02:38
@badc0ded do u think the animations are not playing because of the error with the sound object?
max77p
@max77p
Jun 07 2016 02:39
are you doing any outside projects besides fcc? @codersc
Sean DiSanti
@badc0ded
Jun 07 2016 02:39
i'm seeing the computer animations
just not for when i click
Kevin Holmes
@codersc
Jun 07 2016 02:40
@badc0ded ok i get this weird bug where once the game has more than four steps the animations stop playing but the sound will play
@max77p i was trying to do this but the classes are not elf paced so i it was hard for me to follow their recommended pregrssion
Dolan
@dguh
Jun 07 2016 02:43
has anyone had trouble with caesars cipher, i am getting the right output but im not passing any of the tests
Kevin Holmes
@codersc
Jun 07 2016 02:45
@badc0ded yeah i was trying to just play the computer generated sequence to see if it would work so i could test it but the game seems to basically work up until there are more than steps to it
more than four*
Sean DiSanti
@badc0ded
Jun 07 2016 02:46
ok, it looks like you are defining a function inside of another
nevermind
blah, lol sorry
i've copied your code out to atom now and playing with the format and variable names etc for the sake of my tired eyes. it's been a very long day
Kevin Holmes
@codersc
Jun 07 2016 02:47
if your text is highlighted in red in the chat does that mean it wasn't sent?
Sean DiSanti
@badc0ded
Jun 07 2016 02:48
ah
i found issue
real one this time
lol
and why your animation is stopping
  displayCompSeq: function () {
    for (var i = 0; i < this.compSeq.length; i++) {
      doScaledTimeout(i);
    }

    function doScaledTimeout(i) {
      setTimeout(function () {
        game.playSound(i);
        game.flash(i);
      }, i * 1000);
    }
  },
when you've got a length greater than 4
you're calling playsound with a higher number than you have sounds for
because your sequence can have more than your sounds
even though you're iterating through sequence, you can't use index to play that sound
does that make sense?
5th element wouldn't be sound5
it would be compseq[i]
instead of i
that's why your sequence is always 1234 too
lorenalugo
@lorenalugo
Jun 07 2016 02:52
@bitgrower i did it!!!! i iterated the second string and used indexOf
Kevin Holmes
@codersc
Jun 07 2016 02:55
@badc0ded sorry my internet im reading over what you posted now thanks again
CamperBot
@camperbot
Jun 07 2016 02:55
codersc sends brownie points to @badc0ded :sparkles: :thumbsup: :sparkles:
:warning: codersc already gave badc0ded points
Kevin Holmes
@codersc
Jun 07 2016 02:55
interent went out*
Sean DiSanti
@badc0ded
Jun 07 2016 02:55
no problem
let me know if that doesn't make sense, as i said it's been a long day
Kevin Holmes
@codersc
Jun 07 2016 02:58
awesome i got you. loops always trip me up
Dolan
@dguh
Jun 07 2016 02:58
could someone help me with caesars cipher, i am getting the right output but its not passing any of the tests
Sean DiSanti
@badc0ded
Jun 07 2016 02:58
sure @dguh what have you got
Dolan
@dguh
Jun 07 2016 02:59

var code = [];
var codeThirteen = [];
var decode = "";
function rot13(str) { // LBH QVQ VG!
for (i = 0; i < str.length; i++){
code.push(str.charCodeAt(i));

}
for (j = 0; j < code.length; j++){
if (code[j]>=65&&code[j]<=77){
codeThirteen.push(code[j]+=13);}
else if (code[j]>=78 && code[j]<=92){
codeThirteen.push(code[j]-=13);}
else if (code[j]<65||code[j]>92){
codeThirteen.push(code[j]+=0);
}
decode = String.fromCharCode.apply(null,codeThirteen);
}
return decode;
}

// Change the inputs below to test
rot13("SERR CVMMN!");

Sean DiSanti
@badc0ded
Jun 07 2016 02:59
your loops look good, boundary wise, just may ahve to refactor your function a little bit
that was to @codersc
Kevin Holmes
@codersc
Jun 07 2016 02:59
help format
CamperBot
@camperbot
Jun 07 2016 02:59

: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 thecode`.

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

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

Sean DiSanti
@badc0ded
Jun 07 2016 03:00
yes, that helps a lot
formatting
Uliaaan
@uliaaan
Jun 07 2016 03:00
need js code "Record Collection", tnx
Dolan
@dguh
Jun 07 2016 03:00

'''js
var code = [];
var codeThirteen = [];
var decode = "";
function rot13(str) { // LBH QVQ VG!
for (i = 0; i < str.length; i++){
code.push(str.charCodeAt(i));

}
for (j = 0; j < code.length; j++){
if (code[j]>=65&&code[j]<=77){
codeThirteen.push(code[j]+=13);}
else if (code[j]>=78 && code[j]<=92){
codeThirteen.push(code[j]-=13);}
else if (code[j]<65||code[j]>92){
codeThirteen.push(code[j]+=0);
}
decode = String.fromCharCode.apply(null,codeThirteen);
}
return decode;
}

// Change the inputs below to test
rot13("SERR CVMMN!");'''

CamperBot
@camperbot
Jun 07 2016 03:00
:bulb: to format code use backticks! ``` more info
Dolan
@dguh
Jun 07 2016 03:01
sorry
Sean DiSanti
@badc0ded
Jun 07 2016 03:01
back ticks are the ones on the same key as tilde
Dolan
@dguh
Jun 07 2016 03:01
``` codeTest````
Sean DiSanti
@badc0ded
Jun 07 2016 03:01
don't apologize to the bot, it gives it a big head
Dolan
@dguh
Jun 07 2016 03:01
code
oka
okay got it
Uliaaan
@uliaaan
Jun 07 2016 03:02
need js code "Record Collection" lesson, guys, pls
Dolan
@dguh
Jun 07 2016 03:02
var code = [];
var codeThirteen = [];
var decode = "";
function rot13(str) { // LBH QVQ VG!
  for (i = 0; i < str.length; i++){
    code.push(str.charCodeAt(i));

  }
    for (j = 0; j < code.length; j++){
    if (code[j]>=65&&code[j]<=77){
      codeThirteen.push(code[j]+=13);}
      else if (code[j]>=78 && code[j]<=92){
        codeThirteen.push(code[j]-=13);}
      else if (code[j]<65||code[j]>92){
        codeThirteen.push(code[j]+=0);
      }
  decode = String.fromCharCode.apply(null,codeThirteen);
    }  
    return decode;
}

// Change the inputs below to test
rot13("SERR CVMMN!");
got it
this outputs js FREE PIZZA!
Uliaaan
@uliaaan
Jun 07 2016 03:04
need js code "Record Collection - https://www.freecodecamp.com/challenges/record-collection" lesson, guys, pls
Dolan
@dguh
Jun 07 2016 03:04
but it doesnt pass any of the tests
Sean DiSanti
@badc0ded
Jun 07 2016 03:05
one second @dguh i'm looking at your code in another window, just had to do some styling changes
you're pretty close
one sec just testing
none of the tests are passing?
Dolan
@dguh
Jun 07 2016 03:08
yeah
Sean DiSanti
@badc0ded
Jun 07 2016 03:08
try refreshing the page just for laughs
and then resubmit
Dolan
@dguh
Jun 07 2016 03:09
no luck
Sean DiSanti
@badc0ded
Jun 07 2016 03:09
ok, what are the tests on that one again
Dolan
@dguh
Jun 07 2016 03:10
rot13("SERR PBQR PNZC") should decode to "FREE CODE CAMP"
Uliaaan
@uliaaan
Jun 07 2016 03:10
need js code "Record Collection - https://www.freecodecamp.com/challenges/record-collection" lesson, guys, pls
Sean DiSanti
@badc0ded
Jun 07 2016 03:10
look what's happening
ALMY91
@ALMY91
Jun 07 2016 03:10
hello guys
Sean DiSanti
@badc0ded
Jun 07 2016 03:10
when you run it a second time it's appending the new values
ALMY91
@ALMY91
Jun 07 2016 03:10
i dont understand the rational behind this
console.log (a.sort(function(a,b) 
{return a-b})); // Numerical order: "4, 33, 1111, 222"
ALMY91
@ALMY91
Jun 07 2016 03:11
how did this came about?
Sean DiSanti
@badc0ded
Jun 07 2016 03:11
ah
you're declaring your variables outside of the function
should have noticed that one sooner, sorry
move your variables into your function and they'll be reinitialized on each call
ALMY91
@ALMY91
Jun 07 2016 03:12
hope that someone cld shed a light on this
Sean DiSanti
@badc0ded
Jun 07 2016 03:12
one second @ALMY91
Sudeep Narkar
@sudeepnarkar
Jun 07 2016 03:14
Hi guys
Can anyone review my Random Quote Machine?
Dolan
@dguh
Jun 07 2016 03:14
@badc0ded sweet ill remember this for next time
Sean DiSanti
@badc0ded
Jun 07 2016 03:14
no problem
Sudeep Narkar
@sudeepnarkar
Jun 07 2016 03:14
It is pretty basic right now.
Sean DiSanti
@badc0ded
Jun 07 2016 03:14
@ALMY91 http://puu.sh/pjApL/116fe5a91e.png from w3schools.com
basically it performs the compare function on each pair of values, and sorts them based on the result
a-b returns -60 as shown above, but if you do b-a, it goes the other way
does that help?
Greg Duncan
@GregatGit
Jun 07 2016 03:18
@sudeepnarkar Looks great!
ALMY91
@ALMY91
Jun 07 2016 03:19
nvm i found the answer
sampath-Mudhiraj
@sampath-Mudhiraj
Jun 07 2016 03:19
@sudeepnarkar, look
Sean DiSanti
@badc0ded
Jun 07 2016 03:19
good deal
http://www.w3schools.com/jsref/jsref_sort.asp has the explanation from above
Sudeep Narkar
@sudeepnarkar
Jun 07 2016 03:20
@GregatGit Thanks! I have decided to come back to it to add more functionality later.
CamperBot
@camperbot
Jun 07 2016 03:20
sudeepnarkar sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 567 | @gregatgit |http://www.freecodecamp.com/gregatgit
sampath-Mudhiraj
@sampath-Mudhiraj
Jun 07 2016 03:22
@sudeepnarkar looks good. But don't keep HTML elements inside an array.rather create an Json obj and use it.like {quote:'text',author :'text'} use in your app.
Sudeep Narkar
@sudeepnarkar
Jun 07 2016 03:26
@sampath-Mudhiraj Then how to randomly select them?
@sampath-Mudhiraj That was my first idea.
FM
@mafelix
Jun 07 2016 03:41
anyone here use rails?
I'm having problems building a shopping cart logic
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:45

Hello Everyone! regarding Roman Numeral converter..here is the code I wrote, it only fails on identical numbers..I'm guessing I have to use a generic for loop. Is there a better way to finish this problem? Code below
```
function convertToRoman(num) {

var numString = num.toString().split("");
var converted = [];
var temp;

numString.forEach(function(value){
switch(value){
case '0':
break;
case '1':
if (numString.length === 4){
temp = (numString.indexOf(value) === 0)? temp = "M"
:(numString.indexOf(value) === 1)?temp ="C"
:(numString.indexOf(value) === 2)?temp ="X": temp ="I";
converted.push(temp);
}
else if(numString.length === 3){
temp = (numString.indexOf(value) === 0)?temp ="C"
:(numString.indexOf(value) === 1)?temp ="X": temp ="I";
converted.push(temp);
}
else if(numString.length === 2){
temp = (numString.indexOf(value) === 0)?temp ="X": temp ="I";
converted.push(temp);
}
else{
temp = "I";
converted.push(temp);
}
break;
case '2':
if (numString.length === 4){
temp = (numString.indexOf(value) === 0)? temp = "MM"
:(numString.indexOf(value) === 1)?temp ="CC"
:(numString.indexOf(value) === 2)?temp ="XX": temp ="II";
converted.push(temp);
}
else if(numString.length === 3){
temp = (numString.indexOf(value) === 0)?temp ="CC"
:(numString.indexOf(value) === 1)?temp ="XX": temp ="II";
converted.push(temp);
}
else if(numString.length === 2){
temp = (numString.indexOf(value) === 0)?temp ="XX": temp ="II";
converted.push(temp);
}
else{
temp = "II";
converted.push(temp);
}
break;
case '3':
if (numString.length === 4){
temp = (numString.indexOf(value) === 0)? temp = "MMM"
:(numString.indexOf(value) === 1)?temp ="CCC"
:(numString.indexOf(value) === 2)?temp ="XXX": temp ="III";
converted.push(temp);
}
else if(numString.length === 3){
temp = (numString.indexOf(value) === 0)?temp ="CCC"
:(numString.indexOf(value) === 1)?temp ="XXX": temp ="III";
converted.push(temp);
}
else if(numString.length === 2){
temp = (numString.indexOf(value) === 0)?temp ="XXX": temp ="III";
converted.push(temp);
}
else{
temp = "III";
converted.push(temp);
}
break;
case '4':
if (numString.length === 4){
temp = (numString.indexOf(value) === 0)? temp = "MMMM"
:(numString.indexOf(value) === 1)?temp ="CD"
:(numString.indexOf(value) === 2)?temp ="XL": temp ="IV";
converted.push(temp);
}
else if(numString.length === 3){
temp = (numString.indexOf(value) === 0)?temp ="CD"
:(numString.indexOf(value) === 1)?temp ="XL": temp ="IV";
converted.push(temp);
}
else if(numString.length === 2){
temp = (numString.indexOf(value) === 0)?temp ="XL": temp ="IV";
converted.push(temp);
}
else{
temp = "IV";
converted.push(temp);
}
break;
case '5':
if (numString.length === 4){
temp = (numString.indexOf(value) === 0)? temp = "M bar at head"
:(numString.indexOf(value) === 1)?temp ="D"
:(numString.indexOf(value) === 2)?temp ="L": temp ="V";
converted.push(temp);
}
else if(numString.length === 3){
temp = (numString.indexOf(value) === 0)?temp ="D"
:(numString.indexOf(value) === 1)?temp ="L": temp ="V";
converted.push(temp);
}
else if(numString.length === 2){
temp = (numString.indexOf(value) === 0)?temp ="L": temp ="V";
converted.push(temp);
}
else{
temp = "V";
converted.push(temp);
}
break;

damn it ill put it in a pen hahah
Jerry Bendy
@jerrybendy
Jun 07 2016 03:46
long long code … without format .. .. .
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:46
@jerrybendy its the Roman Numeral Converter, it only fails on duplicate numbers..I kinda went brute force on it
@jerrybendy have you finished that one? I'll put the code in a pen
Jerry Bendy
@jerrybendy
Jun 07 2016 03:47
I need translate… hold on ..
can you put your link?
FM
@mafelix
Jun 07 2016 03:48
holy shit that's a lot of code
angelo can you explain really quickly the basic structure or concept you're using for your code?
Ramya
@ramyakatakam
Jun 07 2016 03:48
hello can anyone help me here in record collection

function updateRecords(id, prop, value) {
if(value !=="" && prop!=="tracks")
collection[id][prop]=value;
else if(value!=="" && prop==="tracks")
{

  collection[id][prop[prop.length]]=value;
}

return collection;
}

FM
@mafelix
Jun 07 2016 03:49
what are you trying to do
and what do you think your code is doing?
Ramya
@ramyakatakam
Jun 07 2016 03:50
// Only change code below this line
sry
FM
@mafelix
Jun 07 2016 03:50
your prop!=="tracks" has no space in it.
just for readability sake
Ramya
@ramyakatakam
Jun 07 2016 03:50
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"
}
};
Jerry Bendy
@jerrybendy
Jun 07 2016 03:51
I have done that
FM
@mafelix
Jun 07 2016 03:51
@ramya but explain in laymans terms what you're trying to do with your iteration
Ramya
@ramyakatakam
Jun 07 2016 03:51
in that json object when i run the above code i get undefined in place of tracks prop
Xander Apponi
@xapponi
Jun 07 2016 03:51
hello everyone, I am on the Factorialize a Number challenge. My code is passing for all exempt 0. But the freeCodeCamp side bar is not saying that I have accomplished anything but returning a number. Please help... and is this a bug. Also, I am getting an error message when passing 0, "TypeError: Reduce of array with no initial value". please help.
FM
@mafelix
Jun 07 2016 03:51
I know you're trying to sort something, but what?
Xander Apponi
@xapponi
Jun 07 2016 03:51
var array = [];
function factorialize(num) {

  for (i = num; i > 1; i--) {
    array.push(num);
    num--;
  }

  factorial = array.reduce(function(a,b){
    return(a*b);
  });
  return factorial;
}

factorialize(0);
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:52
@mafelix
Tones
@tonyszhang
Jun 07 2016 03:52
This message was deleted
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:52
Ramya
@ramyakatakam
Jun 07 2016 03:52
and value is setting as "undefined":"take a chance on Me"
Tones
@tonyszhang
Jun 07 2016 03:52
wow, I feel so stupid after having done the "validate US numbers" algorithm..... I did
function telephoneCheck(str) {
  // Good luck!

  var arr = str.split("");

  if(!arr.every(allowed)) {return false;}

  if(nDigits(arr)!=10 && nDigits(arr)!=11) {return false;}

  if(nDigits(arr)==11 && arr[0]!=1) {return false;}

  if(!bracketBalanced(arr)) {return false;}

  return true;
}


function allowed(char) {
// Can have: " ", "-", "(", ")", "number"; must be 7 or 8 numbers.
  if(/ /.test(char) || /-/.test(char) || /\(/.test(char) || /\)/.test(char) || /\d/.test(char)) {
    return true;   
  }
  else {return false;}  
}

function nDigits(arr) {
  var tot = 0;
  for(var i = 0; i < arr.length; i++){
    if(/\d/.test(arr[i])){
      tot++;
    }
  }
  return tot;
}

function bracketBalanced(arr) {
  iLeft = arr.findIndex(function(val){return /\(/.test(val);});
  iRight = arr.findIndex(function(val){return /\)/.test(val);});

  if(iLeft == -1 && iRight == -1) {return true;}
  else if(iLeft == -1 && iRight != -1) {return false;}
  else if(iLeft != -1 && iRight == -1) {return false;}
  else if(iRight - iLeft == 4) {return true;}
  else return false;
}

telephoneCheck("(6505552368)");
FM
@mafelix
Jun 07 2016 03:52
@ramya you're still not explaining in basic human understand words what you're trying to do
@ramya pseudocode it so you can know whats going on
Tones
@tonyszhang
Jun 07 2016 03:52

but the wiki answers after I looked it up used

function telephoneCheck(str) {

   var regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/;

   return regex.test(str);
}

both work, but i can't believe how elegant the "real" solution is....

Ramya
@ramyakatakam
Jun 07 2016 03:53
iam adding that prop and value to json object
Xander Apponi
@xapponi
Jun 07 2016 03:53
which prp
prop
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:53
@FM it converts the numbers to Roman Numerals...I check if the number is in the 1000 100 10 or 1
Jerry Bendy
@jerrybendy
Jun 07 2016 03:53
@AIRyndon May you can made you code clearly
FM
@mafelix
Jun 07 2016 03:53
ya I'm looking at your codepen right now
so you're using a switch statement
Ramya
@ramyakatakam
Jun 07 2016 03:54
updateRecords(5439, "tracks", "Take a Chance on Me");
FM
@mafelix
Jun 07 2016 03:54
and you're coming the number and the length to determine what roman numeral sign to use.
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:54
@mafelix it only fails on duplicate numbers...thing is there should be a better way to write that lol
FM
@mafelix
Jun 07 2016 03:54
comparing*
ya there should be
what do you mean by duplicate?
like 1111?
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:54
yes it will fail on 222, 111
Eldar Tinjić
@EldarT90
Jun 07 2016 03:54
I need help with d3 and svg
FM
@mafelix
Jun 07 2016 03:54
hmm
why don't you do something like this instead?
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:55
I think I should just use a generic loop, I have a feeling I can make it work with a generic loop but the brute force method is so bad lol
FM
@mafelix
Jun 07 2016 03:56
explain your generic loop
CamperBot
@camperbot
Jun 07 2016 03:56
no wiki entry for: your generic loop
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:56
@jerrybendy you mean put more spaces?
Jason Shoemaker
@kutsuya1
Jun 07 2016 03:56
@ramyakatakam I recall needing to push a track
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:56
@FM for loop
FM
@mafelix
Jun 07 2016 03:56
is there a constraint to the max number you're going to get?
or are you making this for every concievable rom num
Ramya
@ramyakatakam
Jun 07 2016 03:56
@kutsuya1 let me try a sec
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:57
nah its just for the challenge, when you go 4000 or above it roman numbers it gets iffy
Jerry Bendy
@jerrybendy
Jun 07 2016 03:57
@AIRyndon Roman Number is decimalism, too. You can try to depart numbers to decimalism
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:57
hahah
FM
@mafelix
Jun 07 2016 03:57
ok
Ramya
@ramyakatakam
Jun 07 2016 03:57
thank u
FM
@mafelix
Jun 07 2016 03:57
then it's easy
make two arrays
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:57
one has the roman numbers? one has the input?
FM
@mafelix
Jun 07 2016 03:57
['M', 'D', 'C', 'L', 'X', 'V', 'I'] && [1000,500,100,50,10,5,1]
Jerry Bendy
@jerrybendy
Jun 07 2016 03:57
@AIRyndon Handle the number with 1000/ 100/ 10 / 1
FM
@mafelix
Jun 07 2016 03:58
get where I'm going at?
Jerry Bendy
@jerrybendy
Jun 07 2016 03:58
@mafelix Maybe its a better way
FM
@mafelix
Jun 07 2016 03:58
divide your input
by numArr[0] take reminder
Angelo Ryndon
@AIRyndon
Jun 07 2016 03:58
use mod?
FM
@mafelix
Jun 07 2016 03:59
yes
no
you can do either way
but it's a little different
if you use divide you can multiple romArr[sameindex] * number of times in an answer string
but you still have to keep track of total_remainder
FM
@mafelix
Jun 07 2016 04:00
so if the number input is 3510
your answer string should be pushed with 3 MMM
'MMM'
Ramya
@ramyakatakam
Jun 07 2016 04:01
collection[id][prop[prop.length]]=[prop].push(value);
FM
@mafelix
Jun 07 2016 04:01
on your first iteration because 3510/1000 is 3
and you do that for every element in the numArr and push the corresponding index of the romArr to answer string
does that make sense?
Angelo Ryndon
@AIRyndon
Jun 07 2016 04:02
3000/1000 = 3 M 500/100 = D 10/10 = X
FM
@mafelix
Jun 07 2016 04:02
yea
Ramya
@ramyakatakam
Jun 07 2016 04:02
@kutsuya1 i tried collection[id][prop[prop.length]]=[prop].push(value) but it is showing "undefined" in prop name.
FM
@mafelix
Jun 07 2016 04:02
so you need a running total_left variable or something
to keep track of what is left from your original number input
Angelo Ryndon
@AIRyndon
Jun 07 2016 04:02
I think I can get the hang of that..I'll try it when I come home from work..thanks a lot :)
FM
@mafelix
Jun 07 2016 04:02
you divide then subtract from the total
npnpnp Lighthouse Labs Web Development Bootcamp Represent
Vancouver, BC. LOL
Eldar Tinjić
@EldarT90
Jun 07 2016 04:03
so, anyone here knows little bit about d3 and svgs ?
basicall i n eed to setup background of svg element, but trhoug d3 command
Lam Pham
@lampham3110
Jun 07 2016 04:08
Hey, could anyone have a look at my codes for Profile Lookup exercise? I've been stuck here for a while but I'm not sure where did i get wrong
FM
@mafelix
Jun 07 2016 04:08
sure....
Lam Pham
@lampham3110
Jun 07 2016 04:08

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

// Change these values to test your function
lookUpProfile("Kristian", "lastName");

FM
@mafelix
Jun 07 2016 04:08
I don't think I've done it yet. but I'll take a look at it to see if I can help
whats the error you're getting?
you're missing a bracket after your first for loop
{
for(var i = 0; i <= contacts.length; i++) {*
if(contacts[i].firstName === firstName || contacts[i]prop) <--- this does not make sense either
Xander Apponi
@xapponi
Jun 07 2016 04:10
You're going tr want to have two if statements
FM
@mafelix
Jun 07 2016 04:10
your or statement is flawed
Xander Apponi
@xapponi
Jun 07 2016 04:11
@lampham3110
Malcolm Walters
@MalWalters
Jun 07 2016 04:11
@ramyakatakam I'm at the same place with the same problem. I haven't got a solution as yet but I think the code is having trouble because there is not a "tracks" property there as yet. The code works for adding "Addicted to Love" but not "Take a Chance on Me". Can anyone confirm or am I heading down the wrong path?
FM
@mafelix
Jun 07 2016 04:11
you have to rewrite the conditional in your first || statement
@lampham3110 does this make sense?
Lam Pham
@lampham3110
Jun 07 2016 04:12
Yes, I'll have a look at it
FM
@mafelix
Jun 07 2016 04:12
@lampham3110 fix your missing bracket in your first for loop/ and the conditional || statement
Lam Pham
@lampham3110
Jun 07 2016 04:13
I just did
FM
@mafelix
Jun 07 2016 04:13
does it give you an output now at least?
Lam Pham
@lampham3110
Jun 07 2016 04:13
it does not give me anything
FM
@mafelix
Jun 07 2016 04:14
what does the output say?
repost your code
Xander Apponi
@xapponi
Jun 07 2016 04:14
Have two if statements nested inside eachother. The first one with check if contacts[i].firstName == firstName the next will check ifcontacts[i].hasOwnProperty(prop) is true. If both are true, return contacts[i][prop]. Close the second if statement, then return "No such property". Then outside the entire for loop, `return "no such contact";
Thomas Hodges
@thodges314
Jun 07 2016 04:14
Hey folks. Has anyone had issued with the <audio> tag while viewing their projects on a telephone?
Liu Dian
@hereitag
Jun 07 2016 04:14

// 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 updateRecords(id, prop, value) {
if(prop!=="tracks" && value!==""){
collection[id][prop]=value;
} else if (prop=="tracks" && value!==""){
collection[id][prop].push(value);
} else if (value===""){
delete collection[id][prop];
} else{
collection[id][prop]=value;
}

return collection;
}

// Alter values below to test your code
updateRecords(1245, "tracks", "ABBA");

i got stuck here. 5439 doesn't have tracks,and I can not use ".push".So what's the best solution?Anyone?

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

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

For the given id in collection:

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

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

If value is blank, delete that prop.

Always return the entire collection object.

Note
Don't forget to use bracket notation when accessing object properties with variables.

Jerry Bendy
@jerrybendy
Jun 07 2016 04:15
…….
Liu Dian
@hereitag
Jun 07 2016 04:16
I can pass if i add "tracks:[]"into 5439 obj,but not feel right
Xander Apponi
@xapponi
Jun 07 2016 04:16
@hereitag Try to identify some of the problems you are having and then ask how solve those. Use specificity. Right now, you are asking others to solve the entire problem for you, and you will lose the value of understanding what is going on.
FM
@mafelix
Jun 07 2016 04:17
this is true
you're trying to learn how to learn to code like code learning inception
write down what you think is happening
read your code outloud
think about it for 10 minutes and if you can't figure out ask for help
seriously you'll sound like a lunatic but reading ur code outloud will help you catch a lot of stupid syntax mistakes
Xander Apponi
@xapponi
Jun 07 2016 04:19
@lampham3110
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === firstName) {

      if (contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];     
      }       
      return "No such property";
    }

  }   
  return "No such contact";
}
FM
@mafelix
Jun 07 2016 04:19
and then the answer is just given.
Liu Dian
@hereitag
Jun 07 2016 04:19
OK,when an attribute(as an array)in an obj is not been defined, how to build one and use .push?
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:19
@hereitag you have to first define tracks property if it isn't there(you should check for that) and then push in it
afsantos3
@afsantos3
Jun 07 2016 04:19
okay so i am on the same problem as heritag i know what the issue is, can I just simply add the tracks to the collection if it's not there?
FM
@mafelix
Jun 07 2016 04:19
@liu dian
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:19
@afsantos3 yes you can define it as an array
FM
@mafelix
Jun 07 2016 04:20
objs in javascript you can add to
obj[prop] = "whatever you want"
afsantos3
@afsantos3
Jun 07 2016 04:20
okay thanks
so like i check if it's in there. if it's not then i add it
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:20
@hereitag also your last else seems useless
@afsantos3 yes
afsantos3
@afsantos3
Jun 07 2016 04:20
thank you guys
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:21
np
Ramya
@ramyakatakam
Jun 07 2016 04:21
@kutsuya1 i got it thanx :)
CamperBot
@camperbot
Jun 07 2016 04:21
ramyakatakam sends brownie points to @kutsuya1 :sparkles: :thumbsup: :sparkles:
:cookie: 379 | @kutsuya1 |http://www.freecodecamp.com/kutsuya1
Liu Dian
@hereitag
Jun 07 2016 04:21
collection[id][prop]=tracks.push(value); shows: collection[id][prop]=tracks.push(value);
FM
@mafelix
Jun 07 2016 04:21
this is a javascript object
object = { hello: "there",
disfunction: function(){
console.log("hello world!");},
momo: 12345;
}
you can put whatever you want in the 'value' of the property including functions
Ramya
@ramyakatakam
Jun 07 2016 04:22
@MalWalters just declare tracks array in the collection
Xander Apponi
@xapponi
Jun 07 2016 04:22
Hey, has anyone done the "factorialize a number challenge without using a recursive function. I passed it using a recursive, but freeCodeCamp hasn't taught recursives yet. What is an alternative way to write a function that factorializes a number. This is what I got
Liu Dian
@hereitag
Jun 07 2016 04:23
shows: tracks is not defined
Xander Apponi
@xapponi
Jun 07 2016 04:23
function factorialize(n) {
  if (n === 0) {
    return 1;
  }

  // This is it! Recursion!!
  return n * factorialize(n - 1);
}

factorialize(0);
FM
@mafelix
Jun 07 2016 04:23
@xapponi you're almost there
Jerry Bendy
@jerrybendy
Jun 07 2016 04:23
@hereitag so, Define it
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:23
@xapponi use loops
Xander Apponi
@xapponi
Jun 07 2016 04:23
This works though
it passes all the tests
but it uses recursion
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:24
@xapponi this will but if you want other methods then
Liu Dian
@hereitag
Jun 07 2016 04:24
i defined it using " var tracks=[]; " but it's not working
Lam Pham
@lampham3110
Jun 07 2016 04:24
@xapponi function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i =0; i <= contacts.length; i++){
if(contacts[i].firstName === firstName ){
if(contacts[i].hasOwnProperty(prop) === true){
return contacts[i].prop;
}
return "No such property";}
// Only change code above this line
return "No such contact";
}
}
I just tried what you said and it does not work with "Kristian", "Sherlock" and "Harry", but I got the last two
Jerry Bendy
@jerrybendy
Jun 07 2016 04:24
var tracks = [];
tracks.push(“xxx”)
Xander Apponi
@xapponi
Jun 07 2016 04:26
Check exactly where your curly brackets are. I just double checked my code and it seems to be working. @lampham3110
afsantos3
@afsantos3
Jun 07 2016 04:26
if(!collection[id].hasOwnProperty(prop)) collection[id] = prop;
collection[id][prop].push(value);
thats what i did for my check and it's still saying that tracks is undefined
Liu Dian
@hereitag
Jun 07 2016 04:26
value="",it's already have ""
afsantos3
@afsantos3
Jun 07 2016 04:26
did i do the if statement correct?
Ramya
@ramyakatakam
Jun 07 2016 04:26
@hereitag declare that property in collection object under that id
Jerry Bendy
@jerrybendy
Jun 07 2016 04:26
    if(contacts[i].firstName === firstName){
      return contacts[i][prop] || "No such property";
    }
Xander Apponi
@xapponi
Jun 07 2016 04:26
Can I see youre code @lampham3110
Jerry Bendy
@jerrybendy
Jun 07 2016 04:27
@hereitag What’s your question exactly?
Liu Dian
@hereitag
Jun 07 2016 04:28
  var tracks=[];
  collection[5439][tracks]=tracks.push("ABBA");   these are my codes
Xander Apponi
@xapponi
Jun 07 2016 04:29
I think @hereitag is having trouble adding the "tracks" property. The function works if the property allready exists to update. But if there is no property, it is not creating one .
Liu Dian
@hereitag
Jun 07 2016 04:29
the results are: "5439": {
"album": "ABBA Gold",
"ABBA": 1
}
I think I am getting there.just trying
Jerry Bendy
@jerrybendy
Jun 07 2016 04:29
collection[5439][tracks] = [“ABBA”];
To init an array with values, you can write it indirectly
Lam Pham
@lampham3110
Jun 07 2016 04:30
@xapponi Yea i got the problem solved, I set i <= contacts.length instead of < and misplaced some curly brackets. Thank you!
CamperBot
@camperbot
Jun 07 2016 04:30
lampham3110 sends brownie points to @xapponi :sparkles: :thumbsup: :sparkles:
:cookie: 243 | @xapponi |http://www.freecodecamp.com/xapponi
Liu Dian
@hereitag
Jun 07 2016 04:30
@jerrybendy only these codes will return tracks is not defined
Xander Apponi
@xapponi
Jun 07 2016 04:30
by the was @hereitag , I love your art on your website. You are very talented!
way*
Jerry Bendy
@jerrybendy
Jun 07 2016 04:31
@hereitag Can I see you full code?
Liu Dian
@hereitag
Jun 07 2016 04:31
@xapponi thank you very much~I appreciate it
CamperBot
@camperbot
Jun 07 2016 04:31
hereitag sends brownie points to @xapponi :sparkles: :thumbsup: :sparkles:
:cookie: 244 | @xapponi |http://www.freecodecamp.com/xapponi
Liu Dian
@hereitag
Jun 07 2016 04:32

@jerrybendy
// 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 updateRecords(id, prop, value) {
if(prop!=="tracks" && value!==""){
collection[id][prop]=value;
} else if (prop=="tracks" && value!==""){
var tracks=[];
collection[5439][tracks]=["ABBA"];
} else if (value===""){
delete collection[id][prop];
} else{
collection[id][prop]=value;
}

return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "ABBA");

UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:32
@xapponi other method using for if you want
function factorialize(n) {
  var fact=1;
for (var i=n;i>-1;i--){
   if(i==0) return fact;
    fact = fact*i;
}
}
factorialize(0);
Jerry Bendy
@jerrybendy
Jun 07 2016 04:33
Why not use Markdown 😥
Liu Dian
@hereitag
Jun 07 2016 04:34
Markdown ? I don't know about it ,i will try
Jerry Bendy
@jerrybendy
Jun 07 2016 04:34
else if (prop=="tracks" && value!==""){
    var tracks=[];
    collection[5439][tracks]=["ABBA"];
}
Jason Shoemaker
@kutsuya1
Jun 07 2016 04:34
@hereitag I recall needing to use .push
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:34
@hereitag you are just pushing "ABBA" for all cases
Liu Dian
@hereitag
Jun 07 2016 04:34
@kutsuya1 yes I think so
@UtkarshShukla7 I am testing
Jerry Bendy
@jerrybendy
Jun 07 2016 04:35
好吧,中文可否
Jason Shoemaker
@kutsuya1
Jun 07 2016 04:35
@hereitag I didn't see it. sorry
Max Cady
@vegemouse
Jun 07 2016 04:35
Hello all. I’m having issues with the Record Collection test. Can anyone help?
Liu Dian
@hereitag
Jun 07 2016 04:35
@UtkarshShukla7 my original solution is : collection[id][prop].push(value);
Max Cady
@vegemouse
Jun 07 2016 04:35
My code is
function updateRecords(id, prop, value) {
if (value !== "") {
if (prop === "tracks") {
collection[id][prop].push(value);
} else collection[id][prop] = value;
} else delete collection[id][prop];
return collection;
}
Jason Shoemaker
@kutsuya1
Jun 07 2016 04:36
What happenes if collection[id][prop] doesn't exist? can't push to it then
afsantos3
@afsantos3
Jun 07 2016 04:36
can anyone look at my code for the record collectio?n
Max Cady
@vegemouse
Jun 07 2016 04:36
How would you solve that?
@kutsuya1
FM
@mafelix
Jun 07 2016 04:37
@kutsuya1 then you make the prop?
Liu Dian
@hereitag
Jun 07 2016 04:37
@vegemouse
TypeError: Cannot read property 'push' of undefined
FM
@mafelix
Jun 07 2016 04:37
then push to the property u just made?
afsantos3
@afsantos3
Jun 07 2016 04:37
function updateRecords(id, prop, value) {
if(value !== "" && prop != "tracks") {
collection[id][prop] = value;
} else if (value !== "" && prop == "tracks") {
if(!(collection[id].hasOwnProperty(prop))) collection[id] = prop;
collection[id][prop].push(value);
} else {
delete collection[id][prop];
}
return collection;
}
UtkarshShukla7
@UtkarshShukla7
Jun 07 2016 04:37
@hereitag check prop using .hasOwnProperty() .If it is push else create it and then push @hereitag
FM
@mafelix
Jun 07 2016 04:37
hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
make the property if it's undefined
and push the value you want to that property
Jerry Bendy
@jerrybendy
Jun 07 2016 04:38
@hereitag If you want to know if tracks defined, you can use `if (xxxx.tracks && typeof xxxx.tracks == “number”)
Jason Shoemaker
@kutsuya1
Jun 07 2016 04:38
@vegemouse hasOwnProperty?
Jerry Bendy
@jerrybendy
Jun 07 2016 04:38
else if (prop=="tracks" && value!==""){
    var tracks=[];
    collection[5439][tracks]=["ABBA"];
}
Sorry
afsantos3
@afsantos3
Jun 07 2016 04:38
im not too sure where im going wrong. am i creating the property correctly?
Liu Dian
@hereitag
Jun 07 2016 04:38
@jerrybendy I know I can solve it this way,but I am looking for easier way
Jerry Bendy
@jerrybendy
Jun 07 2016 04:38
ok
collection[5439][tracks]
collection[5439][tracks] = collection[5439][tracks] ? [value] : collection[5439][tracks].push(value)
FM
@mafelix
Jun 07 2016 04:40
is that really easier?
or more confusing using a ternary
Jerry Bendy
@jerrybendy
Jun 07 2016 04:40
Can it work ? But not easier enough
Liu Dian
@hereitag
Jun 07 2016 04:41
test markdown
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    }}
maybe another "else if" is better
afsantos3
@afsantos3
Jun 07 2016 04:42
i found where i was going wrong on the record collection. if anyone needs any help let me know
n0ep14
@n0ep14
Jun 07 2016 04:43

function palindrome(str) {
// Good luck!

if (/str/gi) {

return true;

} else {

return false;

}

}

palindrome("eye");
am i on the right track. I'm on check Palindromes

afsantos3
@afsantos3
Jun 07 2016 04:43
I did not create the tracks as an empty array
FM
@mafelix
Jun 07 2016 04:43
what is that regex?
@n0ep14
tell me in human words what you're trying to do
and let's translate that into javascript code step by step
Jason Shoemaker
@kutsuya1
Jun 07 2016 04:44
The prop may equal 'tracks', and the album may exist...but it doesn't have a tracks property.
Xander Apponi
@xapponi
Jun 07 2016 04:45
I just got to that challenge @n0ep14
n0ep14
@n0ep14
Jun 07 2016 04:45
@mafelix Yeah. and i'm on check for Palindromes in the bon fire section.
afsantos3
@afsantos3
Jun 07 2016 04:45
make sure to check to see if tracks is a property in the collection id by using .hasOwnProperty
FM
@mafelix
Jun 07 2016 04:45
@n0ep14 so what are you trying to do?
@n0ep14 what is the problem and how are you going to solve it in human pseudo code
@n0ep14 how would you solve it with a piece of paper and pen? or no pen and paper at all?
Xander Apponi
@xapponi
Jun 07 2016 04:48
for this challenge, are we trying to convert to no spaces and all caps, or just check if it does or does not fit the criteria?
FM
@mafelix
Jun 07 2016 04:48
???????????
n0ep14
@n0ep14
Jun 07 2016 04:48
@mafelix Now i'm confused lol But I see your point. I haven't even figured out what it is i'm trying to per se. I was trying to make it return True if the string is exactly the same and False if it's not. But I only get the True and not the false because of the if else I assume
FM
@mafelix
Jun 07 2016 04:48
the string is exactly the same?
so you're comparing two strings?
and that's all?
Liu Dian
@hereitag
Jun 07 2016 04:48
    if(prop!=="tracks" && value!==""){
      collection[id][prop]=value;      
    } else if (prop=="tracks" && value!=="" && collection[id].tracks!==undefined){
      collection[id].tracks.push(value);
    }
      else if (prop=="tracks" && value!=="" && collection[id].tracks===undefined){
      collection[id].tracks=[value];
    } else if (value===""){
      delete collection[id][prop];
    } else{
      collection[id][prop]=value;
    }
FM
@mafelix
Jun 07 2016 04:49
alright
if I were to pseudo code this problem
Liu Dian
@hereitag
Jun 07 2016 04:49
finally I think another "else If" is better, thank you all
Xander Apponi
@xapponi
Jun 07 2016 04:49
nevermind
Liu Dian
@hereitag
Jun 07 2016 04:49
love you guys
FM
@mafelix
Jun 07 2016 04:49
what I am trying to do is check if a string/word is exactly the same if I reverse the string/word
correct?
does that make sense?
that's the definition of a palindrome?
n0ep14
@n0ep14
Jun 07 2016 04:50
Oh
FM
@mafelix
Jun 07 2016 04:50
do you agree with my pseudo code?
have anything to add? anything I missed out?
anything to improve on it?
now how to do I translate that into javascript pseudocode?
line by line
let me explain on the pseudo code
expand*
I'm not on the challenge yet
but I think I got the gist of it
I have a function palindrome that takes a string parameter
I need to somehow check if the string === string(reversed)
if string === string(reversed) {
return true
}else{
return false
}
so the main difficulty of this problem is how do we reverse a string?
in javascript
let's do it!
because everything else is pretty self explanatory right? the rest of the code you guys understand?
n0ep14
@n0ep14
Jun 07 2016 04:54
@mafelix Hmm. I'm seeing things in a different way now. More clarity. Thank you sir! I'm going to keep trying.
CamperBot
@camperbot
Jun 07 2016 04:54
n0ep14 sends brownie points to @mafelix :sparkles: :thumbsup: :sparkles:
:cookie: 185 | @mafelix |http://www.freecodecamp.com/mafelix
Ogundele Olumide
@Lumexralph
Jun 07 2016 04:54

`function lookUpProfile(firstName, prop){
// Only change code below this line
for(var j = 0; j < contacts.length; j++) { //iterate through the array
for(var i in contacts[j]) { //iterate through the object
if (i != prop)
return "yes";

}
}

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastNames");
`
Hello guys, I am working on lookup Profile but in the process of debugging something confusing happened, the code above returns true when both i and prop are string. please be kind to explain.

FM
@mafelix
Jun 07 2016 04:55
thank you. glad to have helped. someday you'll return the favor and I'll give you cookies
Max Cady
@vegemouse
Jun 07 2016 04:55
okay i’m still having issues. Here’s my code
function updateRecords(id, prop, value) {
if (value !== "") { //checks for value
if (prop === "tracks") { // checks if value is tracks
if (collection[id].hasOwnProperty("tracks") === true) { //if tracks exists as a var
collection[id][prop].push(value); //adds tracks to array
} else collection[id].tracks = value;
} else collection[id][prop] = value; // changes prop value
} else delete collection[id][prop]; // deletes if empty
return collection;
}
Coy Sanders
@coymeetsworld
Jun 07 2016 04:56
your else statements have some issues @vegemouse
n0ep14
@n0ep14
Jun 07 2016 04:56
yeah :D coding is really something new to me. I used to do a little c++ about 2 years ago but then I stopped to keep boxing.
Coy Sanders
@coymeetsworld
Jun 07 2016 04:56
you can only have one else statement for one
afsantos3
@afsantos3
Jun 07 2016 04:56
@vegemouse what is your error?
Coy Sanders
@coymeetsworld
Jun 07 2016 04:56
you can have multiple else if statements if you like, but you need to put brackets between them too
FM
@mafelix
Jun 07 2016 04:56
@n0ep14 that's cool. I'm more into the muay thai low kicks.
Laura Stephenson
@lauralstephenson
Jun 07 2016 04:56
I am on the same thing, Max Cady, and my code looks almost exactly like yours and it won't work.
Coy Sanders
@coymeetsworld
Jun 07 2016 04:57
if() {

}
else if () {

}
else if (){

}
else {

}
afsantos3
@afsantos3
Jun 07 2016 04:57
^^^^
FM
@mafelix
Jun 07 2016 04:57
@n0ep14 and c++ I hear is very very advanced. memory allocation and all that.
afsantos3
@afsantos3
Jun 07 2016 04:57
laura what error are you getting
Laura Stephenson
@lauralstephenson
Jun 07 2016 04:57
The error is cannot read property "push" of undefined.

My code: function updateRecords(id, prop, value) {
if (value !== ""){ //If the value is non-blank,

collection[id].prop = value; //then update or set a prop value.

} if(prop == "tracks" && value !== ""){ //If prop is tracks and is non-blank,

     collection[id].tracks.push(value); //push to the end of the tracks array.
}
  else if (value === ""){
     delete collection[id][prop];//If the prop is blank, delete it.
   } 

return collection;

n0ep14
@n0ep14
Jun 07 2016 04:58
@mafelix Yeah c++ plus was actually pretty cool. But the most I did was make a calculator. Pretty awesome still.
Max Cady
@vegemouse
Jun 07 2016 04:58
@afsantos3 Mine has no error, but the second criteria isn’t being met for some reason
afsantos3
@afsantos3
Jun 07 2016 04:58
Okay look at the id that is not working
What differences do you see between that id and the ones that worked @lauralstephenson
Laura Stephenson
@lauralstephenson
Jun 07 2016 04:59
I have also tried collection[id].props.push(value)
Max Cady
@vegemouse
Jun 07 2016 04:59
Stupid question how do you make the text you type in the chat look like code instead of normal text
Xander Apponi
@xapponi
Jun 07 2016 04:59
format help
Coy Sanders
@coymeetsworld
Jun 07 2016 05:00
you can't do .prop @lauralstephenson, props is a variable and you can only use dot notation if you know the property names ahead of time
Xander Apponi
@xapponi
Jun 07 2016 05:00
help format
CamperBot
@camperbot
Jun 07 2016 05:00

: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 thecode`.

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

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

Max Cady
@vegemouse
Jun 07 2016 05:00
@lauralstephenson you need to check to see if “tracks” is defined first
Xander Apponi
@xapponi
Jun 07 2016 05:01
when using String.replace() function, how do I call it with a variable. for example:
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:01

`function updateRecords(id, prop, value) {
if (value !== ""){ //If the value is non-blank,

collection[id].prop = value; //then update or set a prop value.

} if(prop == "tracks" && value !== ""){ //If prop is tracks and is non-blank,

     collection[id].props.push(value); //push to the end of the tracks array.
}
  else if (value === ""){
     delete collection[id][prop];//If the prop is blank, delete it.
   } 

return collection;
}

afsantos3
@afsantos3
Jun 07 2016 05:01
@lauralstephenson you cant use dot notation for props because it is a variable
Xander Apponi
@xapponi
Jun 07 2016 05:01
thanks @mafelix
CamperBot
@camperbot
Jun 07 2016 05:01
xapponi sends brownie points to @mafelix :sparkles: :thumbsup: :sparkles:
:cookie: 186 | @mafelix |http://www.freecodecamp.com/mafelix
Coy Sanders
@coymeetsworld
Jun 07 2016 05:02
collection[id].prop = value; //then update or set a prop value. this line needs to be fixed @lauralstephenson, for one
Max Cady
@vegemouse
Jun 07 2016 05:02
<function updateRecords(id, prop, value) {
  if (value !== "") { //checks for value
    if (prop === "tracks") { // checks if value is tracks
      if (collection[id].hasOwnProperty("tracks") === true) { //if tracks exists as a var
      collection[id][prop].push(value); //adds tracks to array
      } else collection[id].tracks = value;
    } else collection[id][prop] = value; // changes prop value 
  } else delete collection[id][prop]; // deletes if empty
  return collection;
}>
Coy Sanders
@coymeetsworld
Jun 07 2016 05:02
as @afsantos3 said you have to use bracket notation if the property you have is stored in a variable
Max Cady
@vegemouse
Jun 07 2016 05:03
for some reason I cant get the tracks value assigned
afsantos3
@afsantos3
Jun 07 2016 05:03
@vegemouse you must initialize your tracks value as an array
when you add it to the object
Coy Sanders
@coymeetsworld
Jun 07 2016 05:03
collection[id].album; //OK
collection[id]["album"]; //OK
collection[id].artist; //OK
collection[id]["artist"]; //OK
var prop = "album";
collection[id].prop; // Not OK
collection[id][prop]; //OK
Max Cady
@vegemouse
Jun 07 2016 05:04
@afsantos3 how do I do that?
afsantos3
@afsantos3
Jun 07 2016 05:04
if(!collection[id].hasOwnProperty(prop)) collection[id][prop] = [];
    collection[id][prop].push(value);
this is what i did for mine @vegemouse
Coy Sanders
@coymeetsworld
Jun 07 2016 05:05
don't think you need that @afsantos3
actually does that even work?
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:05
@vegemouse, I did exactly that code. It didn't work.
afsantos3
@afsantos3
Jun 07 2016 05:05
@coymeetsworld it works for me, what problem do you see in it?
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:06
Boinging head into wall now.
afsantos3
@afsantos3
Jun 07 2016 05:06
I apologize if I led anyone astray haha
Coy Sanders
@coymeetsworld
Jun 07 2016 05:06
the only thing you need to push would be tracks @afsantos3, right?
anything else is a straight replace
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:06
Yes, the tracks is supposed to push to the end.
Max Cady
@vegemouse
Jun 07 2016 05:06
So you assign the prop as []?
afsantos3
@afsantos3
Jun 07 2016 05:06
Well, I checked to see if tracks was in the property
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:06
I did.
afsantos3
@afsantos3
Jun 07 2016 05:07
let me paste my whole else if statement
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:07
`if(prop == "tracks" && value !== ""){ //If prop is tracks and is non-blank,
     collection[id][prop].push(value); //push to the end of the tracks array.
}
Coy Sanders
@coymeetsworld
Jun 07 2016 05:07
actually in that challenge you don't need to use hasOwnProperty
yeah that code should work @lauralstephenson
what else do you have?
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:07
It doesn't.
Coy Sanders
@coymeetsworld
Jun 07 2016 05:07
also for reference
Jason Shoemaker
@kutsuya1
Jun 07 2016 05:07
@vegemouse else collection[id].tracks = value; tracks needs to be an array
afsantos3
@afsantos3
Jun 07 2016 05:07
else if (value !== "" && prop == "tracks") {
    if(!collection[id].hasOwnProperty(prop)) collection[id][prop] = [];
    collection[id][prop].push(value);
  }
This is the easiest way that I found
Coy Sanders
@coymeetsworld
Jun 07 2016 05:07
put three at beginning of your code with nothing else, then at end with nothing else
that will format the code
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:08

``function updateRecords(id, prop, value) {
if (value !== ""){ //If the value is non-blank,

collection[id].prop = value; //then update or set a prop value.

} if(prop == "tracks" && value !== ""){ //If prop is tracks and is non-blank,

     collection[id][prop].push(value); //push to the end of the tracks array.

}
else if (value === ""){
delete collection[id][prop];//If the prop is blank, delete it.
}

return collection;

Coy Sanders
@coymeetsworld
Jun 07 2016 05:08
3 backticks on their own lines @lauralstephenson
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:08

```function updateRecords(id, prop, value) {
if (value !== ""){ //If the value is non-blank,

collection[id].prop = value; //then update or set a prop value.

} if(prop == "tracks" && value !== ""){ //If prop is tracks and is non-blank,

     collection[id][prop].push(value); //push to the end of the tracks array.

}
else if (value === ""){
delete collection[id][prop];//If the prop is blank, delete it.
}

return collection;

Coy Sanders
@coymeetsworld
Jun 07 2016 05:08
function updateRecords(id, prop, value) {
  if (value !== ""){ //If the value is non-blank, 

    collection[id].prop = value; //then update or set a prop value.

  } if(prop == "tracks" && value !== ""){ //If prop is tracks and is non-blank,

         collection[id][prop].push(value); //push to the end of the tracks array.
  }
      else if (value === ""){
         delete collection[id][prop];//If the prop is blank, delete it.
       } 

  return collection;
there
so collection[id].prop = value; //then update or set a prop value. this is still not right
Max Cady
@vegemouse
Jun 07 2016 05:09
beautiful finished it after about 2 hours lol thank you @coymeetsworld and @afsantos3
CamperBot
@camperbot
Jun 07 2016 05:09
vegemouse sends brownie points to @coymeetsworld and @afsantos3 :sparkles: :thumbsup: :sparkles:
:cookie: 240 | @afsantos3 |http://www.freecodecamp.com/afsantos3
:star2: 1075 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Jun 07 2016 05:09
can't use dot notation on a variable
afsantos3
@afsantos3
Jun 07 2016 05:09
@coymeetsworld I did that earlier and it gave me an undefined error
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:09

`function updateRecords(id, prop, value) {
if (value !== ""){ //If the value is non-blank,

collection[id].prop = value; //then update or set a prop value.

} if(prop == "tracks" && value !== ""){ //If prop is tracks and is non-blank,

     collection[id][prop].push(value); //push to the end of the tracks array.

}
else if (value === ""){
delete collection[id][prop];//If the prop is blank, delete it.
}

return collection;`

Coy Sanders
@coymeetsworld
Jun 07 2016 05:09
see what I posed above at 22:03?
what gave you an undefined error @afsantos3 ?
Jason Shoemaker
@kutsuya1
Jun 07 2016 05:10
@coymeetsworld If tracks doesn't exist, how will it be created as an array?
Max Cady
@vegemouse
Jun 07 2016 05:10
function updateRecords(id, prop, value) {
  if (value !== "") { //checks for value
    if (prop === "tracks") { // checks if value is tracks
      if (collection[id].hasOwnProperty("tracks") === true) { // checks if "tracks" exists as a var
      collection[id][prop].push(value); //adds tracks to array
      } else {
        collection[id][prop] = []; // creates array
        collection[id][prop].push(value); // pushes value to array
      }
    } else collection[id][prop] = value; // changes prop value 
  } else delete collection[id][prop]; // deletes if empty
  return collection;
}
this is the code i used fyi
afsantos3
@afsantos3
Jun 07 2016 05:10
push was undefined for me because tracks did not exist @coymeetsworld
therefore you must set tracks to be an empty array first
Coy Sanders
@coymeetsworld
Jun 07 2016 05:10
I don't believe thats one of the tests though @afsantos3
Jason Shoemaker
@kutsuya1
Jun 07 2016 05:10
@coymeetsworld it changed a few weeks back
@coymeetsworld maybe run the test again. :)
Coy Sanders
@coymeetsworld
Jun 07 2016 05:11
oh crap really? @kutsuya1 ?
lol
yeah I did this in January lol
well that was pointless to talk about haha thanks @kutsuya1
CamperBot
@camperbot
Jun 07 2016 05:11
coymeetsworld sends brownie points to @kutsuya1 :sparkles: :thumbsup: :sparkles:
:cookie: 380 | @kutsuya1 |http://www.freecodecamp.com/kutsuya1
Coy Sanders
@coymeetsworld
Jun 07 2016 05:11
now im going to go back and rewrite it i guess
Jason Shoemaker
@kutsuya1
Jun 07 2016 05:13
@coymeetsworld yep, I had to go back and fix it. :) Glad to help
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:13
brb guys...
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:19
Head still bouncing in to the wall. How to I set tracks to an empty array? Tracks = []?
afsantos3
@afsantos3
Jun 07 2016 05:19
collection[id][prop] = [];
if your prop is tracks
but do this only if tracks is undefined in your id
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:21
Here are the directions, because methinks the directions have changed:

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

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

For the given id in collection:

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

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

If value is blank, delete that prop.

Always return the entire collection object.

Note
Don't forget to use bracket notation when accessing object properties with variables.

Malcolm Walters
@MalWalters
Jun 07 2016 05:21
@vegemouse Thanks Max, creating that empty array was the sticking point. I was trying to create the array and then only have one line of collection[id][prop].push(value); but I was getting tangled up
CamperBot
@camperbot
Jun 07 2016 05:21
malwalters sends brownie points to @vegemouse :sparkles: :thumbsup: :sparkles:
:cookie: 230 | @vegemouse |http://www.freecodecamp.com/vegemouse
afsantos3
@afsantos3
Jun 07 2016 05:21
@lauralstephenson I did this challenge earlier today. Please send your code again
so I may look at it
Coy Sanders
@coymeetsworld
Jun 07 2016 05:22
fixed it @kutsuya1 :thumbsup:
kelyjames
@kelyjames
Jun 07 2016 05:24

Why doesn't this return a 5

function nextInLine(arr, item) {
 testArr.push(item); // Your code here

  return testArr.shift();  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
```js

nextInLine([5,6,7,8,9], 1) should return 5
```js

Laura Stephenson
@lauralstephenson
Jun 07 2016 05:26

`function updateRecords(id, prop, value) {

if (value !==""){
collection[id][prop] = value;//Checks on value
}
else if(prop == "tracks" && value !== ""){
collection[id][prop].push(value); //Pushest racks to last

} else if (value === ""){  //deletes empty one
     delete collection[id][prop];
   } 

}`

Coy Sanders
@coymeetsworld
Jun 07 2016 05:26
@kelyjames you want to use arr, not testArr in your function
kelyjames
@kelyjames
Jun 07 2016 05:26
thanks
afsantos3
@afsantos3
Jun 07 2016 05:27
@lauralstephenson check to see if tracks is in the collection id in your first else if statement
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:27
I'm screwing up my backticks, are they used for each line, or before and after the code?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:27
three backticks, on the first line, then your code, then 3 backticks on last line
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:27
OOO. Thanks.
Coy Sanders
@coymeetsworld
Jun 07 2016 05:27
help format
CamperBot
@camperbot
Jun 07 2016 05:27

: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 thecode`.

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

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

Coy Sanders
@coymeetsworld
Jun 07 2016 05:27
backticks should be on their own lines
afsantos3
@afsantos3
Jun 07 2016 05:27
@lauralstephenson if you are having trouble doing this let me know
Coy Sanders
@coymeetsworld
Jun 07 2016 05:28
also your logic inside the if value !== "" needs to be fixed a bit
if (value !==""){
collection[id][prop] = value;//Checks on value
}
else if(prop == "tracks" && value !== ""){
collection[id][prop].push(value); //Pushest racks to last
}
with this logic what happens if tracks is the prop and value is not an empty string? it won't get to that else-if statement
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:30
This change causes even more errors.
afsantos3
@afsantos3
Jun 07 2016 05:30
@lauralstephenson add an &&
to the first if statement
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:30
After updateRecords(5439, "artist", "ABBA"), artist should be "ABBA"--X
After updateRecords(5439, "tracks", "Take a Chance on Me"), tracks should have "Take a Chance on Me" as the last element.--X
After updateRecords(2548, "artist", ""), artist should not be set--/
After updateRecords(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element.--X
After updateRecords(2548, "tracks", ""), tracks should not be set--/
afsantos3
@afsantos3
Jun 07 2016 05:30
and then the other checks
Coy Sanders
@coymeetsworld
Jun 07 2016 05:31
another way is to nest if/else statement inside the first if statement
if the value is not empty, then check if the property is tracks. If so push the value. If it isn't tracks, replace it
afsantos3
@afsantos3
Jun 07 2016 05:32
@coymeetsworld this is off topic but are you able to return an array?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:32
Thats the way I did it, using && means you're asking if value is not empty twice. While that can work its a little redundant to ask for it twice
return an array from what?
afsantos3
@afsantos3
Jun 07 2016 05:33
well i am on the profile lookup and I can't seem to return the value of the property if it is an array
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:33
I am completely confused. I thought I did that ckeck in the else if, not the if.
 if (value !== ""){
collection[id][prop] = value;//Checks on value
}
else if(prop == "tracks" && value !== ""){
collection[id][prop].push(value); //Pushest racks to last

    } else if (value === ""){  //deletes empty one
         delete collection[id][prop];
       } 
}
afsantos3
@afsantos3
Jun 07 2016 05:35
@lauralstephenson for your first if statement you need to make sure that the prop does not equal tracks
as well as the value not being empty
Donovan
@dnvn999
Jun 07 2016 05:35
Hi all, I am stuck in challenge - Using Objects for Lookups. Here are my codes, can anyone help me? Thanks
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
   {
    "alpha": 
       result = "Adams",

     "bravo": 
      result = "Boston",

   "charlie": 
       result = "Chicago",

    "delta": 
       result = "Denver",

    "echo": 
      result = "Easy",

    "foxtrot":
      result ="Frank"
  };

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

// Change this value to test
phoneticLookup("charlie");
Coy Sanders
@coymeetsworld
Jun 07 2016 05:36
The problem @lauralstephenson is your order of things you're checking
if value happens to not be empty, but the property is tracks, what happens?
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:36
Okay, what do I switch, Coy?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:37
to keep it simple, i would move your else if statement as your if statement
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:37
So, #2 becomes #1.
Coy Sanders
@coymeetsworld
Jun 07 2016 05:37
and your if as the else if statement
yeah, although I don't think that's a particularly good way but that should fix some of the issues
Here's the psuedocode I used. I used a nested if statement instead if that makes more sense
function updateRecords(id, prop, value) {

  if the value is not empty {

    if the property is tracks {
        push the value onto tracks
    } else {
      replace the value of property with value
    }

  } else {
    delete the value of the property

  }

   return collection;
}
@afsantos3 on your issue how are you returning the property from your contact?
it should be the same regardless if its an array or not
afsantos3
@afsantos3
Jun 07 2016 05:39
@coymeetsworld nevermind I got it :)
Coy Sanders
@coymeetsworld
Jun 07 2016 05:39
ah ok
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:40
I switch them and I get "Cannot read property 'push' of undefined.
Donovan
@dnvn999
Jun 07 2016 05:40
Is there anyone helping me since coy is busy?
afsantos3
@afsantos3
Jun 07 2016 05:40
@lauralstephenson check to see if your tracks property exists in your id
Coy Sanders
@coymeetsworld
Jun 07 2016 05:40
@lauralstephenson you need to one more thing
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:40

```function updateRecords(id, prop, value) {

if(prop == "tracks" && value !== ""){
collection[id][prop].push(value); //Pushest racks to last
}

else if (value !== ""){
collection[id][prop] = value;//Checks on value
}
else if (value === ""){ //deletes empty one
delete collection[id][prop];
}
}```

Coy Sanders
@coymeetsworld
Jun 07 2016 05:40
yes what @afsantos3 did, didn't want to overcomplicate it by mentioning that too at same time :)
afsantos3
@afsantos3
Jun 07 2016 05:41
@dnvn999 Your issue lies in your table
Coy Sanders
@coymeetsworld
Jun 07 2016 05:41
@dnvn999 you're missing your break statements
afsantos3
@afsantos3
Jun 07 2016 05:41
you have it set correctly, but there is no variable attached to it
Coy Sanders
@coymeetsworld
Jun 07 2016 05:41
oh wait nvm
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:41
What am I missing?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:41
thats not a switch statement
afsantos3
@afsantos3
Jun 07 2016 05:41
you must set the table itself as a variable
Donovan
@dnvn999
Jun 07 2016 05:42
@afsantos3 I know, here is a new one but it cant work
js
Coy Sanders
@coymeetsworld
Jun 07 2016 05:42
@lauralstephenson
if(prop == "tracks" && value !== ""){
// need something else here
collection[id][prop].push(value); //Pushest racks to last
}
Donovan
@dnvn999
Jun 07 2016 05:42

  // Only change code below this line
   val = {
    "alpha":
       result = "Adams";
       break;

     "bravo": 
      result = "Boston",

   "charlie": 
       result = "Chicago",

    "delta": 
       result = "Denver",

    "echo": 
      result = "Easy",

    "foxtrot":
      result ="Frank",
  };

  // Only change code above this line
  return result;
}
Coy Sanders
@coymeetsworld
Jun 07 2016 05:42
once you determine value is not empty and the property is tracks, you need to see if that collection[id] has the property "tracks"
afsantos3
@afsantos3
Jun 07 2016 05:42
@dnvn999 you are checking the val, not setting it to something else
Coy Sanders
@coymeetsworld
Jun 07 2016 05:42
if it doesn't you need to create it
you can check to see if collection[id] has a property by using the hasOwnProperty method
afsantos3
@afsantos3
Jun 07 2016 05:43
in your current code you are setting your value to the table
Donovan
@dnvn999
Jun 07 2016 05:43
what is the code for checking again? @afsantos3
Zach
@Moose1551
Jun 07 2016 05:44
Is there a way to add to a unicode value ? For example. To turn 70 to 83, could you do something along the lines of:
fromCharCode(70 + 13);
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:44
This is wrong:else if (value !== "" && value = "tracks"){ collection[id][prop] = value;//Checks on value }
Coy Sanders
@coymeetsworld
Jun 07 2016 05:44
@lauralstephenson like what happens when you run updateRecords(5439, "tracks", "Take a chance on me");
afsantos3
@afsantos3
Jun 07 2016 05:44
@dnvn999 check the example you see the var alpha?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:44
this is the object that's given to you:
5439: {
      album: "ABBA Gold"
    }
as you can see there's no tracks property
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:45
Yes, @coymeetsworld . It has no tracks.
Coy Sanders
@coymeetsworld
Jun 07 2016 05:45
collection[id][prop].push(value); //Pushest racks to last so this won't work (i.e. collection[5439]["tracks"].push(value))
afsantos3
@afsantos3
Jun 07 2016 05:45
your table should resemble var alpha. think of your table as an object
Norberto
@nortocode
Jun 07 2016 05:45
@dnvn999 val = { 'a':'b', 'c':'d.... }
Coy Sanders
@coymeetsworld
Jun 07 2016 05:46
right so you need to create that property and initialize it as an empty array (i.e. []);
then you can push value into it afterwards
Jonathan Mitchell
@Vanhealen
Jun 07 2016 05:46
how do i follow someone on codewars?
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:47
This is still wrong: else if (value !== "" && value = []){
Coy Sanders
@coymeetsworld
Jun 07 2016 05:47
well there you're setting value equal to []
which you don't want to do, you're not modifying value
your else if statement was fine
like i said above:
if(prop == "tracks" && value !== ""){
// need something else here
collection[id][prop].push(value); //Pushest racks to last
}
that need something else is you need to check if collection[id] has the property tracks, it won't always
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:48
I am just getting increasingly frustrated.
Coy Sanders
@coymeetsworld
Jun 07 2016 05:48
as you can see from the ABBA example:
5439: {
      album: "ABBA Gold"
    }
Donovan
@dnvn999
Jun 07 2016 05:49
@afsantos3 @nortocode should it be `"alpha" : "Adams"' or 'alpha: "Adams"'?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:49
its ok you just need to do one more thing and you should be ok
afsantos3
@afsantos3
Jun 07 2016 05:49
"alpha": "Adams" is fine
but do not forget the comma
Coy Sanders
@coymeetsworld
Jun 07 2016 05:49
but you see what happens when collection[5439]["tracks"].push(value) is called
since that object does not have a property named tracks, this won't work. Only property it has is album
so you need to check if tracks exists (using the hasOwnProperty() method)
if it doesn't, you need to create it
Malcolm Walters
@MalWalters
Jun 07 2016 05:50
@dnvn999 Hi Donovan, you don't need the result = in lookups.
Donovan
@dnvn999
Jun 07 2016 05:51
this is my codes now but it still doesnt work
// Only change code below this line
   val = {
    "alpha":"Adams",

     "bravo":"Boston",

   "charlie":"Chicago",

    "delta": "Denver",

    "echo": "Easy",

    "foxtrot":"Frank",
  };

  // Only change code above this line
  return result;
}
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:52
Coy, you're going to have to spell it out. I don't know what to attach hasownproperty to.
Divya Pinto
@divpinto18
Jun 07 2016 05:52

Hey guys i am having trouble with the pigLatin algorithm.... i wanted to try switch/case to see if it works... but i keep getting stuck....

var fir;

function translatePigLatin(str) {
str = str.split("");
fir = str[0];
str = str.join("");

switch (fir) {
  case /[bcdfghjklmnpqrstvwxyz]/.test(fir):
    var ind = str.substr(1);
    str = str.split("");
    str = ind + str[0] + "ay";

    break;


}

return str;
}

translatePigLatin("pig");

Laura Stephenson
@lauralstephenson
Jun 07 2016 05:53
hasOwnProperty.
afsantos3
@afsantos3
Jun 07 2016 05:53
@dnvn999 try var lookup = {
Coy Sanders
@coymeetsworld
Jun 07 2016 05:53
sure
Divya Pinto
@divpinto18
Jun 07 2016 05:53

var fir;

function translatePigLatin(str) {
str = str.split("");
fir = str[0];
str = str.join("");

switch (fir) {
  case /[bcdfghjklmnpqrstvwxyz]/.test(fir):
    var ind = str.substr(1);
    str = str.split("");
    str = ind + str[0] + "ay";

    break;


}

return str;
}

translatePigLatin("pig");

var fir;

function translatePigLatin(str) {
str = str.split("");
fir = str[0];
str = str.join("");

switch (fir) {
  case /[bcdfghjklmnpqrstvwxyz]/.test(fir):
    var ind = str.substr(1);
    str = str.split("");
    str = ind + str[0] + "ay";

    break;


}

return str;
}

translatePigLatin("pig");

afsantos3
@afsantos3
Jun 07 2016 05:53
@dnvn999 you are still changing the val if you have val =, you must check what val is
Coy Sanders
@coymeetsworld
Jun 07 2016 05:53
collection[id].hasOwnProperty("tracks") would return true if collection[id] has the tracks property
false if no
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:54
so this is an else if statement?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:54
no its just an if statement you can nest
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:54
where do I nest it? on the second else if?
sorry, the first else if
Coy Sanders
@coymeetsworld
Jun 07 2016 05:54
if(prop == "tracks" && value !== ""){
  if (collection[id].hasOwnProperty("tracks")) {
     // add tracks property here
  }
  collection[id][prop].push(value); //Pushest racks to last
}
afsantos3
@afsantos3
Jun 07 2016 05:55
@dnvn999 also makesure to return your val inside your lookup object
return lookup[val];
ABHIII
@aviralsharma1997
Jun 07 2016 05:55
@lauralstephenson @coymeetsworld push is not working there I completed the challenge yesterday
Coy Sanders
@coymeetsworld
Jun 07 2016 05:55
so basically what that says is the value is not empty (so you're not deleting anything), and the property you're trying to add to is the tracks property
the next check is if the id even has a tracks property. In some cases (i.e. ABBA) it doesn't.
afsantos3
@afsantos3
Jun 07 2016 05:55
@aviralsharma1997 it works if you add an empty tracks array to an id without tracks
Coy Sanders
@coymeetsworld
Jun 07 2016 05:56
so thats what that if statement is for
if you don't have that property, then the push won't work
Clinkzc
@clinkzc
Jun 07 2016 05:56
stand in line
Coy Sanders
@coymeetsworld
Jun 07 2016 05:56
so you need to add it first, and initialize it to an array
i.e. collection[id]["tracks"] = [];
Clinkzc
@clinkzc
Jun 07 2016 05:56
Can someone help me with Stand in Line?
Laura Stephenson
@lauralstephenson
Jun 07 2016 05:56
if(prop == "tracks" && value !== ""){ if (collection[id].hasOwnProperty("tracks"));{ collection[id][prop].push(value); //Pushes tracks to last }
Divya Pinto
@divpinto18
Jun 07 2016 05:57
Can someone help me with pigLatin?
Coy Sanders
@coymeetsworld
Jun 07 2016 05:57
if you ran that on id 5439
5439: {
      album: "ABBA Gold"
    }
yes that part is fine @lauralstephenson
ABHIII
@aviralsharma1997
Jun 07 2016 05:57
@afsantos3 thnx for reminding that but I did it using the copy fn and it worked without creating the array
CamperBot
@camperbot
Jun 07 2016 05:57
aviralsharma1997 sends brownie points to @afsantos3 :sparkles: :thumbsup: :sparkles:
:cookie: 245 | @afsantos3 |http://www.freecodecamp.com/afsantos3
Coy Sanders
@coymeetsworld
Jun 07 2016 05:57
but you're more concerned with if it DOESNT have that property
you need to deal with that still
vg22
@vg22
Jun 07 2016 05:57
Can someone take a look at my code for the largestOfArray

function largestOfFour(arr) {
// You can do this!
var max=0,i=0,j=0;
var newArray=[];
for (i=0;i<arr.length;i++){ for(j=0;j<=arr.length;j++) if(arr[i][j]>max){
max=arr[i][j];

   }
   newArray.push(max);

}
console.log(newArray);
return newArray;
}

largestOfFour([[13, 27, 18, 26],[13, 27, 18, 26],[4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Laura Stephenson
@lauralstephenson
Jun 07 2016 05:58
If it is missing, or untrue...it need to be deleted.
vg22
@vg22
Jun 07 2016 05:59
it is not passing largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]) should return [27,5,39,1001]
this case
ABHIII
@aviralsharma1997
Jun 07 2016 05:59
Can somebody help with profile lookout
afsantos3
@afsantos3
Jun 07 2016 05:59
@aviralsharma1997 I just did that one what do you need?
ABHIII
@aviralsharma1997
Jun 07 2016 05:59
How to compare the firstnames
Coy Sanders
@coymeetsworld
Jun 07 2016 05:59
if its missing you need to add it @lauralstephenson
you're only deleting something if value is equal to an empty string
Clinkzc
@clinkzc
Jun 07 2016 06:00
can someone help with Stand in Line
abb=arr[arr.legnth -1];
arr=arr.pop;

function nextInLine(arr, item) {
// Your code here
arr=arr.push(item);
firstItem= arr[0];
arr.shift();
return firstItem; // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

afsantos3
@afsantos3
Jun 07 2016 06:00
@aviralsharma1997 what do you need to check all of the names?
@aviralsharma1997 remember that contacts is an array!
Coy Sanders
@coymeetsworld
Jun 07 2016 06:00
@clinkzc you don't assign arr to arr.push()
afsantos3
@afsantos3
Jun 07 2016 06:00
so you need some kind of loop
Coy Sanders
@coymeetsworld
Jun 07 2016 06:01
arr.push returns the new length of the array. You don't need to set that to anything
Clinkzc
@clinkzc
Jun 07 2016 06:01
what else can I do @coymeetsworld
Coy Sanders
@coymeetsworld
Jun 07 2016 06:01
just arr.push(item) is fine
ABHIII
@aviralsharma1997
Jun 07 2016 06:01
@afsantos3 just tell me how to check the firstnames do I have to do tht like an array
Coy Sanders
@coymeetsworld
Jun 07 2016 06:01
rest should work, although you can improve it a bit too
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:01
} else if (collection[id].hasOwnProperty("tracks"));{ --tests for a positive, not a negative. How do I check for a negative? And do I put it just before the delete collection line?
afsantos3
@afsantos3
Jun 07 2016 06:01
if(contacts.firstName == firstName)
sorry
for(var i = 0; i < contacts.length; i++) {
Donovan
@dnvn999
Jun 07 2016 06:02
@afsantos3 like this?
  // Only change code below this line
   var lookup(val) = {
    "alpha":"Adams",

     "bravo":"Boston",

   "charlie":"Chicago",

    "delta": "Denver",

    "echo": "Easy",

    "foxtrot":"Frank",

     return lookup(val);

  }

  // Only change code above this line
  return result;
}
Coy Sanders
@coymeetsworld
Jun 07 2016 06:02
else if (!collection[id].hasOwnProperty("tracks") @lauralstephenson, put a bang at the beginning which means "not"
akshayananddbg
@akshayananddbg
Jun 07 2016 06:02

// Example
function ourFunction(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function myFunction(wasThatTrue) {

// Only change code below this li

// Only change code above this line.

}

// Change this value to test
myFunction(true);

Coy Sanders
@coymeetsworld
Jun 07 2016 06:02
but you don't need an else if for this, you only need an if
afsantos3
@afsantos3
Jun 07 2016 06:02
@dnvn999 remove (val) from var lookup
akshayananddbg
@akshayananddbg
Jun 07 2016 06:02
trueOrFalse should be a function
trueOrFalse(true) should return a string
trueOrFalse(false) should return a string
trueOrFalse(true) should return "Yes, that was true"
trueOrFalse(false) should return "No, that was false"
how can i solve this
afsantos3
@afsantos3
Jun 07 2016 06:03
@dnvn999 your return should be lookup[val] not lookup(val)
ABHIII
@aviralsharma1997
Jun 07 2016 06:03
@afsantos3 tht just went out of my mind 😜 thnx man
CamperBot
@camperbot
Jun 07 2016 06:03
aviralsharma1997 sends brownie points to @afsantos3 :sparkles: :thumbsup: :sparkles:
:warning: aviralsharma1997 already gave afsantos3 points
Max Cady
@vegemouse
Jun 07 2016 06:03

Can anybody help with "Iterate Through an Array with a For Loop” pls? my code is

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var myTotal = 0;

for (var i = 0; i < myArr.length; i++) {
  myTotal += myArr[i];

}

I’m getting back “myTotal = 0”

  • “total = 0”
afsantos3
@afsantos3
Jun 07 2016 06:03
@aviralsharma1997 also do i messed up the if statement
@aviralsharma1997 contacts[i].firstName
Donovan
@dnvn999
Jun 07 2016 06:03
@afsantos3 i changed both but there are syntax errors now
afsantos3
@afsantos3
Jun 07 2016 06:03
send your code please
ABHIII
@aviralsharma1997
Jun 07 2016 06:03
I will do it anyway @afsantos3
akshayananddbg
@akshayananddbg
Jun 07 2016 06:04
plz suggest.
sent the code
Coy Sanders
@coymeetsworld
Jun 07 2016 06:04
try refreshing @vegemouse, that looks fine to me
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:04
Okay, Coy, you gotta spell it out again. Is it:
Donovan
@dnvn999
Jun 07 2016 06:04
  var result = "";

  // Only change code below this line
   var lookup[val]= {
    "alpha":"Adams",

     "bravo":"Boston",

   "charlie":"Chicago",

    "delta": "Denver",

    "echo": "Easy",

    "foxtrot":"Frank",

     return lookup;

  };

  // Only change code above this line
  return result;
}
Coy Sanders
@coymeetsworld
Jun 07 2016 06:04
oh it should be total not myTotal @vegemouse
afsantos3
@afsantos3
Jun 07 2016 06:04
@dnvn999 remove the return lookup from inside the table
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:04
else if (value === "" ){ //deletes empty one if (collection[id].hasOwnProperty("tracks"));{ delete collection[id][prop];
afsantos3
@afsantos3
Jun 07 2016 06:05
remove [val] from var lookup[val] {
Max Cady
@vegemouse
Jun 07 2016 06:05
Oops that was it lol thank you @coymeetsworld
CamperBot
@camperbot
Jun 07 2016 06:05
vegemouse sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: vegemouse already gave coymeetsworld points
Coy Sanders
@coymeetsworld
Jun 07 2016 06:05
np
afsantos3
@afsantos3
Jun 07 2016 06:05
@dnvn999 remember that your lookup is an object and your val is a property that you are searching for in your object
kirbyedy
@kirbyedy
Jun 07 2016 06:06
@vegemouse loop looks good, but shouldn`t the myTotal be actually just total
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:06

``function updateRecords(id, prop, value) {

if(prop == "tracks" && value !== ""){
if (collection[id].hasOwnProperty("tracks"));{
collection[id][prop].push(value); //Pushes tracks to last
}

}

else if (value !== ""){
collection[id][prop] = value;//Checks on value
}
else if (value === "" ){ //deletes empty one
if (collection[id].hasOwnProperty("tracks"));{
delete collection[id][prop];

}
}```

Max Cady
@vegemouse
Jun 07 2016 06:06
@kirbyedy thx
CamperBot
@camperbot
Jun 07 2016 06:06
vegemouse sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star2: 1067 | @kirbyedy |http://www.freecodecamp.com/kirbyedy
kirbyedy
@kirbyedy
Jun 07 2016 06:06
@vegemouse here is the text
Declare and initialize a variable total to 0. Use a for loop to add the value of each element of the myArr array to total.
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:06
I'm definitely missing a bracket somewhere..
Donovan
@dnvn999
Jun 07 2016 06:06
@afsantos3 it still wont work
  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;
}
afsantos3
@afsantos3
Jun 07 2016 06:06
almost there
@dnvn999 how will you return the value of the property?
vg22
@vg22
Jun 07 2016 06:07
can someone help me?
Coy Sanders
@coymeetsworld
Jun 07 2016 06:07
no @lauralstephenson its the semicolon you added here:
if (collection[id].hasOwnProperty("tracks"));{
afsantos3
@afsantos3
Jun 07 2016 06:07
@dnvn999 look at your return statement
Coy Sanders
@coymeetsworld
Jun 07 2016 06:07
semicolon terminates the line from executing further, you want to remove that
Donovan
@dnvn999
Jun 07 2016 06:08
@afsantos3 return is given as requirement initially
Coy Sanders
@coymeetsworld
Jun 07 2016 06:08
also best way to look at it is not if "tracks" exists, but rather if it doesn't. In that case you need to do something extra
afsantos3
@afsantos3
Jun 07 2016 06:08
@dnvn999 sorry let me check my code
vg22
@vg22
Jun 07 2016 06:08
I am stuck at largetsOfFour
afsantos3
@afsantos3
Jun 07 2016 06:08
@dnvn999 set your result equal to something
Donovan
@dnvn999
Jun 07 2016 06:09
@afsantos3 sure, no worries
afsantos3
@afsantos3
Jun 07 2016 06:09
and then return your result
Coy Sanders
@coymeetsworld
Jun 07 2016 06:09
You could write
if (collection[id].hasOwnProperty("tracks")){
  collection[id][prop].push(value); //Pushes tracks to last
} else {
  //add the tracks property to collection[id]
 collection[id][prop].push(value); //Pushes tracks to last
}
but you're specifying push twice that way, you can rewrite it so that you only need to specify it once
like this:
if (!collection[id].hasOwnProperty("tracks")){
  //add the tracks property to collection[id]
}
collection[id][prop].push(value); //Pushes tracks to last
Donovan
@dnvn999
Jun 07 2016 06:09
@afsantos3 var lookup= { "alpha": return = "Adams",
something like this?
Coy Sanders
@coymeetsworld
Jun 07 2016 06:10
much more succinct that way
afsantos3
@afsantos3
Jun 07 2016 06:10
@dnvn999 okay so you are looking for a value within your object correct?
and the lookup is your object
not like that @dnvn999
result = _
Donovan
@dnvn999
Jun 07 2016 06:11
the challenge title is Using Objects for Lookups
afsantos3
@afsantos3
Jun 07 2016 06:11
I know
Rashid Naushad
@rashidnaushad
Jun 07 2016 06:11

Hey guys, where do you think I'm going wrong with this "Mutation" algorithm problem?
I'm expected to write a function which returns true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
This is my code:


function mutation(arr) {
  var term2chk = arr[1].split();
  var result;
  for(var i=0;i<term2chk.length;i++){
    if((arr[0].toUpperCase().indexOf(term2chk[i].toUpperCase()))==-1){
      result= false;
    }
    else{
      result= true;
    }
  }
  return result;
}

mutation(["hello", "hey"]);

it returns false correctly for mutation(["hello","hey"]) ,and other false cases, but returns false for all but one true case, i.e mutation(["hello","Hello"]).

afsantos3
@afsantos3
Jun 07 2016 06:11
@dnvn999 try result = lookup[val]; after your lookup object
after you close it with };
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:12
Coy, I"m still making errors. Sorry!

```function updateRecords(id, prop, value) {

if(prop == "tracks" && value !== ""){
if (!collection[id].hasOwnProperty("tracks")){
//add the tracks property to collection[id]
}
collection[id][prop].push(value); //Pushes tracks to last
} else if (value !== ""){
collection[id][prop] = value;//Checks on value
}
else if (value === "" ){ //deletes empty one
delete collection[id][prop];
}
}```

feel like the stupidest coder in history...
Donovan
@dnvn999
Jun 07 2016 06:13
@afsantos3 Thank you so much, it finally works
CamperBot
@camperbot
Jun 07 2016 06:13
dnvn999 sends brownie points to @afsantos3 :sparkles: :thumbsup: :sparkles:
:cookie: 250 | @afsantos3 |http://www.freecodecamp.com/afsantos3
afsantos3
@afsantos3
Jun 07 2016 06:13
@dnvn999 anytime :)
vg22
@vg22
Jun 07 2016 06:13
please take a look at my code
afsantos3
@afsantos3
Jun 07 2016 06:14
@lauralstephenson you do not haev anythign in this if statement
f (!collection[id].hasOwnProperty("tracks")){
//add the tracks property to collection[id]
}
Donovan
@dnvn999
Jun 07 2016 06:14
@afsantos3 It is confusing sometimes, haha
Coy Sanders
@coymeetsworld
Jun 07 2016 06:14
replace //add the tracks property to collection[id] with collection[id]["tracks"] = []; @lauralstephenson
afsantos3
@afsantos3
Jun 07 2016 06:14
@dnvn999 indeed it is!
Coy Sanders
@coymeetsworld
Jun 07 2016 06:14
that will create a tracks property and initialize it to an empty array
then when you run collection[id]["tracks"].push(value), the code will work
youre missing a bracket in your 2nd for loop @vg22
Max Cady
@vegemouse
Jun 07 2016 06:17
@lauralstephenson !collection[id].hasOwnProperty("tracks") has to be set to true or false.. This doesn’t create the property, it just checks if the property exists. If it doesn’t exist, you have to create it and set it to [], and then assign it
Coy Sanders
@coymeetsworld
Jun 07 2016 06:17
also you're not resetting max anywhere
Max Cady
@vegemouse
Jun 07 2016 06:18
Sorry if I’m confusing you more lol
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:18
I am hopelessly confused. The code I have now is:
if(prop == "tracks" && value !== ""){ collection[id].["tracks"] = []; //add the tracks property to collection[id] } collection[id][prop].push(value); //Pushes tracks to last } else if (value !== ""){ collection[id][prop] = value;//Checks on value } else if (value === "" ){ //deletes empty one delete collection[id][prop]; }
kwal0203
@kwal0203
Jun 07 2016 06:18
Hey guys, any idea on how they make the start button look like it's being pushed in on the simon game? Simon Game
Coy Sanders
@coymeetsworld
Jun 07 2016 06:19
you replaced wrong line @lauralstephenson
replace //add the tracks property to collection[id] with collection[id]["tracks"] = []; @lauralstephenson
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:20
Do I replace hasOwnProperty?
vg22
@vg22
Jun 07 2016 06:21
@coymeetsworld it is failing for this largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Max Cady
@vegemouse
Jun 07 2016 06:21
@lauralstephenson you keep it, you just need to make it equal to true or false
Coy Sanders
@coymeetsworld
Jun 07 2016 06:22
did you reset max after going through each inner array @vg22?
Zach
@Moose1551
Jun 07 2016 06:23
Am I even close to returning a unicode value of 78 with the second for loop if the original unicode value was 65?
function rot13(str) { 

var strArray = str.split('');
var newString = '';
var emptyArray = [];

  for (var i = 0; i < strArray.length; i++) {
newString += strArray[i].charCodeAt(0) + " ";

}
  for (var j= 0; j < newString.length; j++) {
   if (newString[0] >= 65 && newString[0] <= 78) {
     return newString.fromCharCode(+13);
   } 
 }

}
rot13("SERR PBQR PNZC");
Coy Sanders
@coymeetsworld
Jun 07 2016 06:23
no @lauralstephenson, you replace //add the tracks property to collection[id] line I put in
everything else was fine
Zach
@Moose1551
Jun 07 2016 06:23
Obviously not, but I'm dying over here.
Coy Sanders
@coymeetsworld
Jun 07 2016 06:24
@Moose1551 you don't actually have to create a string array, you can iterate through a string
vg22
@vg22
Jun 07 2016 06:24
@coymeetsworld so after the inner loop iterates once ,max should be set to 0 again ?
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:24
It says it wants dot notation. That's the only difference. It still won't run:
Coy Sanders
@coymeetsworld
Jun 07 2016 06:24
after it iterates every time @vg22
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:24

```function updateRecords(id, prop, value) {

if(prop == "tracks" && value !== ""){
if (!collection[id].hasOwnProperty("tracks")){
collection[id].tracks = [];
//add the tracks property to collection[id]
}
collection[id][prop].push(value); //Pushes tracks to last
} else if (value !== ""){
collection[id][prop] = value;//Checks on value
}
else if (value === "" ){ //deletes empty one
delete collection[id][prop];
}
}
```

After updateRecords(5439, "artist", "ABBA"), artist should be "ABBA"--X
After updateRecords(5439, "tracks", "Take a Chance on Me"), tracks should have "Take a Chance on Me" as the last element.--X
After updateRecords(2548, "artist", ""), artist should not be set--/
After updateRecords(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element.--X
After updateRecords(2548, "tracks", ""), tracks should not be set--/
Coy Sanders
@coymeetsworld
Jun 07 2016 06:26
you need to return collection at end of function @lauralstephenson
Markus Kiili
@Masd925
Jun 07 2016 06:27
@lauralstephenson When the tracks array is absent, you could just assign [value] to the tracks property.
Coy Sanders
@coymeetsworld
Jun 07 2016 06:27
@Masd925 but then with the logic it would push twice
Markus Kiili
@Masd925
Jun 07 2016 06:27
@coymeetsworld ok, did't see that.
Coy Sanders
@coymeetsworld
Jun 07 2016 06:27
you would need to put the push function inside an else statement
yeah problem is just she's not returning the object after she's done
thats the only issue I see
Adetunji Iyaniwura
@Iadetunji
Jun 07 2016 06:29
pls i need help with challenge 169:Word Blanks
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:29
1 million thanks to @coymeetsworld
CamperBot
@camperbot
Jun 07 2016 06:29
:star2: 1076 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
lauralstephenson sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
Laura Stephenson
@lauralstephenson
Jun 07 2016 06:30
I survived!
Coy Sanders
@coymeetsworld
Jun 07 2016 06:30
:ok_hand: @lauralstephenson
no problem
Adetunji Iyaniwura
@Iadetunji
Jun 07 2016 06:30
@coymeetsworld ,pls can you help me with the challenge 169
Zach
@Moose1551
Jun 07 2016 06:31
@coymeetsworld, thanks. I edited it down. Is this even close to being a possibility?
 if (str.fromCharCode() >= 65 && <= 78) {
    return str.fromCharCode() + 13);
  }
Adetunji Iyaniwura
@Iadetunji
Jun 07 2016 06:31
@coymeetsworld ,cant just figure out how to do it
CamperBot
@camperbot
Jun 07 2016 06:31
:star2: 1077 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
moose1551 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
Yan Bin
@yanbin92
Jun 07 2016 06:31
function palindrome(str) {
// Good luck!
var temp=str.replace(",","").replace(".","").replace(" ","").toLowerCase();
console.log(temp);
for(var i=0;i<temp.length/2;i++){
if(temp.charAt(i)===temp.charAt(temp.length-1-i))
continue;
else
return false;
}
return true;
}
palindrome("A man, a plan, a canal. Panama");
temp don't change what is the problem
kirbyedy
@kirbyedy
Jun 07 2016 06:32
@yanbin92 maybe you should use regex
o
Rashid Naushad
@rashidnaushad
Jun 07 2016 06:32

I'm expected to write a function which Returns true if the string in the first element of the array contains all of the letters of the string in the second element of the array.


function mutation(arr) {
  var term2chk = arr[1].split("");
  var result=0;
  for(var i=0;i<term2chk.length;i++){
    if((arr[0].toUpperCase().indexOf(term2chk[i].toUpperCase()))==-1){
      result=false;
    }
    else{
      result++;
    }
  }
  if(result==term2chk.length){
    return true;
  }else{
    return false;
  }
  //return result;
}

mutation(["hello", "hey"]);

what do you guys think of my code..
how can I improve it?

check this as well
Yan Bin
@yanbin92
Jun 07 2016 06:33
@kirbyedy thanks
CamperBot
@camperbot
Jun 07 2016 06:33
yanbin92 sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star2: 1069 | @kirbyedy |http://www.freecodecamp.com/kirbyedy
Markus Kiili
@Masd925
Jun 07 2016 06:33
@rashidnaushad You don't actually need any arrays. You can loop characters and use indexOf on strings.
Adetunji Iyaniwura
@Iadetunji
Jun 07 2016 06:34
pls can anyone help me with the challenge 169
Markus Kiili
@Masd925
Jun 07 2016 06:35
@rashidnaushad You could also do without the result variable too. Just loop second string characters and use indexOf to see whether the character is found on the first string. If not, return false. After loop return true.
Adetunji Iyaniwura
@Iadetunji
Jun 07 2016 06:36
@Masd925 ,hello
Rashid Naushad
@rashidnaushad
Jun 07 2016 06:36
@Masd925 how can I loop on characters of string without splitting into an array?
Markus Kiili
@Masd925
Jun 07 2016 06:37
@rashidnaushad Using str.charAt(i) and str.length. Make simple for loop over indices.
Rashid Naushad
@rashidnaushad
Jun 07 2016 06:38
oh...ofcourse..thanks man
@Masd925 thanks
CamperBot
@camperbot
Jun 07 2016 06:38
rashidnaushad sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1753 | @masd925 |http://www.freecodecamp.com/masd925
Adetunji Iyaniwura
@Iadetunji
Jun 07 2016 06:38
@Masd925 .hello
Krzysztof Borowy
@Krizzu
Jun 07 2016 06:43
Hola
Fernand
@Ferdyboy81
Jun 07 2016 06:46
hi guys! how can i make my business title hover the screen to the left when my page is opened?http://codepen.io/Ferdyboy81/pen/XKmpZy
FM
@mafelix
Jun 07 2016 06:47
you're using bootstrap right
Fernand
@Ferdyboy81
Jun 07 2016 06:48
@mafelix yes
FM
@mafelix
Jun 07 2016 06:48
@Ferdyboy81 you can go class="text-left" but that will float the text left to the container of the words
it won't be out of the container
if you want it to be out of the container you need to change the html
and take the title text out of the container div
and then apply css afterwords
wards*
Fernand
@Ferdyboy81
Jun 07 2016 06:49
ok i just want to add a little bit of animation to it. :) ima try it right now.
FM
@mafelix
Jun 07 2016 06:49
wait
wut
you want animation?
go look up css transitions then
I thought you just wanted your text to be on the left
Fernand
@Ferdyboy81
Jun 07 2016 06:49
i meant like you know when i open the page i just want the title to slid to the right
slide to the right or left i meant
FM
@mafelix
Jun 07 2016 06:49
you can do it with css
or jquery
jquery.animate
you're probably gonna have to take it out of the container
Fernand
@Ferdyboy81
Jun 07 2016 06:51
@mafelix cool thanks brother!
CamperBot
@camperbot
Jun 07 2016 06:51
ferdyboy81 sends brownie points to @mafelix :sparkles: :thumbsup: :sparkles:
:cookie: 208 | @mafelix |http://www.freecodecamp.com/mafelix
FM
@mafelix
Jun 07 2016 06:51
and I don't know how it'll affect mobile responsiveness
actually I lied
jquery
Fernand
@Ferdyboy81
Jun 07 2016 06:52
this is what i kinda wanted to do: <marquee behavior="slide" direction="left">HTML slide-in text...</marquee>
FM
@mafelix
Jun 07 2016 06:52
just write your own jquery
that's using a library
marquee behavior
Zach
@Moose1551
Jun 07 2016 06:53
Is this even close to being a possibility?
for (var i = 0; i < str.length; i++) {
 newString += str[i].charCodeAt(0) + " ";
 if (str.fromCharCode(65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78)) {
   return str.charCodeAt(i) + 13;
 }
FM
@mafelix
Jun 07 2016 06:53
@Moose1551 run it and tell us?
@Moose1551 Lol...
Zach
@Moose1551
Jun 07 2016 06:56
Yeah, I understand that aspect. I don't understand why I keep getting "str.fromCharCode is not a function". I don't get any of it to tell you the truth.
Zach
@Moose1551
Jun 07 2016 06:59
haha, dude, I've read over that and over that. I'm completely lost. Second time through these algorithms, and I've learned zilch.
taka93shi
@taka93shi
Jun 07 2016 06:59
anyone familiar with android studio
FM
@mafelix
Jun 07 2016 07:00
@Moose1551 are you doing a code decipher challenge?
moving letters of the alphabet or something
Zach
@Moose1551
Jun 07 2016 07:01
Yessir. Caesers Cipher to decode an ROT13.
FM
@mafelix
Jun 07 2016 07:02
I think your loop is flawed
what is newString?
just a start with the charcodes?
string?
or is it actual letters
console.log that variable
and see if it's what you expect
Zach
@Moose1551
Jun 07 2016 07:04

@mafelix, I'm sure it is. I have no idea how to use loops. Literally I've gone through codecademy for loops twice and FCC tutorials about 3 times. Can't grasp it for some reason. Here is the full code:

```js

FM
@mafelix
Jun 07 2016 07:04
and then what are you comparing in your if statement here
you're comparing the entire str?
Zach
@Moose1551
Jun 07 2016 07:05
function rot13(str) {

var newString =