These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
May 2017
Rick Willcox
@willcoxDev
May 23 2017 00:05 UTC

Can anyone help me shorten this code, or point me in the right direction. The answer was easy to get but it feels a little hacky the way I did it.

```

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

findLongestWord("The quick brown fox jumped over the lazy dog");
eyesore-
@eyesore-
May 23 2017 00:06 UTC
@willcoxDev You could do it with reduce
Rick Willcox
@willcoxDev
May 23 2017 00:07 UTC
hmm
oh wow just looking online and someone put an answer up
and used the exact same variable
as me
looks dodgy rofl
after having a look at the reduce way and the sort way, mine actually seems fine. Neither of them really reduce the code, thanks for the help
@eyesore- thanks
CamperBot
@camperbot
May 23 2017 00:11 UTC
willcoxdev sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 91 | @eyesore- |http://www.freecodecamp.com/eyesore-
Don Bachibonge
@dbib
May 23 2017 00:12 UTC
Can any one help me with my code, i'm doing a factorisation chanlege and normaly my code should work but i don't know why that doesn't work in free code camp console.
eyesore-
@eyesore-
May 23 2017 00:12 UTC
@willcoxDev
No problem.
function findLongestWord(str) {
  return str
    .split(' ')
    .reduce( (result, word) => {
      if(word.length > result.length) result = word
      return result
    })
}
CamperBot
@camperbot
May 23 2017 00:14 UTC
:bulb: to format code use backticks! ``` more info
Don Bachibonge
@dbib
May 23 2017 00:15 UTC
here are my code:
function factorialize(num) {
  let solde = 1;
  while(num > 1){
    solde = solde * num;
    num = num - 1;
  }
  return solde;
}
eyesore-
@eyesore-
May 23 2017 00:18 UTC
@dbib What error is it giving you?
@dbib that should work
Don Bachibonge
@dbib
May 23 2017 00:22 UTC
here is error:
loopProtect is not defined
feedback please!
Don Bachibonge
@dbib
May 23 2017 00:29 UTC
i'have try to use for loop but that give me the same error
Joseph
@revisualize
May 23 2017 00:31 UTC
Hello.
eyesore-
@eyesore-
May 23 2017 00:31 UTC
Goodbye.
Joseph
@revisualize
May 23 2017 00:31 UTC
@dbib if you can calculate how many times a loop will run beforw you run it... you should use a for loop.
It is always better to count your loop upward if possible.
Don Bachibonge
@dbib
May 23 2017 00:34 UTC
@revisualize
i'have try that doesn't work i'have try it in my computer terminal and that work greatly but in free code camp console that give me always the error even with while or for loop
Joseph
@revisualize
May 23 2017 00:37 UTC
I want to see the for code.
sraza6
@sraza6
May 23 2017 00:38 UTC

hey i dont understand what im doing wrong with this challenge

<body>
<script>
const dataset = [
[ 34, 78 ],
[ 109, 280 ],
[ 310, 120 ],
[ 79, 411 ],
[ 420, 220 ],
[ 233, 145 ],
[ 333, 96 ],
[ 222, 333 ],
[ 78, 320 ],
[ 21, 123 ]
];


const w = 500;
const h = 500;

const svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);

svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", (d, i) => d[0])
.attr("cy", (d, i) => h - d[1])
.attr("r", 5);

svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
// Add your code below this line
.text((d) => d)
.attr("x",(d,i)=> d[0]+5)
.attr("y", (d,i)=> h-d[1]);


// Add your code above this line
</script>
</body>

please help

Don Bachibonge
@dbib
May 23 2017 00:39 UTC
@revisualize my for loop code
function factorialize(num) { let solde = 1; let vaa = num; for (let i = 0; i < vaa.length; i++){ solde *= vaa; vaa -= 1; } return solde; }
sraza6
@sraza6
May 23 2017 00:40 UTC
also that challege is for D3
Joseph
@revisualize
May 23 2017 00:41 UTC
@dbib a number doesnt have a .length
@dbib replace vaa.length with num
Don Bachibonge
@dbib
May 23 2017 00:42 UTC
@revisualize that also not work
Joseph
@revisualize
May 23 2017 00:44 UTC
function factorialize(num) { let solde = 1; for (let i = 1; i < num; i++){ solde *= i; } return solde; }
<=
Instead of <
Im on my phone so, i cant run that.
Does that work?
Don Bachibonge
@dbib
May 23 2017 00:47 UTC
@revisualize not that not work
they give me the same error:
"loopProtect is not defined"
Rick Willcox
@willcoxDev
May 23 2017 00:47 UTC
Hey guys, I am having trouble with js .sort function
it is working fine with every toher array
except for one that looks like [1000, 1001, 857, 1]
its sorts it to 1 1000 1001 857
eyesore-
@eyesore-
May 23 2017 00:48 UTC
@willcoxDev Yeah, it sorts to unicode
David Miller
@DavidMillerFL
May 23 2017 00:49 UTC
Just watched a tutorial on youtube regarding Seek and Destroy. There’s zero percent chance I would have ever figured that out. I still don’t fully understand exactly what’s taking place with the loop inside the other loop for example
Starting to worry I simply may not be cut out for this. Any suggestions guys?
Long Nguyen
@longnt80
May 23 2017 00:51 UTC
@DavidMillerFL do you understand all the challenges before that?
Rick Willcox
@willcoxDev
May 23 2017 00:52 UTC
@eyesore- Ok i got the answer now but that is weird so sort just adds up the total of each unicode number ?
and 857 unicode is bigger than 1001?
eyesore-
@eyesore-
May 23 2017 00:53 UTC
@willcoxDev It will sort by it's unicode value. Which is by character. That is why it works for text. In numbers you start to get 1, 10, 11, 2, 3, 4 ...
Long Nguyen
@longnt80
May 23 2017 00:53 UTC

@willcoxDev

except for one that looks like [1000, 1001, 857, 1]
its sorts it to 1 1000 1001 857

you need a function
David Miller
@DavidMillerFL
May 23 2017 00:54 UTC

Yes. I understood mostly all the challenges prior to this.

Sometimes I needed a hint or help from the people here.

Sometimes I’d struggle, but eventually get it after asking or reading or watch.

But there were also some where my brain would just go blank @longnt80

Joseph
@revisualize
May 23 2017 00:54 UTC
@dbib Okay, I'm home.
eyesore-
@eyesore-
May 23 2017 00:54 UTC
@DavidMillerFL Don't beat yourself up too much man. It can be difficult. Just take the challenge and function one step at a time. It can also help to diagram what is going on.
Don Bachibonge
@dbib
May 23 2017 00:55 UTC
@revisualize great try it too to see if that will work for you
David Miller
@DavidMillerFL
May 23 2017 00:55 UTC
I think the reason this one was so difficult is because it introduced .filter and something called argument objects and never really touched on those concepts before @longnt80
Long Nguyen
@longnt80
May 23 2017 00:55 UTC
@DavidMillerFL oh yeah, you need to read those concept slowly
Joseph
@revisualize
May 23 2017 00:55 UTC
@dbib It works.
Long Nguyen
@longnt80
May 23 2017 00:55 UTC
from different sources
David Miller
@DavidMillerFL
May 23 2017 00:56 UTC
@eyesore- I appreciate that. And yes diagrams help. Good point!
Joseph
@revisualize
May 23 2017 00:56 UTC
@dbib Here:
image.png
Cody Perry
@cperry24
May 23 2017 00:56 UTC
hello
Long Nguyen
@longnt80
May 23 2017 00:56 UTC
@DavidMillerFL usually, I have to read at least 2 sources for each concept FCC introduces
Cody Perry
@cperry24
May 23 2017 00:57 UTC
I'm having some trouble on understand the Truncate a string challenge
eyesore-
@eyesore-
May 23 2017 00:57 UTC
@dbib Your original answer works. It looks like the challenge is looking for a variable that is not present. Have you tried refreshing your browser?
David Miller
@DavidMillerFL
May 23 2017 00:57 UTC
@longnt80 That’s a good strategy, I’ll try that from now on. :) Thanks dude.
CamperBot
@camperbot
May 23 2017 00:57 UTC
davidmillerfl sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 291 | @longnt80 |http://www.freecodecamp.com/longnt80
Long Nguyen
@longnt80
May 23 2017 00:57 UTC
@DavidMillerFL once I understand how to use the method, I can figure out the challenge
David Miller
@DavidMillerFL
May 23 2017 00:57 UTC
Where do you read about these things?
Long Nguyen
@longnt80
May 23 2017 00:58 UTC
@DavidMillerFL start with MDN and w3school
Don Bachibonge
@dbib
May 23 2017 00:58 UTC
@eyesore- no let me try
Cody Perry
@cperry24
May 23 2017 00:58 UTC

`function truncateString(str, num) {
if (str.length > num) {
return str.slice(0, num);
}
}

truncateString("A", 1);`

David Miller
@DavidMillerFL
May 23 2017 00:58 UTC
MDN, while very thorough isn’t too… layman-ish
Long Nguyen
@longnt80
May 23 2017 00:58 UTC
@DavidMillerFL
yeah, that's why you need w3school
Joseph
@revisualize
May 23 2017 00:58 UTC

@dbib This code:

function factorialize(num) {
  let solde = 1;
  while(num > 1){
    solde = solde * num;
    num = num - 1;
  }
  return solde;
}

Works for me as well.

eyesore-
@eyesore-
May 23 2017 00:59 UTC
@DavidMillerFL If you get super stuck on something shoot me a message and I can walk you through it.
David Miller
@DavidMillerFL
May 23 2017 00:59 UTC
@eyesore- Thanks so much that means a lot. I appreciate it.
CamperBot
@camperbot
May 23 2017 00:59 UTC
davidmillerfl sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 92 | @eyesore- |http://www.freecodecamp.com/eyesore-
Joseph
@revisualize
May 23 2017 00:59 UTC
image.png
@dbib Here --^
eyesore-
@eyesore-
May 23 2017 00:59 UTC
@DavidMillerFL No problem.
Joseph
@revisualize
May 23 2017 01:00 UTC
@dbib So.... Yeah.. I don't know what your problem is.
David Miller
@DavidMillerFL
May 23 2017 01:00 UTC
I’m gonna take a break. Halo Top ice cream might make me a better programmer, so I can’t take the risk and not eat it
Long Nguyen
@longnt80
May 23 2017 01:02 UTC
@DavidMillerFL but don't ask too soon, just read the materials first. Most of these basic challenge is not that complicated, you just need to understand the basic. Sometimes, in MDN they already have an example that can solve the challenge. You just have to read it from top to bottom though, that's the hard part.
Don Bachibonge
@dbib
May 23 2017 01:02 UTC
@revisualize , @eyesore- that doesn't work let me try to change the browser
@revisualize ,@eyesore i change the browser and that work very well
thank you
CamperBot
@camperbot
May 23 2017 01:05 UTC
dbib sends brownie points to @revisualize and @eyesore :sparkles: :thumbsup: :sparkles:
:warning: @eyesore's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:star2: 3995 | @revisualize |http://www.freecodecamp.com/revisualize
Dovydas Stirpeika
@Giveback007
May 23 2017 01:23 UTC
I'm baffled
Capture.PNG
nothing makes sense anymore
billjen23
@billjen23
May 23 2017 01:24 UTC

in Iterate Through an Array with a For Loop iam using this code should equal 20 but outputs 5
// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
for (var i = 0; i < myArr.length; i++) {
total += myArr[i];
}
var total = [i];

gerome0123
@gerome0123
May 23 2017 01:25 UTC
i guys i have each checkbox in my table i just want to hide the checkbox and appear when hovering the row is there anyone have a guide to do that???
Manish Giri
@Manish-Giri
May 23 2017 01:25 UTC
@billjen23 var total = [i];
why are you doing this?
billjen23
@billjen23
May 23 2017 01:26 UTC
that is where i outputs to
Manish Giri
@Manish-Giri
May 23 2017 01:26 UTC
what?
Brandon Guerrero
@TheDevWizard
May 23 2017 01:26 UTC
how is everyone doing?
Dovydas Stirpeika
@Giveback007
May 23 2017 01:26 UTC
does anyone know why index of is -1? when it shouldn't be?
eyesore-
@eyesore-
May 23 2017 01:28 UTC
Why are you passing a boolean to indexOf?
Dovydas Stirpeika
@Giveback007
May 23 2017 01:29 UTC
if that letter already exists it will not write it again
index of -1 means that value was not found
therefore if -1 it will execute the code
eyesore-
@eyesore-
May 23 2017 01:31 UTC
Look at what you are doing though.
Dovydas Stirpeika
@Giveback007
May 23 2017 01:31 UTC
@eyesore- what am I doing?
eyesore-
@eyesore-
May 23 2017 01:31 UTC
takenGrid.indexOf(pos === -1)
Dovydas Stirpeika
@Giveback007
May 23 2017 01:32 UTC
oh....
eyesore-
@eyesore-
May 23 2017 01:32 UTC
pos === -1 is going to be a boolean
I'm guessing you want that outside haha
Dovydas Stirpeika
@Giveback007
May 23 2017 01:32 UTC
@eyesore- tnx
CamperBot
@camperbot
May 23 2017 01:32 UTC
giveback007 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 93 | @eyesore- |http://www.freecodecamp.com/eyesore-
eyesore-
@eyesore-
May 23 2017 01:32 UTC
No problem!
Dovydas Stirpeika
@Giveback007
May 23 2017 01:32 UTC
@eyesore- went in to full tunnel visions
:D
eyesore-
@eyesore-
May 23 2017 01:33 UTC
It's cool. Completely has happened to me.
Rick Willcox
@willcoxDev
May 23 2017 01:33 UTC
I cant seem to find the syntax for pushing to a multi dimensinoal array
I am trying
 multiArray[i].push(arr[j]);
Christopher McCormack
@cmccormack
May 23 2017 01:33 UTC
@willcoxDev Javascript doesn't actually have multidimensional arrays, just nested arrays
Rick Willcox
@willcoxDev
May 23 2017 01:34 UTC
hmm
Dovydas Stirpeika
@Giveback007
May 23 2017 01:34 UTC
@cmccormack hey dude!
Christopher McCormack
@cmccormack
May 23 2017 01:34 UTC
@willcoxDev that syntax could be fine but no context to tell
@Giveback007 heya
billjen23
@billjen23
May 23 2017 01:34 UTC
is there a tutorial that goes deeper into this lesson my code is not working im totaly lost
Rick Willcox
@willcoxDev
May 23 2017 01:34 UTC
function chunkArrayInGroups(arr, size) {
  var multiArray = [];
  for(var i=0;i<size;i++){
    multiArray.push(i);
    for(var j=0;j<arr.length;j++){
      multiArray[i].push(arr[j]);
    }
  }
  return arr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
type error multiarray[i].push is not a function
Thomas Magnus
@tmag298
May 23 2017 01:35 UTC
Can anyone explain this challenge to me?
Matthew
@IMDBLM
May 23 2017 01:35 UTC
You'ins I'm having some difficulty on Seek and Destroy. I've figured out how to swap the argument into an array, but I can't make heads or tails of the Array.filter(). I'm fairly certain that I need to filter the array according to search criteria but the MDN is confusing.
Christopher McCormack
@cmccormack
May 23 2017 01:35 UTC
@willcoxDev why are you storing an integer in the first for loop? Numbers don't have push methods
eyesore-
@eyesore-
May 23 2017 01:35 UTC
One punch man, where are you stuck?
Long Nguyen
@longnt80
May 23 2017 01:35 UTC
@willcoxDev multiarray[i] is not an array
Thomas Magnus
@tmag298
May 23 2017 01:35 UTC
Oh my bad, link was super long! Anyway, can anyone explain why removing the last console.log() line makes the function run?
I'm not stuck I just don't understand this^^
Bart
eyesore-
@eyesore-
May 23 2017 01:36 UTC
Haha I forgot I had that.
Dovydas Stirpeika
@Giveback007
May 23 2017 01:37 UTC
ONE PUNCH!!!!
Rick Willcox
@willcoxDev
May 23 2017 01:37 UTC
oh i think i see what you mean
ill go give it anothe crack
Christopher McCormack
@cmccormack
May 23 2017 01:37 UTC
@tmag298 the idea is to show you what the value is, if you passed the test you might not see the value. Removing it prevents viewing the value but allows the tests to complete. At least I think... :)
eyesore-
@eyesore-
May 23 2017 01:37 UTC
The reason it fails is because that variable is defined within a function so console.log does not have access to it.
Thomas Magnus
@tmag298
May 23 2017 01:37 UTC
But within the function if you write console.log() it does?
eyesore-
@eyesore-
May 23 2017 01:37 UTC
Yup!
Thomas Magnus
@tmag298
May 23 2017 01:38 UTC
Word, that's all.
Thankyou @eyesore-
CamperBot
@camperbot
May 23 2017 01:38 UTC
tmag298 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 94 | @eyesore- |http://www.freecodecamp.com/eyesore-
eyesore-
@eyesore-
May 23 2017 01:38 UTC
No problem! Anytime.
Thomas Magnus
@tmag298
May 23 2017 01:42 UTC
@eyesore- got another question
eyesore-
@eyesore-
May 23 2017 01:43 UTC
Sup
Thomas Magnus
@tmag298
May 23 2017 01:43 UTC
https://tinyurl.com/lu699rp
In this challenge, we invoke a local variable outside of a function. So local variables can be invoked, but not processed outside of its function? Is this the case?
Dovydas Stirpeika
@Giveback007
May 23 2017 01:44 UTC
good nigh everyone
eyesore-
@eyesore-
May 23 2017 01:45 UTC
@tmag298
// someVar equals 'Hat' in the global scope
var someVar = "Hat";
function myFun() {
  // someVar equals 'Head' inside this function
  var someVar = "Head";
  return someVar;
}
Good night
So if you were to run
console.log(myFun()) // = 'Head'
console.log(someVar) // = 'Hat'
Does that make sense?
Invoking is when you invoke a function. Running myFun() that is invoking. Creating a variable is declaring. I'm not trying to be a grammar cop here, but just for future reference.
aj141
@aj141
May 23 2017 01:50 UTC
Good Evening Campers,
image.png
i am a new javascript learner
i did not get the first one?
Any thoughts?
eyesore-
@eyesore-
May 23 2017 01:53 UTC
Refresh your browser. You should be good.
aj141
@aj141
May 23 2017 01:53 UTC
no idea
it does not function
eyesore-
@eyesore-
May 23 2017 01:53 UTC
What is the name of the lesson?
aj141
@aj141
May 23 2017 01:53 UTC
javascript
Storing Values with the Assignment Operator
Long Nguyen
@longnt80
May 23 2017 01:54 UTC
@aj141 I think you have to write var b = a; under the last comment:
eyesore-
@eyesore-
May 23 2017 01:54 UTC
You need to reset your code and only make changes under the comment.
aj141
@aj141
May 23 2017 01:54 UTC
@longnt80 not functioning
eyesore-
@eyesore-
May 23 2017 01:55 UTC
Reset your code and only make changes under the comment.
Long Nguyen
@longnt80
May 23 2017 01:55 UTC
@aj141 yeah you should do what @eyesore- said
aj141
@aj141
May 23 2017 01:55 UTC
correct
thank you all
eyesore-
@eyesore-
May 23 2017 01:56 UTC
@aj141 No proble.
Andrej Stupar
@fatmike-slo
May 23 2017 02:01 UTC
Exercise Repeat a string repeat a string. I'v laid down this code which works in my editor, won't let me pass the exercise by no means even if the result output is correct... anyone?
    function repeatStringNumTimes(str, num) {
        var holder = [];
        var re = /\b/g;

        if (num < 0) {
            return holder.toString();
        }
        for (var i = 0; i < num; i++) {

            holder.push(str);
        }
        var a = holder.join("");

        var b = a.replace(re, '"');

        return b;

    }

    repeatStringNumTimes("abc", 4);
eyesore-
@eyesore-
May 23 2017 02:04 UTC
@fatmike-slo Why are you using regex?
Andrej Stupar
@fatmike-slo
May 23 2017 02:04 UTC
to add the brackets at the start and end of the output as requested
eyesore-
@eyesore-
May 23 2017 02:05 UTC
@fatmike-slo It doesn't ask you for brackets though. You just have to return 'abcabcabcabc'
Andrej Stupar
@fatmike-slo
May 23 2017 02:07 UTC
ahem ... there was no need for added brackets ... lol it works if i ouput var a
it's getting late, have to sleep :D thnx !!
eyesore-
@eyesore-
May 23 2017 02:07 UTC
Yeah, you dont need to do regex haha. No problem!
Oh, also I would suggest to get in the habit of making descriptive variable names especially if you are planning on working as a developer.
Andrej Stupar
@fatmike-slo
May 23 2017 02:10 UTC
this was just a paste from my editor where i write sloppy to save time, but u'r right, will try to be more descriptive :)
eyesore-
@eyesore-
May 23 2017 02:11 UTC
Oh, no worries! Just a suggestion. haha
Thomas Magnus
@tmag298
May 23 2017 02:11 UTC
I'm back! Very simple question
Rakshit Sinha
@sinharaksh1t
May 23 2017 02:11 UTC

Function to add an element from function parameter into a Linked List

this.add = function(element){
    // Only change code below this line
      var node = new Node(element);
      if(this.size() === 0) {
        this.element=element;
        head = element;
      }
      else {
        var dummyNode=0;
        while(this.next!==null) {
          dummyNode = this.element;
        }
        dummyNode.next = element;
      }
    length++;
    // Only change code above this line
  };

Any help on where am I going wrong?

Thomas Magnus
@tmag298
May 23 2017 02:11 UTC
how do I even create a queue for this challenge? https://tinyurl.com/lxbwk38
Rakshit Sinha
@sinharaksh1t
May 23 2017 02:11 UTC
I am too bad at this! and it's confusing me . :/
eyesore-
@eyesore-
May 23 2017 02:12 UTC
@tmag298 Do you have anything written yet?
Thomas Magnus
@tmag298
May 23 2017 02:12 UTC
I don't even know where to start lol
Like do I just edit the return statement?
Wisdom Peters
@blackcytographer
May 23 2017 02:12 UTC
good evening world pls i need your help on this
Thomas Magnus
@tmag298
May 23 2017 02:13 UTC
@sinharaksh1t don't say that!
Wisdom Peters
@blackcytographer
May 23 2017 02:13 UTC

function abTest(a, b) {
// Only change code below this line
if (a || b < 0) {
return undefined;
}

// Only change code above this line

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

// Change values below to test your code
abTest(2,2);

eyesore-
@eyesore-
May 23 2017 02:14 UTC
@tmag298 well if you are building a queue a good way to do it is with an array since you've got methods like push pop shift etc...
@sinharaksh1t Is that for a lesson? Could you send me the name?
Moisés Man
@moigithub
May 23 2017 02:15 UTC
@blackcytographer ur code saying...
if a have a truthy value OR b is < 0
Rakshit Sinha
@sinharaksh1t
May 23 2017 02:15 UTC
@tmag298 ah lol.. I was talking about the question which I posted above... and yes that's from beta.freecodecamp.com
also, about your question, where are you getting stuck at ?
Matthew
@IMDBLM
May 23 2017 02:22 UTC
@revisualize you still around?
Andrew Saganda
@asaganda
May 23 2017 02:25 UTC
@Lumexralph I've applied what i thought were the correct loops but they didn't work. How do i know when to apply the proper loop?
Are you still available?
karthiksagr
@karthiksagr
May 23 2017 02:26 UTC
Can anyone help with the following question?

We will now use our knowledge of strings to build a "Mad Libs" style word game we're calling "Word Blanks". You will create an (optionally humorous) "Fill in the Blanks" style sentence.

You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.

You will also need to use additional strings, which will not change, and must be in between all of the provided words. The output should be a complete sentence.

We have provided a framework for testing your results with different words. The tests will run your function with several different inputs to make sure all of the provided words appear in the output, as well as your extra strings.

Screen Shot 2017-05-22 at 10.34.08 PM.png
eyesore-
@eyesore-
May 23 2017 02:29 UTC
@karthiksagr When you put things inside quotes then they are strings.
@karthiksagr So if you call 'myNoun' it will output 'myNoun' and not 'dog'
Long Nguyen
@longnt80
May 23 2017 02:31 UTC
@karthiksagr when this line runs:
wordBlanks("dog", "big", "ran", "quickly");
it will call the function: function wordBlanks(myNoun, myAdjective, myVerb, myAdverb)
and "dog", "big", "ran", "quickly" will be values for the parameters (myNoun, myAdjective, myVerb, myAdverb) in the function
you have to create a sentence made up of those words and assign to result
@karthiksagr you got the right idea, but the syntax is wrong. Parameter should not be in quotation marks
karthiksagr
@karthiksagr
May 23 2017 02:33 UTC
Screen Shot 2017-05-22 at 10.39.07 PM.png
eyesore-
@eyesore-
May 23 2017 02:33 UTC
You want to make it dynamic and use the variables.
Long Nguyen
@longnt80
May 23 2017 02:34 UTC
@karthiksagr no, use the parameters like the first one you showed us
@karthiksagr also, remember to add spaces between each word
Jason G
@Jay33Canada
May 23 2017 02:36 UTC

I'll give you a hint with a short version @karthiksagr

result = "The " + myAdjective + " " + myNoun;

this would be something like "The little cat"
but you need to come up with one on your own

Thomas Magnus
@tmag298
May 23 2017 02:43 UTC
@sinharaksh1t I don't even really know where to start. Like is a queue just created like we create functions with something like function myFunction()?
Rick Willcox
@willcoxDev
May 23 2017 02:47 UTC
Can someone point me in the right direction for whre I am going wrong with this questions
eyesore-
@eyesore-
May 23 2017 02:48 UTC
@tmag298 A is FIFO data structure. So it's first in first out. In JS you could see an Array as a queue.
Rick Willcox
@willcoxDev
May 23 2017 02:48 UTC

function mutation(arr) {
  if (arr[0].toLowerCase().indexOf(arr[1].toLowerCase())){
    return true;
  }
  return false;
}

mutation(["hello", "Hello"]);
eyesore-
@eyesore-
May 23 2017 02:48 UTC
@willcoxDev What is it supposed to do?
Rick Willcox
@willcoxDev
May 23 2017 02:49 UTC
return true if all the charcters at index 1 are in index 0
false otherwise
eyesore-
@eyesore-
May 23 2017 02:50 UTC
Cool, so right now you are just checking the first letter. What if I had mutation(['hello', 'hEllo'])?
Joseph
@revisualize
May 23 2017 02:50 UTC
Hello.
Rick Willcox
@willcoxDev
May 23 2017 02:51 UTC
@eyesore- is the arr[0] not "hello"
Abhishek Tiwari
@fillopfy
May 23 2017 02:51 UTC
function mutation(arr) {
  var m=arr[0].toLowerCase();
  var n=arr[1].toLowerCase();

  for(var i=0;i<n.length;i++)
    {
      if(m.indexOf(n[i])!==-1 )
      {
        return true;
      }
      return false;
    }
}
what is wrong with my code
eyesore-
@eyesore-
May 23 2017 02:52 UTC
Yeah, sorry. I misread what you had.
@willcoxDev If you are going to lowerCase both. Why not just compare them with ===?
Legacy
@punyparker
May 23 2017 02:52 UTC
Hello, can i get some help
Rick Willcox
@willcoxDev
May 23 2017 02:52 UTC
I thought === was strict
Legacy
@punyparker
May 23 2017 02:52 UTC
@fillopfy I just solved that yesterday, so hard.
Rick Willcox
@willcoxDev
May 23 2017 02:52 UTC
the question says to try using indexOf()
eyesore-
@eyesore-
May 23 2017 02:53 UTC
@willcoxDev If they are strings it's cool.
Legacy
@punyparker
May 23 2017 02:53 UTC
function rot13(str) { // LBH QVQ VG!
  var strArr = [];
  for (var i = 0; i < str.length;i++) {
    var char = str.charCodeAt(i) - 13;
    strArr.push(String.fromCharCode(char));
  }
  return strArr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Rick Willcox
@willcoxDev
May 23 2017 02:53 UTC
yeh its alwasy strings
Abhishek Tiwari
@fillopfy
May 23 2017 02:53 UTC
@punyparker it is passing all the test except the first one
Rick Willcox
@willcoxDev
May 23 2017 02:53 UTC
in the example
Long Nguyen
@longnt80
May 23 2017 02:53 UTC
@punyparker please don't give your solution
Legacy
@punyparker
May 23 2017 02:53 UTC
Can someone help me with the above.
Rick Willcox
@willcoxDev
May 23 2017 02:53 UTC
im working through it now
and want to get it
Abhishek Tiwari
@fillopfy
May 23 2017 02:54 UTC
@longnt80 can you see my code and what is wrong in it
Long Nguyen
@longnt80
May 23 2017 02:54 UTC
@punyparker sorry, I thought you gave the solution to @fillopfy
Rick Willcox
@willcoxDev
May 23 2017 02:54 UTC
yeh same hhaa
Legacy
@punyparker
May 23 2017 02:54 UTC
@longnt80 different one xD
I keep getting the wrong answer
@longnt80 can you help?
Run the code and you will see
eyesore-
@eyesore-
May 23 2017 02:55 UTC
@willcoxDev The reason why it does not work is because it is the same word. So it begins at 0. With type coercion 0 turns into false
Long Nguyen
@longnt80
May 23 2017 02:56 UTC
@punyparker let me check
Abhishek Tiwari
@fillopfy
May 23 2017 02:56 UTC

@eyesore- and this one:
function mutation(arr) {
var m=arr[0].toLowerCase();
var n=arr[1].toLowerCase();

for(var i=0;i<n.length;i++)
{
if(m.indexOf(n[i])!==-1 )
{
return true;
}
return false;
}
}

Legacy
@punyparker
May 23 2017 02:56 UTC
It's supposed to return Free code camp
sanu921
@sanu921
May 23 2017 02:56 UTC

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

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

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

Could anyone help me
i dont know why my cide is not working
eyesore-
@eyesore-
May 23 2017 02:57 UTC
@fillopfy You want to switch your conditional. You want to be checking if it does not exist in the other string and if it doesn't then return false.
@fillopfy that way you are terminating right when you have the answer.
sanu921
@sanu921
May 23 2017 02:58 UTC
I have to return the value if it axists in the object otherwise not found
Abhishek Tiwari
@fillopfy
May 23 2017 02:58 UTC
@eyesore- but it is passing all the test except {hello,hye}
eyesore-
@eyesore-
May 23 2017 02:59 UTC
@fillopfy Yeah, your code is only checking the first letter is that is the case. So when it hits 'h' it does not equal -1 which then returns true.
@fillopfy You dont want to do that.
@sanu921 Check out the different between dot notation and bracket notation
Abhishek Tiwari
@fillopfy
May 23 2017 03:00 UTC
@eyesore- i am not understanding
eyesore-
@eyesore-
May 23 2017 03:00 UTC
@fillopfy post your code again
Abhishek Tiwari
@fillopfy
May 23 2017 03:01 UTC
function mutation(arr) {
  var m=arr[0].toLowerCase();
  var n=arr[1].toLowerCase();

  for(var i=0;i<n.length;i++)
    {
      if(m.indexOf(n[i])!==-1 )
      {
        return true;
      }
      return false;
    }
}
Long Nguyen
@longnt80
May 23 2017 03:02 UTC
@punyparker you need half of the letters in alphabet to + 13 in charcode
Legacy
@punyparker
May 23 2017 03:04 UTC
@longnt80 what do you mean
a is 65
eyesore-
@eyesore-
May 23 2017 03:05 UTC
@fillopfy
  for(var i=0;i<n.length;i++)
    {
      // n[i] = 'h'
      // if indexOf 'h' does not equal -1
      // 'h' is in m so it does not equal -1
      if(m.indexOf(n[i])!==-1 )
      {
        // since 'h' is in m
        // function returns true and it does not check anything else
        return true;
      }
      return false;
    }
}

mutation(['hello', 'hye'])
Long Nguyen
@longnt80
May 23 2017 03:05 UTC
@fillopfy in your code, if the first letter is contained, it will quit the loop and not check for the next letter
Legacy
@punyparker
May 23 2017 03:05 UTC
65-13 isnt a letter
eyesore-
@eyesore-
May 23 2017 03:06 UTC
@fillopfy You want to be checking if n[i] is not in m then return false. If the loop is not and it never returned then you should return true
Masaki
@masaki1223
May 23 2017 03:06 UTC

Hi guys, can anybody tell me what 'Everything Be True' challenge's problem means? "Check if the predicate (second argument) is truthy on all elements of a collection (first argument).

Remember, you can access object properties through either dot notation or [] notation."

Abhishek Tiwari
@fillopfy
May 23 2017 03:06 UTC
@eyesore- @longnt80 hmm, i got it . It return the value after checking only the initial value
Long Nguyen
@longnt80
May 23 2017 03:07 UTC
@fillopfy yeah you need to move your return true outside of the loop so it can goes through all the letters
Masaki
@masaki1223
May 23 2017 03:07 UTC
check if its truthy means second arg is in each object in first arg, right?
Long Nguyen
@longnt80
May 23 2017 03:08 UTC
@punyparker in ceasar cipher, A will be N right? So when you input A it will translate to N by adding 13 in charCode. But in the opposite, if you input N, it will translate to A by subtract 13 in charCode.
Abhishek Tiwari
@fillopfy
May 23 2017 03:09 UTC
@longnt80 when i did that, all the test failed and the first test passed
Long Nguyen
@longnt80
May 23 2017 03:09 UTC
@fillopfy please post your code again
Legacy
@punyparker
May 23 2017 03:09 UTC
@longnt80 but suppose you input A, and thats 65. 65 -13 isn't a letter.
Abhishek Tiwari
@fillopfy
May 23 2017 03:10 UTC
function mutation(arr) {
  var m=arr[0].toLowerCase();
  var n=arr[1].toLowerCase();

  for(var i=0;i<n.length;i++)
    {
      if(m.indexOf(n[i])!==-1 )
      {
        return true;
      }
      return false;
    }
}
@longnt80 this is passing all test except the first one
Long Nguyen
@longnt80
May 23 2017 03:10 UTC
@punyparker yeah, it's not a letter, you have to convert it to letter again
Abhishek Tiwari
@fillopfy
May 23 2017 03:10 UTC
@longnt80 but when I interchanged the statments, first condition passed and all failed
Rick Willcox
@willcoxDev
May 23 2017 03:11 UTC
try ```
Legacy
@punyparker
May 23 2017 03:11 UTC
@longnt80 How would I do that, that's my problem.
Yes, I've used that
Rick Willcox
@willcoxDev
May 23 2017 03:12 UTC
if(m.indexOf(n[i]) < 0){
     return false;
}
return true;
Long Nguyen
@longnt80
May 23 2017 03:12 UTC

@fillopfy

if(m.indexOf(n[i])!==-1 )
      {
        return true;

this will stop the loop if the first letter is matched

Rick Willcox
@willcoxDev
May 23 2017 03:13 UTC
its bascailly saying if the first letter in the same as the other first letter return true
so ["he", "hr"] returns true
Long Nguyen
@longnt80
May 23 2017 03:13 UTC
@fillopfy you need to do the opposite: stop the loop if the letter is not matched
Rick Willcox
@willcoxDev
May 23 2017 03:13 UTC
as both first letters are H
Abhishek Tiwari
@fillopfy
May 23 2017 03:14 UTC
@willcoxDev same result
Long Nguyen
@longnt80
May 23 2017 03:14 UTC
@fillopfy here's the opposite:
if(m.indexOf(n[i]) === -1 )
      {
        return false;
Rick Willcox
@willcoxDev
May 23 2017 03:14 UTC
have u swapped your false and true?
eyesore-
@eyesore-
May 23 2017 03:14 UTC
Are you dropping the return true outside the loop?
That is pretty essential in it.
Abhishek Tiwari
@fillopfy
May 23 2017 03:15 UTC
function mutation(arr) {
  var m=arr[0].toLowerCase();
  var n=arr[1].toLowerCase();

  for(var i=0;i<n.length;i++)
    {
      if(m.indexOf(n[i])<0 )
      {
        return false;
      }
      return true;
    }
}
eyesore-
@eyesore-
May 23 2017 03:15 UTC
You dont want to return true until the end of the loop and it has checked everything
Abhishek Tiwari
@fillopfy
May 23 2017 03:15 UTC
this also pass all except first
Rick Willcox
@willcoxDev
May 23 2017 03:15 UTC
your return true is insdie ur for loop
move it outside
eyesore-
@eyesore-
May 23 2017 03:15 UTC
Yeah, you are returning true in your loop so you are still having the same issue.
Long Nguyen
@longnt80
May 23 2017 03:15 UTC
@punyparker ok let's break it down. What's the charcode of A?
Rick Willcox
@willcoxDev
May 23 2017 03:15 UTC
for (var i=0; i<n.length; i++){
    if (m.indexOf(n[i]) < 0){
      return false;
    }
  }
  return true;
  }
Abhishek Tiwari
@fillopfy
May 23 2017 03:15 UTC
@eyesore- aha...finally worked
@longnt80 @willcoxDev @eyesore- thanks everyne
CamperBot
@camperbot
May 23 2017 03:16 UTC
fillopfy sends brownie points to @longnt80 and @willcoxdev and @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 250 | @willcoxdev |http://www.freecodecamp.com/willcoxdev
:cookie: 95 | @eyesore- |http://www.freecodecamp.com/eyesore-
:cookie: 292 | @longnt80 |http://www.freecodecamp.com/longnt80
eyesore-
@eyesore-
May 23 2017 03:16 UTC
No problem.
Nick Forlivio
@whackdev
May 23 2017 03:16 UTC
should I be using sass in codepen or is it just something else to learn?
Legacy
@punyparker
May 23 2017 03:16 UTC
@longnt80 65
eyesore-
@eyesore-
May 23 2017 03:16 UTC
@whackdev If you want to do front end then you should definitely learn some kind of precompiler like SASS or LESS
Rick Willcox
@willcoxDev
May 23 2017 03:17 UTC
@eyesore- do you just chill in this chat to help people
Long Nguyen
@longnt80
May 23 2017 03:17 UTC
@fillopfy you should tinker with that
Rick Willcox
@willcoxDev
May 23 2017 03:17 UTC
i noticed your score is low meaning you havent done much of the camp correct?
but you clearly know whats going on
Long Nguyen
@longnt80
May 23 2017 03:17 UTC
@punyparker what's the charcode of N?
eyesore-
@eyesore-
May 23 2017 03:17 UTC
@willcoxDev I've done very little. Yeah, I come on from time to time to help out.
Nick Forlivio
@whackdev
May 23 2017 03:17 UTC
@willcoxDev the scores only go up when someone sends brownie points
Rick Willcox
@willcoxDev
May 23 2017 03:18 UTC
weird my cookie score is 250 whichs is the same as my score of how many parts I ahve done
Long Nguyen
@longnt80
May 23 2017 03:18 UTC
@whackdev no, you also ad points when complete challenges
Abhishek Tiwari
@fillopfy
May 23 2017 03:18 UTC
@longnt80 tinker?
eyesore-
@eyesore-
May 23 2017 03:18 UTC
@willcoxDev I definitely believe that teaching is the best way to solidify your knowledge. Most devs write blog posts, but I really don't like writing.
Rick Willcox
@willcoxDev
May 23 2017 03:18 UTC
image.png
Long Nguyen
@longnt80
May 23 2017 03:18 UTC
@fillopfy meaning play around with it to understand how return works
Rick Willcox
@willcoxDev
May 23 2017 03:19 UTC
is what I was refering 2
eyesore-
@eyesore-
May 23 2017 03:19 UTC
I think I've done like 5 lessons at most.
Rick Willcox
@willcoxDev
May 23 2017 03:19 UTC
@eyesore- ah true
Abhishek Tiwari
@fillopfy
May 23 2017 03:19 UTC
@longnt80 yeah, I was using the wrong comparison and then returning true within the loop
Nick Forlivio
@whackdev
May 23 2017 03:20 UTC
@willcoxDev I think you get points for both because mine is 277 and I haven't completed that many challenges I'm only on intermediate
eyesore-
@eyesore-
May 23 2017 03:20 UTC
Yeah, so instead of blogging I just come on here or I will write tests to implement methods from scratch like reduce in case anyone wants to get real deep with JS
Abhishek Tiwari
@fillopfy
May 23 2017 03:21 UTC
@eyesore- you said, teaching is the best way to learn
does anyone teach code like freecodecamp does
eyesore-
@eyesore-
May 23 2017 03:22 UTC
Like person or another site?
But yeah teaching someone else really shows if you understand the concept to begin with.
Nick Forlivio
@whackdev
May 23 2017 03:23 UTC
@fillopfy interactivepython.org has some great python modules, that's where I started
Long Nguyen
@longnt80
May 23 2017 03:24 UTC
@punyparker
translating: A to N:
A -> 65 -> 65+13 -> 78 -> N
translating N to A:
N -> 78 -> 78 -13 -> 65 -> A
@punyparker so the first half of the letters from A-Z with need to +13 in their charcode, and the last half of the letters from A-Z with need to -13 in their charcode.
Anker
@ankerpeet
May 23 2017 03:27 UTC
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line

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

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "lastName");
Any ideas how to help me on this one?
Rick Riggs
@wikiwiggs
May 23 2017 03:28 UTC
@ankerpeet First ask what prop is referring to.
Manish Giri
@Manish-Giri
May 23 2017 03:28 UTC
@ankerpeet contacts[i].prop
Legacy
@punyparker
May 23 2017 03:29 UTC
@longnt80 THANKS SO MUCH
CamperBot
@camperbot
May 23 2017 03:29 UTC
punyparker sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @longnt80 |http://www.freecodecamp.com/longnt80
Manish Giri
@Manish-Giri
May 23 2017 03:29 UTC
prop isn't really a direct property on the object
@ankerpeet also, else return "No such contact";- does this make sense in the for loop?
Anker
@ankerpeet
May 23 2017 03:30 UTC
@Manish-Giri Its only a paramter for the lookUpProfile function?
Rick Willcox
@willcoxDev
May 23 2017 03:30 UTC
anyone know how to turn off all notifications from this chat
Manish Giri
@Manish-Giri
May 23 2017 03:30 UTC
@ankerpeet yes
so using dot notation won't work
Rick Willcox
@willcoxDev
May 23 2017 03:30 UTC
I set it to only show when I am mentioned by name
Anker
@ankerpeet
May 23 2017 03:31 UTC
bracket notation then?
@Manish-Giri
Manish Giri
@Manish-Giri
May 23 2017 03:31 UTC
@ankerpeet yup
Masaki
@masaki1223
May 23 2017 03:31 UTC
addTogether(2)(3) if the call is this, how can I access to the second closure? arguments[1]would not access to (3)
Rick Riggs
@wikiwiggs
May 23 2017 03:31 UTC

@ankerpeet

if(contacts[i].prop === prop)

ask if this should be:

if(contacts[prop] === prop)

if it should why or why not?
what about:

if(contacts[prop] == prop)
Anker
@ankerpeet
May 23 2017 03:32 UTC
@wikiwiggs Let me adjust my code a bit and i'll be back. thank you
CamperBot
@camperbot
May 23 2017 03:32 UTC
ankerpeet sends brownie points to @wikiwiggs :sparkles: :thumbsup: :sparkles:
:cookie: 306 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
Charles Astor
@CodeAstor
May 23 2017 03:33 UTC

function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) >=0 && arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) >=0)
newArr.push(ne[i]);

}
return newArr;
}

diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);

Long Nguyen
@longnt80
May 23 2017 03:33 UTC
@masaki1223 you need to read the link they give you in the challenge
Peter Kay
@deuscode
May 23 2017 03:34 UTC
$(document).ready(function() {

    $.ajax({
        type: 'GET',
        url: 'https://wind-bow.glitch.me/twitch-ap/streams/freecodecamp?callback=?',
        header: {'Client-ID': 'hs5elqgum44iq9qdg3a1a3ydpyp00b'},
        success: function(data) {
            console.log(data);
        },
        error: function(err) {
            console.log("error");
        }
    });
});
I am getting an Access-Control-Allow-Oirigin header is present error. Can someone explain to me what I am doing wrong with this test call?
Charles Astor
@CodeAstor
May 23 2017 03:34 UTC
Hi, I'm trying to beat the challenge Intermediate Algorithm Scripting: Diff Two Arrays
Charles Astor
@CodeAstor
May 23 2017 03:35 UTC
and not getting the correct result even though I think I should be getting a new Array with different values from each array like the challenge specifies
I'm only passing 5 test though
eyesore-
@eyesore-
May 23 2017 03:36 UTC
@longnt80 What he is talking about is more currying than closure.
Charles Astor
@CodeAstor
May 23 2017 03:36 UTC

function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) >=0 && arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) >=0)
newArr.push(ne[i]);

}
return newArr;
}

diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);

Here is my code, I'm not sure how to format it how it looks in the browser
Long Nguyen
@longnt80
May 23 2017 03:36 UTC
@eyesore- but there's an example in that link which explain that case
Rick Riggs
@wikiwiggs
May 23 2017 03:37 UTC

@deuscode try this:

$(document).ready(function() {

    $.ajax({
        type: 'GET',
        url: 'https://crossorigin.me/https://wind-bow.glitch.me/twitch-ap/streams/freecodecamp?callback=?',
        header: {'Client-ID': 'hs5elqgum44iq9qdg3a1a3ydpyp00b'},
        success: function(data) {
            console.log(data);
        },
        error: function(err) {
            console.log("error");
        }
    });
});

Read more:
https://crossorigin.me/

Nick Forlivio
@whackdev
May 23 2017 03:37 UTC
@CodeAstor put your code in backticks ```
Charles Astor
@CodeAstor
May 23 2017 03:38 UTC
function diffArray(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
   var ne =arr1.concat(arr2);
  for(var i = 0; i < arr1.length;i++){
    if(arr1.indexOf(ne[i]) >=0 && arr2.indexOf(ne[i]) ==-1)
      newArr.push(ne[i]);
    if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) >=0)
      newArr.push(ne[i]);

  }
  return newArr;
}

diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
Thanks
Long Nguyen
@longnt80
May 23 2017 03:39 UTC

@masaki1223
here's the exmaple:

function makeAdder(x) {
  return function(y) {
    return x + y;
  };
}

var add5 = makeAdder(5);
var add10 = makeAdder(10);

console.log(add5(2));  // 7
console.log(add10(2)); // 12

you can see add5(2) is exactly makeAdder(5)(2)

Peter Kay
@deuscode
May 23 2017 03:39 UTC
@wikiwiggs is that a proxy?
@wikiwiggs I'm unsure if it can pass the headers to the call... getting a "header is required"
Rick Riggs
@wikiwiggs
May 23 2017 03:40 UTC
Yeah, if you were running (serving up these API calls) it would server side like on a Node or PHP backend, but because you are on the client side for these code pen exercises you will have this issue.
@deuscode Give me a second, lets see if we can try something else.
Anker
@ankerpeet
May 23 2017 03:42 UTC
@Manish-Giri so would I have to use the .hasOwnProperty function?
Nick Forlivio
@whackdev
May 23 2017 03:42 UTC
@CodeAstor what are you trying to do? it looks like the code is pushing ne[i] no matter what
Peter Kay
@deuscode
May 23 2017 03:42 UTC
@wikiwiggs I'm actually running locally, going to upload this to my webhost after I'm done with the project
Charles Astor
@CodeAstor
May 23 2017 03:43 UTC
@whackdev Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
Peter Kay
@deuscode
May 23 2017 03:43 UTC
@wikiwiggs I used the http://localhost for my twitch client_id redirect
eyesore-
@eyesore-
May 23 2017 03:43 UTC
@deuscode You want to read about CORS. That will help you out.
Charles Astor
@CodeAstor
May 23 2017 03:43 UTC
So I start out by combining two arrays
Peter Kay
@deuscode
May 23 2017 03:43 UTC
@wikiwiggs yep, I am using a jsonp callback parameter to get around the CORS
Charles Astor
@CodeAstor
May 23 2017 03:43 UTC
and then I check if the value on ne[i] is in one of the originals but not in the others
Then add them in
Peter Kay
@deuscode
May 23 2017 03:44 UTC
@eyesore- yep, I am using a jsonp callback parameter to get around the CORS
Rick Riggs
@wikiwiggs
May 23 2017 03:44 UTC
@deuscode
$(document).ready(function() {

    $.ajax({
        type: 'GET',
        url: 'https://crossorigin.me/https://wind-bow.glitch.me/twitch-ap/streams/freecodecamp?client_id=hs5elqgum44iq9qdg3a1a3ydpyp00b?callback=?',
        success: function(data) {
            console.log(data);
        },
        error: function(err) {
            console.log("error");
        }
    });
});
Charles Astor
@CodeAstor
May 23 2017 03:45 UTC

```function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) != -1&& arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) != -1)
newArr.push(ne[i]);

}
return newArr;
}
```

lol
Peter Kay
@deuscode
May 23 2017 03:45 UTC
even hard coding the client_id I get a Header is required @wikiwiggs
Charles Astor
@CodeAstor
May 23 2017 03:46 UTC

```function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) != -1&& arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) != -1)
newArr.push(ne[i]);

}
return newArr;
}```

Nick Forlivio
@whackdev
May 23 2017 03:46 UTC
@CodeAstor ok I see it now, I did that one differently
Anker
@ankerpeet
May 23 2017 03:46 UTC
@Manish-Giri I figured it out. Thank you!
CamperBot
@camperbot
May 23 2017 03:46 UTC
ankerpeet sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5613 | @manish-giri |http://www.freecodecamp.com/manish-giri
Masaki
@masaki1223
May 23 2017 03:46 UTC

function addTogether(x) {
 return function(y){
   return x+y;
 };

  var newArr=[].slice.apply(arguments);
  var result=newArr[0]+newArr[1];

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

    if(typeof newArr[i]!=='number'){
      result=undefined;
      break;
    }
  }
  return result;

}
var sumTwoAnd = addTogether(2);
sumTwoAnd(3);
addTogether(2,3);
I want to make this work, but i dont know how to. Any help? How can I put another function in addTogether function?
Charles Astor
@CodeAstor
May 23 2017 03:47 UTC
Not sure why the back ticks aren't working for me anymore
Masaki
@masaki1223
May 23 2017 03:47 UTC
This is the last challenge in intemidiate challenge
Peter Kay
@deuscode
May 23 2017 03:47 UTC
@wikiwiggs I might end up just biting the bullet and creating a dotenv backend to store API keys and call it via ajax.... argh lol
Charles Astor
@CodeAstor
May 23 2017 03:47 UTC
Yeah, I'm probably not doing it the best way @whackdev
Rick Riggs
@wikiwiggs
May 23 2017 03:47 UTC
@deuscode
I think that's gonna be the best bet.
Rick Willcox
@willcoxDev
May 23 2017 03:47 UTC
man the .filter() function is really throwing me through a loop
confusing the heck outa me
Nick Forlivio
@whackdev
May 23 2017 03:48 UTC
@CodeAstor I don't think so I like the idea I just didn't think of it that way. What does your output look like? are you just getting the value of ne?
Rick Riggs
@wikiwiggs
May 23 2017 03:48 UTC
@deuscode That's the project I'm currently procrastinating on, this very project. It's more fitting for a different cert in the code school. It has way more to do with backend nuances.
Nick Forlivio
@whackdev
May 23 2017 03:49 UTC
@willcoxDev hated that one
Peter Kay
@deuscode
May 23 2017 03:49 UTC
@wikiwiggs yeah... I've procrastinated this a whole bunch... I even have to take down my wiki pedia viewer because i forgot I stored the API client side... :\
Charles Astor
@CodeAstor
May 23 2017 03:49 UTC
Well I'm passing about 5 test so it's working on some of them
eyesore-
@eyesore-
May 23 2017 03:49 UTC
You guys want to implement filter from scratch so you know it inside and out?
Peter Kay
@deuscode
May 23 2017 03:50 UTC
@wikiwiggs looks like they should put in the ciriculuum on how to create a backend with dotenv lol...
Rick Willcox
@willcoxDev
May 23 2017 03:50 UTC
@whackdev The .filter() page shows an example almsot exactly the same as what you hvae to do for ther answer but even stepping through the code on pythontutor.com its confusing as fk
Peter Kay
@deuscode
May 23 2017 03:50 UTC
@wikiwiggs thanks for the effort tho!
CamperBot
@camperbot
May 23 2017 03:50 UTC
deuscode sends brownie points to @wikiwiggs :sparkles: :thumbsup: :sparkles:
:cookie: 307 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
Rick Riggs
@wikiwiggs
May 23 2017 03:50 UTC
@deuscode I have a backend sort of setup for this if you would like to use it.
Peter Kay
@deuscode
May 23 2017 03:51 UTC
@wikiwiggs I would like to see how you created it and/or articles you used to go through it. I'm still new to backend work
Rick Riggs
@wikiwiggs
May 23 2017 03:51 UTC
@eyesore- you going to hijack the prototype of the array?
Nick Forlivio
@whackdev
May 23 2017 03:51 UTC
@CodeAstor try looking at what's failing you should be able to figure out why you are getting what you are against the expected results
eyesore-
@eyesore-
May 23 2017 03:51 UTC
Nah, I was just going to write some tests on a jsbin to implement the function.
Rick Riggs
@wikiwiggs
May 23 2017 03:51 UTC
@deuscode No articles really, just Twitch's API, and my long history with PHP.
Nick Forlivio
@whackdev
May 23 2017 03:52 UTC
@CodeAstor whats the name of that challenge?
Charles Astor
@CodeAstor
May 23 2017 03:52 UTC
@whackdev Intermediate Algorithm Scripting: Diff Two Arrays
Nick Forlivio
@whackdev
May 23 2017 03:52 UTC
@willcoxDev I know I tried folowing it exactly and it wsa still hard
Peter Kay
@deuscode
May 23 2017 03:53 UTC
@wikiwiggs ahhh, that must help a lot. I host on webfaction, so I'll look into how to integrate a backend service with their documentation
Nick Forlivio
@whackdev
May 23 2017 03:53 UTC
@CodeAstor ok I thought it was a different one let me take a look at it
Rick Riggs
@wikiwiggs
May 23 2017 03:53 UTC
@eyesore- I'm gonna help Peter Kay for a bit, but I'm curious to see you take on this.
eyesore-
@eyesore-
May 23 2017 03:53 UTC
I can do reduce first because I have that one set up already haha
Rick Riggs
@wikiwiggs
May 23 2017 03:54 UTC
@deuscode Let's go into Private chat.
Peter Kay
@deuscode
May 23 2017 03:54 UTC
@wikiwiggs sure thing
Long Nguyen
@longnt80
May 23 2017 03:54 UTC
@masaki1223 there are 2 cases:
  • addTogether(2, 3): this case arguments.length is more than 1
  • addTogether(2)(3): this case arguments.length is 1
    you need to use if to check
Rick Willcox
@willcoxDev
May 23 2017 03:58 UTC
If I have this line destroyer([1, 2, 3, 1, 2, 3], 2, 3); How do I reference the 2 and the 3 at the end in a function since it not in the array
Long Nguyen
@longnt80
May 23 2017 03:58 UTC
@willcoxDev use the keyword arguments
Rick Willcox
@willcoxDev
May 23 2017 03:59 UTC
ok thanks
Charles Astor
@CodeAstor
May 23 2017 04:00 UTC
@whackdev I figured it out, I wasn't iterating over the entire array, the logic was working but I was only going from ar1.length instead of ne.length lol. Thanks for the help!
CamperBot
@camperbot
May 23 2017 04:00 UTC
codeastor sends brownie points to @whackdev :sparkles: :thumbsup: :sparkles:
:cookie: 278 | @whackdev |http://www.freecodecamp.com/whackdev
Rick Willcox
@willcoxDev
May 23 2017 04:00 UTC
@longnt80 thanks
CamperBot
@camperbot
May 23 2017 04:00 UTC
willcoxdev sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 294 | @longnt80 |http://www.freecodecamp.com/longnt80
Long Nguyen
@longnt80
May 23 2017 04:00 UTC
:+1:
Nick Forlivio
@whackdev
May 23 2017 04:03 UTC
@CodeAstor :+1:
Rick Willcox
@willcoxDev
May 23 2017 04:11 UTC
I know my thinking is a bit off. As splicing out i will mess it up for the next loop butI keep getting type error because arr[i] isnt a string so I cant use indexOf() but struggling to fix

function destroyer(arr) {
   for(var i=0; i<arr.length;i++){
     for(var j=1; j<(arguments.length); j++){
       if (arr[i].toString.indexOf(arguments[j]) >=0){
          arr.splice(i,1);        
       }       
     }  


   }
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Traek Wells
@TraekWells
May 23 2017 04:13 UTC
can anyone tell me why I can’t use this[i].title instead of movie[i].title?
var movies = [
  {
    title: 'Troy',
    rating: 5,
    hasWatched: true
  },
  {
    title: 'Alien: Covenant',
    rating: 4.5,
    hasWatched: true
  },
  {
    title: 'Wonder Woman',
    rating: 4.5,
    hasWatched: false
  },
  {
    title: 'Mad Max',
    rating: 4,
    hasWatched: true
  }
];

for (var i = 0; i < movies.length; i++) {
  if (movies[i].hasWatched === false) {
    console.log('You have not seen ' + movies[i].title + ' - ' + movies[i].rating + ' stars');
  } else {
    console.log('You have seen ' + movies[i].title + ' - ' + movies[i].rating + ' stars')
  }
}
Rick Willcox
@willcoxDev
May 23 2017 04:13 UTC
am I on the right track?, kill what ever elements in my array are part of my arguements
Markus Ivancsics
@ivancsicsmarkus
May 23 2017 04:15 UTC
@TraekWells this would refer to the object window outside of an object.
Traek Wells
@TraekWells
May 23 2017 04:17 UTC
mmm
@ivancsicsmarkus even if I replace every ‘movies’ instance with this besides the for loop, it still wouldn’t work?
‘this’*
Markus Ivancsics
@ivancsicsmarkus
May 23 2017 04:18 UTC
@TraekWells @TraekWells What do you mean?
@TraekWells How?
Traek Wells
@TraekWells
May 23 2017 04:19 UTC
@ivancsicsmarkus
for (var i = 0; i < movies.length; i++) {
  if (this[i].hasWatched === false) {
    console.log('You have not seen ' + thisi].title + ' - ' + this[i].rating + ' stars');
  } else {
    console.log('You have seen ' + this[i].title + ' - ' + this[i].rating + ' stars')
  }
}
this wouldn’t work either?
Markus Ivancsics
@ivancsicsmarkus
May 23 2017 04:19 UTC
@TraekWells Yes. I said this refers to the window object not for the movies object.
@TraekWells this works inside constructors. Than it refers to the current object.
@TraekWells But outside… it refers the (global) window object.
carousel not working
Traek Wells
@TraekWells
May 23 2017 04:24 UTC
@ivancsicsmarkus ahhhhh I see. Thanks for clearing that up. Makes sense why the code I posted wouldn’t work
CamperBot
@camperbot
May 23 2017 04:24 UTC
traekwells sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:cookie: 511 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
Claudio Restifo
@Marmiz
May 23 2017 04:24 UTC
@shenoyabhijith you have to initialize it via jQuery:
    $(document).ready(function(){
      $('.carousel').carousel();
    });
abhijith shenoy
@shenoyabhijith
May 23 2017 04:27 UTC
not working
Claudio Restifo
@Marmiz
May 23 2017 04:32 UTC
@shenoyabhijith it's working on my end
Rick Riggs
@wikiwiggs
May 23 2017 04:38 UTC
@eyesore- did you show it yet?
eyesore-
@eyesore-
May 23 2017 04:39 UTC
@wikiwiggs Nah. Let me send you the link with all the test.
Rick Willcox
@willcoxDev
May 23 2017 04:40 UTC

why is this

return (arguments[1].toString()).indexOf(value);

Not the same as

var a1 = arguments[1].toString();
return a1.indexOf(value);
for reference the second example works
the first does not
Rick Riggs
@wikiwiggs
May 23 2017 04:41 UTC
@eyesore- Your killing me man, I haven't had the time to go learn up on ES6 yet
amelink
@amelink
May 23 2017 04:41 UTC
hi, can someone help me for Factorialize a Number exercise please?
eyesore-
@eyesore-
May 23 2017 04:42 UTC
@wikiwiggs the tests are written in ES6, but you can do the answer in ES5
Rick Willcox
@willcoxDev
May 23 2017 04:42 UTC
@amelink i can help, I just did that one. First do you understand what a factorial is?
eyesore-
@eyesore-
May 23 2017 04:42 UTC
@wikiwiggs shit, I'll do it right now if you want me to. haha
Rick Riggs
@wikiwiggs
May 23 2017 04:43 UTC
@eyesore- I'm just confused since to me it looks like you created your own reduce function that was completely empty.
with the exception of you have defined parameters.
Markus Ivancsics
@ivancsicsmarkus
May 23 2017 04:44 UTC
@willcoxDev arguments is not an array. It is just array-like. Sometimes it behaves strangely, like above.
eyesore-
@eyesore-
May 23 2017 04:44 UTC
@wikiwiggs Oh, I made that for someone. They asked what way they could understand reduce better and I told them to implement it from scratch so I wrote all those tests to help them.
amelink
@amelink
May 23 2017 04:44 UTC
@willcoxDev I don't know what it is exactly, but I understand the example
eyesore-
@eyesore-
May 23 2017 04:44 UTC
@wikiwiggs I thought you wanted to give it a crack. Let me write the actual reduce function and I will send it to you.
Rick Willcox
@willcoxDev
May 23 2017 04:45 UTC
@amelink example 6! is 6x5x4x3x2x1 2! is 2x1
so just create a loop
Rick Riggs
@wikiwiggs
May 23 2017 04:45 UTC
@eyesore- OK, I thought there was some sort of ES6 iterative definition magic going on or something.
Rick Willcox
@willcoxDev
May 23 2017 04:45 UTC
and inside product *= i
eyesore-
@eyesore-
May 23 2017 04:46 UTC
@willcoxDev Haha not completely. Just in the tests. Pretty proud of those.
Rick Willcox
@willcoxDev
May 23 2017 04:46 UTC
a factorial is just the number times every number below it down to 1
eyesore-
@eyesore-
May 23 2017 04:47 UTC
@wikiwiggs Paste this in and you have a reducer
function reduce(collection, iterator, accumulator) {
  var accumUndefined = arguments.length < 3

  collection.forEach(function(item){
    if(accumUndefined) {
      accumUndefined = false
      accumulator = item
    } else {
      return accumulator = iterator(accumulator, item)
    }
  })

  return accumulator
}
amelink
@amelink
May 23 2017 04:47 UTC
@willcoxDev I don't have the same example, mine was 5! = 1 2 3 4 5 = 120
I understand this example but I don't where to start to do it
Rick Willcox
@willcoxDev
May 23 2017 04:49 UTC
whatever the number is
just times that number vy every other number below it
5x4x3x2x1 = 120
so just write a for loop that loops from i = 1 to i = number and times a variable product by i each loop then return the product
Rick Riggs
@wikiwiggs
May 23 2017 04:51 UTC
@eyesore- Is that how it is actually written?
eyesore-
@eyesore-
May 23 2017 04:51 UTC
@wikiwiggs I'm not sure if that is the one that is used, but it will work as a reducer.
Rick Riggs
@wikiwiggs
May 23 2017 04:52 UTC
@eyesore- in the method i meant, ok, I was just curious.
eyesore-
@eyesore-
May 23 2017 04:52 UTC
@wikiwiggs Also, each browser engine may have their own.
Rick Riggs
@wikiwiggs
May 23 2017 04:52 UTC
@eyesore- good to know, do you know of a reference for built-ins on a per browser basis?
Rick Willcox
@willcoxDev
May 23 2017 04:53 UTC
@amelink something liek this
function factorial(num){
  var result = 1;
  for (var i=1; i<num; i++){
    result *= i;
  }
  return result;
}

factorial(5);
eyesore-
@eyesore-
May 23 2017 04:54 UTC
@wikiwiggs I couldn't think of another way to implement it. I don't think it's public. Specially with sort that is one everyone takes pride in, but I think the majority use a radix sort.
Rick Riggs
@wikiwiggs
May 23 2017 04:54 UTC
I love the sprt method.
especially when I can spell it correctly
eyesore-
@eyesore-
May 23 2017 04:55 UTC
Haha have you implemented one before?
amelink
@amelink
May 23 2017 04:55 UTC
thank you @willcoxDev for your explanations
CamperBot
@camperbot
May 23 2017 04:55 UTC
amelink sends brownie points to @willcoxdev :sparkles: :thumbsup: :sparkles:
:cookie: 252 | @willcoxdev |http://www.freecodecamp.com/willcoxdev
eyesore-
@eyesore-
May 23 2017 04:55 UTC
they are rough when it comes to performance.
Rick Riggs
@wikiwiggs
May 23 2017 04:56 UTC
I have, but I've done it in lisp a long time ago, and don't remember how I implemented it.
Rick Willcox
@willcoxDev
May 23 2017 04:56 UTC
hey eyesore I have a doozy for you.
Rick Riggs
@wikiwiggs
May 23 2017 04:56 UTC
I sure love it in JS though
eyesore-
@eyesore-
May 23 2017 04:56 UTC
Oh, also for a browser reduce is probably produces with a for loop since that is better performing than forEach
What's up?
Rick Willcox
@willcoxDev
May 23 2017 04:56 UTC
function destroyer(arr) {
  var array = arguments[0];
  var a1 = arguments[1].toString();
  var a2 = arguments[2].toString();
  array = array.filter(function(value){
    return a1.indexOf(value);
  });
  array = array.filter(function(value){
    return a2.indexOf(value);
  });

  return array;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
so this works
as long as there are only 2 arguments
after the array
obviously i need to do some sort of loop
eyesore-
@eyesore-
May 23 2017 04:58 UTC
What are you trying to do?
Is this Seek and Destroy?
Rick Willcox
@willcoxDev
May 23 2017 04:58 UTC
yes
Moisés Man
@moigithub
May 23 2017 04:58 UTC
[1,2,3].indexOf("1")
result: -1 <-- mean NOT found
WHY u toString ?
Rick Willcox
@willcoxDev
May 23 2017 04:58 UTC
because you cant do indexOf() on an int
only a string
I get type error
i guess i am wrong
eyesore-
@eyesore-
May 23 2017 04:59 UTC
You can do indexOf on an Array
Rick Willcox
@willcoxDev
May 23 2017 04:59 UTC
I tried
eyesore-
@eyesore-
May 23 2017 04:59 UTC
Its a prototype to string and array
Rick Riggs
@wikiwiggs
May 23 2017 04:59 UTC
You can also do a replace on a string
Rick Willcox
@willcoxDev
May 23 2017 05:00 UTC
array = array.filter(function(value){
    return arguments[1].indexOf(value);
but this doenst work
eyesore-
@eyesore-
May 23 2017 05:00 UTC
What if you have a ton of arguments?
Rick Willcox
@willcoxDev
May 23 2017 05:00 UTC
exactly
my issue
but the thing is
I cant use this code
eyesore-
@eyesore-
May 23 2017 05:01 UTC
You gotta loop through arguments, but you also have to keep in mind that arguments is not an Array
Rick Willcox
@willcoxDev
May 23 2017 05:01 UTC
I get type error so I cannot simply iterate through them as in
return arguments[i].indexOf(value);
Moisés Man
@moigithub
May 23 2017 05:01 UTC
@willcoxDev sry u r right.. kind of...
indexOF only works on arrays and string..
Rick Willcox
@willcoxDev
May 23 2017 05:02 UTC
@moigithub all g bro everyone learning, even the pros sometimes :D
Moisés Man
@moigithub
May 23 2017 05:02 UTC
@willcoxDev what u can do is
[a1, a2].indexOf(value)
which will create an array.. but ofc this will only have 2 elements.. IF u pass more values to the func it wont work
Rick Riggs
@wikiwiggs
May 23 2017 05:02 UTC
just use arguments[i] and push that into a new array, then you can operate on that array like an array
Rick Willcox
@willcoxDev
May 23 2017 05:03 UTC
@wikiwiggs ok let me ive that a crack
Rick Riggs
@wikiwiggs
May 23 2017 05:03 UTC
you should still loop
eyesore-
@eyesore-
May 23 2017 05:03 UTC
Yeah, you have to loop. That is for sure.
Rick Riggs
@wikiwiggs
May 23 2017 05:03 UTC
the bigger picture here is learn how to do it well for all cases
eyesore-
@eyesore-
May 23 2017 05:04 UTC
After this you should implement filter from scratch haha I'll send you some tests.
Rick Willcox
@willcoxDev
May 23 2017 05:04 UTC
ok let me do this first haha
i think im ontop something with the new array idea
Rick Riggs
@wikiwiggs
May 23 2017 05:04 UTC
@eyesore- I take issue with filter, map, and forEach
they all seem the same to me
with the exception of their name of course
eyesore-
@eyesore-
May 23 2017 05:04 UTC
Yeah, I can tell from that code the sent the last time haha
Rick Riggs
@wikiwiggs
May 23 2017 05:05 UTC
@eyesore- am I wrong, or do they actually all have the same mechanism?
eyesore-
@eyesore-
May 23 2017 05:06 UTC
@wikiwiggs I'm writing up an explanation on each
Rick Willcox
@willcoxDev
May 23 2017 05:06 UTC
destroyer([1, 2, 3,4, 5, 6], 7, 8);
wait so is the first arguement [1,2,3,4,5,6] and second 7 and the thrid 8 or
arg1 = 1, arg2=2
eyesore-
@eyesore-
May 23 2017 05:06 UTC
Filter will create a new array with all items that pass your callback.
Map will create a new array from all the items being passed through your callback.
forEach will mutate the array with whatever callback you pass.
Moisés Man
@moigithub
May 23 2017 05:07 UTC
yes @willcoxDev
Rick Willcox
@willcoxDev
May 23 2017 05:07 UTC
?
Markus Kiili
@Masd925
May 23 2017 05:07 UTC
@willcoxDev First argument is the array.
Rick Riggs
@wikiwiggs
May 23 2017 05:07 UTC
arguments[0] is the array, arguments[1] is 7, arguments[2] = 8
eyesore-
@eyesore-
May 23 2017 05:08 UTC
destroyer([1, 2, 3,4, 5, 6], 7, 8);
// [1, 2, 3,4, 5, 6] = 1
// 7 = 2
// 8 = 3
Rick Willcox
@willcoxDev
May 23 2017 05:08 UTC
 var array = [];
  for (var i=1; i<arr.length; i++){
    array.push(arguments[i]);
  }
is how I am making the new array
Moisés Man
@moigithub
May 23 2017 05:08 UTC
ur condition should be based on arguments.length instead
Rick Willcox
@willcoxDev
May 23 2017 05:09 UTC
oh ok
Markus Kiili
@Masd925
May 23 2017 05:09 UTC
@willcoxDev arr is the same as arguments[0]
Rick Willcox
@willcoxDev
May 23 2017 05:09 UTC
ok that worked
eyesore-
@eyesore-
May 23 2017 05:10 UTC
@wikiwiggs this is how filter works:
  var filter = function(collection, test) {
    var result = []

    collection.forEach(function(item) {
      if( test(item) ){
        result.push(item)
      }
    })

    return result
  }
@wikiwiggs this is map:
  var map = function(collection, iterator) {
    var result = []

    collection.forEeach(function(item) {
      result.push(iterator(item))
    })

    return result
  }
Rick Riggs
@wikiwiggs
May 23 2017 05:11 UTC
@eyesore- so filter is a truth collector?
and so is map
eyesore-
@eyesore-
May 23 2017 05:12 UTC
Yeah, pretty much. If it's true with whatever function you give it then it will throw it in the new array.
Rick Riggs
@wikiwiggs
May 23 2017 05:12 UTC
without the truth check
eyesore-
@eyesore-
May 23 2017 05:12 UTC
Map will throw it into the new array with whatever the function you give.
Rick Willcox
@willcoxDev
May 23 2017 05:13 UTC
function destroyer(arr) {
  var array = [];
  for (var i=1; i<arguments.length; i++){
    array.push(arguments[i]);
  }
  for (var j=0;j<array.length;j++){
    array = array.filter(function(value){
      return array[j].indexOf(value);
    });
  }
  return array;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I got told not to make a a function within a loop
eyesore-
@eyesore-
May 23 2017 05:13 UTC
Yeah. So if you want to + 1 each item or so forth
Markus Kiili
@Masd925
May 23 2017 05:13 UTC
@willcoxDev You don't need the j loop.
Rick Riggs
@wikiwiggs
May 23 2017 05:14 UTC
@willcoxDev that's where I use reduce.
eyesore-
@eyesore-
May 23 2017 05:14 UTC
You can make a copy of arguments with .slice
Markus Kiili
@Masd925
May 23 2017 05:14 UTC
@willcoxDev Filter iterates arr and indexOf iterates array.
@eyesore- That is the preferred ES5 way of turning arguments object into an array.
eyesore-
@eyesore-
May 23 2017 05:15 UTC
Yeah, I know.
Rick Riggs
@wikiwiggs
May 23 2017 05:15 UTC
but then again, I see all of these array methods as for loops anyway, so don't listen to me on this one.
eyesore-
@eyesore-
May 23 2017 05:15 UTC
Haha ^
Rick Riggs
@wikiwiggs
May 23 2017 05:18 UTC
@eyesore- So when I use filter, I normally pass in a function to operate on each element, and instead I should be passing a function that returns based on a truth boolean of comparison such as a<b return b-a
eyesore-
@eyesore-
May 23 2017 05:18 UTC
Yeah, you definitely want to be thinking of the output as a boolean.
Rick Riggs
@wikiwiggs
May 23 2017 05:18 UTC
which sounds like sort and reverse to me.
@eyesore- So am I over simplifying in seeing these all as for loops, and sorts?
eyesore-
@eyesore-
May 23 2017 05:20 UTC
Those keep all elements and just switches their position. Filter will knock out elements that dont fit your truth test.
Oh, without a doubt! They all have they're own functionality that help you in different ways.
Rick Riggs
@wikiwiggs
May 23 2017 05:20 UTC
but so would any other function that I create, if I put an if condition do this else do nothing correct?
eyesore-
@eyesore-
May 23 2017 05:22 UTC
Well I mean you could think that you can create all these functions, but why would you do that if it's something that is already made for you?
abhijith shenoy
@shenoyabhijith
May 23 2017 05:22 UTC
i want to center it using container
and add some padding between images
Rick Riggs
@wikiwiggs
May 23 2017 05:23 UTC
@eyesore- that's not quite it.
eyesore-
@eyesore-
May 23 2017 05:23 UTC
You get into the point of why use any prototypes? Why use jQuery? Why use JS, just write your own language.
Oh, shit. Ignore that.
What do you mean then?
Rick Riggs
@wikiwiggs
May 23 2017 05:23 UTC
I just see these as loops, so I leverage them to iterate in their own context without actually having to write the traditional for loop structure.
eyesore-
@eyesore-
May 23 2017 05:24 UTC
Oh, okay. I guess you could do that with map, reduce, and forEach.
You may fall into some issues with filter.
Markus Kiili
@Masd925
May 23 2017 05:25 UTC
@willcoxDev Those methods are implicit loops suited for some specific thing.
Rick Riggs
@wikiwiggs
May 23 2017 05:25 UTC
well I think that most of the time, I'm hijacking my own functions return before filter cares to do anything with its own
Rick Willcox
@willcoxDev
May 23 2017 05:25 UTC

ok I still dont get why this wont work

function destroyer(arr) {
  var kill = [];
  for (var i=1; i<arguments.length; i++){
    kill.push(arguments[i]);
  }
  arr = arr.filter(function(value){
      return kill.indexOf(value);
    });

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

this is returning [1,3,1,3]

My understanding is that it should use both values stored in kill but it only seems to be usings the first

Markus Kiili
@Masd925
May 23 2017 05:25 UTC
@willcoxDev You need to return true/false from the callback function.
Rick Willcox
@willcoxDev
May 23 2017 05:25 UTC
the array "kill" is storing [2, 3]
i checked
eyesore-
@eyesore-
May 23 2017 05:26 UTC
@wikiwiggs I would definitely suggest to not do that though /: Specially if you start working on a team. You are going to get yelled at constantly.
Rick Riggs
@wikiwiggs
May 23 2017 05:26 UTC
@eyesore- LOL, I see that
Markus Kiili
@Masd925
May 23 2017 05:26 UTC
@willcoxDev You need to return false if value is found on kill, and true otherwise.
Now you are returning the first index.
Rick Riggs
@wikiwiggs
May 23 2017 05:26 UTC
@willcoxDev
function destroyer(arr) {
  var kill = [];
  for (var i=1; i<arguments.length; i++){
    kill.push(arguments[i]);
  }
  arr = arr.filter(function(value){
      kill.push(value);
    });

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I'm doing this on purpose, it doesn't solve anything
Nazar Maksymchuk
@MANTENN
May 23 2017 05:27 UTC
it returns blank because you didnt change arguements to arr
eyesore-
@eyesore-
May 23 2017 05:27 UTC
Alright good. I was about to say something about that filter function.
Nazar Maksymchuk
@MANTENN
May 23 2017 05:28 UTC

function destroyer(arr) {
var kill = [];
for (var i=1; i<arr.length; i++){
kill.push(arr[i]);
}
arr = arr.filter(function(value){
kill.push(value);
});

return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

try that
Rick Riggs
@wikiwiggs
May 23 2017 05:28 UTC
@eyesore- I was just showing inverse symmetry to see if he can pick up on the mistake
Nazar Maksymchuk
@MANTENN
May 23 2017 05:29 UTC
if you want more youll have to manually add it
Markus Kiili
@Masd925
May 23 2017 05:29 UTC
@willcoxDev You need to compare that indexOf with -1. Then it works.
eyesore-
@eyesore-
May 23 2017 05:30 UTC
@MANTENN That is actually wrong with what he is trying to do.
Rick Willcox
@willcoxDev
May 23 2017 05:30 UTC
function destroyer(arr) {
  var kill = [];
  for (var i=1; i<arguments.length; i++){
    kill.push(arguments[i]);
  }
  arr = arr.filter(function(value){
      if (kill.indexOf(value) >= 0){
          return false;
          }
      else{
        return true;
      }
    });

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Ok I did it. Now to fully understand
Ogundele Olumide
@Lumexralph
May 23 2017 05:31 UTC
@Masd925 Good Morning
Markus Kiili
@Masd925
May 23 2017 05:31 UTC
@willcoxDev Just return kill.indexOf(value)===-1; is simpler.
@Lumexralph Morning.
Nazar Maksymchuk
@MANTENN
May 23 2017 05:31 UTC
@eyesore arguments is undefined it wont loop
eyesore-
@eyesore-
May 23 2017 05:31 UTC
@MANTENN arguments is defined in every function. They are the parameters.
Nazar Maksymchuk
@MANTENN
May 23 2017 05:32 UTC
@eyesore I know, he only has one argument and its arr
eyesore-
@eyesore-
May 23 2017 05:32 UTC
@MANTENN Just look up the lesson man: Seek and Destroy
Nazar Maksymchuk
@MANTENN
May 23 2017 05:32 UTC
unless he did this
var arguuments = arr;
or its from a global value
eyesore-
@eyesore-
May 23 2017 05:32 UTC
That is wrong too.
Rick Riggs
@wikiwiggs
May 23 2017 05:33 UTC
@MANTENN Look at the last line, there are three arguments being passed to this one function
Markus Kiili
@Masd925
May 23 2017 05:33 UTC
@MANTENN arguments is a special keyword. It evaluates to an array-like object that holds all the passed arguments.
Ogundele Olumide
@Lumexralph
May 23 2017 05:33 UTC
@MANTENN arguments is a local variable
Nazar Maksymchuk
@MANTENN
May 23 2017 05:33 UTC
@eyesore thanks I guess im not there yet.
CamperBot
@camperbot
May 23 2017 05:33 UTC
mantenn sends brownie points to @eyesore :sparkles: :thumbsup: :sparkles:
:warning: @eyesore's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Ogundele Olumide
@Lumexralph
May 23 2017 05:33 UTC
@Masd925 How's your night?
Rick Willcox
@willcoxDev
May 23 2017 05:33 UTC
ok so return kill.indexOf(value)===-1; returns only when the index isnt found?
Markus Kiili
@Masd925
May 23 2017 05:33 UTC
@Lumexralph Fine. How was yours.
@willcoxDev It returns true if value is not found on kill, and false otherwise.
eyesore-
@eyesore-
May 23 2017 05:34 UTC
@MANTENN It's cool man. No problem.
Rick Riggs
@wikiwiggs
May 23 2017 05:34 UTC
@willcoxDev any time an index is not found in an array it is -1
Nazar Maksymchuk
@MANTENN
May 23 2017 05:34 UTC
@eyesore first time I hear of it
Ogundele Olumide
@Lumexralph
May 23 2017 05:34 UTC
@Masd925 it was good
Rick Willcox
@willcoxDev
May 23 2017 05:34 UTC
@MANTENN @eyesore- @wikiwiggs @MANTENN thanks
CamperBot
@camperbot
May 23 2017 05:34 UTC
willcoxdev sends brownie points to @mantenn and @eyesore- and @wikiwiggs :sparkles: :thumbsup: :sparkles:
:cookie: 152 | @mantenn |http://www.freecodecamp.com/mantenn
:cookie: 96 | @eyesore- |http://www.freecodecamp.com/eyesore-
:cookie: 308 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
Ogundele Olumide
@Lumexralph
May 23 2017 05:34 UTC
@willcoxDev yes
eyesore-
@eyesore-
May 23 2017 05:34 UTC
@MANTENN You'll run into it more. It's really useful actually.
Rick Willcox
@willcoxDev
May 23 2017 05:34 UTC
waht is it returning exactly
Rick Riggs
@wikiwiggs
May 23 2017 05:35 UTC
an invalid position in the index address to the array
Markus Kiili
@Masd925
May 23 2017 05:35 UTC
@willcoxDev When you compare indexOf with -1, it means is it not found?.
eyesore-
@eyesore-
May 23 2017 05:35 UTC
@mantenn Just be more open when someone opposes what you say man.
Rick Willcox
@willcoxDev
May 23 2017 05:36 UTC
oh so it is returning only those that are not found and therfore the ones I want in the array
Nazar Maksymchuk
@MANTENN
May 23 2017 05:36 UTC
@eyesore ok'
Markus Kiili
@Masd925
May 23 2017 05:36 UTC
@willcoxDev Yes, filter keeps those elements that when passed into the callback return true. So just the ones that are not found on kill.
eyesore-
@eyesore-
May 23 2017 05:36 UTC
So whatever turns to true in the filter function will be put into the new array
What he said
Rick Riggs
@wikiwiggs
May 23 2017 05:40 UTC
@eyesore- OK, so I'm going to tread lightly, because you know my tendancy already to use array methods like for loops.
what about them, in the way that I use them would be volitile in a team situation?
eyesore-
@eyesore-
May 23 2017 05:42 UTC
@wikiwiggs So the biggest thing in a team situation is that it will confuse people on what you are really trying to do. Some may also add extra complexity that you do not need.
Rick Riggs
@wikiwiggs
May 23 2017 05:43 UTC
@eyesore- The reason for asking is this:
we are taught or should be taught early on what return does inside of a function correct?
eyesore-
@eyesore-
May 23 2017 05:44 UTC
Let's say you make something and then leave the company. You used a filter when you were just trying to loop through something. The next person that gets the legacy code can think that it was supposed to filter something, but can't see what needs to be filtered.
Yeah, definitely. Everyone should know terminations. That's actually why I don't use semicolons.
You just want to be as clear as possible with your code. With your variable names and helper functions.
Rick Riggs
@wikiwiggs
May 23 2017 05:45 UTC
@eyesore- not just terminations, but highly specific return values (not all the time, but could be thought of that way).
eyesore-
@eyesore-
May 23 2017 05:45 UTC
Overall the biggest thing that I see is that it sends someone down the wrong path on what your code is doing.
If I saw that in production I wouldn't think that you were just trying to loop I would think that you just didnt know how to filter correctly.
Rick Riggs
@wikiwiggs
May 23 2017 05:46 UTC
@eyesore- I get that, but hey if we are in a team, then code reviews & pair programming should get everyone on the same page correct?
eyesore-
@eyesore-
May 23 2017 05:47 UTC
@willcoxDev Haha type coercion is wild.
Markus Kiili
@Masd925
May 23 2017 05:47 UTC
@eyesore- Best way to obscure good code.
eyesore-
@eyesore-
May 23 2017 05:48 UTC
@wikiwiggs Definitely! Code Review is awesome. From my experience there is not as much pair programming... Specially in startups.
@Masd925 Do you use typescript or flow?
Nazar Maksymchuk
@MANTENN
May 23 2017 05:49 UTC
@eyesore floating-point inprecision, does it mention in wiki with ECC memory it can be fixed?
Rick Riggs
@wikiwiggs
May 23 2017 05:49 UTC
@eyesore- I'm just very curious on this, because I still don't necessarily see this as bad practice, counter-intuitive maybe (if you don't understand return)
Markus Kiili
@Masd925
May 23 2017 05:49 UTC
@eyesore- No, just vanilla JS and angularJS at work.
Nazar Maksymchuk
@MANTENN
May 23 2017 05:49 UTC
"single-precision floating-point hardware"
HeebieGeeBee
@HeebieGeeBee
May 23 2017 05:50 UTC
good morning
Markus Kiili
@Masd925
May 23 2017 05:50 UTC
@HeebieGeeBee Morning.
Rick Riggs
@wikiwiggs
May 23 2017 05:50 UTC
@HeebieGeeBee hello
eyesore-
@eyesore-
May 23 2017 05:50 UTC
Float in-precision is an issue in many languages. If it can be fixed that's cool. I haven't really ran into it impeding me from doing something.
Rick Riggs
@wikiwiggs
May 23 2017 05:51 UTC
thats what strings and truncate are for
Will Waymel
@willwaymel
May 23 2017 05:51 UTC

having issues with CORS and my codepen coming from http... any way to change codepen to https? I thought it already was but I'm getting this error:

(Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://codepen.io" from accessing a cross-origin frame.)

and this error:

(XMLHttpRequest cannot load https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=. The 'Access-Control-Allow-Origin' header has a value 'https://s.codepen.io' that is not equal to the supplied origin. Origin 'http://s.codepen.io' is therefore not allowed access.)

eyesore-
@eyesore-
May 23 2017 05:52 UTC
@wikiwiggs Yeah, I mean with bad practice I do feel like 'Fuck you, it works' sometimes, but not everyone thinks the same and unfortunately people leave projects so the more uniform everyones code is and following certain guidelines the better.
Ogundele Olumide
@Lumexralph
May 23 2017 05:52 UTC
@HeebieGeeBee Bro! Morning
Nazar Maksymchuk
@MANTENN
May 23 2017 05:52 UTC
@willwaymel try adding a cors request header
Will Waymel
@willwaymel
May 23 2017 05:53 UTC
yeah, i added https://crossorigin.me/ but it still didn't work @MANTENN . I'm trying to figure out if I have to put something like what's described here https://www.html5rocks.com/en/tutorials/cors/
Nazar Maksymchuk
@MANTENN
May 23 2017 05:54 UTC
@willwaymel could be a server side issue.
Will Waymel
@willwaymel
May 23 2017 05:54 UTC
weird thing is, it works fine on my mobile browser, and when someone else tried from their computer @MANTENN
Rick Riggs
@wikiwiggs
May 23 2017 05:54 UTC
@eyesore- so seeing how I constantly would have a tendancy to do this, would you consider it a reason to clone, and append the prototype in this case?
or just use the forEach method?
eyesore-
@eyesore-
May 23 2017 05:55 UTC
@wikiwiggs If it's something simple use forEach or if you want to create a new array use map. You also get into mutating which in my opinion it's better to not mutate.
kreuel
@kreuel
May 23 2017 05:56 UTC
hi guys can you assist me on the Random Quote Machine, The getJSON function which is pointed to API(https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en) does not return anything, but when I paste the url in the browser it returns data.
$(document).ready(function(){
  $("#newQuote").on("click", function(){
    $.getJSON("https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en", function(json){
      $(".message").html(JSON.stringify(json));
    });
  });
});
Rick Riggs
@wikiwiggs
May 23 2017 05:56 UTC
@eyesore- yeah but then again who care if you mutate a slice correct?
Nazar Maksymchuk
@MANTENN
May 23 2017 05:56 UTC
@willwaymel could be a old browser on there pc
eyesore-
@eyesore-
May 23 2017 05:56 UTC
@wikiwiggs Keep in mind I don't take super hard stances on majority of things. Like semicolons or tabs VS spaces. There's another person on here that got in a huge argument with me about semicolons. His name is joseph I'm sure you;ve talked to him.
HeebieGeeBee
@HeebieGeeBee
May 23 2017 05:56 UTC
@kreuel are you using https for your codepen?
eyesore-
@eyesore-
May 23 2017 05:56 UTC
@wikiwiggs Yeah, if you mutate after copying then fuck it. That is a new array.
Will Waymel
@willwaymel
May 23 2017 05:56 UTC
@MANTENN but that fact that it doesn't work on my browser...
Rick Riggs
@wikiwiggs
May 23 2017 05:56 UTC
@eyesore- I don't remember if I had
Will Waymel
@willwaymel
May 23 2017 05:57 UTC
@HeebieGeeBee how do you specify what codepen uses?
Manish Giri
@Manish-Giri
May 23 2017 05:57 UTC
There's another person on here that got in a huge argument with me about semicolons.
lol
I can imagine
Nazar Maksymchuk
@MANTENN
May 23 2017 05:57 UTC
@willwaymel ask @eyesore he is more experienced than me.
eyesore-
@eyesore-
May 23 2017 05:57 UTC
@Manish-Giri You use semicolons?
Will Waymel
@willwaymel
May 23 2017 05:57 UTC
@MANTENN thanks
kreuel
@kreuel
May 23 2017 05:57 UTC
Hi @HeebieGeeBee, yes I'm using HTTPS, but i can also use HTTP any difference?
HeebieGeeBee
@HeebieGeeBee
May 23 2017 05:57 UTC
@willwaymel in your browser url bar it will say https
eyesore-
@eyesore-
May 23 2017 05:57 UTC
@wikiwiggs I think his username is revitualize or something like that.
abhijith shenoy
@shenoyabhijith
May 23 2017 05:57 UTC
how to align the card to center
?
Manish Giri
@Manish-Giri
May 23 2017 05:57 UTC
@eyesore- no I meant about the Joseph bit
HeebieGeeBee
@HeebieGeeBee
May 23 2017 05:57 UTC
@kreuel what does it say in your devtools console?
Manish Giri
@Manish-Giri
May 23 2017 05:57 UTC
sorry, wrong quote
Rick Riggs
@wikiwiggs
May 23 2017 05:58 UTC
still no bells ringing for me.
Will Waymel
@willwaymel
May 23 2017 05:58 UTC
@HeebieGeeBee got it... :) sorry, thanks. Yeah I was looking in my mobile browser and it didn't show up right away
CamperBot
@camperbot
May 23 2017 05:58 UTC
willwaymel sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1677 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
eyesore-
@eyesore-
May 23 2017 05:58 UTC
@Manish-Giri Oh, I dont like that guy. I think he's an asshole.
Will Waymel
@willwaymel
May 23 2017 05:58 UTC
@MANTENN thanks
CamperBot
@camperbot
May 23 2017 05:58 UTC
willwaymel sends brownie points to @mantenn :sparkles: :thumbsup: :sparkles:
:cookie: 154 | @mantenn |http://www.freecodecamp.com/mantenn
Manish Giri
@Manish-Giri
May 23 2017 05:58 UTC
yeah I know the feeling..
@eyesore-
HeebieGeeBee
@HeebieGeeBee
May 23 2017 05:58 UTC
@Manish-Giri :wave:
Manish Giri
@Manish-Giri
May 23 2017 05:58 UTC
@HeebieGeeBee :wave:
eyesore-
@eyesore-
May 23 2017 05:58 UTC
@wikiwiggs I'm surprised. He is on here all the time.
Manish Giri
@Manish-Giri
May 23 2017 05:58 UTC
howdy
HeebieGeeBee
@HeebieGeeBee
May 23 2017 05:58 UTC
@Manish-Giri you been getting into arguments?
Ogundele Olumide
@Lumexralph
May 23 2017 05:58 UTC
@Manish-Giri gggm :smiling_imp:
Rick Riggs
@wikiwiggs
May 23 2017 05:59 UTC
I am not really on here all that much.
Will Waymel
@willwaymel
May 23 2017 05:59 UTC

@eyesore- hey @MANTENN said you might know what to do about this...
...
having issues with CORS and my codepen coming from http... any way to change codepen to https? I thought it already was but I'm getting this error:

(Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://codepen.io" from accessing a cross-origin frame.)

and this error:

(XMLHttpRequest cannot load https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=. The 'Access-Control-Allow-Origin' header has a value 'https://s.codepen.io' that is not equal to the supplied origin. Origin 'http://s.codepen.io' is therefore not allowed access.)

abhijith shenoy
@shenoyabhijith
May 23 2017 05:59 UTC
@Manish-Giri
Manish Giri
@Manish-Giri
May 23 2017 05:59 UTC
@HeebieGeeBee lol, not lately anyway, I barely have the time these days for all that
how to align this card to center
Manish Giri
@Manish-Giri
May 23 2017 05:59 UTC
@Lumexralph supper gggm :bow: :smiling_imp:
Rick Riggs
@wikiwiggs
May 23 2017 05:59 UTC
I just started FCC less than three weeks ago
kreuel
@kreuel
May 23 2017 06:00 UTC
@HeebieGeeBee the DevTool console is empty
eyesore-
@eyesore-
May 23 2017 06:00 UTC
@willwaymel you should be able to go to https://codepen.io/
Manish Giri
@Manish-Giri
May 23 2017 06:00 UTC
@shenoyabhijith that's materialize-css right?
use their in-built class for centering
abhijith shenoy
@shenoyabhijith
May 23 2017 06:00 UTC
yeah
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:00 UTC
@kreuel post your codepen link
Ogundele Olumide
@Lumexralph
May 23 2017 06:00 UTC
@Manish-Giri :smirk:
Rick Willcox
@willcoxDev
May 23 2017 06:00 UTC
z
abhijith shenoy
@shenoyabhijith
May 23 2017 06:00 UTC
i tried center-align
wont work
eyesore-
@eyesore-
May 23 2017 06:01 UTC
I'm getting off now. Catch you all later.
abhijith shenoy
@shenoyabhijith
May 23 2017 06:01 UTC
@Manish-Giri
Will Waymel
@willwaymel
May 23 2017 06:01 UTC
@eyesore- yeah it's already like that when I open my pen... i don't know why it's saying i'm coming from http.
Manish Giri
@Manish-Giri
May 23 2017 06:01 UTC
@Lumexralph where's our partner in crime @joreyesl
Rick Willcox
@willcoxDev
May 23 2017 06:01 UTC
is it align-center?
Will Waymel
@willwaymel
May 23 2017 06:01 UTC
@eyesore- wait no. it just says "codepen.io/willwaymel/pen/BRONwq"
Rick Riggs
@wikiwiggs
May 23 2017 06:01 UTC
@eyesore- have a good evening
jazmynejack
@jazmynejack
May 23 2017 06:01 UTC
i need a bit of help the last instruction that says a should be assigned to b with = what do they mean by that
Rick Riggs
@wikiwiggs
May 23 2017 06:01 UTC
/morning
Will Waymel
@willwaymel
May 23 2017 06:02 UTC
@eyesore- thanks... don't know why that one was opening from there
CamperBot
@camperbot
May 23 2017 06:02 UTC
willwaymel sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 97 | @eyesore- |http://www.freecodecamp.com/eyesore-
eyesore-
@eyesore-
May 23 2017 06:02 UTC
@willwaymel Yeah, you want to run it via https. I think codepen is moving to only https.
Ogundele Olumide
@Lumexralph
May 23 2017 06:02 UTC
@Manish-Giri been wondering where you guys are till you showed up, still wondering which programming wilderness @joreyesl is
Manish Giri
@Manish-Giri
May 23 2017 06:02 UTC
@shenoyabhijith your card is in col s12 m6
eyesore-
@eyesore-
May 23 2017 06:02 UTC
No problem
Rick Riggs
@wikiwiggs
May 23 2017 06:02 UTC
@eyesore- thanks for the array talks
Manish Giri
@Manish-Giri
May 23 2017 06:02 UTC
it'll only span 6 columns
@Lumexralph lol yea havn't seen him much
Victor Popescu
@VicPopescu
May 23 2017 06:02 UTC
@jazmynejack var potato = something, something it is assigned to potato
Nazar Maksymchuk
@MANTENN
May 23 2017 06:03 UTC
@willwaymel works on my browser firefox 54.0
Markus Kiili
@Masd925
May 23 2017 06:03 UTC
@HeebieGeeBee Was potato your dummy variable?
Will Waymel
@willwaymel
May 23 2017 06:04 UTC
@MANTENN and @eyesore- .... thanks again, was going to spend the next hour figuring out how to manually do the CORS . it was just displaying codepen.io (not revealing it was http) and my other pens were open in https. i changed it now and it works... :) thanks so much
CamperBot
@camperbot
May 23 2017 06:04 UTC
willwaymel sends brownie points to @mantenn and @eyesore- :sparkles: :thumbsup: :sparkles:
:warning: willwaymel already gave eyesore- points
:warning: willwaymel already gave mantenn points
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:04 UTC
@Masd925 lol its spreading
jazmynejack
@jazmynejack
May 23 2017 06:04 UTC
that doesn't really help
Will Waymel
@willwaymel
May 23 2017 06:08 UTC
now that my other page works.... another doesn't ... getting this error Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://codepen.io" from accessing a cross--origin frame. ---
any ideas?
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:08 UTC
@kreuel use https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=? and your browser devtools console shows more than the codepen console
Aimy24
@Aimy24
May 23 2017 06:15 UTC
function trueOrFalse(wasThatTrue) {
if (wasThatTrue) {
return "Yes, that was true";
}
return "No, that was false";
}trueOrFalse(false);
kreuel
@kreuel
May 23 2017 06:15 UTC
@HeebieGeeBee okay now I see the red messages in the browser devtools console. will open a new browser and try again and try the new API. any reason why i have more codepen console?
Aimy24
@Aimy24
May 23 2017 06:15 UTC
what is wrong
in it
Ogundele Olumide
@Lumexralph
May 23 2017 06:16 UTC
@Aimy24 check the string you're to return if it's same as FCC
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:16 UTC
@kreuel dont know what you mean
Aimy24
@Aimy24
May 23 2017 06:17 UTC
i check all
Nazar Maksymchuk
@MANTENN
May 23 2017 06:17 UTC
@willwaymel its the same CORS issue.
Ogundele Olumide
@Lumexralph
May 23 2017 06:17 UTC
@Aimy24 I don't understand, what are the instructions from FCC?
Manish Giri
@Manish-Giri
May 23 2017 06:17 UTC
@Lumexralph @HeebieGeeBee you guys hear about the Manchester thing
Will Waymel
@willwaymel
May 23 2017 06:18 UTC
@MANTENN I know... this time my browser really does say its running at https though
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:18 UTC
@Manish-Giri what manchester thing?
Ogundele Olumide
@Lumexralph
May 23 2017 06:18 UTC
@Manish-Giri yeah Ariana Grande concert
Manish Giri
@Manish-Giri
May 23 2017 06:18 UTC
so sad
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:18 UTC
what happened?
Manish Giri
@Manish-Giri
May 23 2017 06:18 UTC
@HeebieGeeBee there was a bombing
Will Waymel
@willwaymel
May 23 2017 06:18 UTC
it's not actually the exact same, before it was pointing out that i was at http://codepen @MANTENN
Manish Giri
@Manish-Giri
May 23 2017 06:18 UTC
22 dead, more than 50 injured
Ogundele Olumide
@Lumexralph
May 23 2017 06:18 UTC
@Manish-Giri very sad.... will we ever no peace again?
Markus Kiili
@Masd925
May 23 2017 06:18 UTC
@HeebieGeeBee You use potato because you are afraid of grain lectins?
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:19 UTC
havent looked at any news
Will Waymel
@willwaymel
May 23 2017 06:19 UTC
@Manish-Giri that's terrible. where was this?
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:19 UTC
@Lumexralph to be fair there never has been peace
@Masd925 not afraid
Manish Giri
@Manish-Giri
May 23 2017 06:19 UTC
@willwaymel Manchester Arena at an Ariana Grande concert
Manchester, UK
Will Waymel
@willwaymel
May 23 2017 06:19 UTC
@Manish-Giri no way
Manish Giri
@Manish-Giri
May 23 2017 06:19 UTC
yup
Ogundele Olumide
@Lumexralph
May 23 2017 06:19 UTC
@HeebieGeeBee violence is kind of the increase across countries and continents
Markus Kiili
@Masd925
May 23 2017 06:20 UTC
@HeebieGeeBee So no greater message there at all?
Manish Giri
@Manish-Giri
May 23 2017 06:20 UTC
most people there were teens
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:20 UTC
just that potatoes are awesome
Ogundele Olumide
@Lumexralph
May 23 2017 06:20 UTC
damn!
kreuel
@kreuel
May 23 2017 06:22 UTC
@HeebieGeeBee the new API that you've provided solved the issue and I opened by CodePen on a new Incognito Page and it does not have any red messages in the DevTool console. Just curious why did you use JSONP instead of JSON? then add jsonp=? parameter at the end.
Will Waymel
@willwaymel
May 23 2017 06:22 UTC
@MANTENN can you check and see if you get errors loading this one? https://codepen.io/willwaymel/pen/NjEVEM?editors=0010
Manish Giri
@Manish-Giri
May 23 2017 06:22 UTC
@Lumexralph only a matter of time before ISIS says we did it
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:22 UTC
@kreuel gets rid of the CORS issue
abhijith shenoy
@shenoyabhijith
May 23 2017 06:23 UTC
how to get padding
between place hoder images
xn_x
@ak4438
May 23 2017 06:23 UTC

function repeatStringNumTimes(str, num) {
// repeat after me
for(var i=0;i<num;i++)
{
str+=str;
}
return str;
}

repeatStringNumTimes("abc", 3);

Nazar Maksymchuk
@MANTENN
May 23 2017 06:23 UTC
@willwaymel it loads fine except the font
xn_x
@ak4438
May 23 2017 06:23 UTC
output should be
abcabcabc
kreuel
@kreuel
May 23 2017 06:24 UTC
@HeebieGeeBee thank you very much in assisting me on this issue.
CamperBot
@camperbot
May 23 2017 06:24 UTC
kreuel sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1678 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
xn_x
@ak4438
May 23 2017 06:24 UTC
but it is
abcabcabcabcabcabcabcabc
how to get padding between images
Manish Giri
@Manish-Giri
May 23 2017 06:24 UTC
@ak4438 that code won't work
Mamun Abdullah
@thetradecoder
May 23 2017 06:24 UTC
@Aimy24 your code is okay, if it not passes check the requirement, and if also that's ok, close and reload your browser
Manish Giri
@Manish-Giri
May 23 2017 06:24 UTC
as is shown by your output
abhijith shenoy
@shenoyabhijith
May 23 2017 06:24 UTC
@Manish-Giri
Will Waymel
@willwaymel
May 23 2017 06:24 UTC
@MANTENN you get an error on the font?
Nazar Maksymchuk
@MANTENN
May 23 2017 06:24 UTC
@willwaymel yes CORS error
Markus Kiili
@Masd925
May 23 2017 06:25 UTC
@ak4438 str+=str; doubles the amount of added strings.
Rick Willcox
@willcoxDev
May 23 2017 06:25 UTC
any idea why I am getting atype error here?
 var array = str.split("");
  var numArray = [];
  numArray.push(array.charCodeAt(1));
Ogundele Olumide
@Lumexralph
May 23 2017 06:25 UTC
@Manish-Giri sighs.....
Markus Kiili
@Masd925
May 23 2017 06:25 UTC
@ak4438 result += str; would add it once.
Nazar Maksymchuk
@MANTENN
May 23 2017 06:26 UTC
@willcoxDev look for errors next to it
not on the line it only reports
Rick Willcox
@willcoxDev
May 23 2017 06:27 UTC
it says array.charCodeAt is not a function
Ogundele Olumide
@Lumexralph
May 23 2017 06:27 UTC
@willcoxDev you should use that on a string not an array
Rick Willcox
@willcoxDev
May 23 2017 06:27 UTC
Yeh thats waht i figured
but the thing is a sting in the array?
"E" is at index pos 1
Ogundele Olumide
@Lumexralph
May 23 2017 06:27 UTC
@willcoxDev nope
Mamun Abdullah
@thetradecoder
May 23 2017 06:28 UTC
@shenoyabhijith use 'padding' instead of 'padding-left', it will padding all upper, right, bottom and left
abhijith shenoy
@shenoyabhijith
May 23 2017 06:28 UTC
wont work
checked @fsdmamun
Nazar Maksymchuk
@MANTENN
May 23 2017 06:28 UTC
@willcoxDev it could be that the that function is not inherited
Ogundele Olumide
@Lumexralph
May 23 2017 06:28 UTC
@willcoxDev you should loop through the array to get the string then you can use that method
abhijith shenoy
@shenoyabhijith
May 23 2017 06:29 UTC
adding padding adds space only at the top and sides
Ogundele Olumide
@Lumexralph
May 23 2017 06:29 UTC
@willcoxDev why don't you simply use str.charCodeAt(1) ?
Muhammad Hussain
@ReactorboY
May 23 2017 06:29 UTC
function lookUpProfile(firstName, prop){
// Only change code below this line
    for (var i = 0;i < contacts.length; i++){
      if(contacts[i].firstName && contacts[i].hasOwnProperty(prop)){
        return contacts[i].prop;
      }
    }


// Only change code above this line
}
what I am dooing wrong ??
Rick Willcox
@willcoxDev
May 23 2017 06:29 UTC
im confused now. the array is holding a list of strings?
i dunno lol
Ogundele Olumide
@Lumexralph
May 23 2017 06:29 UTC
@willcoxDev why do you want to split the str ? string
HeebieGeeBee
@HeebieGeeBee
May 23 2017 06:29 UTC
@ReactorboY prop is a variable and youre not comparing firstName to anything
Nazar Maksymchuk
@MANTENN
May 23 2017 06:30 UTC
@willcoxDev arrays can hold strings, numbers objects
Jun
@kysnazz
May 23 2017 06:30 UTC
my weather app suddenly stop working plz help... https://codepen.io/knazz/pen/LyXMrq
Ogundele Olumide
@Lumexralph
May 23 2017 06:30 UTC
@ReactorboY i have a pseudo code that might help
Rick Willcox
@willcoxDev
May 23 2017 06:30 UTC
I need to get the char code and minus 13 from it then convert back into a string
the idea was to split up the words and then concat them at the end
to reform the sentence
Long Nguyen
@longnt80
May 23 2017 06:30 UTC
@willcoxDev
The charCodeAt() method returns the Unicode of the character at the specified index in a string.
won't work with array
Ogundele Olumide
@Lumexralph
May 23 2017 06:30 UTC
@willcoxDev str is what?
help me out
need to add some padding
between placeholder images
Rick Willcox
@willcoxDev
May 23 2017 06:31 UTC

function rot13(str) { // LBH QVQ VG!
  var array = str.split("");
  var numArray = [];
  numArray.push(str.charCodeAt(1));



  return str;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Ogundele Olumide
@Lumexralph
May 23 2017 06:31 UTC
@ReactorboY
Here's an outline, if you follow it step-wise it'll help a great deal in telling you what to do or step you missed
1. you need a loop to pick each objects in the contacts array
    1.1  in the loop you need to 
         1.1.1  check if the objects picked has the firstName property equal to the firstName parameter
                  1.1.1.1 you need to check if it has a property prop
                                  return the value of prop in the object
                 1.1.1.2  return no such property if  1.1.1.1 is false
2.  when your loop is done looking through  contacts return no such contact
@willcoxDev you need to split the str from the spaces not as characters
@willcoxDev var array = str.split(" ");
Rick Willcox
@willcoxDev
May 23 2017 06:32 UTC
yeh i had that before
so i got the words
Ogundele Olumide
@Lumexralph
May 23 2017 06:33 UTC
@willcoxDev loop through the array, pick each string at the index then you can get the character unicode you want
Nazar Maksymchuk
@MANTENN
May 23 2017 06:33 UTC
@willcoxDev it returns the variable str
Jun
@kysnazz
May 23 2017 06:34 UTC
plz help ヾ(。>﹏<。)ノ https://codepen.io/knazz/pen/LyXMrq
René
@RenevandenHeuvel
May 23 2017 06:34 UTC
Hi all, can someone explain the example in challenge 152:
var ourArray = [3,2,1];
ourArray[0] = 1; // equals [1,2,1]
?
Nazar Maksymchuk
@MANTENN
May 23 2017 06:35 UTC
@RenevandenHeuvel computers count from 0
so ourArray[0] is the first item in the array
ourArray[1] is the second and so on.
mboesiger90
@mboesiger90
May 23 2017 06:36 UTC
Hello I am stuck on "Using Objects for Lookup" which is lesson 205. Sorry I dont know how to link my code
René
@RenevandenHeuvel
May 23 2017 06:36 UTC
@MANTENN i allready understood , but thans anyway :)
mboesiger90
@mboesiger90
May 23 2017 06:36 UTC
but I am stuck on how to integrate the value into the lookup
Nazar Maksymchuk
@MANTENN
May 23 2017 06:38 UTC
@RenevandenHeuvel
var myData = myArray[0];
@mboesiger90 create an object like in the example and using the key of the object, you in bracket notation select it from the object and return it
mboesiger90
@mboesiger90
May 23 2017 06:43 UTC
thank you I figured it out
Nazar Maksymchuk
@MANTENN
May 23 2017 06:43 UTC
so var lookup = {
"Alpha" : "Adams",...
}
mboesiger90
@mboesiger90
May 23 2017 06:43 UTC
btw so I know for the future how do you copy code over to the chat here?
Nazar Maksymchuk
@MANTENN
May 23 2017 06:43 UTC
CTRL + C - to copy
CTRL + V to paste
it will be in pure text to mark it up hover over the icon below compose mode
mboesiger90
@mboesiger90
May 23 2017 06:44 UTC
ok thanks
Nazar Maksymchuk
@MANTENN
May 23 2017 06:44 UTC
It will have the letter m and an arrow point downwards
mboesiger90
@mboesiger90
May 23 2017 06:44 UTC
ah yep i see it
Muhammad Hussain
@ReactorboY
May 23 2017 06:45 UTC

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

  }
}

return "No such property";
```

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

      }
    }
  return "No such property";
Rick Willcox
@willcoxDev
May 23 2017 06:45 UTC
to those that were helping me before I am almost there
function rot13(str) { // LBH QVQ VG!
  var numArray = [];
  for(var i=0;i<str.length;i++){
    if((str.charCodeAt(i)) !== 32){
      numArray.push(str.charCodeAt(i)-13);
    }
    else{
      numArray.push(str.charCodeAt(i));
    }
  }
  var finalStr = '';
  for (var j=0;j<numArray.length;j++){
    finalStr += String.fromCharCode(numArray[j]);
  }
  return finalStr;
}

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

>>>> F8EE C5DE CAM6 (meant to return FREE CODE CAMP)
Rick Riggs
@wikiwiggs
May 23 2017 06:46 UTC
@willcoxDev did you ever get your string split figured out?
Rick Willcox
@willcoxDev
May 23 2017 06:47 UTC
It seems to be working for the most part but not quite
Rick Riggs
@wikiwiggs
May 23 2017 06:47 UTC
@wikiwiggs Is this Cesar's cipher?
Markus Kiili
@Masd925
May 23 2017 06:48 UTC
@ReactorboY .prop looks for property key "prop", not the key stored in parameter prop.
Rick Willcox
@willcoxDev
May 23 2017 06:48 UTC
yes ceasars
Nazar Maksymchuk
@MANTENN
May 23 2017 06:48 UTC
@willcoxDev find a common pattern and shift each character based on it.
Muhammad Hussain
@ReactorboY
May 23 2017 06:48 UTC
got that already but thnx @Masd925
CamperBot
@camperbot
May 23 2017 06:48 UTC
reactorboy sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4113 | @masd925 |http://www.freecodecamp.com/masd925
Rick Riggs
@wikiwiggs
May 23 2017 06:49 UTC
@willcoxDev you need to be able to subtract once you get beyond a certain point in the alphabet a whole lot more than 13
Markus Kiili
@Masd925
May 23 2017 06:49 UTC
@willcoxDev First you need to test if the character is at range A-Z and only transform the charcode if it is.
Nazar Maksymchuk
@MANTENN
May 23 2017 06:50 UTC
@Masd925 regex
Markus Kiili
@Masd925
May 23 2017 06:50 UTC
@MANTENN Yes, regexp or charcode check.
Rick Riggs
@wikiwiggs
May 23 2017 06:50 UTC
After M you need to start thinking this way
Long Nguyen
@longnt80
May 23 2017 06:50 UTC
@willcoxDev Ceasars Cipher means A will become N, and N will translated to A
Nazar Maksymchuk
@MANTENN
May 23 2017 06:51 UTC
@longnt80 no it depends on the pattern
Rick Willcox
@willcoxDev
May 23 2017 06:51 UTC
its a wheel
i see the error now
Rick Riggs
@wikiwiggs
May 23 2017 06:51 UTC
@MANTENN No its a constant offset
Rick Willcox
@willcoxDev
May 23 2017 06:51 UTC
its 13 away
always
Rick Riggs
@wikiwiggs
May 23 2017 06:51 UTC
that loops in on itself
Rick Willcox
@willcoxDev
May 23 2017 06:51 UTC
there is not trick
Long Nguyen
@longnt80
May 23 2017 06:51 UTC
@MANTENN i know, in this challenge it is like that
Nazar Maksymchuk
@MANTENN
May 23 2017 06:51 UTC
@wikiwiggs well that's what I meant
Rick Willcox
@willcoxDev
May 23 2017 06:51 UTC
like a circle
Rick Riggs
@wikiwiggs
May 23 2017 06:51 UTC
yes
M becomes A
Long Nguyen
@longnt80
May 23 2017 06:53 UTC
@wikiwiggs no in this challenge, 13 means N become A
A -> 65 -> 65+13 -> 78 -> N
Rick Riggs
@wikiwiggs
May 23 2017 06:53 UTC
@willcoxDev meaning when I said subtract a whole lot more, if you are only relying on subtraction then it will change. @longnt80 OK, forgive me I am pretty tired. Make sure the math is right.
Long Nguyen
@longnt80
May 23 2017 06:54 UTC
@wikiwiggs no problem, just make sure it doesn't confuse @willcoxDev
Rick Riggs
@wikiwiggs
May 23 2017 06:54 UTC
@longnt80 Thanks for looking out
CamperBot
@camperbot
May 23 2017 06:54 UTC
wikiwiggs sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 295 | @longnt80 |http://www.freecodecamp.com/longnt80
Rick Riggs
@wikiwiggs
May 23 2017 07:00 UTC
@willcoxDev Hows it working out?
Nazar Maksymchuk
@MANTENN
May 23 2017 07:03 UTC
Think I should take a break and continue tom. Bye
Rick Willcox
@willcoxDev
May 23 2017 07:04 UTC
ok
I got it to work with 1 example
but my code is hacky and wont work with other symbols
i need to use regex
to check a match or something
function rot13(str) { // LBH QVQ VG!
  var numArray = [];
  for(var i=0;i<str.length;i++){
    if((str.charCodeAt(i)) !== 32 && (str.charCodeAt(i)) >= 78){
      numArray.push(str.charCodeAt(i)-13);
    }
    else if((str.charCodeAt(i)) !== 32 && (str.charCodeAt(i)) < 78){
      numArray.push(str.charCodeAt(i)+13);
    }
    else if((str.charCodeAt(i)) === 32){
      numArray.push(str.charCodeAt(i));
    }
  }
  var finalStr = '';
  for (var j=0;j<numArray.length;j++){
    finalStr += String.fromCharCode(numArray[j]);
  }
  return finalStr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Markus Kiili
@Masd925
May 23 2017 07:07 UTC
@willcoxDev You should not care for charcode 32 (you should only care if the character is A-Z or something else). Just test if the charcode is between 65-90 and then if it is on the lower or top half.
Rick Willcox
@willcoxDev
May 23 2017 07:10 UTC
yeh i acually just figured this out
without seeing ur repsonse

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

// Change the inputs below to test
rot13("SERR PBQR PNZC");
no works
now
So it will only do the conversion on capital letters
i assume there is a much better solution though
Long Nguyen
@longnt80
May 23 2017 07:11 UTC
@willcoxDev turn str to uppercase first
Rick Willcox
@willcoxDev
May 23 2017 07:12 UTC
Yeh thats true, the question specially states that all letters will be uppercase though so i didnt bother
Markus Kiili
@Masd925
May 23 2017 07:13 UTC
@longnt80 Not required, but maybe reasonable.
Rick Willcox
@willcoxDev
May 23 2017 07:13 UTC
yeh i just added it
str = str.toUpperCase(); under the function at the top
thanks for all your help guys
@Masd925 @longnt80 @wikiwiggs @MANTENN thanks
CamperBot
@camperbot
May 23 2017 07:14 UTC
willcoxdev sends brownie points to @masd925 and @longnt80 and @wikiwiggs and @mantenn :sparkles: :thumbsup: :sparkles:
:cookie: 170 | @mantenn |http://www.freecodecamp.com/mantenn
:cookie: 296 | @longnt80 |http://www.freecodecamp.com/longnt80
:cookie: 309 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
:star2: 4114 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
May 23 2017 07:14 UTC
@willcoxDev You can solve it with map/replace and one remainder operation. Even on one line.
:+1:
Long Nguyen
@longnt80
May 23 2017 07:16 UTC

@Masd925

one remainder operation

I can't think of the use for this in this case? Why?

Markus Kiili
@Masd925
May 23 2017 07:18 UTC
@longnt80 cc%26+65 will do the charcode mapping.
Long Nguyen
@longnt80
May 23 2017 07:19 UTC
@Masd925 what is cc%26?
cc?
Markus Kiili
@Masd925
May 23 2017 07:19 UTC
@longnt80 That uses the remainder operator to map the charcode cc, once it has been tested to be on the range A-Z cc>64 && cc<91
Long Nguyen
@longnt80
May 23 2017 07:19 UTC
26 means the number of aphabet letters
Markus Kiili
@Masd925
May 23 2017 07:20 UTC
function rot13(str) {
  return str.split("").map(function(char){
      var cc = char.charCodeAt(0);
      return (cc>64 && cc<91) ? String.fromCharCode(cc%26+65) : char;
  }).join("");
}
Anshul Adlakha
@anshuladlakha
May 23 2017 07:20 UTC
Can anyone help me understand how to use APIs with jquery.
I dont get it at all.
Markus Kiili
@Masd925
May 23 2017 07:21 UTC
@longnt80 I think there are clearer ways to do the mapping, but that is a compact way.
Long Nguyen
@longnt80
May 23 2017 07:21 UTC
@Masd925 thanks, I'll take a look
CamperBot
@camperbot
May 23 2017 07:21 UTC
longnt80 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4115 | @masd925 |http://www.freecodecamp.com/masd925
Long Nguyen
@longnt80
May 23 2017 07:23 UTC
@Masd925 btw, in this line return (cc>64 && cc<91) ? String.fromCharCode(cc%26+65) : char;, I know the ? and : create an if statement. But what is the term for it or can you give me a link to read about it?
Markus Kiili
@Masd925
May 23 2017 07:24 UTC
@longnt80 Conditional operator / ternary operator. Great way to obscure code.
Long Nguyen
@longnt80
May 23 2017 07:24 UTC
@Masd925 thanks again
CamperBot
@camperbot
May 23 2017 07:24 UTC
longnt80 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: longnt80 already gave masd925 points
Brandon Guerrero
@TheDevWizard
May 23 2017 07:25 UTC
Hey can anyone help me? I am supposed to Declare a local variable myVar inside myLocalScope. I don't understand what is wrong. It says I have not completed the "No global myVar variable" part of the challenge?

function myLocalScope() {
  'use strict';
  var myVar = "Hello";


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

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


// Now remove the console log line to pass the test
Rick Riggs
@wikiwiggs
May 23 2017 07:26 UTC
@TheDevWizard try moving your console.log(myVar) statement to immediately after myLocalScope();
Blauelf
@Blauelf
May 23 2017 07:28 UTC
@wikiwiggs That would be the non-working intermediate step, where one is meant to see the error such code causes
Rick Riggs
@wikiwiggs
May 23 2017 07:28 UTC
and then of course remove like the comments say
and run again
this exercise is all about proving to yourself that you can't access the local variable.
Blauelf
@Blauelf
May 23 2017 07:29 UTC
I'd say "try reloading the page".
At least for me, this code worked at the second click on "Run tests". Not sure why not on first.
Rick Riggs
@wikiwiggs
May 23 2017 07:30 UTC
the first part of the challenge is trying to see