These are chat archives for FreeCodeCamp/HelpJavaScript

26th
Jun 2017
koder3
@koder3
Jun 26 2017 00:00

function binaryAgent(str) {
var e = []
var r = str.split(" ")
for (var i = 0; i < r.length; i++){
  e.push(String.fromCharCode(parseInt(r[i], 2)))
}
return e.join("")
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111")
any way i can optimize this @sjames1958gm
Michael
@HAWKKER
Jun 26 2017 00:00
The wording here is confusing me. "MYVAR is not the same as MyVar nor myvar. It is possible to have multiple distinct variables with the same name but different casing. It is strongly recommended that for the sake of clarity, you do not use this language feature." What does it mean by language feature, is it telling me not to use capatilization, or myvar, or javascript as a whole? I don't know if I'm just being silly..
Sparkin
@seanparkin
Jun 26 2017 00:00
'''
'''
CamperBot
@camperbot
Jun 26 2017 00:00
:bulb: to format code use backticks! ``` more info
Stephen James
@sjames1958gm
Jun 26 2017 00:01
@koder3 Not really - you can use map instead of for loop
  return str.split(' ').map(function(e) {
    return String.fromCharCode(parseInt(e, 2));
  }).join('');
Sparkin
@seanparkin
Jun 26 2017 00:02
@dyon3334
function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;

  var newArr = [];
  for (i =0;i<arr.length;i++) {
  var result = Math.round(2*Math.PI*Math.sqrt(Math.pow(earthRadius+arr[i].avgAlt,3)/GM));
  newArr.push({name: arr[i].name, orbialPeriod: result});
}
  return newArr;

}
onejo578
@onejo578
Jun 26 2017 00:03
@HAWKKER it just means that, even though you can use two variables with the same spelling (ie, myVar and myVAR), you should avoid it as it's confusing.
CamperBot
@camperbot
Jun 26 2017 00:04
koder3 sends brownie points to @seanparkin :sparkles: :thumbsup: :sparkles:
:cookie: 294 | @seanparkin |http://www.freecodecamp.com/seanparkin
koder3
@koder3
Jun 26 2017 00:04
@sjames1958gm thats beautiful. thanks
CallMeOrange
@EgnaroDev
Jun 26 2017 00:04
@HAWKKER and JavaScript are case sensitive, for that challenge I believe you just have to fix these variables to match both
Joseph
@revisualize
Jun 26 2017 00:05
:|
kumquatfelafel
@kumquatfelafel
Jun 26 2017 00:06
@HAWKKER By language feature, they mean the fact that javascript is case sensitive. (which is why you could have myvar, myVar, etc.)
Michael
@HAWKKER
Jun 26 2017 00:06
@onejo578
CallMeOrange
@EgnaroDev
Jun 26 2017 00:06
yeah what @kumquatfelafel said
Joseph
@revisualize
Jun 26 2017 00:06
@HAWKKER JavaScript is case sensitive. You should have learned that in one of the lessons.
CallMeOrange
@EgnaroDev
Jun 26 2017 00:06
lol now 3 guys have said it
Michael
@HAWKKER
Jun 26 2017 00:07
@onejo578 Thank you, I just shouldn't use the two at the same time. Makes sense.
CamperBot
@camperbot
Jun 26 2017 00:07
hawkker sends brownie points to @onejo578 :sparkles: :thumbsup: :sparkles:
:cookie: 2 | @onejo578 |http://www.freecodecamp.com/onejo578
kumquatfelafel
@kumquatfelafel
Jun 26 2017 00:07
It's not over until everybody says it!
Joseph
@revisualize
Jun 26 2017 00:07
Look.
Repeating the same thing from multiple isn't always a bad thing.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 00:07
^true. Differing perspective and some such. ;)
Michael
@HAWKKER
Jun 26 2017 00:07
@revisualize I Understood they were case sensitive but the wording was confusing, this is the first tutorial to explain it..
Joseph
@revisualize
Jun 26 2017 00:08
If I ask a question and 4 people say the same thing differently. That re-affirms the response as factual.
Thomas
@thojaco
Jun 26 2017 00:09
@revisualize thanks!
CamperBot
@camperbot
Jun 26 2017 00:09
thojaco sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4256 | @revisualize |http://www.freecodecamp.com/revisualize
CallMeOrange
@EgnaroDev
Jun 26 2017 00:09
@HAWKKER well now you have understood that JS is case-sensitive, do you need any help with that challenge?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 00:10
@HAWKKER yeah, I getcha. You have to look at the context a bit to figure out that by "language feature" they mean that.
CallMeOrange
@EgnaroDev
Jun 26 2017 00:11
Alright I managed to figure this out, so is this good way to do it?

function multiplyAll(arr) {
  var product = 1;

  for (var i = 0; i < arr.length; i++) {
    for (var j=0; j < arr[i].length; j++) {
  product = product*arr[i][j];
    }
} 
  return product;
}

multiplyAll([[1],

             [2],

             [3]]);
I tried var array = arr[i][j] then return product*array; that didn't work why?
Is it because they are in different scopes?
Michael
@HAWKKER
Jun 26 2017 00:12
@MCTwoDigitZero No thank you, I have struggled with some of these basic initial javascript tutorials but I'm getting there
CamperBot
@camperbot
Jun 26 2017 00:12
hawkker sends brownie points to @mctwodigitzero :sparkles: :thumbsup: :sparkles:
:cookie: 336 | @mctwodigitzero |http://www.freecodecamp.com/mctwodigitzero
CallMeOrange
@EgnaroDev
Jun 26 2017 00:12
@HAWKKER Alright, Good Luck with JavaScript
Take notes if needed :/
Michael
@HAWKKER
Jun 26 2017 00:12
:)
Moisés Man
@moigithub
Jun 26 2017 00:13
i and j are only defined inside the loop
soo probably was scopes as u said @MCTwoDigitZero
CallMeOrange
@EgnaroDev
Jun 26 2017 00:13
I see
So that was only reason
thanks @moigithub
CamperBot
@camperbot
Jun 26 2017 00:14
mctwodigitzero sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3421 | @moigithub |http://www.freecodecamp.com/moigithub
Sunny Wong
@swong194
Jun 26 2017 00:16
hi
every1 does javascript allow for negative index arrays
Sparkin
@seanparkin
Jun 26 2017 00:17
@swong194 I am pretty sure that you can't have a negative array index
Can anyone help me with my issue with the Map the Debris challenge?
Moisés Man
@moigithub
Jun 26 2017 00:20
@swong194 some methods allows negative index like mdn.io/slice
Sunny Wong
@swong194
Jun 26 2017 00:22
@moigithub @seanparkin thanks, that sucks i thought i saw a FCC where i used negative index
CamperBot
@camperbot
Jun 26 2017 00:22
swong194 sends brownie points to @moigithub and @seanparkin :sparkles: :thumbsup: :sparkles:
:cookie: 295 | @seanparkin |http://www.freecodecamp.com/seanparkin
:star2: 3422 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Jun 26 2017 00:29
T=2×PI×a3GM T = 2 \times PI \times \sqrt{\frac{a^3}{GM}}
@seanparkin
CallMeOrange
@EgnaroDev
Jun 26 2017 00:33
@moigithub What kind of formula is that?
Moisés Man
@moigithub
Jun 26 2017 00:34
debris map, from the wiki if i recall
Sparkin
@seanparkin
Jun 26 2017 00:35
@moigithub yeah that was the code that I was using. Realized that I misspelled one of the variables. Thank you for the help
CamperBot
@camperbot
Jun 26 2017 00:35
seanparkin sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3423 | @moigithub |http://www.freecodecamp.com/moigithub
J-Mag Guthrie
@baseballpoetess
Jun 26 2017 00:41
@revisualize gracias
CamperBot
@camperbot
Jun 26 2017 00:41
baseballpoetess sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4257 | @revisualize |http://www.freecodecamp.com/revisualize
Yang Lu
@Luyang2016
Jun 26 2017 00:46

var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){
// 请把你的代码写在这条注释以下
for(var i=0;i<4;i++){
  if (contacts[i].firstName==firstName){
    if (contacts[i].hasOwnProperty(prop)){return contacts[i][prop];  
    }
    else{return "No such property";}
  }
else{return "No such contact";}


}
}

lookUp("Sherlock", "likes");
Why can't I pass this?
It's profile lookup in basic Javascript.
luccifer00
@luccifer00
Jun 26 2017 00:48
@Luyang2016 you should use .length property
Yang Lu
@Luyang2016
Jun 26 2017 00:49
Where? @luccifer00
luccifer00
@luccifer00
Jun 26 2017 00:49
i < contacts.length; i++
instead "4"
@Luyang2016 why do u use 4?
Yang Lu
@Luyang2016
Jun 26 2017 00:50
I still can't pass
Is it the for loop?
luccifer00
@luccifer00
Jun 26 2017 00:51
let me see
else{return "No such contact"; try to put outside the loop @Luyang2016
Yang Lu
@Luyang2016
Jun 26 2017 00:54
I think something is wrong with the for loop. Because when i =0, only the name akira satisfies.
And only this condition is right .
luccifer00
@luccifer00
Jun 26 2017 00:55
the loop is ok, if u add what i said before contacts.length
also you shold use strict equal in firstName === firstName
Yang Lu
@Luyang2016
Jun 26 2017 00:57

var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){

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



}
  else{return "No such contact";}
}

lookUp("Sherlock", "likes");
You mean like this.?Now it says the grammar is wrong
luccifer00
@luccifer00
Jun 26 2017 01:01
you no need the last else
just return without {}
that should work
crimsonangel665
@crimsonangel665
Jun 26 2017 01:03
hey, having trouble with
Returning Boolean Values from Functions: cant get it to equal true
function isLess(a, b) {
// Fix this code
return a === b;
}
// Change these values to test
isLess(10, 15);
Yang Lu
@Luyang2016
Jun 26 2017 01:04
@luccifer00 It passed. Thank you.
CamperBot
@camperbot
Jun 26 2017 01:04
luyang2016 sends brownie points to @luccifer00 :sparkles: :thumbsup: :sparkles:
:cookie: 240 | @luccifer00 |http://www.freecodecamp.com/luccifer00
Grigor Minasyan
@gogminsam
Jun 26 2017 01:05
Can someone help me with Caesars Cipher?

function rot13(str) { // LBH QVQ VG!
  var newarr = [];
  for (i=0; i<str.length; i++) {
    if (str.charCodeAt(i)>=65 || str.charCodeAt(i) <= 77) {
      newarr.push(String.fromCharCode(i+13));
    } else if (str.charCodeAt(i)>=78 || str.charCodeAt(i) <= 90) {
      newarr.push(String.fromCharCode(i-13));
    } else {
      newarr.push(str[i]);
    }

  }
  newarr.join("");
  return newarr; 

}

// Change the inputs below to test
rot13("SERR PBQR PNZABCAM");
luccifer00
@luccifer00
Jun 26 2017 01:05
@crimsonangel665 use the logic
Grigor Minasyan
@gogminsam
Jun 26 2017 01:05
What's wrong with my code?
Moisés Man
@moigithub
Jun 26 2017 01:05
@crimsonangel665 read the funciton name
and check what ur IF condition doing
@gogminsam space is charcode 32
and 32 is <= 77
luccifer00
@luccifer00
Jun 26 2017 01:07
@crimsonangel665 if the name of the function isLess (a, b) why u want to make strict equal??
crimsonangel665
@crimsonangel665
Jun 26 2017 01:07
isLess(10,15) should return true
is what its asking me to di
do*
luccifer00
@luccifer00
Jun 26 2017 01:08
@crimsonangel665 yes, that is true.... but you have to write your code
crimsonangel665
@crimsonangel665
Jun 26 2017 01:09
mine is exactly the same as the example and that is what is confusing me
luccifer00
@luccifer00
Jun 26 2017 01:09
no no @crimsonangel665 isLess (a,b) to test your function you can change that values isLess(1,100)
Grigor Minasyan
@gogminsam
Jun 26 2017 01:09
@moigithub I have changed || to && and it still doesnt work, return something like this
["", "\u000e","",........
luccifer00
@luccifer00
Jun 26 2017 01:09
so @crimsonangel665 10 is a, and 15 is b!!! rewrite your code
@crimsonangel665 in your code you write a===b the function reads, 10===15.... thats is becouse the result is false! becouse 10, isn't equal to 15.... so what sign could be insted === ??? ... think about it..
Jose R Perez
@perezvenegas
Jun 26 2017 01:12
help!
"Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed."
crimsonangel665
@crimsonangel665
Jun 26 2017 01:13
@luccifer00 im still confused but ill have a play
luccifer00
@luccifer00
Jun 26 2017 01:15
its simple @crimsonangel665
function isLess(a, b) {
// Fix this code
return a === b; //you should change === to <, becouse a is minos to b, (a,b) is (10,15)
}
// Change these values to test
isLess(10, 15);
read the comments that i added
crimsonangel665
@crimsonangel665
Jun 26 2017 01:17
then why would the example show something different?
@luccifer00 thankyou btw
CamperBot
@camperbot
Jun 26 2017 01:18
crimsonangel665 sends brownie points to @luccifer00 :sparkles: :thumbsup: :sparkles:
:cookie: 241 | @luccifer00 |http://www.freecodecamp.com/luccifer00
luccifer00
@luccifer00
Jun 26 2017 01:18
if you read the example the functios is called function isEqual(a,b)
crimsonangel665
@crimsonangel665
Jun 26 2017 01:20
i didnt think the function name mattered it could of been apple
Joseph
@revisualize
Jun 26 2017 01:21
@luccifer00 minos?
What is minos?
luccifer00
@luccifer00
Jun 26 2017 01:22
sorry minor!
Joseph
@revisualize
Jun 26 2017 01:22
@luccifer00 Less than.
luccifer00
@luccifer00
Jun 26 2017 01:22
haha i have english problems!!
Daniel Narilton
@spaganger
Jun 26 2017 01:23
I'm struggling to get the index of the smallest element in my array: https://codepen.io/anon/pen/LLzyvg?editors=0010 Anyone?
Moisés Man
@moigithub
Jun 26 2017 01:23
@gogminsam soo whats ur current code ?
Tricia
@patricia07
Jun 26 2017 01:24
hey guys can u help me please
is this right?
var thirdLetterOfLastName = lastName[3];
Moisés Man
@moigithub
Jun 26 2017 01:25
JS uses 0 based index @patricia07
Ravi Kishore Thella
@ravikishorethella
Jun 26 2017 01:25
@patricia07 count starts from zero
@patricia07 if you want the third character then it should be lastName[2]
Tricia
@patricia07
Jun 26 2017 01:29
oh i see thanks!!!
JuanDavid31
@JuanDavid31
Jun 26 2017 01:35
Hello everybody
Have someone done the Smallest Common Multipli challenge? i think it is badly written
Joel Korcsmaros
@lossness
Jun 26 2017 01:37
Can someone check out this gist? It's passing the test but it's not actually printing anything to console. glitch maybe? (prob not) https://gist.github.com/lossness/f64d78cb4589de7478dcd3994d48c0b9
JuanDavid31
@JuanDavid31
Jun 26 2017 01:39
These are the outputs
Hi, I work as a programmer
Hi, I work as a super programmer
seems ok to me
Joel Korcsmaros
@lossness
Jun 26 2017 01:39
probably glitch in codecademy
thx @JuanDavid31
CamperBot
@camperbot
Jun 26 2017 01:40
lossness sends brownie points to @juandavid31 :sparkles: :thumbsup: :sparkles:
:cookie: 280 | @juandavid31 |http://www.freecodecamp.com/juandavid31
JuanDavid31
@JuanDavid31
Jun 26 2017 01:40
you are welcome
Karen
@karengeerts
Jun 26 2017 01:43

Hi all - I'm stuck with Mutations challenge. The code does what the challenge prescribes - but it is not accepted as a correct solution.
What am I doing wrong?

function mutation(arr) {
var sourceString = arr[0];
var checkString = arr[1];
var iterations = checkString.length;
var value = "true";
sourceString = sourceString.toLowerCase();
checkString = checkString.toLowerCase();
for (var i=0; i<=iterations; i++){
var letter = checkString.charAt(i);
var check = sourceString.indexOf(letter);
if (check == -1){
value ="false";
}
}
return value;
}
mutation(["voodoo", "no"])

Moisés Man
@moigithub
Jun 26 2017 01:44
@karengeerts u need to return a boolean value.. true or false
without quotes.. quotes.. make it a string
Karen
@karengeerts
Jun 26 2017 01:49
I understand the boolean value but not your comment re quotes and strings?
Karen
@karengeerts
Jun 26 2017 01:55
thx @moigithub - the boolean comment pointed me in the right direction!
CamperBot
@camperbot
Jun 26 2017 01:55
karengeerts sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3424 | @moigithub |http://www.freecodecamp.com/moigithub
Aizaz Shahid
@aizazshahid
Jun 26 2017 01:56

@karengeerts please paste your code as formatted, next time when you will try to paste:
```
put your code between those backticks, but remember to put ``` them in new lines.

```

Karen
@karengeerts
Jun 26 2017 02:01
thx @forwebtech - I saw the little markdown help button too late! will remember for next time
CamperBot
@camperbot
Jun 26 2017 02:01
karengeerts sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 728 | @forwebtech |http://www.freecodecamp.com/forwebtech
Joseph
@revisualize
Jun 26 2017 02:06
hey hey
CallMeOrange
@EgnaroDev
Jun 26 2017 02:10
?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:15

Say I wanted to take a numeric string and add 1 to each digit such that, e.g. "9309" becomes "104110". If I were to do something like this (I'm sure there are better ways, but bear with me)

function addOneToDigits1(number) {
  return number.split('').reduce((a,b) => a + (+b +1)).join(''); //This doesn't modify first digit
}
function addOneToDigits2(number) {
  return number.split('').reduce((a,b) => (+a + 1) + b).join(''); //This doesn't modify last digit
}
function addOneToDigits3(number) {
  return number.split('').reduce((a,b) => (+a + 1) + '' + (+b + 1)).join(''); //this doubly modifies sandwiched digits
}

So I know that for the first and second one, you could always shift/unshift or pop/push a " ", e.g., to trick it into modifying the untouched digit, but... this just feels a bit disappointing somehow. Is there a way to handle the ends using reduce alone, or would you want to call some other method to do that?

kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:21
^ when I say using reduce alone, I mean without using shift or the like
(low priority question) :p
fdemaa
@fdemaa
Jun 26 2017 02:26
@kumquatfelafel Can you help me with my algorithm ? I m trying to slice an array a X number of times in subarrays, i m trying to use a loop, but i dont know how to slice it properly in subarrays;
kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:26
(I notice there is an "initialValue" in documentation, but can you still include this using =>?)
@fdemaa possibly? Getting a bit tired, and may misadvise. Do you have any code to look at?
Claudio Restifo
@Marmiz
Jun 26 2017 02:29

@kumquatfelafel the way I'd approach it:

1- convert the string into an array with split
2- map into the array, convert the string into a number and add 1
3- take those numbers, convert back to string values and join them together.

You should be able to use reduce, but I don't see the need of it when all you want is to just add 1 to each element of the array. Map seems more intuitive.

fdemaa
@fdemaa
Jun 26 2017 02:29
@kumquatfelafel yes but its just all wrong lol okey i will show you

function chunkArrayInGroups(arr, size) {
   /*
  Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.

  */

  var emptyArray=[];
  var iterations= Math.ceil(arr.length/size);
  console.log(iterations);


  for ( i=0; i<=iterations; i++ ){
    var temporary = arr.slice(size);
    emptyArray.push(temporary);
    }
console.log(emptyArray);
}

chunkArrayInGroups(["a", "b", "c", "d","e"], 2);
kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:30
@Marmiz thanks
CamperBot
@camperbot
Jun 26 2017 02:30
kumquatfelafel sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 958 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Jun 26 2017 02:31
@kumquatfelafel remember to work with the correct type of variable, in JS
('10') +1 returns 101 [String 10 + number 1 returns '101']
Grigor Minasyan
@gogminsam
Jun 26 2017 02:32
@moigithub this is my code
Ryan Malm
@Rybar
Jun 26 2017 02:32
How are people with free codepen accounts solving the CORS problem when doing AJAX requests, like for the random quote generator?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:32
@Marmiz aye :). I've come to get a lot more careful about that than I was at first.
Grigor Minasyan
@gogminsam
Jun 26 2017 02:32

``` function rot13(str) { // LBH QVQ VG!
var newarr = [];
for (i=0; i<str.length; i++) { if (str.charCodeAt(i)>=65 || str.charCodeAt(i) <= 77) {
newarr.push(String.fromCharCode(i+13));
} else if (str.charCodeAt(i)>=78 || str.charCodeAt(i) <= 90) {
newarr.push(String.fromCharCode(i-13));
} else {
newarr.push(str[i]);
}

}
newarr.join("");
return newarr;

}

// Change the inputs below to test
rot13("SERR PBQR PNZABCAM"); ```

Moisés Man
@moigithub
Jun 26 2017 02:33
@Rybar using JSONP
@gogminsam backticks on its OWN line
and u still using OR (which is wrong)
true OR false --- > result true
if at least 1 side is true.. the whole thing becomes true
Ryan Malm
@Rybar
Jun 26 2017 02:35
@moigithub Thanks.
CamperBot
@camperbot
Jun 26 2017 02:35
rybar sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3425 | @moigithub |http://www.freecodecamp.com/moigithub
Grigor Minasyan
@gogminsam
Jun 26 2017 02:35
@moigithub the backticks were for code, im on phone they didn't work. There's no backticks on my code
kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:35
@fdemaa arr.slice(size) will take from the arr[size] until (inclusive) arr[arr.length - 1] (end of array).
Grigor Minasyan
@gogminsam
Jun 26 2017 02:36
@moigithub sorry I sent you the wrong code, my current code is with && but it still doesn't work
Moisés Man
@moigithub
Jun 26 2017 02:37
u doing -13 on the index.. and should be -13 on the char code @gogminsam
fdemaa
@fdemaa
Jun 26 2017 02:37
@kumquatfelafel thanks, i will check that then
CamperBot
@camperbot
Jun 26 2017 02:37
fdemaa sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Claudio Restifo
@Marmiz
Jun 26 2017 02:37

@fdemaa remember that the first parameter in slice is where you wnat to start "slicing" so

var temporary = arr.slice(size);

you are start slicing your array from arr[2] in this case

Moisés Man
@moigithub
Jun 26 2017 02:39
@fdemaa slice can take a second parameter/index
if u dont specify it will slice from first param to last element
fdemaa
@fdemaa
Jun 26 2017 02:39
@Marmiz @moigithub thanks!
Yes i forget about the (begin, end) LOL
CamperBot
@camperbot
Jun 26 2017 02:39
fdemaa sends brownie points to @marmiz and @moigithub :sparkles: :thumbsup: :sparkles:
:cookie: 959 | @marmiz |http://www.freecodecamp.com/marmiz
:star2: 3426 | @moigithub |http://www.freecodecamp.com/moigithub
CallMeOrange
@EgnaroDev
Jun 26 2017 02:45
Hey this is my Profile Lookup code..

var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
  var result = contacts;

  for (var i = 0; i < result; i++) {    
  } 
  var value = result;

   if (firstName!==result[i].firstName) {
    return "No such contact"; 
  } else {
    return "No such property";
  }
  return value;
}

lookUpProfile("Akira", "likes");
My question is ... I want to know if these if statements are correct
:zzz:
Forget it.. they are working but I think they may be wrong somehow..
kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:55

@MCTwoDigitZero Your for loop is empty. Additionally, your if else is basically saying

if(firstName!==result[i].firstName)
   return "No such contact"; //But we've only checked one contact.
else if(firstName === result[i].firstName)
   return "No such property"; //Why? We haven't checked for any properties.

You're also not utilizing your for loop.

As for

var result = contacts;
var value = result;

There's not much point in creating these variables.

Eric Hasegawa
@EricHasegawa
Jun 26 2017 02:56
I'm on the "Return Largest Number in Arrays" challenge, can anyone help me out?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 02:57
@EricHasegawa sure.
Eric Hasegawa
@EricHasegawa
Jun 26 2017 02:57
function largestOfFour(arr) {

  var standard = 0;

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

    for (var j=0; i< arr[i]; i++) {
      if (arr[j] > standard ) {
      standard = arr[i];
    }
    }




  }


  return standard;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@kumquatfelafel
I'm not sure how to progress from here, is this looking okay so far?
sethsdo
@sethsdo
Jun 26 2017 02:59

'''function lookUpProfile(firstName, prop){
// Only change code below this line
var i = 0;

while (i < contacts.length) {
if (contacts[i].hasOwnProperty(firstName) === true) {
return contacts[i][firstName];
} else {
return "No such contact";
}

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

}

i++;
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

Hey, I pretty new and have been working on this problem for awhile, could someone point me to what I'm missing in this code?
fdemaa
@fdemaa
Jun 26 2017 03:01
@sethsdo you have to use a for loop and inside put the conditions
well you are using it
lol
i didnt saw it
sethsdo
@sethsdo
Jun 26 2017 03:02
sorry, i formatted it wrong when I submitted it.
fdemaa
@fdemaa
Jun 26 2017 03:03
You have to return contacts[i]prop, when the 2 conditions are true:
when firstname is an actual firstname and the property exist
Eric Hasegawa
@EricHasegawa
Jun 26 2017 03:03
@sethsdo I think you can edit it even after sending it to the chat, try clicking the three dots to the right of the message
kumquatfelafel
@kumquatfelafel
Jun 26 2017 03:03
@EricHasegawa Right. So, first things first, we want this function to return an array. Also, you're referencing the elements of your 2d array incorrectly. Also, your conditions (checks) for the for loop are incorrect. You want i < arr.length, for example. Putting .length after an array's variable name will give you the number of elements in said array.
@EricHasegawa Indeed, comments can be edited for a period of time after they're posted
Eric Hasegawa
@EricHasegawa
Jun 26 2017 03:05

function largestOfFour(arr) {

  var standard = 0;

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

    for (var j=0; i< arr[j]; i++) {
      if (arr[j] > standard ) {
      standard = arr[j];
    }
    }




  }


  return standard;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@kumquatfelafel Is that looking better?
Sorry that second for loop should say j++, I corrected it in my code
aewalefo
@aewalefo
Jun 26 2017 03:09

Hello friends! I am working through "Stand in Line" in Basic Java Script.

These are the instructions:
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
This is what I've done so far:
function nextInLine(arr, item) {
// Your code here
arr = [1, 2, 3];
item = 4;
arr = arr.push(item);
arr = arr.shift(0);
return nextInLine;

I'm getting an error that says "arr.shift is not a function"

Can someone help me understand what I'm missing please?

Claudio Restifo
@Marmiz
Jun 26 2017 03:16
@aewalefo can you please post your code? with all the braces and functions call? It's hard to understand what you did with the info provided
aewalefo
@aewalefo
Jun 26 2017 03:18

@Marmiz sure, let me try to copy/paste again. I've been messing with it, so it's different now. This is my entire screen:

function nextInLine(arr, item) {
// Your code here
arr = [1, 2, 3];
item = 4;
arr.push(item);
removed = arr.shift();

return removed; // 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));

fdemaa
@fdemaa
Jun 26 2017 03:20
@EricHasegawa yes you should fix some things in the if also
Claudio Restifo
@Marmiz
Jun 26 2017 03:20
@aewalefo
You are passing two arguments to the functions, meaning that inside it arr and item are already declared and populated with values.
So for instance if I am calling my functions with some values they will be passed to my functions.
function nextInLine(arr, item) {
 // inside here arr is [1,2,3]
//and item is 6
}

nextInLine([1,2,3], 6)

while in your code you are:

var testArr = [1,2,3,4,5] //this is an array called testArray
nextInLine(testArr, 6)) // I am passing into my function testArray and 6

function nextInLine(arr, item) {
//i receive testArray and here it's called arr
// 6 is now called item


arr = [1, 2, 3]; // but wait now arr is this thig, it's no more testArray
item = 4; // same for item. now it's 4 and not 6
arr.push(item);
removed = arr.shift();
return removed; // Change this line
}

Make sense?

aewalefo
@aewalefo
Jun 26 2017 03:26
@Marmiz ok, so are you saying that I did not need to declare values for arr and item? I only need to "add the number to the end of the array, then remove the first element of array"?
Claudio Restifo
@Marmiz
Jun 26 2017 03:27

@aewalefo for the rest your function idea is correct:

arr.push(item);
removed = arr.shift();
return removed; // Change this line

but by declaring values inside the function with this:

arr = [1, 2, 3];
item = 4;

does not matter which value I decide to pass they will aways be [1,2,3] and 4. Which is not what you want, you want your function to works with the values it receive

aewalefo
@aewalefo
Jun 26 2017 03:27
@Marmiz GOT IT!!! :D
@Marmiz I deleted my assignments and it worked :) thank you!!
CamperBot
@camperbot
Jun 26 2017 03:28
aewalefo sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 961 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Jun 26 2017 03:30
@aewalefo to give you a simpler example: I create a function that takes a number and give me back the number +1.
But if inside i declare number to be a specific value it will always be that, no matter what I pass to it
function add1(num){
  num = 6
  return num +1
}

add1(3) // expect to be 4 but it return 7
add1(1) // expect to be 2 but return 7
CallMeOrange
@EgnaroDev
Jun 26 2017 03:31
Can someone help me with Profile Lookup :/
I think Im close but statements are probably wrong..
kumquatfelafel
@kumquatfelafel
Jun 26 2017 03:32

@EricHasegawa I would review nested for loops challenge.
You can think of a 2d array as being a bit like a grid.
arr[0][0] arr[0][1] arr[0][2] arr[0][3]
arr[1][0] arr[1][1] arr[1][2] arr[1][3]
arr[2][0] arr[2][1] arr[2][2] arr[2][3]

If you say arr, it will reference the entire array. If you say arr[0], it will reference the array containing elements arr[0][0] arr[0][1] arr[0][2] arr[0][3]. (note, each row is essentially it's own array).
If you want to reference a single value in the array, you have to include both coordinates, or "indices". For example, arr[1,1] would give me whatever value is stored in arr[1][1].

If I say arr.length, it will tell me how many elements (arr[0], arr[1], arr[2]) there are. You can also think of it like "how many rows".

If I say arr[0].length, it will tell me how many elements there are in arr[0] (arr[0][0], arr[0][1], arr[0][2], arr[0][3]).

When you say "i < arr[j]", this is wrong. When you say "arr[j] > standard", this is wrong. When you say "standard = arr[j]", this is also wrong.

You have the right idea, but you are not applying it properly for 2d-arrays, nested for loops, and you still need to take care of the return. The return itself will require not a single value, but an array of the highest value for each sub-array in the original array. Is there a function we can use to add elements to an array?

(technically, you don't have to do it this way, but understanding how to do it with nested for loop still important, and a good starting point)

grhiong
@grhiong
Jun 26 2017 03:34

function mutation(arr) {
// 请把你的代码写在这里
var first = arr.slice(0,1).join();
var str = arr.slice(1,2).join();
var sep = str.split("");
for(var i in sep)
{
if(first.toLowerCase().indexOf(sep[i].toLowerCase()) != -1)
{
return true;
}
else
{
return false;
}
}

}

mutation(["hello", "hey"]);
the result should be false,however it returns true,who can tell me the reason?

@Marmiz
CallMeOrange
@EgnaroDev
Jun 26 2017 03:35
Let me restart Profile Lookup then follow instructions by order this time :/
Alma Niu
@Justdoit2
Jun 26 2017 03:40
replacing if else chains with switch
CallMeOrange
@EgnaroDev
Jun 26 2017 03:41
@Justdoit2 Me?
Claudio Restifo
@Marmiz
Jun 26 2017 03:41
@grhiong I think you confused the -1 of indexOf.
indexOf return -1 if the element is not there... so why would you want to return true if the element is not there?
sethsdo
@sethsdo
Jun 26 2017 03:41
@fdemaa thanks for your tips, I got it worked out. Although it's not as elegant as I was wanting, the good thing is it works! :smile:
CamperBot
@camperbot
Jun 26 2017 03:41
sethsdo sends brownie points to @fdemaa :sparkles: :thumbsup: :sparkles:
:cookie: 292 | @fdemaa |http://www.freecodecamp.com/fdemaa
Joseph
@revisualize
Jun 26 2017 03:43
I don't feel like I've done enough in here today.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 03:43
@revisualize If it makes you feel any better, I don't feel like I've done enough anywhere today. :p
Joseph
@revisualize
Jun 26 2017 03:44
@kumquatfelafel I went on a couple of bike rides.
That was fun.
Of course, I have an electric bike.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 03:45
@revisualize It's... not powered by rodents... is it?
Matthew
@muzcmancoder91
Jun 26 2017 03:46
How do I Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.

function abTest(a, b) {
// Only change code below this line

// Only change code above this line

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

Joseph
@revisualize
Jun 26 2017 03:46
@muzcmancoder91 Write an if statement for me.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 03:47
Pretty much just took dogs for a few walks, got lunch, took shower. Not very eventful day.
Matthew
@muzcmancoder91
Jun 26 2017 03:48
an if statement for a and b together?
Joseph
@revisualize
Jun 26 2017 03:48
@muzcmancoder91 I didn't mention anything about a or b. I just asked you to write an if statement for me.
Matthew
@muzcmancoder91
Jun 26 2017 03:49
if (){
}
Joseph
@revisualize
Jun 26 2017 03:49
@muzcmancoder91 Great. Can you add a condition to that if statement ... for a variable a being less than 0?
Matthew
@muzcmancoder91
Jun 26 2017 03:50
if (a < 0) {
}
Joseph
@revisualize
Jun 26 2017 03:50
Great.
Matthew
@muzcmancoder91
Jun 26 2017 03:51
Thanks
Joseph
@revisualize
Jun 26 2017 03:51
@muzcmancoder91 Can you add an additional condition to that if condition for having another variable ... or b less than 0
Matthew
@muzcmancoder91
Jun 26 2017 03:52
} else if (b < 0) {
}
Joseph
@revisualize
Jun 26 2017 03:52
@muzcmancoder91 No.
Matthew
@muzcmancoder91
Jun 26 2017 03:52
?
Joseph
@revisualize
Jun 26 2017 03:52
@muzcmancoder91 I didn't mention anything about an else
Matthew
@muzcmancoder91
Jun 26 2017 03:54
Do I use a ||?
Joseph
@revisualize
Jun 26 2017 03:54
@muzcmancoder91 That's an or in JavaScript.
Matthew
@muzcmancoder91
Jun 26 2017 03:55
Ok could you give me a clue?
Joseph
@revisualize
Jun 26 2017 03:55
@muzcmancoder91 How about you show me what you've come up with and we'll work from there.
Matthew
@muzcmancoder91
Jun 26 2017 03:56
if (a < 0 || b < 0) {
return undefined;
}
Joseph
@revisualize
Jun 26 2017 03:56
@muzcmancoder91 GREAT!
@muzcmancoder91 So, what's your question again?
@muzcmancoder91 Did you see what I did there by the way that I asked you questions? And how I had you break the problem down. Then how you solved it on your own.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 03:59
@muzcmancoder91 If you feel like answering an additional conceptual question to test your understanding, why would you use || as opposed to && here?
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:04
please help problem 171
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:04
@DevinderThakur link/code?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:05
ah
tiger500
@tiger500
Jun 26 2017 04:05
guys can u help me Create a // style comment that contains at least five letters.
Create a / / style comment that contains at least five letters.
Make sure that you close the comment with a */.
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:07

my codes are...................................function nextInLine(arr, item) {
// Your code here
var removedNum= arr.shift();
arr.unshift(6);

return removedNum; // 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));

langtson
@langtson
Jun 26 2017 04:08
I think it means @tiger500
/* 12345 */
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:08

@DevinderThakur So your removal will *mostly* work properly, but mostly isn't quite always enough.

You're supposed to add to the end, and then afterwards remove from beginning of array.

tiger500
@tiger500
Jun 26 2017 04:09
@langtson thanks
CamperBot
@camperbot
Jun 26 2017 04:09
tiger500 sends brownie points to @langtson :sparkles: :thumbsup: :sparkles:
:cookie: 4 | @langtson |http://www.freecodecamp.com/langtson
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:10
@kumquatfelafel
Joseph
@revisualize
Jun 26 2017 04:10
@DevinderThakur You're doing things out of order.
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:10
@kumquatfelafel checking it
Joseph
@revisualize
Jun 26 2017 04:10
@DevinderThakur Also, where does .. .unshift() put the element?
@DevinderThakur Why are you using the arr parameter and not the item parameter?
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:11
@revisualize checking it
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:17
Yeah. You shouldn't be adding the literal value 6 to the array. You don't know what value the person using your function will want to add. They might add 6, sure, but they also might add 23, or "kumquatfelafel is spelled wrong".
victortran2015
@victortran2015
Jun 26 2017 04:22

Counting Cards
In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called Card Counting.

Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

Count Change Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K', 'A'
You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.

Example Output
"-3 Hold"
"5 Bet"

Hint
Do NOT reset count to 0 when value is 7, 8, or 9.

can anyone help me with this one please ?
This is what I have done so far

var count = 0;

function cc(card) {
// Only change code below this line
var count = 0;
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count=count+1;
break;

   case 7:
case 8:
case 9:
  count=count;
  break;


  case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
  count=count-1;
  break;

}

if (count<=0){

return "\""+count+" "+"Hold"+"\"" ;

}
else {return "\""+count+" "+"Bet"+"\"";

  }

}

// Only change code above this line
}

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

kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:24

@victortran2015 They don't actually want the quotes on the outside.

Just 0 Hold, 3 Bet, etc is fine.

severusKen
@severusKen
Jun 26 2017 04:24
Hi everyone, just a small question for the FrontEnd challenge number 145. I don't understand the first requirement which is: "myStr should have encoded text with the proper escape sequences and no spacing."
M-C-Haker
@M-C-Haker
Jun 26 2017 04:25
Looking for some assistance on the mymusic array. Task: Add a new album to the myMusic array. Add artist and title strings, release_year number, and a formats array of strings. To add a new ablum would you use some sort of .shift to add the album? how do you poing additional strings to specific properties?
severusKen
@severusKen
Jun 26 2017 04:25
My code has met all the requirement but this.
var myStr="\FirstLine\\nSecondLine\rThirdLine";
fdemaa
@fdemaa
Jun 26 2017 04:26
@M-C-Haker shift is for arrays, not for objects
you have an array?
M-C-Haker
@M-C-Haker
Jun 26 2017 04:26
it says its an array @fdemaa
fdemaa
@fdemaa
Jun 26 2017 04:27
do you have the code?
M-C-Haker
@M-C-Haker
Jun 26 2017 04:27
In fact it's an array which contains an object
I listed the task above here is code
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
];
fdemaa
@fdemaa
Jun 26 2017 04:31

you need to add another object,and inside that put the properties and the array that the exercise told you

To add the album wich is the object you have to do it like:

{

new album

}

Csaba Balogh
@JasonCorp84
Jun 26 2017 04:31
Hello everyone!
var obj2 = Object.keys(source).toString();// source keys
  var valami = source.obj2;
Joseph
@revisualize
Jun 26 2017 04:31
@severusKen Because you're not escaping things in the correct order ... your code isn't meeting all of the requirements.
Csaba Balogh
@JasonCorp84
Jun 26 2017 04:31
what is wrong with this ?
Joseph
@revisualize
Jun 26 2017 04:33
@JasonCorp84 Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
Csaba Balogh
@JasonCorp84
Jun 26 2017 04:33
@revisualize awesome! Thank you!
CamperBot
@camperbot
Jun 26 2017 04:33
jasoncorp84 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4258 | @revisualize |http://www.freecodecamp.com/revisualize
Csaba Balogh
@JasonCorp84
Jun 26 2017 04:34
That was exactly what i was looking for
severusKen
@severusKen
Jun 26 2017 04:34
@revisualize Oh i forgot the order ... Thks alot :)
tiger500
@tiger500
Jun 26 2017 04:35
how u make a should be assigned to b with =
dascreator
@dascreator
Jun 26 2017 04:35
Hello all, I am having a hard time figuring out what I am missing with a switch statement. Can anyone help?
Joseph
@revisualize
Jun 26 2017 04:35
@tiger500 How do you assign the value of 7 to a variable num?
tiger500
@tiger500
Jun 26 2017 04:36
var a=7;
var b = 7;
Joseph
@revisualize
Jun 26 2017 04:36
@tiger500 Nope.
tiger500
@tiger500
Jun 26 2017 04:36
then how
Joseph
@revisualize
Jun 26 2017 04:36
@tiger500 Can you answer my question?
Csaba Balogh
@JasonCorp84
Jun 26 2017 04:36
```var num = 7;
var num = 7;
Joseph
@revisualize
Jun 26 2017 04:37
@JasonCorp84 I'm asking them NOT you.
But, thanks though?
Csaba Balogh
@JasonCorp84
Jun 26 2017 04:37
sorry
M-C-Haker
@M-C-Haker
Jun 26 2017 04:37
@fdemaa oh i see now, i guess i was reading it wrong we're adding additional information to my music now necessiarily modifying what's in the current variable, if that makes any sense
@fdemaa thanks
CamperBot
@camperbot
Jun 26 2017 04:37
m-c-haker sends brownie points to @fdemaa :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @fdemaa |http://www.freecodecamp.com/fdemaa
fdemaa
@fdemaa
Jun 26 2017 04:37
@M-C-Haker np man!
Joseph
@revisualize
Jun 26 2017 04:38
@tiger500 How do you assign the value of 7 to a variable num? ... var num = 7;
Now if you want you can use a variable to store values.
Like in mathmatics. num + 3 = 10 What is the value of num?
var x = num + 3; ... That outputs 10
So, you can do several things with variables. But, you need to understand that variables hold values and variables can be used with other variables.
So, how do you assign the value of 5 to a variable x? ... x = 5; (Which is also overwriting the previous value of 10 from above.
How do you assign the value of x to a variable y?
Look at the way things are written. var y = x;
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:38
= is known as an assignment operator. You can ... I'm too tired. I leave this in your capable hands @revisualize :p
Matthew
@muzcmancoder91
Jun 26 2017 04:38
What's wrong with my code?

var total = 0;

for (var i = 0; i < myArray.length; i++){
total += myArray[i];
}

Use a for loop to work to push the values 1 through 5 onto myArray.
dascreator
@dascreator
Jun 26 2017 04:38
image.png
any help getting this one going would be greatly appreciated.
Joseph
@revisualize
Jun 26 2017 04:38
@dascreator You're console.log'ing when you should be changing the value of the variable answer
@dascreator Can you delete the spam?
dascreator
@dascreator
Jun 26 2017 04:39
sorry for the repetitive sends, my computer froze then released my several attempts at once. lol
Joseph
@revisualize
Jun 26 2017 04:39
@dascreator You can delete posts.
CallMeOrange
@EgnaroDev
Jun 26 2017 04:40
@revisualize Hey
Do you have any notes for Profile Lookup :/
Joseph
@revisualize
Jun 26 2017 04:40
@MCTwoDigitZero I do.
I've solved that challenge 5 different ways.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:40
(To delete, click ... that shows up when you drag mouse over your comment)
dascreator
@dascreator
Jun 26 2017 04:41
done thanks.
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:41
CallMeOrange
@EgnaroDev
Jun 26 2017 04:41
@revisualize Can you take a look at mine?
Joseph
@revisualize
Jun 26 2017 04:41
@MCTwoDigitZero Sure.
CallMeOrange
@EgnaroDev
Jun 26 2017 04:41


function lookUpProfile(firstName, prop) {

  for (var i = 0; i < contacts.length; i++) {
   console.log(contacts[i]);

  if (firstName !== contacts[i].firstName) {
   return "No such contact";
 } else if (prop !== contacts[i].hasOwnProperty(prop)) {
   return "No such property";
 }
  }

}

lookUpProfile("Kristian", "lastName");
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:41
@kumquatfelafel thanks
CamperBot
@camperbot
Jun 26 2017 04:41
devinderthakur sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Joseph
@revisualize
Jun 26 2017 04:42
@MCTwoDigitZero WHY!? WHY!? Did you post the huge array?
CallMeOrange
@EgnaroDev
Jun 26 2017 04:42
Relax..
Joseph
@revisualize
Jun 26 2017 04:42
@MCTwoDigitZero Okay. Let me ask you a question.
CallMeOrange
@EgnaroDev
Jun 26 2017 04:42
Yes?
dascreator
@dascreator
Jun 26 2017 04:42
@revisualize thanks for the help, got it!
CamperBot
@camperbot
Jun 26 2017 04:42
dascreator sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4259 | @revisualize |http://www.freecodecamp.com/revisualize
Matthew
@muzcmancoder91
Jun 26 2017 04:42

// Setup
var myArray = [];

// Only change code below this line.

for (var i = 0; i < 5; i++){
myArray.push(i);
}

Csaba Balogh
@JasonCorp84
Jun 26 2017 04:42

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

  if (collection[i].hasOwnProperty(valami)){

    arr.push(collection[i]);
  }
}
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:42
@camperbot how to send brownie points
Csaba Balogh
@JasonCorp84
Jun 26 2017 04:43
I got some weird error here
CallMeOrange
@EgnaroDev
Jun 26 2017 04:43
@DevinderThakur type thanks @person
You did it but no space
Matthew
@muzcmancoder91
Jun 26 2017 04:43
It says myArray should equal [1, 2, 3, 4, 5]
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:44
thanks@ @MCTwoDigitZero
CamperBot
@camperbot
Jun 26 2017 04:44
devinderthakur sends brownie points to @mctwodigitzero :sparkles: :thumbsup: :sparkles:
:cookie: 344 | @mctwodigitzero |http://www.freecodecamp.com/mctwodigitzero
CallMeOrange
@EgnaroDev
Jun 26 2017 04:44
@muzcmancoder91 So what is i < 5
Joseph
@revisualize
Jun 26 2017 04:44
@MCTwoDigitZero Let's first evaluate this:
(firstName !== contacts[i].firstName)
So, with the function call of .... lookUpProfile("Kristian", "lastName");
you're basically doing...
("Kristian" !== contacts[i].firstName)
Then you need to look at the fact that...
i = 0; on the first iteration.
So... ("Kristian" !== contacts[0].firstName)
Then.. ("Kristian" !== "Akira")
is ("Kristian" !== "Akira") true or false?
Matthew
@muzcmancoder91
Jun 26 2017 04:44
@MCTwoDigitZero I'm not sure :D
CallMeOrange
@EgnaroDev
Jun 26 2017 04:44
false?
Joseph
@revisualize
Jun 26 2017 04:45
@MCTwoDigitZero Look at it again.
CallMeOrange
@EgnaroDev
Jun 26 2017 04:45
@muzcmancoder91 i < 5 var i is less than 5
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:45
thanks @MCTwoDigitZero
CamperBot
@camperbot
Jun 26 2017 04:45
devinderthakur sends brownie points to @mctwodigitzero :sparkles: :thumbsup: :sparkles:
:warning: devinderthakur already gave mctwodigitzero points
CallMeOrange
@EgnaroDev
Jun 26 2017 04:45
@revisualize alright
Matthew
@muzcmancoder91
Jun 26 2017 04:45
I guess
Joseph
@revisualize
Jun 26 2017 04:45
@MCTwoDigitZero Is 1 !== 5 true or false?
CallMeOrange
@EgnaroDev
Jun 26 2017 04:45
@revisualize false
Joseph
@revisualize
Jun 26 2017 04:46
@MCTwoDigitZero 1 not equal to 5 ... is false?
Csaba Balogh
@JasonCorp84
Jun 26 2017 04:46
1 is not equal to 5
CallMeOrange
@EgnaroDev
Jun 26 2017 04:46
oh..
Joseph
@revisualize
Jun 26 2017 04:46
In what world is 1 not equal to 5 ... false?
Is this the twilight zone?
CallMeOrange
@EgnaroDev
Jun 26 2017 04:46
1 is not equal to 5..
Matthew
@muzcmancoder91
Jun 26 2017 04:46
yes it's not equal
CallMeOrange
@EgnaroDev
Jun 26 2017 04:46
I dont understand how it is true
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:46
@DevinderThakur I... don't remember what I did, but np :laughing:
CallMeOrange
@EgnaroDev
Jun 26 2017 04:46
Ok this is confusing
Joseph
@revisualize
Jun 26 2017 04:47
@MCTwoDigitZero Because 1 is NOT equal to 5.
Matthew
@muzcmancoder91
Jun 26 2017 04:47
Correct it's not
Joseph
@revisualize
Jun 26 2017 04:47
1 is 1 ... 5 is 5
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:47
thanks@ @kumquatfelafel
CamperBot
@camperbot
Jun 26 2017 04:47
devinderthakur sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: devinderthakur already gave kumquatfelafel points
CallMeOrange
@EgnaroDev
Jun 26 2017 04:47
Yes I understand... I thought it meant false
Ok its true
Joseph
@revisualize
Jun 26 2017 04:47
@MCTwoDigitZero Let's first evaluate this:
(firstName !== contacts[i].firstName)
So, with the function call of .... lookUpProfile("Kristian", "lastName");
you're basically doing...
("Kristian" !== contacts[i].firstName)
Then you need to look at the fact that...
i = 0; on the first iteration.
So... ("Kristian" !== contacts[0].firstName)
Then.. ("Kristian" !== "Akira")
is ("Kristian" !== "Akira") true or false?
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:47
Matthew
@muzcmancoder91
Jun 26 2017 04:47
I'm not just trying to figure out what I'm doing wrong
CallMeOrange
@EgnaroDev
Jun 26 2017 04:48
true
But doesn't it check all objects first?
Joseph
@revisualize
Jun 26 2017 04:48
@MCTwoDigitZero So because "Kristian" is not equal to "Akira" ... with it being true... The true statement is invoked.
@MCTwoDigitZero Where in my explanation do you see me looking at any other object?
Dave Reichert
@davidreichert
Jun 26 2017 04:49
I need help on Using Objects for Lookups
CallMeOrange
@EgnaroDev
Jun 26 2017 04:49
@revisualize None..
Dave Reichert
@davidreichert
Jun 26 2017 04:49

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

// 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;
}

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

Joseph
@revisualize
Jun 26 2017 04:49
@MCTwoDigitZero Okay.
Dave Reichert
@davidreichert
Jun 26 2017 04:49
// Setup
function phoneticLookup(val) {
  var result = "";

  // 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;
}

// Change this value to test
phoneticLookup("charlie");
M-C-Haker
@M-C-Haker
Jun 26 2017 04:49
@fdemaa ok i guess i'm still not doing something right
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:49
today i will only learn how to send brownie points @camperbot
Joseph
@revisualize
Jun 26 2017 04:49
@davidreichert You're overwriting the val parameter with an object.
CallMeOrange
@EgnaroDev
Jun 26 2017 04:49
So how do I make it to test all objects first?
M-C-Haker
@M-C-Haker
Jun 26 2017 04:49
var myMusic = [
[
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
]
[
{
"artist": "Rage Against the Machine",
"title": "Killing in the name of",
"release_year": 2010,
"formats": [
"CD",
"MP3",
"Apple Music"],
}
]
];
Joseph
@revisualize
Jun 26 2017 04:49
@MCTwoDigitZero You need to change your code.
CallMeOrange
@EgnaroDev
Jun 26 2017 04:49
Right..
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:49
Joseph
@revisualize
Jun 26 2017 04:50
@DevinderThakur You're not including a space.
CallMeOrange
@EgnaroDev
Jun 26 2017 04:50
@DevinderThakur You need space between them.. are you trolling?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:50
@muzcmancoder91 in your code, for the first iteration what is the value of i?
for(var i = 0; i < 5; i++) {
  arr.push(i); //the first time this line of your code is executed, what is added to array?
}
Dave Reichert
@davidreichert
Jun 26 2017 04:50
@revisualize What does var result = ""; do?
Devinder Thakur
@DevinderThakur
Jun 26 2017 04:50
no
Joseph
@revisualize
Jun 26 2017 04:50
@davidreichert It declares a variable called result and assigns it the value of an empty string.
@davidreichert What does var num = 7; do?
Dave Reichert
@davidreichert
Jun 26 2017 04:51
It creates a variable called num and assigns a value of 7 to it
Joseph
@revisualize
Jun 26 2017 04:51
@davidreichert Great.
jasonrest
@jasonrest
Jun 26 2017 04:51
Solved! quick question about Ceaser's Cipher. Why is it necessary to join after the decoded array has been arranged? I don't understand why that's necessary.
function rot13(str) { // LBH QVQ VG!  
  var abc = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'];

  var decoded = [];

  for (i = 0;i < str.length; i++){
    var newArr = abc.indexOf(str[i]) + 13;
    if (abc.indexOf(str[i]) == -1){
      decoded.push(str[i]);
    }
    else{
      decoded.push(abc[newArr]);
    }
  }
  return decoded.join(""); 
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Matthew
@muzcmancoder91
Jun 26 2017 04:51
@kumquatfelafel Is it 0?
Coy Sanders
@coymeetsworld
Jun 26 2017 04:52
because you need to return a string @jasonrest. decoded is an array
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:52
@muzcmancoder91 why is that your guess?
Joseph
@revisualize
Jun 26 2017 04:52
@jasonrest Because you're returning an array if you don't .join() ... The instructions state to return a string.
@coymeetsworld :wave:
Matthew
@muzcmancoder91
Jun 26 2017 04:53
Thanks @kumquatfelafel
CamperBot
@camperbot
Jun 26 2017 04:53
:cookie: 324 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
muzcmancoder91 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
Coy Sanders
@coymeetsworld
Jun 26 2017 04:53
@revisualize hey
Matthew
@muzcmancoder91
Jun 26 2017 04:53
I had to change the 0 to a 1
jasonrest
@jasonrest
Jun 26 2017 04:53
@coymeetsworld @revisualize got it. Thanks. attention to detail.
CamperBot
@camperbot
Jun 26 2017 04:53
jasonrest sends brownie points to @coymeetsworld and @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4260 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 2880 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:53
@muzcmancoder91 :+1:
Matthew
@muzcmancoder91
Jun 26 2017 04:53
Thanks! It's been a long evening haha
Coy Sanders
@coymeetsworld
Jun 26 2017 04:53
yep thats important @jasonrest :+1:
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:54
@muzcmancoder91 get it. Quite frankly, I'm surprised I'm still able to speak.
:p
Matthew
@muzcmancoder91
Jun 26 2017 04:54
Yes agreed :D
Dave Reichert
@davidreichert
Jun 26 2017 04:55
@revisualize Why doesn't this work?
// Setup
function phoneticLookup(val) {
  var result = "";

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

// Change this value to test
phoneticLookup("charlie");
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:55
@davidreichert Dave.val searches for "val" as opposed to "alpha" or "bravo" or etc.
Joseph
@revisualize
Jun 26 2017 04:56
@davidreichert Because you're doing it backwards.
M-C-Haker
@M-C-Haker
Jun 26 2017 04:56
trying to create a mymusic[1] object but it's saying that's not valid anyone have any advice on this challenge?
Joseph
@revisualize
Jun 26 2017 04:56
@davidreichert Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:56
^this :laughing:
Joseph
@revisualize
Jun 26 2017 04:57
@M-C-Haker How do you create an array with two elements... Each of them is an object: [ { ... } , { ... } ] The ...s are supposed to be your object properties.
tiger500
@tiger500
Jun 26 2017 04:58

// Setup
var a;
var b = 2;
var b=7;
var a=7;

// Only change code below this line

what did i do wrong

Joseph
@revisualize
Jun 26 2017 04:59
@tiger500 Did you read what I wrote?
@tiger500
How do you assign the value of 7 to a variable num? ... var num = 7;
Now if you want you can use a variable to store values.
Like in mathmatics. num + 3 = 10 What is the value of num?
var x = num + 3; ... That outputs 10
So, you can do several things with variables. But, you need to understand that variables hold values and variables can be used with other variables.
So, how do you assign the value of 5 to a variable x? ... x = 5; (Which is also overwriting the previous value of 10 from above.
How do you assign the value of x to a variable y?
Look at the way things are written. var y = x;
kumquatfelafel
@kumquatfelafel
Jun 26 2017 04:59
@tiger500 Hint: You can also have variables to the right of the assignment operator, =.
Joseph
@revisualize
Jun 26 2017 04:59
@tiger500 I posted it again for your reading pleasure.
@tiger500 You're also doing things out of order.
@tiger500 You're also changing code above the line.
Variables hold values.
tiger500
@tiger500
Jun 26 2017 05:03
@revisualize @kumquatfelafel thanks
CamperBot
@camperbot
Jun 26 2017 05:03
tiger500 sends brownie points to @revisualize and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 4261 | @revisualize |http://www.freecodecamp.com/revisualize
Csaba Balogh
@JasonCorp84
Jun 26 2017 05:04
  var obj2 = Object.keys(source).toString();// source keys
  var valami = source[obj2];

  for (var i = 0; i < collection.length){
   if(valami === collection[i][obj2]){
     arr.push(collection[i][obj2]);
   }
    }
what am I missing here ?
Jason Spence
@sfrjrs
Jun 26 2017 05:04
I'm stuck.
for (var i = 0; i < contacts.length; i++) {
if(contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)) {
return contacts[i].prop;
} else if(contacts[i].firstName != firstName) {
return 'No such contact';
} else if(!contacts[i].hasOwnProperty(prop)) {
return 'No such property';
}
}
Joseph
@revisualize
Jun 26 2017 05:04
@sfrjrs You have a few issues.
@sfrjrs First...
@sfrjrs Re: contacts[i].prop; ... Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
Ruben Dario
@rubendmatos1985
Jun 26 2017 05:05
Hello friends. I need some help
M-C-Haker
@M-C-Haker
Jun 26 2017 05:05
@revisualize that's pretty much what i have, but it is not correct
var myMusic =
[
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
];
[
{
"artist": "Rage Against the Machine",
"title": "Killing in the name of",
"release_year": 2010,
"formats": [
"CD",
"MP3",
"Apple Music"],
}
];
Joseph
@revisualize
Jun 26 2017 05:05
@M-C-Haker It isn't correct.
Ruben Dario
@rubendmatos1985
Jun 26 2017 05:06
I am making the diferent challenges
in Jascript
Manish Giri
@Manish-Giri
Jun 26 2017 05:06
@M-C-Haker looks like you have 2 sets of [ ]?
Zack
@CrowsVeldt
Jun 26 2017 05:06
@JasonCorp84 You're missing the iterator in your 'if' statement. add: i++ to the end
Ruben Dario
@rubendmatos1985
Jun 26 2017 05:06
but i made the code correctly
and the web site dont let me go forward
Zack
@CrowsVeldt
Jun 26 2017 05:06
@JasonCorp84 That's what I noticed anyway
Manish Giri
@Manish-Giri
Jun 26 2017 05:06
@M-C-Haker to add elements to an array, you only separate them with ,
like numbers = [1, 2, 3]
Csaba Balogh
@JasonCorp84
Jun 26 2017 05:06
@CrowsVeldt thank you!
CamperBot
@camperbot
Jun 26 2017 05:06
jasoncorp84 sends brownie points to @crowsveldt :sparkles: :thumbsup: :sparkles:
:cookie: 292 | @crowsveldt |http://www.freecodecamp.com/crowsveldt
Zack
@CrowsVeldt
Jun 26 2017 05:06
:)
M-C-Haker
@M-C-Haker
Jun 26 2017 05:07
@revisualize correct dirctions state "Add a new album to the myMusic array. Add artist and title strings, release_year number, and a formats array of strings." so basically create another array first on billy joel already given,..
Joseph
@revisualize
Jun 26 2017 05:07
@M-C-Haker You have this...
var myMusic =
[
{
....
}
];  // the ; is a statement terminator 
[
{
...
}
];
Manish Giri
@Manish-Giri
Jun 26 2017 05:07
if your array elements are objects, same rule applies
things = [{ object1}, {object2}]
@M-C-Haker
Joseph
@revisualize
Jun 26 2017 05:07
@M-C-Haker You're making [ { ... } ] ; [ { ... } ]
Manish Giri
@Manish-Giri
Jun 26 2017 05:07
@rubendmatos1985 post your code.
Ryan Nelson
@iamryandnelson
Jun 26 2017 05:08
I'm getting a horrible audio lag on mobile :worried: . Can someone tell me how to fix this, please?
https://codepen.io/iamryandnelson/pen/BZWrmq
Jon
@jonandrepedersen
Jun 26 2017 05:08
function truncateString(str, num) {
  var reLength = str.slice(0,num);

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

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Can't believe I actually made this all by myself. Very proud. However, I would like to ask if there are any bad habits or otherwise better ways of coding this. Help much appreciated.
https://www.freecodecamp.com/challenges/truncate-a-string
M-C-Haker
@M-C-Haker
Jun 26 2017 05:08
@Manish-Giri it's asking me to add another album, if i just separate with commons it is telling me i have duplicate properties
Manish Giri
@Manish-Giri
Jun 26 2017 05:09
@M-C-Haker fix the problem of the double [ ] I pointed out, then post your code again
M-C-Haker
@M-C-Haker
Jun 26 2017 05:10
@Manish-Giri you're the man, thanks i should have been using the comma, instead of the ';'
CamperBot
@camperbot
Jun 26 2017 05:10
m-c-haker sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6116 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jun 26 2017 05:10
@M-C-Haker :+1:
Joseph
@revisualize
Jun 26 2017 05:10
@sfrjrs Second...
When you make the function call of lookUpProfile("Kristian", "lastName");
You have a problem with...
else if(contacts[i].firstName != firstName)
Because if we break it down when i = 0;
(contacts[i].firstName != firstName)
(contacts[0].firstName != firstName)
(contacts[0].firstName != "Kristian")
("Akira" != "Kristian")
... You're then doing a return "No such contact";
M-C-Haker
@M-C-Haker
Jun 26 2017 05:10
@Manish-Giri how long have you been coding?
Manish Giri
@Manish-Giri
Jun 26 2017 05:11
@M-C-Haker been a while, about 4 years seriously, 6-7 in total..
David Bercovici
@davidberco
Jun 26 2017 05:11
Hello everyone, the task of word blanks in javascript, which operators do I have to use?
Manish Giri
@Manish-Giri
Jun 26 2017 05:12
@davidberco + for string concatenation..
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:12
@jonandrepedersen If num is 2, for example, and str is 10 characters long, your return should be the first 2 characters of str, followed by "..."
Joseph
@revisualize
Jun 26 2017 05:12
@davidberco = and +
Jon
@jonandrepedersen
Jun 26 2017 05:12
@kumquatfelafel I will test that now, thanks
CamperBot
@camperbot
Jun 26 2017 05:13
jonandrepedersen sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
M-C-Haker
@M-C-Haker
Jun 26 2017 05:13
@Manish-Giri ok i'm happy to here that, i think this is the 2nd or 3rd time you've helped me out and i was starting to get a little frustated and wondering how come this guy has all the answers lol. Not everyone is counting in the weeks like me i guess. Appreciate the help again.
Manish Giri
@Manish-Giri
Jun 26 2017 05:14
lol
welcome, and good luck!
@M-C-Haker
Jon
@jonandrepedersen
Jun 26 2017 05:14
@kumquatfelafel it does do that. And as mentioned, I succeeded in the challenge. However, I am sure the code could have been written better
David Bercovici
@davidberco
Jun 26 2017 05:14
@revisualize there is something I missing because I cannot get the result, thanks I will try it harder
CamperBot
@camperbot
Jun 26 2017 05:14
davidberco sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4262 | @revisualize |http://www.freecodecamp.com/revisualize
Manish Giri
@Manish-Giri
Jun 26 2017 05:15
@davidberco remember to add spaces, you won't pass without those.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:15
@jonandrepedersen oh. Misread that as asking for help. I should be going to sleep haha
Jon
@jonandrepedersen
Jun 26 2017 05:16
@kumquatfelafel Hehe no worries, but maybe you also meant that I shouldn't rely on my new variable but rather keep the code consistent with str? That there is no need for the var basically? :)
I got a feeling of that, just not sure how I would go about it
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:17
@jonandrepedersen Maybe. Whatever is right. That's obviously what I meant. :p
Joseph
@revisualize
Jun 26 2017 05:17
Okay.
David Bercovici
@davidberco
Jun 26 2017 05:17
@Manish-Giri hum, spaces into the strings? I'm quite lost
Jon
@jonandrepedersen
Jun 26 2017 05:18
@kumquatfelafel :p
Joseph
@revisualize
Jun 26 2017 05:18
@davidberco " " <-- a space
"These words have spaces between them."
Manish Giri
@Manish-Giri
Jun 26 2017 05:19
@davidberco when you use the function parameters, you need to add spaces between them, like
myNoun + " " + ... + " " + ...
CallMeOrange
@EgnaroDev
Jun 26 2017 05:20
@revisualize You said you had 5 ways to solve Profile Lookup, can you use switch statements?
David Bercovici
@davidberco
Jun 26 2017 05:20
@revisualize oh got it
@Manish-Giri oh now I know what you mean
Joseph
@revisualize
Jun 26 2017 05:20
@MCTwoDigitZero Yes, but, that's just silly.
CallMeOrange
@EgnaroDev
Jun 26 2017 05:20
True
I was curiously :/ , not planning to use it
Ryan Nelson
@iamryandnelson
Jun 26 2017 05:21
Why do I get a horrible audio lag on mobile? :worried: . Anyone had this problem?
https://codepen.io/iamryandnelson/pen/BZWrmq
CallMeOrange
@EgnaroDev
Jun 26 2017 05:22
Looks like I wont be able to solve Profile Lookup today
Night...
Joseph
@revisualize
Jun 26 2017 05:23
@MCTwoDigitZero Did you read the document that I linked you to?
CallMeOrange
@EgnaroDev
Jun 26 2017 05:23
@revisualize No sorry.. I deleted the tab
can you link me to it again?
Too many tabs annoyed me, sorry
CallMeOrange
@EgnaroDev
Jun 26 2017 05:23
@revisualize thanks
CamperBot
@camperbot
Jun 26 2017 05:23
mctwodigitzero sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4263 | @revisualize |http://www.freecodecamp.com/revisualize
CallMeOrange
@EgnaroDev
Jun 26 2017 05:24
I will read it when I come back
Night guys
Mohamed Osman
@trc5019
Jun 26 2017 05:24
Hey guys I'm creating a factory function and needed some help . I wanted to know why introduce is not a function here when i call it on the person object
function person(firstName, lastName, age, gender, employed, occupation, married) {
return {
   sayName() {
     return firstName + " " + lastName;
   }

}  

return {
    introduce() {
     return "Hello, my name is " + firstName + " " + lastName + "." + "I am " + age + " years old. I am a " + gender + ".";
   }

 }
}

var john = person("John", "Doe", 18, "male", false, null, true);

console.log(john.introduce());
Joseph
@revisualize
Jun 26 2017 05:24
@trc5019 Ummm...
@trc5019 introduce() will never get accessed.
Manish Giri
@Manish-Giri
Jun 26 2017 05:25
@trc5019 the return after the first point terminates the function.
Joseph
@revisualize
Jun 26 2017 05:26
The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:26

@MCTwoDigitZero For example.

if (x < a) 
  doSomething();
else if(x < b)
  doSomethingElse();
else
  dance();

is logically equivalent to

switch(true){
case x<a:
  doSomething();
  break;
case x<b:
  doSomethingElse();
  break;
default:
  dance();
  break;
}

But you'd never really go through the trouble of doing something like that with a switch statement.

Mohamed Osman
@trc5019
Jun 26 2017 05:26
@Manish-Giri i understand so what can i do to make it work?
Manish Giri
@Manish-Giri
Jun 26 2017 05:27
@trc5019 maybe create an object with the 2 functions as properties, and return that object?
CallMeOrange
@EgnaroDev
Jun 26 2017 05:27
@kumquatfelafel I dont like switch statements, I can use it but I want to use if statements for this challenge
I was charging my laptop, so Im leaving...
Bye
Mohamed Osman
@trc5019
Jun 26 2017 05:28
@Manish-Giri thanks
CamperBot
@camperbot
Jun 26 2017 05:28
trc5019 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6117 | @manish-giri |http://www.freecodecamp.com/manish-giri
David Bercovici
@davidberco
Jun 26 2017 05:28
I'm still in the problem of madlibs. I cannot figure out what is the meaning of:
wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
Ian Nicholson
@ipnicholson
Jun 26 2017 05:29

What am I doing wrong?

Type Error: arr.shift is not a function.

function nextInLine(arr, item) {
  arr = arr.push(item);
  removed = arr.shift();
  return removed;  
}
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:29
@ipnicholson arr.push() returns length of array iirc
Krittiya Clark
@krittiyaclark
Jun 26 2017 05:29
Hi everyone - I am struck with the weather app project. What is a better way to show weather icons? I use http://erikflowers.github.io/weather-icons/
Ian Nicholson
@ipnicholson
Jun 26 2017 05:30
Manish Giri
@Manish-Giri
Jun 26 2017 05:30
@ipnicholson arr.push() returns the length of the new array, so arr is now a number.
and .shift() won't work on number.
@davidberco code?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:30
@ipnicholson ^^^ It does both. Many functions perform an operation along with returning a value of some kind. Well... other than undefined. But either way, you wouldn't want arr = arr. push(item) unless you were sure that push returned the new array. Which, as stated, it doesn't so this gets you into trouble.
Ian Nicholson
@ipnicholson
Jun 26 2017 05:34
@Manish-Giri I'm calling this on an array:
// 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));
Manish Giri
@Manish-Giri
Jun 26 2017 05:35
@ipnicholson if you're stuck - post your code, not the setup
Veronica Eulenberg
@HappyViki
Jun 26 2017 05:36
Why doesn’t it return the length?
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  arr = collection.filter(function(value){
    var sNum = 0;
    for (var i in source) {
      if (value[i] == source[i]) {
        return source.length;
      }
    }

  });

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

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });
Ian Nicholson
@ipnicholson
Jun 26 2017 05:36
@Manish-Giri Here's everything:
function nextInLine(arr, item) {
  arr = arr.push(item);
  removed = arr.shift([0]);
  return removed;  
}

// 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));
Manish Giri
@Manish-Giri
Jun 26 2017 05:37
@ipnicholson
  1. as I said earlier, .push() returns a length
  2. .shift() doesn't take any arguments, just .shift()
Joseph
@revisualize
Jun 26 2017 05:37

@ipnicholson Because of how you've written your code. You're making arr a number.
Look:
The push() method adds one or more elements to the end of an array and returns the new length of the array.
So, when you do:

var myArr = [ 2 , 4 , 6 , 8 ];
var len = myArr.push(10);

the value of myArr becomes [ 2 , 4 , 6 , 8 , 10 ]
And the value of len is a number 5
But, instead by doing....

var myArr = [ 2 , 4 , 6 , 8 ];
var myArr = myArr.push(10);

myArr is now just 5

Manish Giri
@Manish-Giri
Jun 26 2017 05:37
@ipnicholson unless you need the length of the new array, you should just do arr.push(item)
Urio
@Urio
Jun 26 2017 05:37
hello can someone tell me why
arr[i].toLowerCase()
doesnt work on arr=["hello","Hello"]?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:37
Joseph
@revisualize
Jun 26 2017 05:37
@Urio Strings are immutable.
Manish Giri
@Manish-Giri
Jun 26 2017 05:38
@Urio you need to save the value from .toLowerCase()
it won't change in place.
Joseph
@revisualize
Jun 26 2017 05:38
@Urio
var myArr = [ "Word" ];
myArr[0].toLowerCase(); // This doesn't mutate the Array element.
Urio
@Urio
Jun 26 2017 05:39
@revisualize that's what I have
Joseph
@revisualize
Jun 26 2017 05:39
@Urio But, that doesn't work.
David Bercovici
@davidberco
Jun 26 2017 05:39

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

// Your code above this line
return result;
}

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

Joseph
@revisualize
Jun 26 2017 05:39
@Urio myArr[0] is a string and strings are immutable.
Manish Giri
@Manish-Giri
Jun 26 2017 05:39
@davidberco where's the code you wrote?
Aizaz Shahid
@aizazshahid
Jun 26 2017 05:40
@Urio .toLowerCase() returns the new string, so you also need to assign it.
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:40
And the way toLowerCase gets around strings being immutable is by returning a new string, and thus you need to... ^^^
Ian Nicholson
@ipnicholson
Jun 26 2017 05:40
@Manish-Giri @revisualize Thanks, I will have another go at it. That .push() returns the length of the new array was not made clear to me in the lesson on it.
CamperBot
@camperbot
Jun 26 2017 05:40
ipnicholson sends brownie points to @manish-giri and @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4264 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 6118 | @manish-giri |http://www.freecodecamp.com/manish-giri
Urio
@Urio
Jun 26 2017 05:41
@revisualize Thanks I fixed it
CamperBot
@camperbot
Jun 26 2017 05:41
urio sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4265 | @revisualize |http://www.freecodecamp.com/revisualize
Veronica Eulenberg
@HappyViki
Jun 26 2017 05:41
How do I get source’s length?
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

return source.length;

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

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });
Joseph
@revisualize
Jun 26 2017 05:41
@HappyViki source is an object.
David Bercovici
@davidberco
Jun 26 2017 05:41
@Manish-Giri myNoun += myAdjective += myVerb += myAdverb;
Joseph
@revisualize
Jun 26 2017 05:42
@HappyViki Do Objects have .lengths?
Manish Giri
@Manish-Giri
Jun 26 2017 05:42
what's the += for?
@davidberco
Joseph
@revisualize
Jun 26 2017 05:42
I need to go to bed.
Veronica Eulenberg
@HappyViki
Jun 26 2017 05:42
@revisualize it doesn’t look like it. that’s why I’m asking.
Joseph
@revisualize
Jun 26 2017 05:43
@HappyViki You can't get the length of an object.
Veronica Eulenberg
@HappyViki
Jun 26 2017 05:43
@revisualize I guess I’ll go a different route then :(
Joseph
@revisualize
Jun 26 2017 05:44
@HappyViki You can get all of the Object Keys and have them put into an array.. then you can get the .length of the new array.
Joseph
@revisualize
Jun 26 2017 05:45
Which is linked in the...
Here are some helpful links:
Global Object
Object.prototype.hasOwnProperty()
Object.keys()
Veronica Eulenberg
@HappyViki
Jun 26 2017 05:45
lol
me = lazy
me = should stop being lazy
;being lazy isn’t helpful.
Joseph
@revisualize
Jun 26 2017 05:46
It's like someone wanted to help you. So, they gave you a list of some possible helpful links.
Okay. I'm out.
Baibhav Gautam
@baibhavx
Jun 26 2017 05:52
Guys I am doing the pomodoro clock project. In order to tick the clock down I am trying to use setTimeout inside a while loop but its not working and the browser freezes. Anyone know whats going on?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 05:53
@davidberco Not only do you need the words, you also need to include spaces between the words.
rajeshvarisharma
@rajeshvarisharma
Jun 26 2017 05:59
Stand in Line 169
function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
return item; // Change this line
}
error?
Coy Sanders
@coymeetsworld
Jun 26 2017 06:00
what is your function returning @rajeshvarisharma ?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:00
@rajeshvarisharma You want to return the item you've removed.
Coy Sanders
@coymeetsworld
Jun 26 2017 06:00
and what do they ask you to return?
rajeshvarisharma
@rajeshvarisharma
Jun 26 2017 06:00
function should return the lement that was removed
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:01
@rajeshvarisharma how do we do that?
Coy Sanders
@coymeetsworld
Jun 26 2017 06:04
@rajeshvarisharma but your code isn't doing that, its returning item
the parameter you're passing in
Gary Fitzwater
@garyfalkland
Jun 26 2017 06:04
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(val);
    case 1:
    answer = "alpha";
    break;

      case 2:
    answer = "beta";
    break;

      case 3:
    answer = "gamma";
    break;

      case 4:
    answer = "delta";
    break;

    default:
      break;


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

// Change this value to test
caseInSwitch(1);
Cant figure this out
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:06
@garyfalkland
switch (val){
blah blah blah
}
Gary Fitzwater
@garyfalkland
Jun 26 2017 06:07
Yeah got thanks
@kumquatfelafel thanks
CamperBot
@camperbot
Jun 26 2017 06:07
garyfalkland sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 327 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Nitin Sahu
@globefire
Jun 26 2017 06:07
var myStr = '<a href= http://www.example.com';
var target = "_blank>Link</a>";

Remove all the backslashes ()
You should have two single quotes ' and four double quotes "
Only remove the backslashes \ used to escape quotes.

var myStr = '<a href= http://www.example.com';

var target = "_blank>Link</a>";

kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:07
@garyfalkland np. Apologies for somewhat lackluster attempt there, but been a long day :p
Nitin Sahu
@globefire
Jun 26 2017 06:07
this is the requirement can't figure out
somebody help
lol anyone there?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:10
@globefire target is not a variable here. That bit was a part of the original string.

target="_blank">Link</a>

Add this ^^^ back into your string myStr, where it was originally.

Nitin Sahu
@globefire
Jun 26 2017 06:12
ok but according to requirement they want me to remove all bacslashes also they need me to remove backslashes \ to used escape quotes i can't understand what to do
ok fine i'll try
image.png
image.png
image.png
Joshua Frias
@Juke-Magic
Jun 26 2017 06:16
guys how to extract "hey" in ["hello", "hey"] using slice
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:16
\ = backslash. Have you deleted all the backslashes in that string, or are there still backslashes present?
Nitin Sahu
@globefire
Jun 26 2017 06:16
no there are backslashes
Stanford Lin
@StanfordLin
Jun 26 2017 06:17
Hi, I need some help with Using Objects for Lookups
Nitin Sahu
@globefire
Jun 26 2017 06:17
there is a condition which says remove all backslashes and there's another condition which says "Only remove the backslashes \ used to escape quotes"
Joshua Frias
@Juke-Magic
Jun 26 2017 06:17
nvm
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:18
@globefire whenever a \ comes immediately before a ", it is being used to escape quotes.
Nitin Sahu
@globefire
Jun 26 2017 06:19
yup I got it

You should have two single quotes ' and four double quotes "

then what does this condition means?

kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:20
The other aspect of this is that you might notice, things have gone a bit off now that you've removed the backslashes. The reason for this is that when the " characters are not escaped, they're treated as the beginning/end of a string.
Nitin Sahu
@globefire
Jun 26 2017 06:21
yes correct
@globefire what about this condition?
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:22
However, if you replace the outermost " on both sides with ', it will treat " as ", much like it did when you had the \
Nitin Sahu
@globefire
Jun 26 2017 06:23
ohhhh i got it
thanks man
Stanford Lin
@StanfordLin
Jun 26 2017 06:23
nvm I got it
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:24
@globefire so "a\"\"\"a" and 'a"""a' will give you same string, but the second one a lot easier to type right? ;)
Nitin Sahu
@globefire
Jun 26 2017 06:24
thanks @kumquatfelafel
CamperBot
@camperbot
Jun 26 2017 06:24
globefire sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 328 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:24
np
Nitin Sahu
@globefire
Jun 26 2017 06:25
yes @kumquatfelafel perfect
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:26
@globefire One thing worth noting though is that when you have single quotes ' on the outside, suddenly you have to use \ to escape single quotes on the inside :laughing:
So it's kind of a trade-off... one poison for another. :p
David Bercovici
@davidberco
Jun 26 2017 06:28
@Manish-Giri adding the word to string :|
Kelechi Chinaka
@ke1echi
Jun 26 2017 06:33
@Manish-Giri so much ambiguities i cant place ma hands on..still have not fixed that code
Menlam Choden
@menlam
Jun 26 2017 06:44

function bouncer(arr) {
// Don't show a false ID to this bouncer.

var right=arr.filter(function(arr){return arr;});
return right;
}

bouncer([7, "ate", "", false, 9]);
*this is my code and it works,,, i wasjust testing ,,but instead it worked for all testcases,, how,,, should't it return all array

Joshua Frias
@Juke-Magic
Jun 26 2017 06:45
guys will a==A be true??
tiger500
@tiger500
Jun 26 2017 06:49
guys how do u studlyCapVar is defined and has a value of 10
Dan Couper
@DanCouper
Jun 26 2017 06:50
@21-Orange case sensitive, so no.
tiger500
@tiger500
Jun 26 2017 06:52
how do u define studlyCapvar as a value of 10
anyone
kumquatfelafel
@kumquatfelafel
Jun 26 2017 06:58

@menlam filter keeps values in array that meet a given condition and doesn't keep those that don't. In this case, when you say return arr (which is not the same as the arr you're filtering btw), this is actually coerced into a value that is either true or false (behind the scenes). In javascript, there are "falsy" and "truthy" values. Falsy values are values other than and including false that, when cast to a boolean, become false. Truthy values become true.

https://developer.mozilla.org/en-US/docs/Glossary/Falsy
https://developer.mozilla.org/en-US/docs/Glossary/Truthy

Dan Couper
@DanCouper
Jun 26 2017 06:58
@menlam You have stumbled across the easiest way to solve this, but you've named your parameter confusingly. filter goes through your array one by one, and the function runs once for every value. The argument you give to that function just represents one value. You've called it arr, but inside that function it isn't the array, it's just a value in the array, you have just given it the same name. arr.filter(function(arrValue) { return arrValue; }). Does that make sense? I'll explain why it works if it does
Menlam Choden
@menlam
Jun 26 2017 07:00
@DanCouper yeah can you explain me why it works hehe,,, very confusing whatever you said,, new to programming
kumquatfelafel
@kumquatfelafel
Jun 26 2017 07:01
@DanCouper I'll leave it in your capable hands (*evil laugh*)
G'night :p
Menlam Choden
@menlam
Jun 26 2017 07:02
@kumquatfelafel sorry did not see your comment..hehe.. thanks though :)
CamperBot
@camperbot
Jun 26 2017 07:02
menlam sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 329 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Dan Couper
@DanCouper
Jun 26 2017 07:03
@menlam So it's what @kumquatfelafel said as well, filter takes a function that has to return true of false for a single value. You give that function to filter, and filter runs it for every element in your array. 2 secs, I'll just get to my computer, it's easier if I show an example
Hard to type on a phone
kumquatfelafel
@kumquatfelafel
Jun 26 2017 07:03
@menlam Honestly, I'm so tired I have no clue how much of that is true. It just seemed like I was only one on at moment haha
though yeah. night
Dan Couper
@DanCouper
Jun 26 2017 07:04
:) :sleeping:
Menlam Choden
@menlam
Jun 26 2017 07:04
@DanCouper Yeah that I understood, but I have not given any conditions, so on what basis is it getting filtered
@kumquatfelafel night , thanks anyway
CamperBot
@camperbot
Jun 26 2017 07:05
menlam sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: menlam already gave kumquatfelafel points
Dan Couper
@DanCouper
Jun 26 2017 07:05
:thumbsup: sooooo, the function has to return true or false, and if it doesn't, filter will convert truthy values to true, and falsey values to false
Menlam Choden
@menlam
Jun 26 2017 07:06
Oh @DanCouper now I got it,, thanks :)
CamperBot
@camperbot
Jun 26 2017 07:06
menlam sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 806 | @dancouper |http://www.freecodecamp.com/dancouper
Dan Couper
@DanCouper
Jun 26 2017 07:06
so if you just return the value, it will read bouncer([7, "ate", "", false, 9]); as bouncer([true, true, false, true, true])
Note this is exactly what if statements do as well - if(0) will be false, if(1) will be true
:thumbsup: is a bit magical, JS rules for coercing things to true or false are something you have to be careful with (you'll find it's one of the major problems in the language, because wierd things sometimes get treated as true/false)
Menlam Choden
@menlam
Jun 26 2017 07:10
okay @DanCouper thanks a lot
CamperBot
@camperbot
Jun 26 2017 07:10
menlam sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: menlam already gave dancouper points
Dan Couper
@DanCouper
Jun 26 2017 07:12
:) Oh, and this is the same as using the filter, just for completeness:
result = [];
for (let i = 0; i < arr.length; i++) {
  if (arr[i]) result.push(arr[i])
}
return result;
Menlam Choden
@menlam
Jun 26 2017 07:14
@DanCouper :+1:
Blauelf
@Blauelf
Jun 26 2017 07:18
I think JavaScript's coercion rules to boolean are not that weird (six falsy values, anything else is truthy). Coercion rules for example for == or + are a lot weirder.
Kshitijaa Jaglan
@KshitijaaJaglan
Jun 26 2017 07:24
how can I add a fade in effect using js to body on loading? codepen link-https://codepen.io/Kshitijaa/pen/PjJzzZ
Dan Couper
@DanCouper
Jun 26 2017 07:25
@Blauelf it's more when you're checking things like existence of stuff in the DOM it gets painful; it's not that they're hard, it's that you just need to be careful & that there are a few footguns
if can force a very defensive coding style, which means more boilerplate
Blauelf
@Blauelf
Jun 26 2017 07:27
@DanCouper Like a property in one browser being a string (which could be empty and therefore falsy) and a function in another browser (which is always truthy)? I think I've seen such thing, but usually wrote code like if (typeof something === "function").
Stanford Lin
@StanfordLin
Jun 26 2017 07:28
Hey, can anyone give me a hand on nesting for loops?
Dan Couper
@DanCouper
Jun 26 2017 07:30
Was thnking more like
const foo = document.querySelector('.foo');
const bars = document.querySelectorAll('.bars');

// ..........later
if (foo) /* do something */;
if (bars) /* do something else, but this is always true */;
Very easy to fix, but very easy to make the mistake in the first place
& gets painful on large apps
Stanford Lin
@StanfordLin
Jun 26 2017 07:34
nvm, got it to work
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:34
hi guys
Write function parseFloat (for Javascript parseF) which takes a string and returns a number or Nothing (for Python None, for Javascript null) if conversion is not possible.
function parseF(s) {
  return (isNaN(Number(s)) == true) ? null : parseFloat(Number(s));
}
what am i doing wrong
@Blauelf
Blauelf
@Blauelf
Jun 26 2017 07:38
Looks like a codewars kata :D
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:38
yea :smile: @Blauelf
Blauelf
@Blauelf
Jun 26 2017 07:39
@kelechichinaka I think that one should at least return null for empty string. Do you have specific test cases where it fails?
Or did they somehow keep you from using parseFloat? (BTW, Number(s) already creates a float)
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:42
should return null where its NaN
Claudio Restifo
@Marmiz
Jun 26 2017 07:43
@kelechichinaka I suggest you to use Number.isNaN instead of the plain isNaN method.
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:43
am having a hard time with the isNaN
Blauelf
@Blauelf
Jun 26 2017 07:44
Are ".5" or "5." valid numbers in this definition?
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:45
yes
Claudio Restifo
@Marmiz
Jun 26 2017 07:46
@kelechichinaka is a string like two suppose to be returned?
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:47
no 2.0
Claudio Restifo
@Marmiz
Jun 26 2017 07:47
Because if not you can simply switch to:
  return (Number.isNaN(s) === true) ? null : parseFloat(Number(s));
tried that already , fails 2 tests @Marmiz
Claudio Restifo
@Marmiz
Jun 26 2017 07:48
even better : Number(s) since as @Blauelf suggested you don't need to parse it in this case
Blauelf
@Blauelf
Jun 26 2017 07:48
I just tried a regular expression, and it worked well.
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:49
:clap: never imagined that
Blauelf
@Blauelf
Jun 26 2017 07:50
Probably overkill. Most of the solutions tested on isNaN(parseFloat(s)).
Oh, test cases are not complete. The test case "47,11" would return 47 for many of the solutions, as parseFloat would end parsing at ,.
Kelechi Chinaka
@ke1echi
Jun 26 2017 07:53
am lost :worried: @Blauelf
mrjerem
@mrjerem
Jun 26 2017 07:53

help I have no idea where to start "The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.

You are given a variable celsius representing a temperature in Celsius. Use the variable fahrenheit already defined and apply the algorithm to assign it the corresponding temperature in Fahrenheit.

Blauelf
@Blauelf
Jun 26 2017 07:55
@kelechichinaka The test cases allow about any solution, complete or not.
Tiago Malheiro
@Azzrah
Jun 26 2017 07:55
is this a bug? why this works in this challenge https://www.freecodecamp.com/challenges/falsy-bouncer
function bouncer(arr) {
 var correct = arr.filter(function correction(value){
   return value;
  });
  return correct;
}

bouncer([1, null, NaN, 2, undefined]);
Claudio Restifo
@Marmiz
Jun 26 2017 07:55
@mrjerem it's like math, but instead of x and y 's you name them Celsius and Farenheit
Blauelf
@Blauelf
Jun 26 2017 07:56
@Azzrah filter treats all truthy values like true and all falsy values like false
Tiago Malheiro
@Azzrah
Jun 26 2017 07:57
@Blauelf So filter does all the work by itself? Well that was lucky of me, I reached this code by mistake
mrjerem
@mrjerem
Jun 26 2017 07:57
ah got it! I wasn't sure if I needed to put var on front of them
Blauelf
@Blauelf
Jun 26 2017 07:59
@Azzrah Usually, you want to return true or false in a filter callback, mostly for better readability. filter won't care, it tests for truthy/falsy only (like if and many others do)
Claudio Restifo
@Marmiz
Jun 26 2017 07:59
@mrjerem you put var when you want to instruct the computer that 'the following is a varaible with this name, keep it save somewhere cos I may need it later'
mrjerem
@mrjerem
Jun 26 2017 08:00
so you put var in front of a word and you can use it later with just the word yes?
Thomas Faller
@thomasfaller
Jun 26 2017 08:00
Hey guys!
I just finished my Integer to Romannumber challenge and I came up with that:
https://codepen.io/thomasfaller/pen/VWMxLj?editors=0012
I started with a complicated set of looping that was hard to troubleshoot. But in the end the object/table does the trick. Is that good or can it be improved?
Claudio Restifo
@Marmiz
Jun 26 2017 08:03

@mrjerem yes:

var x = 1

then you can reuse the values somewhere:

y = x * 2

// y = 2
mrjerem
@mrjerem
Jun 26 2017 08:03
@Marmiz okay clear enough for now thanks :smile:
CamperBot
@camperbot
Jun 26 2017 08:03
mrjerem sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 962 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Jun 26 2017 08:10

@thomasfaller It's good for sure ^^, but as everything can be improved.
For starter you could have a table that have only the 'breaking point' of roman numerals:

eg: you don't need to know that 1 - 2 - 3 - 4 are I - II - III - IV
but you only need to know that from 1 to 3 you can add as many I as needed, until you reach the next breaking point of four that is a IV.

Then use this concept of looping to construct the string.

Mai Thinh
@mthinh
Jun 26 2017 08:15
Do I need a loop for "Title Case a Sentence" challenge ? pls?
schizo99
@shashank1999coder
Jun 26 2017 08:16

function golfScore(par, strokes) {
// Only change code below this line
if (strokes = 1) {
return "Hole-in-one";

}
else if (strokes <=par-2){
return "Eagle";

}
else if (strokes = par-1 ) {
return "Birdie";
}
else if (strokes = par) {
return "Par";
}
else if (strokes = par + 1) {
return "Bogey";
}
else if (strokes = par+2 ) {
return "Double Bogey";
}
else if ( strokes >=par+3){
return "Go Home!"
}
else {
return "Change Me";
}
// Only change code above this line
}

// Change these values to test
golfScore(5, 4);
what's wrong plz help

Alan Alickovic
@alan2207
Jun 26 2017 08:17
@shashank1999coder if strokes = 1
needs to be === instead of =
= is assigment operator
you have that in several conditions
schizo99
@shashank1999coder
Jun 26 2017 08:18
@alan2207 thanks
CamperBot
@camperbot
Jun 26 2017 08:18
shashank1999coder sends brownie points to @alan2207 :sparkles: :thumbsup: :sparkles:
:cookie: 463 | @alan2207 |http://www.freecodecamp.com/alan2207
Blauelf
@Blauelf
Jun 26 2017 08:18
@shashank1999coder Also, check spelling, I think it's "Hole-in-one!"
schizo99
@shashank1999coder
Jun 26 2017 08:18
that was very silly mistake by me
Alan Alickovic
@alan2207
Jun 26 2017 08:19
@shashank1999coder you will get used to it
Mai Thinh
@mthinh
Jun 26 2017 08:19
Do I need a loop for "Title Case a Sentence" challenge ? pls?
Alan Alickovic
@alan2207
Jun 26 2017 08:20
@mthinh you could also use regular expression
lazzlo
@lazzlo
Jun 26 2017 08:26
@thomasfaller You are aware that your code breaks when you enter a number above 9999, right?
mrjerem
@mrjerem
Jun 26 2017 08:29
I can't get thios writen out as I want "FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine"
it comes out as "var myStr ="FirstLine\n\SecondLine\\rThirdLine\""
Claudio Restifo
@Marmiz
Jun 26 2017 08:31
@mrjerem the extra " at the end is a typo or in your code?
mrjerem
@mrjerem
Jun 26 2017 08:32
@Marmiz Its not type its reffering to the whole "var.... text
Thomas Faller
@thomasfaller
Jun 26 2017 08:33
@Lazzlo Of course it does but the FreeCodeCamp challenge doesn’t test number over that limit. I could just add the missing ones in the table though.
:innocent:
Zack
@CrowsVeldt
Jun 26 2017 08:34
@mrjerem if you put backticks (`)around your code it will be formatted automatically and easier to read
mrjerem
@mrjerem
Jun 26 2017 08:34
No I added it here on chat to refer to my code :D
@CrowsVeldt okay thanks :)
CamperBot
@camperbot
Jun 26 2017 08:34
mrjerem sends brownie points to @crowsveldt :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @crowsveldt |http://www.freecodecamp.com/crowsveldt
Claudio Restifo
@Marmiz
Jun 26 2017 08:34
@mrjerem read this to learn to format text in chat
lazzlo
@lazzlo
Jun 26 2017 08:34
@thomasfaller Yeah, I know it doesn't test them. I just mentioned it because the way your code is structured makes it hard for it to scale upwards in case you would ever want that in the future.
Nitin Sahu
@globefire
Jun 26 2017 08:36
hi
Blauelf
@Blauelf
Jun 26 2017 08:37
lo
Thomas Faller
@thomasfaller
Jun 26 2017 08:37
@Lazzlo You’re right, it’s not the best possible converter, I’ll work on one that scales up. Thanks ;)
CamperBot
@camperbot
Jun 26 2017 08:37
thomasfaller sends brownie points to @lazzlo :sparkles: :thumbsup: :sparkles:
:cookie: 7 | @lazzlo |http://www.freecodecamp.com/lazzlo
Menlam Choden
@menlam
Jun 26 2017 08:38

function mutation(arr) {
var y=arr[0].indexOf(arr[1]);
if(y==-1)
{
return false;
}
else
{
return true;
}
}

mutation(["Mary", "Army"]); This is true for only some case,,, whats wrong

lazzlo
@lazzlo
Jun 26 2017 08:38
@thomasfaller :)
@Lazzlo Let me know if you need help
@thomasfaller Oops wrong tag
Alan Alickovic
@alan2207
Jun 26 2017 08:40
@menlam are you handling uppercase and lowercase?
because you should
Menlam Choden
@menlam
Jun 26 2017 08:48
@alan2207 yeah, but first why is it not working for all cases

@alan2207 function mutation(arr) {
arr[0].toLowerCase();
arr[1].toLowerCase();
var arr1=arr[0].split('');
var arr2=arr[1].split('');
var y=arr[0].indexOf(arr[1]);
if(y==-1)
{
return false;
}
else
{
return true;
}

}

mutation(["Mary", "Army"]);

it works for mutation(["hello", "hey"])
Alan Alickovic
@alan2207
Jun 26 2017 08:50
@menlam but letters in second item doesn't have to be in order, the task is just to check if the first item contains all the letters of the second item
Menlam Choden
@menlam
Jun 26 2017 08:50
yeah @alan2207 how to do that
Alan Alickovic
@alan2207
Jun 26 2017 08:51
you need to loop through all letters in second item, and if any of letters are not also in first item, you need to return false
otherwise it is true
Menlam Choden
@menlam
Jun 26 2017 08:52
@alan2207 okay, let me check and get back to you
@alan2207 thanks
CamperBot
@camperbot
Jun 26 2017 08:52
menlam sends brownie points to @alan2207 :sparkles: :thumbsup: :sparkles:
:cookie: 464 | @alan2207 |http://www.freecodecamp.com/alan2207
Menlam Choden
@menlam
Jun 26 2017 08:55

@alan2207 function mutation(arr) {
arr[0].toLowerCase();
arr[1].toLowerCase();
var arr1=arr[0].split('');
var arr2=arr[1].split('');
for(var i=0;i<=arr2.length;i++)
{
if(arr2[i]==arr1)
{
return true;
}
else
{
return false;
}
}

}

mutation(["Mary", "Army"]);

@alan2207 did not work, maybe I am doing something wrong,
Alan Alickovic
@alan2207
Jun 26 2017 08:56
@menlam inside for loop you need to check if the letter is not included in the first item
if so, just return false
otherwise after the loop . you can return true, since all letters are contained within first item
Menlam Choden
@menlam
Jun 26 2017 08:58
@alan2207 Sorry I did not get you
Alan Alickovic
@alan2207
Jun 26 2017 08:58
@menlam ok, let's go slowly
Menlam Choden
@menlam
Jun 26 2017 08:59
@alan2207 thanks :)
CamperBot
@camperbot
Jun 26 2017 08:59
menlam sends brownie points to @alan2207 :sparkles: :thumbsup: :sparkles:
:warning: menlam already gave alan2207 points
Blauelf
@Blauelf
Jun 26 2017 08:59
@menlam toLowerCase returns a new string (cannot change the one it's working on as strings are immutable), you could for example use it like var arr1 = arr[0].toLowerCase().split('');
Alan Alickovic
@alan2207
Jun 26 2017 09:00
tou do not have to split items, since we can loop through strings as well
Blauelf
@Blauelf
Jun 26 2017 09:00
@menlam Also, i < arr2.length instead of <=, and what @alan2207 said, strings are array-like (have length and numeric properties).
Menlam Choden
@menlam
Jun 26 2017 09:01
@Blauelf okay, so what am I doing wrong
Alan Alickovic
@alan2207
Jun 26 2017 09:02
@menlam loop through the second item, and check if any of its letters are contained within the first item, you can use indexOf method
Kamal
@kpbro
Jun 26 2017 09:02
hey. can someone help me a little in frontend? i am stuck on random quote machine
i have used api for random quotes but, it is showing same quote everytime and not random
Long Nguyen
@longnt80
Jun 26 2017 09:04
please try to beat my AI:
https://codepen.io/longnt80/full/BZWBxm/
jasonrest
@jasonrest
Jun 26 2017 09:05
just a quick question. In order to generate a random quote, this should be working right?
var quote = ["test quote 1", "test quote 2", "test quote 3", "test quote 4"];
function randomquote(){
    var randomNumber = Random.Range(0,4);
    var newQuote = quote[randomNumber];    
    return newQuote;
}
randomquote();
Kamal
@kpbro
Jun 26 2017 09:06
@jasonrest it will work fine. but u should have much more quotes than 4. And if you use api it is better
jasonrest
@jasonrest
Jun 26 2017 09:07
@kpbro this is just a test to make sure I understand the logic of my solution. and I am new to Api's. do you mean use Json to connect to another quote source.
Markus Kiili
@Masd925
Jun 26 2017 09:08
@jasonrest You have this Random.Range defined somewhere?
Long Nguyen
@longnt80
Jun 26 2017 09:08
@jasonrest Random.Range is this javascript?
Kamal
@kpbro
Jun 26 2017 09:08
@jasonrest i am trying the same challenge. i succeed in taking quote from api, but it is not ranom everytime
jasonrest
@jasonrest
Jun 26 2017 09:09
@longnt80 I apologize is that not a built in function
@kpbro seems you're ahead of me. just starting on it.
schizo99
@shashank1999coder
Jun 26 2017 09:10

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case 1:
console.log("alpha");
break;

case 2:
  console.log("beta");
  break;

case 3:
  console.log("gamma");
  break;

case 4:
  console.log("delta");
  break;

}

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

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

pz help
Kamal
@kpbro
Jun 26 2017 09:10
@jasonrest u have to create function for random number using math.rand
Alan Alickovic
@alan2207
Jun 26 2017 09:10
@shashank1999coder you need also default value, i think
jasonrest
@jasonrest
Jun 26 2017 09:11
@kpbro oh math.rand is the built in function.
Markus Kiili
@Masd925
Jun 26 2017 09:11
@jasonrest Math.random() will give a random float between 0(inclusive) and 1(exclusive). There was a challenge earlier about generating random integers.
Kamal
@kpbro
Jun 26 2017 09:11
@jasonrest yep.. using math.rand use some logic to get in your range of 0 to 4
@Masd925 hey can you help me with api?
jasonrest
@jasonrest
Jun 26 2017 09:13
@Masd925 right. has to be
function getRandomArbitrary(min, max) {
  return Math.random() * (max - min) + min;
}
schizo99
@shashank1999coder
Jun 26 2017 09:13
@alan2207 still not working
Alan Alickovic
@alan2207
Jun 26 2017 09:13
@shashank1999coder what challenge is it?
@Masd925 you need to round it to lower whole number
Markus Kiili
@Masd925
Jun 26 2017 09:14
@alan2207 Yes.