These are chat archives for FreeCodeCamp/HelpJavaScript

20th
May 2017
Jim Bob
@Doorek
May 20 2017 00:14
I'm doing one of the javascript lessons, and it says error: do not change code above the line.. What does that mean ?
Nevermind, I actually read X_X..
buddermancer
@buddermancer
May 20 2017 00:15
h
Yes
For a second I thought you were illiterate
monkeyfingerz
@monkeyfingerz
May 20 2017 00:18
Can someone help with my clock and break button funciton
Anthony Henry
@Ahenry80
May 20 2017 00:22
function smallestCommons(arr) {
  var i = 1;
  while(arr[0] !== arr[1]){
    arr[0] = arr[0] * i;
    arr[1] = arr[1] * i;
    i = i + i;
    if(arr[0] === arr[1]){
      break;
    }
  }
   return arr[0];
}


smallestCommons([1,5]);
How do i get i to count up and multiply by the two numbers in the array because i keep on getting null
mobilecititechs
@mobilecititechs
May 20 2017 00:25
What am I doing wrong?
Build myStr from "This is the start." and "This is the end." using + operator.
var myStr = "This is the start" + "This is the end.";
myStr should have a value of This is the start. This is the end.
Roxroy
@roxroy
May 20 2017 00:28
@mobilecititechs , you need to add the period and space,
var myStr = "This is the start." + " This is the end.";
monkeyfingerz
@monkeyfingerz
May 20 2017 00:29
var myStr= "This is the start."+" "+"This is the end.";
@roxroy could you check out my code?
monkeyfingerz
@monkeyfingerz
May 20 2017 00:40
nvrmind i got it thanks everyone
Long Nguyen
@longnt80
May 20 2017 01:08
@Ahenry80 i count up by how many?
FlashHero
@FlashHero
May 20 2017 01:22
function spinalCase(str) {
  var result=[];
  str=str.match(/[A-Za-z0-9-?]/g).join('');
  for(var i=0;i<str.length;i++){
   if(str[i]===str[i].toUpperCase()&&i!==0){
      result.push('-'+str[i]);
    }else if(str[i]==='-'){
      result.push('-');
    }else{
      result.push(str[i]);
    }
  }
  return result.join('').toLowerCase();
}

spinalCase('AllThe-small Things');
can someone help me please
4sipita
@4sipita
May 20 2017 01:24

function switchOfStuff(val) {
var answer = "";
// Only change code below this line

switch (answer) {
case a:
answer = "apple";
break;
case b:
answer = "bird";
break;
case c:
answer = "cat";
break;

  default:
  answer = "stuff";
  break;

}

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

// Change this value to test
switchOfStuff("a");

Joseph
@revisualize
May 20 2017 01:25
@4sipita So, you have a few issues.
@4sipita You have var answer = ""; then ... you do ... switch (answer) ... The value of answer is "".
@4sipita Additionally, case a: ... the variable a is undefined. So you can't have the comparison of answer === a
Joseph
@revisualize
May 20 2017 01:36
Hello?
Mohamed Derhalli
@derhallim
May 20 2017 01:37
is it me ur looking for?
amelink
@amelink
May 20 2017 01:38
Hi, can someone tell me the difference between "+" and "g" in regular expression please?
Coy Sanders
@coymeetsworld
May 20 2017 01:44
+ is one or more of what you're looking for, g is a global flag that checks the entire string you're running the regex on @amelink
Jim Bob
@Doorek
May 20 2017 01:47
Convert Celsius to Fahrenheit .. Wtf
bterry7
@bterry7
May 20 2017 02:04
Can someone help me with this? I'm going through the Javascript lessons and cannot for the life of me figure out why it isn't working. It's the lesson on "Testing Objects for Properties" and this is my code so far

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

function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)){
return myObj.checkProp;
}

return "Not Found";
}

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

I need to figure out how to do picutres*
Coy Sanders
@coymeetsworld
May 20 2017 02:05
@bterry7 you want to use bracket notation for returning the object property, not dot notation
dot notation will find the property with the name checkProp, not the value of the variable checkProp
Gabe Rotberg
@grotberg
May 20 2017 02:06
@bterry7 what @coymeetsworld said. You can't use dot notation with variables. You have to use bracket.
bterry7
@bterry7
May 20 2017 02:07
ok so it should be
if (myObj.hasOwnProperty[checkProp]){
return myObj.checkProp;
}
er
myObj[checkProp] on the second line
Coy Sanders
@coymeetsworld
May 20 2017 02:08
no
i mean yes to your correction
bterry7
@bterry7
May 20 2017 02:08
ok
that still doesn't work
Coy Sanders
@coymeetsworld
May 20 2017 02:08
hasOwnProperty shouldn't be changed
bterry7
@bterry7
May 20 2017 02:08

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

function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty[checkProp]){
return myObj[checkProp];
}

return "Not Found";
}

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

doesn't work
Coy Sanders
@coymeetsworld
May 20 2017 02:09
revert your if statement, that shouldn't have been changed
bterry7
@bterry7
May 20 2017 02:09
bracket notation on the second line of the if statement but not the first? or both lines?
wait
giv me a sec
buddermancer
@buddermancer
May 20 2017 02:10
Coy why is you in 2 chat rooms @coymeetsworld
Coy Sanders
@coymeetsworld
May 20 2017 02:10
hasOwnProperty is a function
bterry7
@bterry7
May 20 2017 02:10
yeah
buddermancer
@buddermancer
May 20 2017 02:10
You just really love helping people
Coy Sanders
@coymeetsworld
May 20 2017 02:10
multithreading :thumbsup:
buddermancer
@buddermancer
May 20 2017 02:10
loll
Coy Sanders
@coymeetsworld
May 20 2017 02:10
also waiting for my iphone to restore, it bricked i need to go play some cards lol
bterry7
@bterry7
May 20 2017 02:10
there we go
thank you kindly
Coy Sanders
@coymeetsworld
May 20 2017 02:11
np
buddermancer
@buddermancer
May 20 2017 02:11
Nice job
Mohamed Derhalli
@derhallim
May 20 2017 02:11
ty @coymeetsworld
CamperBot
@camperbot
May 20 2017 02:11
derhallim sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 2597 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
May 20 2017 02:12
yw? @derhallim for what
Mohamed Derhalli
@derhallim
May 20 2017 02:13
for helping others
Coy Sanders
@coymeetsworld
May 20 2017 02:13
ah lol yeah no problem
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:15
any json experts here? I had a simple doubt while doing the first intermediate project of generating a random quote

$.getJSON("https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1", function(json) {
html+="<p >"+json[0].content+"</p>";

  $("#quote-here").html(html);

});

this code isn't working after 2nd or subsequent clicks on newquote button

Michael Cavataio
@MCavataio
May 20 2017 02:22
@sinharaksh1t could you send the codpen
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:23
Ralph Patrick
@rpcpancil
May 20 2017 02:31
function multiplyAll(arr) {
var product = 1;
for (var i = 0; i < arr.lenght; i++){
for (var j = 0; j < arr[i].lenght; j++){
product = product * arr[i][j];
}
}
return product;
what is wrong with my code above?
it cannot get the correct output
Coy Sanders
@coymeetsworld
May 20 2017 02:34
for (var j = 0; j < arr[i].lenght; j++){ @rpcpancil
have a typo there
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:35
length* @rpcpancil
Michael Cavataio
@MCavataio
May 20 2017 02:35
@sinharaksh1t it looks like you'll need a query parameter to pull a new random quote if you look in the console you could see that the click button is still working
but the same quote is being generated from json request
Ralph Patrick
@rpcpancil
May 20 2017 02:36
thanks mate@
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:36
@MCavataio sorry i didnt catch that
cud u elaborate a bit more
Ralph Patrick
@rpcpancil
May 20 2017 02:37
thank Coy Sanders
Coy Sanders
@coymeetsworld
May 20 2017 02:37
np
Michael Cavataio
@MCavataio
May 20 2017 02:38
image.png
so with the current json request you could see that it's continuosly retrieving the same quote
it looks like if we create a random number to add to the request instead of
$.getJSON("https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1"
Roxroy
@roxroy
May 20 2017 02:41
@monkeyfingerz, it looks good. Is there anything else you want me to look at?
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:41
you mean in place of "filter[orderby]=rand" i stick in a random numbr?
Garo
@Garabed96
May 20 2017 02:41
how are you guys doing intermediate algorithms
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:41
@MCavataio
Garo
@Garabed96
May 20 2017 02:41
I'm so losty
Vicky Lai
@vickylai
May 20 2017 02:48
Name the weirdest sandwiches you can think of. Go!
I promise this is relevant to coding.
Michael Cavataio
@MCavataio
May 20 2017 02:51
var $ = jQuery; $.ajaxSetup({ cache: false }); $(document).ready(function() { $("#newquote").on("click",function() { var html=""; $.getJSON("https://quotesondesign.com/wp-json/posts?
@sinharaksh1t it looked the request being cached by the browser
Vicky Lai
@vickylai
May 20 2017 02:52
Totally thought I was in general. My bad. /out
Michael Cavataio
@MCavataio
May 20 2017 02:54
so everytime the request was sent for a new quote.. the browser had the request cached and thought it already knew what the response should be, but the request was never actually getting to the api and just retrieving the same quote that was already retrieved
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:56
@MCavataio oh man
@MCavataio all right let me look into how to stop it from caching!! thanks man for your help!
CamperBot
@camperbot
May 20 2017 02:57
sinharaksh1t sends brownie points to @mcavataio :sparkles: :thumbsup: :sparkles:
:cookie: 8 | @mcavataio |http://www.freecodecamp.com/mcavataio
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:58
How do you debug these things?
Michael Cavataio
@MCavataio
May 20 2017 02:58
do you use the developer tools ?
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:58
I was almost completely lost!
@MCavataio not really! But i can learn! only valid for google chrom?
i use safari but I can switch to chrome if it helps me debug
Michael Cavataio
@MCavataio
May 20 2017 02:58
each browser has their own
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:59
@MCavataio all right ! will venture into it as soon as i fix my current issue! thanks again man! :D
CamperBot
@camperbot
May 20 2017 02:59
sinharaksh1t sends brownie points to @mcavataio :sparkles: :thumbsup: :sparkles:
:warning: sinharaksh1t already gave mcavataio points
Michael Cavataio
@MCavataio
May 20 2017 02:59
but for chrome I was console logging the response back after the click function
```function(json) {
console.log(json[0].content);
html+="<p >"+json[0].content+"</p>";
Rakshit Sinha
@sinharaksh1t
May 20 2017 02:59
could you please send me the code ?
oh awesome thanks!
Michael Cavataio
@MCavataio
May 20 2017 03:00
and then i saw that the quote was retrieving the same quote
Mohamed Derhalli
@derhallim
May 20 2017 03:00
@vickylaiio :joy:
Michael Cavataio
@MCavataio
May 20 2017 03:00
I then looked into the network tab in the developer tools , which shows any ajax request being sent
image.png
and there you could see that the request was cached
Rakshit Sinha
@sinharaksh1t
May 20 2017 03:07
@MCavataio how did you understand from that image that the query is being cached?
Michael Cavataio
@MCavataio
May 20 2017 03:08
if you see the size of the request it says from (disk cache)
Rakshit Sinha
@sinharaksh1t
May 20 2017 03:09
ah, that's what i was guessing but I thought it wouldn't make sense!
but thanks again so much man! You really taught me something new today!
:D
Michael Cavataio
@MCavataio
May 20 2017 03:12
image.png
@sinharaksh1t
no problem! That shows it better where the first request actually took 384ms but then the second request only took 4ms since it already had it cached
Rakshit Sinha
@sinharaksh1t
May 20 2017 03:16
crazy man! this is really useful now as I will be building more projects using json and apis
Revanth Murigipudi
@Revanth97
May 20 2017 03:20
Hi, I'm trying to do this convert first letter of every word in a string to uppercase, this is what I've got till now, I feel like I'm missing out something over here, could someone help me out?
function titleCase(str) {
  str.toLowerCase();
  var splittedString = str.split(" ");
  for(var i=0;i<str.length;i++) {
    var c=splittedString[i].charAt(0);
    c.toUpperCase();
  }
  return splittedString.join("");
}

titleCase("I'm a little tea pot");
Michael Cavataio
@MCavataio
May 20 2017 03:22
awesome happy to help out.. good luck @sinharaksh1t
Revanth Murigipudi
@Revanth97
May 20 2017 03:24
anyone /
?
Michael Cavataio
@MCavataio
May 20 2017 03:25
@Revanth97 take a look at c.toUpperCase()
Revanth Murigipudi
@Revanth97
May 20 2017 03:25
It shows error with the charAt() function
firstLetter.toUpperCase();
i mean
says typererror:cant read the property charAt of undefined
Michael Cavataio
@MCavataio
May 20 2017 03:26
also you're using str instread of splittedString in the for loop
Revanth Murigipudi
@Revanth97
May 20 2017 03:27
oops , you mean the condition for the loop right?
Michael Cavataio
@MCavataio
May 20 2017 03:28
right
Revanth Murigipudi
@Revanth97
May 20 2017 03:29
ok

```function titleCase(str) {
str.toLowerCase();
var splittedString = str.split(" ");
for(var i=0;i<splittedString.length;i++) {
var c=splittedString[i].charAt(0);
c.toUpperCase();
}
return splittedString.join(" ");
}

titleCase("I'm a little tea pot");
```

function titleCase(str) {
  str.toLowerCase();
  var splittedString = str.split(" ");
  for(var i=0;i<splittedString.length;i++) {
    var c=splittedString[i].charAt(0);
    c.toUpperCase();
  }
  return splittedString.join(" ");
}

titleCase("I'm a little tea pot");
this doesnt show any errror , but the output isnt as expected
:/
Michael Cavataio
@MCavataio
May 20 2017 03:30
right you havent modified splittedString or created a result
yash5657
@yash5657
May 20 2017 03:30
can some one help me with #216

function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0;i<contacts.length;i++)
while(firstName==contacts[i]["firstName"])
while(prop==contacts[i][""])
{

}

// Only change code above this line
}

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

Revanth Murigipudi
@Revanth97
May 20 2017 03:31
function titleCase(str) {
  str.toLowerCase();
  var splittedString = str.split(" ");
  for(var i=0;i<splittedString.length;i++) {
    splittedString[i].charAt(0).toUpperCase();
  }
  return splittedString.join(" ");
}

titleCase("I'm a little tea pot");
even this doesnt work :/
Cory Johnson
@CygnusSW
May 20 2017 03:37
I may be mistaken, but I would take a second look at the charAt documentation. then I'd follow that long chain of method calls ("splittedString[i]...") through to make sure each method call is doing what you want it to. I'm pretty sure there's a step or two missing in that process.
Revanth Murigipudi
@Revanth97
May 20 2017 03:39
Yea i feel the same too mate, but idk whats wrong
Cory Johnson
@CygnusSW
May 20 2017 03:41

So, your first part (splittedString[i]) selects the word itself.

.charAt returns a single letter

.toUpperCase returns that single letter as upper case

that's all good
but now that you've converted the letter to upper case, you have to do something with it
Joseph
@revisualize
May 20 2017 03:43
@Revanth97 splittedString[i].charAt(0).toUpperCase(); strings are immutable.
eyesore-
@eyesore-
May 20 2017 03:43
@Revanth97 toLowerCase and toUpperCase do not mutate.
Joseph
@revisualize
May 20 2017 03:43
@Revanth97 So, you need to use that line to actually change the string and reassign it.
Revanth Murigipudi
@Revanth97
May 20 2017 03:44
so I should create a new string to store them right?
i mean the tolowercase and touppercase functions
i shud be creating a new variable to store them and try to append them right>
?
Cory Johnson
@CygnusSW
May 20 2017 03:44
To what @Revanth97 and @revisualize said if you put in a "console.log(splittedString[i]" after that statement, you'll notice the words are capitalized
Kelechi Chinaka
@ke1echi
May 20 2017 03:45
function pickIt(arr){
  var odd=[],even=[];
  //coding here
  for (var i = 0; i < arr.length; i++) {
    if (arr[i]%2 == 0) {
      even.push(i);
    }else{
      odd.push(i);
    }
  }

  return [odd,even];
}
guys what am i doing wrong
Joseph
@revisualize
May 20 2017 03:46
This message was deleted
@kelechichinaka What are you trying to do?
@kelechichinaka Why are you pushing i and not arr[i]?
@kelechichinaka Is that a freeCodeCamp challenge?
@Revanth97 You don't have to create a new string.. You can overwrite the existing.
Kelechi Chinaka
@ke1echi
May 20 2017 03:48
oh fixed, i was not push the element in the array @revisualize
CW @revisualize
Joseph
@revisualize
May 20 2017 03:48
@kelechichinaka I was told today that I should work on codewars challenges.
@kelechichinaka Was my assumption correct?
Revanth Murigipudi
@Revanth97
May 20 2017 03:49
@revisualize but its not working right :/
Joseph
@revisualize
May 20 2017 03:49
@Revanth97 Show me?
Kelechi Chinaka
@ke1echi
May 20 2017 03:49
CW is great @revisualize ..real life challenges
Revanth Murigipudi
@Revanth97
May 20 2017 03:50
function titleCase(str) {
  str.toLowerCase();
  var splittedString = str.split(" ");
  for(var i=0;i<splittedString.length;i++) {
    splittedString[i].charAt(0).toUpperCase();
  }
  return splittedString.join(" ");
}

titleCase("I'm a little tea pot");
this is what i got
eyesore-
@eyesore-
May 20 2017 03:51
@Revanth97 You are doing toLowerCase in the beginning. That isn't mutating your string.
Revanth Murigipudi
@Revanth97
May 20 2017 03:51
sry i dont get it,
Joseph
@revisualize
May 20 2017 03:52

@Revanth97 This line:

    splittedString[i].charAt(0).toUpperCase();

Doesn't do anything.
Let's say you have a string:

var str = "hello";

by doing
str[0].toUpperCase();
Doesn't change the value of str[0]
str is a string. And strings are immutable.
even doing str[0] = str[0].toUpperCase(); doesn't do anything.
Because str is a string and strings are immutable.

@Revanth97 Even, str.toLowerCase(); is NOT mutating the string.
eyesore-
@eyesore-
May 20 2017 03:52
@Revanth97 He will explain.
Joseph
@revisualize
May 20 2017 03:52
@Revanth97 You have to do str = str.toLowerCase(); This is how you overwrite the value of the string.
@eyesore- Thanks.
CamperBot
@camperbot
May 20 2017 03:52
:cookie: 87 | @eyesore- |http://www.freecodecamp.com/eyesore-
revisualize sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
yash5657
@yash5657
May 20 2017 03:53
I was able to resolve last 2 tests
eyesore-
@eyesore-
May 20 2017 03:53
Yeah
yash5657
@yash5657
May 20 2017 03:53
but 1st 3 are failing

function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0;i<contacts.length;i++){
if(firstName == contacts[i].firstName){
if(prop == contacts[i].hasOwnProperty(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", "likes");

Joseph
@revisualize
May 20 2017 03:53
@yash5657 Your loop isn't looping.
@yash5657 That's one of your problems.
@yash5657 Another problem is:
return contacts[i].prop;
Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
@Revanth97 Does anything that I wrote make sense?
@yash5657 Why is your loop not looping?
The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
Revanth Murigipudi
@Revanth97
May 20 2017 03:55
@revisualize oh, one moment i'll try
oh, that worked str=str.toLowerCase()
could you please explain why it works this way but not the other way around
Joseph
@revisualize
May 20 2017 03:56

@yash5657 So, if I throw up an example for loop:

for ( var i = 0; i < 10000000; i++ ) {
    if (evaluation) {
        return "truth";
    } else {
        return "lies";
    }
 }

This exact loop.. Does not loop.
Because once the return statement is triggered the whole function stops ... including the loop

@Revanth97

STRINGS ARE IMMUTABLE.

yash5657
@yash5657
May 20 2017 03:56
got you, so what would the best solution be instead of return
?? @revisualize
Joseph
@revisualize
May 20 2017 03:56
@yash5657 using return.
@yash5657 Not every if requires an else.
@yash5657 Let's say you were at a big business event and you're quite popular (with all those skills you have) throughout the event you got handed 200 business cards (Which will remain unordered). Now, I walk up to you at the end and ask you.. Do you have a Business Card for "Jane Smith"? Now you loop look through your stack of 200 business cards. When would you tell me that you didn't have a business card for Jane?
yash5657
@yash5657
May 20 2017 03:58
yeah I was trying to issue to notices through 2 diff else statements
one for contact and one for property
eyesore-
@eyesore-
May 20 2017 03:58
@Revanth97 If you need more explanation I'd be down to walk through it with you.
Joseph
@revisualize
May 20 2017 03:58

@Revanth97

var str = "HELLO";
str.toLowerCase();

...
the str.toLowerCase(); line... Is doing something. But, you're not storing the result anywhere.

yash5657
@yash5657
May 20 2017 03:58
@revisualize
Joseph
@revisualize
May 20 2017 03:58
@yash5657 Could you answer the Jane question that I posted?
yash5657
@yash5657
May 20 2017 03:59
after checking all 200 @revisualize
Joseph
@revisualize
May 20 2017 03:59
@yash5657 So, you're saying that after you loop look through all of the contacts cards in your array of object stack. That you'd tell me you don't have one for the individual?
@yash5657
  // code before a for loop.
for (..........) {
  // Code inside of a for loop.
}
  // code after a for loop.
yash5657
@yash5657
May 20 2017 04:00
yeah
Joseph
@revisualize
May 20 2017 04:01
@yash5657 Like how I posted that so quickly?
@yash5657 It's like I had it pre-typed up.
@yash5657 And was leading you into a response.
@yash5657 because... you know.. reasons.
Georgi Yudin
@gyudin
May 20 2017 04:02
Hi guys! What "!" means in "return !args.includes(val);". Is it reversing the result?
Joseph
@revisualize
May 20 2017 04:02
@gyudin Not.
@gyudin !true is...
not true... false
Georgi Yudin
@gyudin
May 20 2017 04:04
Got it, thx. Thought it might be some shortened version for "if" statement xD
Joseph
@revisualize
May 20 2017 04:04
@gyudin Nope. It is just switching the boolean value.
@yash5657 Where you at now? Did that help at all?
@yash5657 The code that you posted is close to being done.
@yash5657 Just have to change a few things. One being the dot notation issue. The other being when no such contact is returned.
yash5657
@yash5657
May 20 2017 04:06
yeah I was trying to follow you
Joseph
@revisualize
May 20 2017 04:06
@yash5657 Oh, Another being: if(prop == contacts[i].hasOwnProperty(prop)){ ... That won't work.
yash5657
@yash5657
May 20 2017 04:07
making necessary changes @revisualize
Joseph
@revisualize
May 20 2017 04:08
@yash5657 .hasOwnProperty() method only returns a boolean value (true or false back to the function caller.
So, if(prop == contacts[i].hasOwnProperty(prop)){ ... the value of prop would need to be true and you'd need to have an object property key of true for that if condition to become true
yash5657
@yash5657
May 20 2017 04:09
for (var i=0; i<contacts.length; i++){
if(firstName == contacts[i].firstName) {
while(contacts[i].hasOwnProperty(prop)){
return contacts[i].prop;
}
return ("No such property");
}
return ("No such contact");
}
// Only change code above this line
}
Joseph
@revisualize
May 20 2017 04:09
@camperbot Thanks.
CamperBot
@camperbot
May 20 2017 04:09
revisualize sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 3257 | @camperbot |http://www.freecodecamp.com/camperbot
Joseph
@revisualize
May 20 2017 04:09
@yash5657 WHAT?
@yash5657 Where did the while come from?
yash5657
@yash5657
May 20 2017 04:10
I just chnaged it to while form if to see if that makes any diff
but still I couldnt pass 1st 3 tests
Joseph
@revisualize
May 20 2017 04:10
Well NOW you have a bunch of new issues.
@yash5657 Okay. Do you want to cover all of the new issues?
@yash5657 return contacts[i].prop; is prop a variable or a string?
yash5657
@yash5657
May 20 2017 04:11
string
Rick Riggs
@wikiwiggs
May 20 2017 04:12
hello all, I was wondering if I could get another pair of eyes on this. if you look at the developer tools console, you will see the type error. I've been looking at this so long, I believe that I'm too mentally exhausted to even troubleshoot reasonably.:
http://codepen.io/wikiwiggs/pen/QvZNLr?editors=0011
Joseph
@revisualize
May 20 2017 04:12
@yash5657 Incorrect.
@yash5657 In your function prop is a parameter. and parameters are treated just like variables that get their value from the function call.
@yash5657 Ergo, prop in your function is treated like a variable.
Bill
@BALMYIV
May 20 2017 04:13
easy question, that's sucking my soul. I can't get my sub arrays to sort.

function largestOfFour(arr) {
for (var x = 0 ; x < arr.length, x++;) { arr[x].sort(function(a,b) {return b-a;});

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

Joseph
@revisualize
May 20 2017 04:14
@BALMYIV Does .sort() mutate the array?
Bill
@BALMYIV
May 20 2017 04:14
sort in this case should sort the numbers in the sub arrays in decending order
yash5657
@yash5657
May 20 2017 04:14
@revisualize ohhh ok
Joseph
@revisualize
May 20 2017 04:15
@BALMYIV It does.
@BALMYIV But, does the .sort() method actually mutate the array?
Rick Riggs
@wikiwiggs
May 20 2017 04:15
I like to slice my arrays first personally
Bill
@BALMYIV
May 20 2017 04:15
it does mutate the array.
rick, I know there are other ways to do it, but I'm curious why I can't make this wokr
Rick Riggs
@wikiwiggs
May 20 2017 04:17
@BALMYIV try this: arr[x] = arr[x].slice().sort(function(a,b){return b-a;});
Luis Felipe López G.
@luishendrix92
May 20 2017 04:17
.sort does in fact mutate the array
which is a shame :(
Joseph
@revisualize
May 20 2017 04:17
What?
Luis Felipe López G.
@luishendrix92
May 20 2017 04:17
so does .reverse()
so you gotta be careful
eyesore-
@eyesore-
May 20 2017 04:18
Yeah, sort mutates.
Joseph
@revisualize
May 20 2017 04:18
var myArr = [8,2,4,6,3,7,9,1];
myArr.sort(function (a, b) { return a - b; });
console.log(myArr);
Shit.
Okay.
eyesore-
@eyesore-
May 20 2017 04:18
Yeah, you should try it out. It mutates.
Joseph
@revisualize
May 20 2017 04:18
I'm wrong.
eyesore-
@eyesore-
May 20 2017 04:18
Okay.
Joseph
@revisualize
May 20 2017 04:18
deleted comment.
Damn it.
The sort() method sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points.
/me goes back to RTFM.
Bill
@BALMYIV
May 20 2017 04:19
@wikiwiggs still got the original array back !
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:20
@wikiwiggs your this.doinit(json) is being bound to the this of the getJSON callback
Rick Riggs
@wikiwiggs
May 20 2017 04:21
@BALMYIV
blob
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:21
easiest way around it is to use an arrow function for your getJSON callback
eyesore-
@eyesore-
May 20 2017 04:21
@BALMYIV You have a syntax error
@BALMYIV In your for loop
Rick Riggs
@wikiwiggs
May 20 2017 04:21
@HeebieGeeBee I'm actually pretty new to using jquery, so this wasn't very clear for me. Thanks for looking.
CamperBot
@camperbot
May 20 2017 04:21
wikiwiggs sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1667 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:22
 $.get("http://wikiwiggs.com/tetrahedron.php?cat=streams&val="+this.user+"", (json) => { 
    this.doinit(json); });
};
@wikiwiggs
Joseph
@revisualize
May 20 2017 04:22
@BALMYIV YOUR FOR!
Jason Luboff
@JLuboff
May 20 2017 04:22
Use a template string if you're going that far @HeebieGeeBee
eyesore-
@eyesore-
May 20 2017 04:22
@BALMYIV for (var x = 0 ; x < arr.length, x++;) this is what you got
Bill
@BALMYIV
May 20 2017 04:22
@eyesore- that sounds about right!
Joseph
@revisualize
May 20 2017 04:22

@BALMYIV You have this:

for (var x = 0 ; x < arr.length, x++;)

that isn't correct.

for (var x = 0; x < arr.length; x++)
Rick Riggs
@wikiwiggs
May 20 2017 04:23
@HeebieGeeBee Could you describe what the difference is from what I am doing? this looks like an ES6 thing????
Joseph
@revisualize
May 20 2017 04:23
@eyesore- Hey, we found the issue at the same time.
eyesore-
@eyesore-
May 20 2017 04:23
Yeah, looks like it haha
Bill
@BALMYIV
May 20 2017 04:23
@revisualize thankyou.
CamperBot
@camperbot
May 20 2017 04:23
balmyiv sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3987 | @revisualize |http://www.freecodecamp.com/revisualize
Conor Murphy
@cmurphy580
May 20 2017 04:24
how does this function return the number that appears an odd number of times in an array?
function findOdd(A) {
  //happy coding!
  return A.reduce((a,b) => a ^ b);
}
Joseph
@revisualize
May 20 2017 04:24
@cmurphy580 What is ^?
eyesore-
@eyesore-
May 20 2017 04:24
It bitwise
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:25
@wikiwiggs without the arrow function the this is referring to the context of the get response whereas you want it to refer the context of where you called the get
Bill
@BALMYIV
May 20 2017 04:26
@BALMYIV thankyou!
CamperBot
@camperbot
May 20 2017 04:26
sorry balmyiv, you can't send brownie points to yourself! :sparkles: :sparkles:
Joseph
@revisualize
May 20 2017 04:26
@BALMYIV I would have 4000 by now if I could.
Bill
@BALMYIV
May 20 2017 04:26
@eyesore- thankyou!
CamperBot
@camperbot
May 20 2017 04:26
balmyiv sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 88 | @eyesore- |http://www.freecodecamp.com/eyesore-
Rick Riggs
@wikiwiggs
May 20 2017 04:26
I'm trying to understand the difference between the arrow function and a standard function @HeebieGeeBee I thought it was just a syntax thing.
eyesore-
@eyesore-
May 20 2017 04:26
No problem!
@wikiwiggs It's a bit of syntax sugar, but also changes binding. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:27
@wikiwiggs has a few more differences too
Conor Murphy
@cmurphy580
May 20 2017 04:27
@revisualize bitwise operator.
Bill
@BALMYIV
May 20 2017 04:28
@eyesore- I haven't been stuck in days. and I spent hours on that. for one comma instead of a semicolon!!!!!!!!
Rick Riggs
@wikiwiggs
May 20 2017 04:28
@eyesore- thanks for the link, I was avoiding ES6 like the plague for a long time, but I guess I need to start using it.
CamperBot
@camperbot
May 20 2017 04:28
wikiwiggs sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 89 | @eyesore- |http://www.freecodecamp.com/eyesore-
eyesore-
@eyesore-
May 20 2017 04:29
@BALMYIV haha it happens man! I've been stuck for days because I was reading docs for the wrong version /:
Jason Luboff
@JLuboff
May 20 2017 04:29
A lot of es6 syntax is awesome. Like template strings and arrow functions
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:29
@JLuboff what are youdoing?
sitting on a plane?
eyesore-
@eyesore-
May 20 2017 04:29
@wikiwiggs Don't avoid it man. It adds awesome stuff. Arrow functions are dope, scoping is great, umm string templates those are cool too.
Bill
@BALMYIV
May 20 2017 04:29
@eyesore- OMG. this stuff is crazy.
Jason Luboff
@JLuboff
May 20 2017 04:30
@HeebieGeeBee I'm the terminal. Plane boarding got delayed 😕
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:30
obama!!!
kao720302
@kao720302
May 20 2017 04:30
hello everyone, I am having the trouble to make this work. Can someone please help? ---> The variable myData should equal the first value of myArray.
The data in variable myArray should be accessed using bracket notation.
// Example
var ourArray = [1,2,3];
var ourData = ourArray[0]; // equals 1

// Setup
var myArray = [1,2,3];

// Only change code below this line.
var myData;
myData = myArray;
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:30
@JLuboff delayed for how long?
Rick Riggs
@wikiwiggs
May 20 2017 04:31
@eyesore- I've been avoiding it because I first needed to brush up on what I already knew, but haven't used in a while.
Jason Luboff
@JLuboff
May 20 2017 04:31
Last I looked...30 minutes
eyesore-
@eyesore-
May 20 2017 04:32
@kao720302 just look at the example. You gotta do the exact same thing.
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:32
ahh not too bad then
kao720302
@kao720302
May 20 2017 04:32
@eyesore- ok and thank I am trying it now
CamperBot
@camperbot
May 20 2017 04:32
kao720302 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 90 | @eyesore- |http://www.freecodecamp.com/eyesore-
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:33
i swear having to deal with airports and air travel is the worst way to start off any holiday
eyesore-
@eyesore-
May 20 2017 04:33
@wikiwiggs Makes sense. If I was you I would sprinkle in some ES6 as you are brushing up so you are as up to date as possible. You know how quickly shit changes in this industry so it's always good to stay up to date.
Jason Luboff
@JLuboff
May 20 2017 04:33
Ya. Just killing time now. Was stressful getting through security but we finally ate dinner a little bit ago
eyesore-
@eyesore-
May 20 2017 04:33
@kao720302 No problem!
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:34
@JLuboff i hear airpost security in america can be pretty brutal nowadays
Rick Riggs
@wikiwiggs
May 20 2017 04:34
@eyesore- That was the main factor in avoiding it, (figure it out W3, let me know when you do, I'll learn that please).
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:34
@JLuboff my local airport is so tiny looks like an old petrol station
Jason Luboff
@JLuboff
May 20 2017 04:34
@HeebieGeeBee eh it's not too bad. Just took a while since we had my wife do a pat down instead of the scan (she's pregnant) and my backpack got flagged since I had protein bars lol
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:35
protein bars? why would they be dangerous?
shoulda sent her through the scan, everyone knows radiation and babies is how superheroes are made @JLuboff
eyesore-
@eyesore-
May 20 2017 04:36
@wikiwiggs unfortunately I don't think they will ever stop with changes. Just gotta go with it /: I think I prefer all the changes over it being stagnant like Java.
Rick Riggs
@wikiwiggs
May 20 2017 04:38
@eyesore- Agreed, I think the biggest pushes for change are no doubt stemming from node though, that's alright though. It's just that since node, things have seemed to be changing hourly.
AIT ASSOU
@toscanoGithub
May 20 2017 04:39
Think of it like the Playoff, 4 arrays in game.
Rick Riggs
@wikiwiggs
May 20 2017 04:40
@eyesore- Before that I learned javascript from webmonkey way back when, and it didn't seem to change for over a decade, other than frameworks, and browser upgrades with more css properties
AIT ASSOU
@toscanoGithub
May 20 2017 04:41
you choose the largest number in each array. Then you check for the largest one. So you have two checks to do. There are many ways to do that.
Jason Luboff
@JLuboff
May 20 2017 04:41
@HeebieGeeBee hmm...about that....I don't know. I guess it could be drugs or explosives?? I've never had issues before (flown several times with them)
eyesore-
@eyesore-
May 20 2017 04:41
@wikiwiggs Oh, yeah. Node definitely made a huge change to the widespread of the JS community. Also V8
@wikiwiggs It's great because that means more jobs, but sucks because it's so hard to keep up with everything
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:42
@JLuboff maybe theyre worried about ppl getting their pump on mid flight
kao720302
@kao720302
May 20 2017 04:42
can anyone explain to me what I am supported to do?--->myData should be equal to 8.
Jason Luboff
@JLuboff
May 20 2017 04:43
Damn right. Gotta do my push ups, pull ups, and planks
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:43
lol
kao720302
@kao720302
May 20 2017 04:43
This is the code-->
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];
eyesore-
@eyesore-
May 20 2017 04:43
@kao720302 What do you have so far?
kao720302
@kao720302
May 20 2017 04:43
I haven't changed them yet becasue I don't know what I should do.
eyesore-
@eyesore-
May 20 2017 04:44
@kao720302 You've gotta change the last line to what you want it to point at. Right now, what does myData equal to?
Anyone want to test their knowledge of reduce and implement it from scratch?
kao720302
@kao720302
May 20 2017 04:46
@eyesore- 0
Rick Riggs
@wikiwiggs
May 20 2017 04:46
@HeebieGeeBee the arrow function no doubt fixed my type error, but I think I'm now returning too quickly, because all of my object assignments are coming up not defined, should I also try to learn up on promises for this? I'd prefer a callback at this point (because I don't understand how to work with promises at this point).
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:47
@wikiwiggs probably
Joseph
@revisualize
May 20 2017 04:47
@kao720302
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];
myArray[0] is [1,2,3]
myArray[0][0] is 1
myArray[0][1] is 2
myArray[1] is [4,5,6]
myArray[1][1] is 5
myArray[2] is [7,8,9]
myArray[2][0] is 7
myArray[3] is [[10,11,12], 13, 14]
myArray[3][0] is [10,11,12]
myArray[3][0][1] is 11
myArray[3][1] is 13
eyesore-
@eyesore-
May 20 2017 04:48
@kao720302 He'll explain. He's got templates for everything.
Rick Riggs
@wikiwiggs
May 20 2017 04:48
@HeebieGeeBee I thought I was using a call back with the arrow function, is that not correct?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:50
@wikiwiggs what do you mean?
@revisualize hi.
Joseph
@revisualize
May 20 2017 04:50
@HeebieGeeBee Hey Hey. How's things?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:50
@revisualize alright, hows you?
Joseph
@revisualize
May 20 2017 04:51
@HeebieGeeBee Chillin'. Thinking about leaving and going to jump on the pool table.
Rick Riggs
@wikiwiggs
May 20 2017 04:51
@HeebieGeeBee meaning my callbacks should be getting fired when my webserver returns something correct?
kao720302
@kao720302
May 20 2017 04:51
@revisualize thank you and how did you figure this templates out?
@eyesore- thank you
CamperBot
@camperbot
May 20 2017 04:51
kao720302 sends brownie points to @revisualize and @eyesore- :sparkles: :thumbsup: :sparkles:
:warning: kao720302 already gave eyesore- points
:star2: 3988 | @revisualize |http://www.freecodecamp.com/revisualize
Manuel Ralda
@mralda
May 20 2017 04:51
Hello, sorry to bother you fellas, I am stuck at the "Understand String Immutability" lesson. I have changed myStr = "Hello World"; above the line below the line... and keep getting the same error: TypeError: Assignment to read-only properties is not allowed in strict mode. I am stumped. Thanks in advance.
Rick Riggs
@wikiwiggs
May 20 2017 04:51
@HeebieGeeBee eg. the anonymous arrow function???
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:51
@wikiwiggs youre using it in the callback of the get
Joseph
@revisualize
May 20 2017 04:51
@kao720302 Practice ... I also spent time pre-typing a bunch of stuff. I'm lazy.
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:52
but youre calling all those gets in a loop
maybe use forEach instread of the loop
or figure out promises
Rick Riggs
@wikiwiggs
May 20 2017 04:53
@HeebieGeeBee yeah but their scope is on the specific objects methods correct?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:53
dont know what you mean by that
kao720302
@kao720302
May 20 2017 04:53
@revisualize thank you
CamperBot
@camperbot
May 20 2017 04:53
kao720302 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: kao720302 already gave revisualize points
Rick Riggs
@wikiwiggs
May 20 2017 04:53
@HeebieGeeBee Sorry stated that wrong, they are referncing the instatiation of a unique object every time.
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:54
forEach is an array iteration method
that takes a callback
i still dont quite get what you mean can you give an example
Rick Riggs
@wikiwiggs
May 20 2017 04:57

@HeebieGeeBee in my loop, I am creating a new instance of an object wih a unique variable name

for (var x=0;x<users.length;x++) {
  console.log(users[x]);
  window["" + users[x]] = new retObj();//<-- creating the new object here
  window["" + users[x]].init(users[x]);//<-- inittializing the $.get function in this method of this instance
}

ForEach of these references I am calling the get API call out to my web server, when that resolves on it's own callback, that's already sub-scoped to that unique instance, which is what you were getting me to change when you noticed which this (this.object instead of this.get function) scope I was referring to.

shouldn't this already resolve instead of timeout???
HeebieGeeBee
@HeebieGeeBee
May 20 2017 04:59
@wikiwiggs sorry i dont quite get what youre saying, its early
why are you using window?
Rick Riggs
@wikiwiggs
May 20 2017 05:05
@HeebieGeeBee ???
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:05
youre creating objects in your window object?
Manuel Ralda
@mralda
May 20 2017 05:06
Thanks guys!
Rick Riggs
@wikiwiggs
May 20 2017 05:06
Because I wanted my name collection to be my varaible name.
kao720302
@kao720302
May 20 2017 05:06
can anyone please take a look of my code? --->
// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.unshift("Happy"); 
// ourArray now equals ["Happy", "J", "cat"]

// Setup
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();

// Only change code below this line.

var myArray = [["paul",35],["dog",3]];
myArray.unshift();
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:06
that doesnt seem like a good idea
kao720302
@kao720302
May 20 2017 05:06
it said--->myArray should now have [["Paul", 35], ["dog", 3]]. and I did.
eyesore-
@eyesore-
May 20 2017 05:07
@kao720302 Does Paul need to be capitalized?
Rick Riggs
@wikiwiggs
May 20 2017 05:07
I could have used eval but that probably would have freaked everyone out in here, because it is such a bad practice in general
eyesore-
@eyesore-
May 20 2017 05:07
@kao720302 Also when you unshift you pass into unshift what you are adding to the array.
@kao720302 you see how above it has ourArray.unshift('Happy')? You want to do something similar.
Rick Riggs
@wikiwiggs
May 20 2017 05:09
window.<variable name> is the same as creating a global variable
kao720302
@kao720302
May 20 2017 05:09
@eyesore- yes it does. Thank you and why I have to put ('happy')?
CamperBot
@camperbot
May 20 2017 05:09
kao720302 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:warning: kao720302 already gave eyesore- points
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:09
@wikiwiggs which isnt a good idea
eyesore-
@eyesore-
May 20 2017 05:09
@kao720302 That was just an example.
Rick Riggs
@wikiwiggs
May 20 2017 05:09
@HeebieGeeBee I just wanted the scope to be global for inspection as well
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:09
but i dunno i would push everything into a holding array
let userObj = [];
users.forEach(val => {
    userObj.push(newObj());
  })  

userObj.forEach(val => {
   val.init();
}
Rick Riggs
@wikiwiggs
May 20 2017 05:10
At that point, I would have to eval it.
kao720302
@kao720302
May 20 2017 05:10
@eyesore- thank you
CamperBot
@camperbot
May 20 2017 05:10
:warning: kao720302 already gave eyesore- points
kao720302 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
eyesore-
@eyesore-
May 20 2017 05:11
@kao720302 no problem.
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:14
something like that
Masaki
@masaki1223
May 20 2017 05:15

function sumPrimes(num) {
  var prime=[];
  for(var i=2; i<=num;){
    prime.push(i);
    i++;
  }
   return prime.filter(function(val){
     if(val%2!==0|val%3!==0|val%5!==0|val%7!==0){
       return true;
     } else 
       return val;
   });
}

sumPrimes(10);
Is this correct to get prime number?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:15
but forget what your code was
Xarri Jorge
@xarrijorge
May 20 2017 05:16
@masaki1223 Think you need two bars to make logical "or": ||
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:16

let userObj = [];
users.forEach((val, index) => {
    userObj.push(newObj());
    userObj[index].init();
  })
might be better
@wikiwiggs
Masaki
@masaki1223
May 20 2017 05:17

function sumPrimes(num) {
  var prime=[];
  for(var i=2; i<=num;){
    prime.push(i);
    i++;
  }
   return prime.filter(function(val){
     if(val%2!==0||val%3!==0||val%5!==0||val%7!==0){
       return true;
     } 
   });
}

sumPrimes(100);
Still it doesn't filter numbers ...
eyesore-
@eyesore-
May 20 2017 05:17
What he said. | is bitwise
Rick Riggs
@wikiwiggs
May 20 2017 05:17

@HeebieGeeBee

var myObjs = {objects : []};
for (var x=0;x<users.length;x++) {
  console.log(users[x]);
  myObjs.objects.push({username : users[x]], object : new retObj()});//<-- creating the new object here
  myObj.objects.forEach(function(x){ x.object.init(); });//<-- inittializing the $.get function in this method of this instance
}

I still don't understand your code - sorry for my ES6 ignorance, but this is what I am thinking from your suggestion, what are your thoughts???

eyesore-
@eyesore-
May 20 2017 05:18
@masaki1223 There is more to primes than that. You should look up examples of prime sieves.
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:19
@wikiwiggs i dont think that for Each inside the loop is good
Nick Forlivio
@whackdev
May 20 2017 05:19
So I'm building the wikipedia viewer and I can get the API call to give me the article titles but I can't figure out how to add the prop argument to jquery to get the images that go with the article
$(document).ready(function(){

        $('#search-button').click(function() {
                    var search = $('#search-box').val();
          $.ajax({
                url: 'https://en.wikipedia.org/w/api.php',
                data: { action: 'query', list: 'search', srsearch: search, prop:'images' && 'titles', format: 'json' },
                dataType: 'jsonp',
                success: function (data) {
                                    console.log(data); 

        for (var i = 0; i < data.query.search.length; i++){
          $('#search-result').append('<p>'+data.query.search[i].title+'</p>');
     }

  }
                                }
            );
        });
    });
Xarri Jorge
@xarrijorge
May 20 2017 05:19
@whackdev where is your pen?
Rick Riggs
@wikiwiggs
May 20 2017 05:20
I'll restructure with reduce instead.
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:23


let userObj = {};
users.forEach((val, index) => {
    userObj[val] = new retObj();
    userObj[val].init();
  })
Rick Riggs
@wikiwiggs
May 20 2017 05:23
@HeebieGeeBee
var myObjs = {objects : []};
users.reduce(function(x,y){
  myObjs.objects.push({username : users[y]], object : new retObj()});
  myObj.objects.forEach(function(z){ z.object.init(); });
},0);
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:23
@wikiwiggs maybe this is what youre trying to do
Rick Riggs
@wikiwiggs
May 20 2017 05:24
@HeebieGeeBee can you pass two parameter into the forEach method?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:25
@wikiwiggs they are already defined but you can give them names
so like the first argument is the current object, and second argument is the index in the array
will need to read the docs on it
dont understand what youre doing wiht reduce there
eyesore-
@eyesore-
May 20 2017 05:27
From that code snippet you posted you have no need to use reduce.
You never use the accumulator of reduce.
Abhijeet Singh
@abhijeetps
May 20 2017 05:31
Need help:
http://beta.freecodecamp.com/en/challenges/basic-javascript/divide-one-decimal-by-another-with-javascript
I wrote
var quotient = (4.4 / 2); // Fix this line
The error is:
var quotient = (4.4 / 2); // Fix this line
Xarri Jorge
@xarrijorge
May 20 2017 05:32
@aps120797 make 2.2
Abhijeet Singh
@abhijeetps
May 20 2017 05:32
The quotient variable should only be assigned once
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 05:32
@aps120797 Reload
@aps120797 Your code is good.
Xarri Jorge
@xarrijorge
May 20 2017 05:32
@aps120797 sorry make 2.0
Abhijeet Singh
@abhijeetps
May 20 2017 05:32
@ivancsicsmarkus Done. Reloaded.
@ivancsicsmarkus Thanks.
@kodinglife Thanks.
CamperBot
@camperbot
May 20 2017 05:33
aps120797 sends brownie points to @kodinglife :sparkles: :thumbsup: :sparkles:
:cookie: 384 | @kodinglife |http://www.freecodecamp.com/kodinglife
Rick Riggs
@wikiwiggs
May 20 2017 05:41
@HeebieGeeBee yeah it would probably look something more like this with reduce:
var myObjs = {objects : []};
users.reduce(function(x,y){
  myObjs.objects.push( { username : users[y], object : function(){ return new retObj();} } );
  myObjs.objects[myObjs.length-1].object.init(users[y]);
},0);
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:41
@wikiwiggs but why are you using reduce at all?
Rick Riggs
@wikiwiggs
May 20 2017 05:42
reduce is just a for loop
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:42
thats what forEach is for
think my new ring tone is just going to be this woman saying 'spider monkey'
eyesore-
@eyesore-
May 20 2017 05:44
Yeah, you don't want to use something with extra functionality to just use it's basic function.
Ogundele Olumide
@Lumexralph
May 20 2017 05:56
@wikiwiggs reduce is to shrink an array actually
@HeebieGeeBee Bro!
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:56
@Lumexralph yo!
how you doing?
Ogundele Olumide
@Lumexralph
May 20 2017 05:57
@HeebieGeeBee great bro, travelled home, should be going for a wedding soon...... you?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:58
nice, have fun
im alright
Ogundele Olumide
@Lumexralph
May 20 2017 05:59
@HeebieGeeBee how's the game now?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 05:59
@Lumexralph coming along
dunno how it was last time you saw it
still got lots to do though
Rick Riggs
@wikiwiggs
May 20 2017 06:01

@Lumexralph try this:

var arr=[1,3,5,7,9];
arr.reduce(function(x,y){
  console.log(y);
},0);

It's a for loop

Ogundele Olumide
@Lumexralph
May 20 2017 06:02
@wikiwiggs you're console.logging
Rick Riggs
@wikiwiggs
May 20 2017 06:02
@Lumexralph It doesn't really matter what I am doing, it's a for loop
Ogundele Olumide
@Lumexralph
May 20 2017 06:03
@wikiwiggs reduce is a form of a loop cos it goes through all the elements in the array..... just saying not really a for loop, i agree with you that it's looping
Rick Riggs
@wikiwiggs
May 20 2017 06:05

@Lumexralph

var arr=[1,3,5,7,9];
var arr2 = [0,2,4,6,8];
arr.reduce(function(x,y){
  x++
  console.log(y);
  console.log(arr2[x]);
},-1);

versus

var arr=[1,3,5,7,9];
var arr2 = [0,2,4,6,8];
arr.reduce(function(x,y){
  x++
  console.log(y);
  console.log(x);
},-1);
Ogundele Olumide
@Lumexralph
May 20 2017 06:06
@wikiwiggs is reduce actually a for loop?
Cory Johnson
@CygnusSW
May 20 2017 06:07
@Lumexralph It's just "sugar" on top of a for loop, with some small, additional logic inside
although, I guess technically it could also be a while loop
HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:08
@Lumexralph how are your projects coming?
Ogundele Olumide
@Lumexralph
May 20 2017 06:08
@Rom2711 :smile: that's what I was trying to explain to @wikiwiggs it's a loop, you're looping but neither is it for or while loop
Rick Riggs
@wikiwiggs
May 20 2017 06:09
@Lumexralph What kind of loop would you consider it?
Ogundele Olumide
@Lumexralph
May 20 2017 06:09
@HeebieGeeBee calculator is on 90% complete for almost a month now, building an Asteroids arcade game I told you about, lost the code and had to restart
@wikiwiggs the idea is what is a loop? why do you loop?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:10
@Lumexralph brutal
you need to github your code
Rick Riggs
@wikiwiggs
May 20 2017 06:10
@Rom2711 A while loop loops while something is true, and so does a for loop, so what's the difference?
Cory Johnson
@CygnusSW
May 20 2017 06:11
I meant under the hood, I don't know how it's implemented, that's all. It doesn't really matter, aside from nerd trivia
May even change, based on browser, I suppose
Ogundele Olumide
@Lumexralph
May 20 2017 06:11
@wikiwiggs reduce method has to pick each element in the array, so looping comes in but neither is it a for or while loop
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 06:12

@wikiwiggs
I would use a for loop for the reason that I may KNOW the NUMBER OF ITERATIONS I need to do and I have an INCREMENTING variable which can be handy sometimes.

I would use while loop when I am NOT SURE how many ITERATIONS I might need to carry out. Examples: Waiting for user to input correct input values and keep looping until he/she inputs the proper value

Ogundele Olumide
@Lumexralph
May 20 2017 06:12
@HeebieGeeBee yes Bro, took soo much motivation to start again, I need to learn more on github ing code, any leads?
HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:12
@Lumexralph its nto really that hard just to create repos and just push updates
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:13

var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = "maps"; // Change this line
myStorage.car["inside"]["glove box"] = gloveBoxContents;

Rick Riggs
@wikiwiggs
May 20 2017 06:13

this method definition loops while there is elements left to be analyzed in an array. so what's the technical difference here:

arr = [1,3,5,7,9];
while(arr.length > -1) {
  console.log(arr.shift());
}

versus

arr = [1,3,5,7,9];
for(var x=0;x<arr.length;x++) {
  console.log(arr.shift());
}
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:13
Use dot and bracket notation to access myStorage
Ogundele Olumide
@Lumexralph
May 20 2017 06:13
@priyanka-bhalla assign this myStorage.car["inside"]["glove box"] to var gloveBoxContents
@HeebieGeeBee if it's that, I know but how to make it host a web app or site
Rick Riggs
@wikiwiggs
May 20 2017 06:14
while & for work for something that is true, for just wants to iterate.
Ogundele Olumide
@Lumexralph
May 20 2017 06:15
@wikiwiggs while also iterates
HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:15
@Lumexralph its just a setting in the settings to publish to github pages
Rick Riggs
@wikiwiggs
May 20 2017 06:15
But it doesn't have to.
HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:15
but they only host static sites i think
Ogundele Olumide
@Lumexralph
May 20 2017 06:15
@HeebieGeeBee not dynamic? :worried:
HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:16
@Lumexralph think you need to use heroku for that
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:16
@Lumexralph still not working
HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:16
when i say static i mean with no back end server stuff going on
Ogundele Olumide
@Lumexralph
May 20 2017 06:16
@HeebieGeeBee oh..... I was thinking no JS
@priyanka-bhalla show your code
@HeebieGeeBee like static sites and dynamic
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:17

var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = myStorage.car["inside"]["glove box"]; // Change this line

HeebieGeeBee
@HeebieGeeBee
May 20 2017 06:17
sorry might be using wrong terminology
Xarri Jorge
@xarrijorge
May 20 2017 06:17
@priyanka-bhalla remove quotes
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:19
still having error they said inside is not defined
Ogundele Olumide
@Lumexralph
May 20 2017 06:19
@priyanka-bhalla that seems right
@priyanka-bhalla or probably FCC wants you to use dot notation for inside property
@HeebieGeeBee :smile: you're not alone
Rick Riggs
@wikiwiggs
May 20 2017 06:21
@ivancsicsmarkus Exactly my point While can work on something while the case is/is not true, for works on a known iterator. while is more flexible, because you can increment a value up or down to force a greater than/less than comaprison to eventually stop it, if that's how you decided to implement the while type of loop. Hence the reduce method of an array is a for loop, because it operates on an incremental principal (each element of the array).
Blara02
@Blara02
May 20 2017 06:37
how do i black box code? using the ` character in triples makes it so that Enter dosent sent the message
Ogundele Olumide
@Lumexralph
May 20 2017 06:37
@Blara02 shift + enter
Blara02
@Blara02
May 20 2017 06:38
that dosent work, could it be chrome ??
Ogundele Olumide
@Lumexralph
May 20 2017 06:39
@Blara02 can you rephrase the question?
Blara02
@Blara02
May 20 2017 06:39
shift+enter dosent send the message
could the problem be that im using google chrome
Ogundele Olumide
@Lumexralph
May 20 2017 06:39
@Blara02 what're you trying to do again? can you illustrate?
Blara02
@Blara02
May 20 2017 06:40
oh sorry
im trying to paste a chunk of code in a black box
Ogundele Olumide
@Lumexralph
May 20 2017 06:41
@Blara02 okay..... is it how to do that? or how to go to the next line before sending the code?
Blara02
@Blara02
May 20 2017 06:41
Shift enter is supposed to drop me down to the next line
but enter also does that
when i use "`" 3 times
and to fix it i have to reload the page
Ogundele Olumide
@Lumexralph
May 20 2017 06:42
@Blara02 oh are you in compose mode or chat mode?
Blara02
@Blara02
May 20 2017 06:42
im not sure
var i = 0;
var count = 0;
var countt = 0;
while (i === 0) {
if (count > 3) {
  return "No such contact";
} else if (contacts[count].firstName == firstName) {
    while (i === 0) {
      if (countt > 3) {
        return "No such property";
      } else if (contacts[count][countt] === prop) {
        i++;
        return contacts[count][prop];
      } else {
        countt++;
      }
    }
} else {
  count++;
}
}
Ogundele Olumide
@Lumexralph
May 20 2017 06:42
finally
Blara02
@Blara02
May 20 2017 06:43
oh hey i did it
thanks @Lumexralph
CamperBot
@camperbot
May 20 2017 06:43
blara02 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1787 | @lumexralph |http://www.freecodecamp.com/lumexralph
Blara02
@Blara02
May 20 2017 06:44
that code is for the look up profile challange
Cynwenn
@Cynwenn
May 20 2017 06:44
Could anyone help me fix my algorithm please?
function findLongestWord(str) {
  var longestar;
  var space = " ";

var entryArray = str.split(space);
for (i = 0; i < (parseInt(entryArray.length)) ; i++){
     for (j = 0; j < (parseInt(entryArray.length)) ; j++){

  if (entryArray[i] < entryArray[j]){
    longestar = entryArray[i];
  }
    longestar = entryArray[j];
  }
  return longestar.length;
}

}


findLongestWord("The quick brown fox jumped over the lazy dog");
Ogundele Olumide
@Lumexralph
May 20 2017 06:45
@Cynwenn why looping twice?
Cynwenn
@Cynwenn
May 20 2017 06:45
@Lumexralph to compare, at least that was the idea
Ogundele Olumide
@Lumexralph
May 20 2017 06:45
@Cynwenn split gave you an array of the words.... you need a loop to pick each word in the array to check it's length
Cynwenn
@Cynwenn
May 20 2017 06:46
@Lumexralph that's what I've written, a loop...
Ogundele Olumide
@Lumexralph
May 20 2017 06:47
@Cynwenn you're using 2 loops, a loop is what you need
Siddhant Shaw
@Mianto
May 20 2017 06:47
function lookUpProfile(firstName, prop){
// Only change code below this line
var flag = 0;
for(var x = 0; x <= contacts.length; x++){
if (contacts[x].firstName === firstName){
if (contacts[x].hasOwnProperty(prop)===true) {
return contacts[x][prop];
}
else {
return "No such property";
}
}
}
return "No such contact";
}this function does not return "No such contact"
Ogundele Olumide
@Lumexralph
May 20 2017 06:48
@Mianto x <= contacts.length contacts[x] will be undefined at last iteration
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 06:48
@Mianto x < contact.length
Ogundele Olumide
@Lumexralph
May 20 2017 06:49
@Mianto the last element in an array is array[array.length - 1]
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 06:49
@Mianto You should always check console, and you will find these bugs easily without help.
Cynwenn
@Cynwenn
May 20 2017 06:51
@Lumexralph I took out one loop and I'm struggling with the same thing
Blara02
@Blara02
May 20 2017 06:51
@Mianto I didnt know ".hasOwnProperty" was a thing but it instantly fixed my code so thanks for that haha
CamperBot
@camperbot
May 20 2017 06:51
blara02 sends brownie points to @mianto :sparkles: :thumbsup: :sparkles:
:cookie: 122 | @mianto |http://www.freecodecamp.com/mianto
Ogundele Olumide
@Lumexralph
May 20 2017 06:52
@Cynwenn in the loop, pick each word length , compare it against a starting variable initialized to 0, if the latter is greater then the former make it the new length to compare with the next word, return that variable when the loop is done
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:53

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

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

// Setup
var myArr = [ 2, 3, 4, 5, 6];
var myTotal = 0;
// Only change code below this line

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

total should be declared and initialized to 0
total should equal 20
You should use a for loop to iterate through myArr
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 06:53
@priyanka-bhalla You should add myArr’s current element (i) and not myTotal’s.
Ogundele Olumide
@Lumexralph
May 20 2017 06:53
@priyanka-bhalla myTotal[i]; is there an array called myTotal or myArr ?
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:54
@Lumexralph thanks dear
CamperBot
@camperbot
May 20 2017 06:54
priyanka-bhalla sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1788 | @lumexralph |http://www.freecodecamp.com/lumexralph
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:56
@Lumexralph but still having two issues
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 06:56
@priyanka-bhalla
myTotal += myArr[i];
What are those issues?
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:56
total should be declared and initialized to 0
total should equal 20
these are two issues
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 06:58
@priyanka-bhalla Could you give me your link?
priyanka bhalla
@priyanka-bhalla
May 20 2017 06:58

var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

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

// Setup
var myArr = [ 2, 3, 4, 5, 6];
var myTotal = 0;
// Only change code below this line

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

Markus Ivancsics
@ivancsicsmarkus
May 20 2017 06:59
@priyanka-bhalla If you don’t give me your link, I can’t help. Sorry.
thanks dear
Nicolas MARTINHO
@NicolasMartinho
May 20 2017 07:13
function destroyer(arr) {
  compArr = []
  result = []
  for (i=1;i<arguments.length;i++) {
    compArr.push(arguments[i]);
  }
  result = compArr.filter(function (arr){
    return arr !== compArr;
  })
  return result;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Hello guys, I have some trouble understanding that filter method. this code gives me [2, 3] as result, what i did wrong ? (it should destroy the given arguments in the given array)
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:14

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

// Only change code above this line
}

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

"Kristian", "lastName" should return "Vos"
"Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
"Harry","likes" should return an array
"Bob", "number" should return "No such contact"
"Akira", "address" should return "No such property"
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 07:15
@priyanka-bhalla You have to loop through your contacts array with a for loop.
@priyanka-bhalla Check if the current element (contacts[i])’s firstName matches witht the given firstName!
@priyanka-bhalla If the firstName matches check if that element has a property called the given prop. If it has return it! (contacts[i][prop])
@priyanka-bhalla If it doesn’t have the prop, return "No such property“. If the firstName doesn’t match at all (after the loop) return "No such contact“.
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 07:20
@priyanka-bhalla ??
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:21
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i=0; i<contacts;i++){
return contacts[i][prop];
}
// Only change code above this line
}
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 07:22
@priyanka-bhalla Not really. That line of code you wrote is perfect but you need conditionals.
maxyogoro
@maxyogoro
May 20 2017 07:23
Not knowing how to proceed on the 'Nesting for loops
Please, help! :)
Joseph
@revisualize
May 20 2017 07:27
@priyanka-bhalla The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
@priyanka-bhalla Once a return statement is triggered... the whole function HALTs. Ergo, your for loop isn't looping.
maxyogoro
@maxyogoro
May 20 2017 07:28
I just solved it
Joseph
@revisualize
May 20 2017 07:28
@priyanka-bhalla Also, you're missing a few if conditions as well.
@maxyogoro Grats.
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:32
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i=0; i<contacts.length;i++){
if(firstName==contacts[i].firstName){
return contacts[i][prop];
}else {
return "No such Property";
}}
Sid Sankhe
@LeCodeurSpatial
May 20 2017 07:35
Stuck with Stand In Line

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

return item; // Change this line
}

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

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

heroiczero
@heroiczero
May 20 2017 07:35
@LeCodeurSpatial review how to Manipulate arrays with ... in your code
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:36
https://www.freecodecamp.com/challenges/profile-lookup#?solution=%0A%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUpProfile(firstName%2C%20prop)%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afor(var%20i%3D0%3B%20i%3Ccontacts.length%3Bi%2B%2B)%7B%0Aif(firstName%3D%3Dcontacts%5Bi%5D.firstName)%7B%0A%20%20return%20contacts%5Bi%5D%5Bprop%5D%3B%0A%7Delse%20%7B%0A%20%20return%20%22No%20such%20Property%22%3B%0A%7D%7D%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Akira%22%2C%20%22likes%22)%3B%0A
Sid Sankhe
@LeCodeurSpatial
May 20 2017 07:39
@heroiczero I tried with push() & pop() earlier, but couldn't reach solution
heroiczero
@heroiczero
May 20 2017 07:39
@LeCodeurSpatial push(content) and you have to shift not pop
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:40
please help me
Sid Sankhe
@LeCodeurSpatial
May 20 2017 07:41
Okay @heroiczero Thanks, I'll try that.
CamperBot
@camperbot
May 20 2017 07:41
lecodeurspatial sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1282 | @heroiczero |http://www.freecodecamp.com/heroiczero
Nicolas MARTINHO
@NicolasMartinho
May 20 2017 07:45
function destroyer(arr) {
  compArr = [];
  result = [];
  for (i=1;i<arguments.length;i++) {
    compArr.push(arguments[i]);
  }
  for(j=0;j<compArr.length;j++) {
  arr = arr.filter(function (num){
    return num !== compArr[j];
  });}
  return arr;
}
This works but could i do better ? it should destroy the given arguments in a given array
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:48
please help
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 07:49
@priyanka-bhalla You should add an other conditional like I said.
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:49
which
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 07:50
@priyanka-bhalla
  • If the firstName matches check if that element has a property called the given prop. If it has return it! (contacts[i][prop])
  • If it doesn’t have the prop, return "No such property“. If the firstName doesn’t match at all (after the loop) return "No such contact“.
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:51
https://www.freecodecamp.com/challenges/profile-lookup#?solution=%0A%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUpProfile(firstName%2C%20prop)%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afor(var%20i%3D0%3B%20i%3Ccontacts.length%3Bi%2B%2B)%7B%0Aif(firstName%3D%3Dcontacts%5Bi%5D.firstName)%7B%0A%20%20return%20contacts%5Bi%5D%5Bprop%5D%3B%0A%7Delse%20%7B%0A%20%20return%20%22No%20such%20Property%22%3B%0A%7D%7D%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Akira%22%2C%20%22likes%22)%3B%0A
@ivancsicsmarkus please see i send a link
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 07:55
@priyanka-bhalla I won’t give you the solution.
@priyanka-bhalla However I gave you the pseudo-code.
@priyanka-bhalla You just have to write the code.
priyanka bhalla
@priyanka-bhalla
May 20 2017 07:56
ok thanks
Md Abu Zafar
@mdaz78
May 20 2017 07:57

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

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

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

What's the error in my code?

checkObj("gift") should return "pony".
checkObj("pet") should return "kitten".

but It is not doing so.

@priyanka-bhalla @ivancsicsmarkus any help?
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 08:00
@mdaz78 You are returning myObj’s „checkProp“.
@mdaz78 You shuld use square bracket notation. Not dot notation.
Md Abu Zafar
@mdaz78
May 20 2017 08:00
yup got it...but why so?
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 08:03
@mdaz78 Because with dot notation it looks for the following property. With bracket it looks for the value inside that.
So:
myObj.checkProp // => myObj’s „checkprop“ value which doesn’t exist
myObj[checkProp] // => looks for a property given by the checkProp variable. Now it is gift.
Sonkeng André
@Andre-Sonkeng
May 20 2017 08:05
hello world, i'm blocked on profile lookup
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 08:11
@Andre-Sonkeng Hello!
@Andre-Sonkeng
  • You have to loop through your contacts array with a for loop.
  • Check if the current element (contacts[i])’s firstName matches witht the given firstName!
  • If the firstName matches check if that element has a property called the given prop. If it has return it! (contacts[i][prop])
  • If it doesn’t have the prop, return "No such property“. If the firstName doesn’t match at all (after the loop) return "No such contact“.
Pieter Stokkink
@forkerino
May 20 2017 08:12
@NicolasMartinho one improvement would be to not put your filter inside a loop, but use .indexOf() to check if the element is in your compArr. You can also turn the top five lines into one line using Array.from and some method chaining to slice off the first element, there's examples on how to do this on the mdn page for arguments.
Sonkeng André
@Andre-Sonkeng
May 20 2017 08:13
thanks
priyanka bhalla
@priyanka-bhalla
May 20 2017 08:14

function randomFraction() {

// Only change code below this line.
Math.random(2.5);
return 0;

// Only change code above this line.
}

The number returned by randomFraction should be a decimal.
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 08:14
@priyanka-bhalla Just return Math.random()!
priyanka bhalla
@priyanka-bhalla
May 20 2017 08:22

var randomNumberBetween0and19 = Math.floor(Math.random() * 10);

function randomWholeNum() {

// Only change code below this line.
Math.floor(9);
return Math.random();
}

The result of randomWholeNum should be a whole number.
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 08:23
@priyanka-bhalla Man think about it!
@priyanka-bhalla The number you pass in to Math.floor will be a whole number.
priyanka bhalla
@priyanka-bhalla
May 20 2017 08:23
okl
Spyrantis Theodoros
@thodorisanta
May 20 2017 08:25
anyone can help me with the minimax chalenge? for the tic tac toe
priyanka bhalla
@priyanka-bhalla
May 20 2017 08:29
@ivancsicsmarkus thanks dear
CamperBot
@camperbot
May 20 2017 08:29
priyanka-bhalla sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:cookie: 500 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
Sid Sankhe
@LeCodeurSpatial
May 20 2017 08:30
@heroiczero missing out nextInLine([5,6,7,8,9], 1) should return 5

I did following function nextInLine(arr, item) {
``` // Your code here
var q=arr.push(item);

arr.shift();

return q; // Change this line
}

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

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

Markus Ivancsics
@ivancsicsmarkus
May 20 2017 08:36
@LeCodeurSpatial q is now the length of the arr.
Johnny
@JohnnyBizzel
May 20 2017 08:49
@thodorisanta Good article: http://neverstopbuilding.com/minimax
aurelienmigeot
@aurelienmigeot
May 20 2017 08:50
Hello, I don't know how to assign proccessArg to processed in my code. can you help me ?

var processed = 2;

function processArg(num) {
return (7);
}

Spyrantis Theodoros
@thodorisanta
May 20 2017 08:54
@JohnnyBizzel should i chose minimax or negamax and why?
Johnny
@JohnnyBizzel
May 20 2017 08:55
@thodorisanta Whatever works for you or whatever you can understand. I have not heard of negamax.
John Otu
@johnotu
May 20 2017 08:58
Hi guys, need someone to pair program on the exact change challenge
Spyrantis Theodoros
@thodorisanta
May 20 2017 08:59
@JohnnyBizzel im watching this video and after 29:20 he says what negamax is and where it differs with minimax. i dont realy understand the difference since i havent worked with minimax either.
https://www.youtube.com/watch?v=aWhb9dr1jNw
Johnny
@JohnnyBizzel
May 20 2017 09:02
@thodorisanta I can't help you much because when I got stuck I copied the algo code from a friend!
Legacy
@punyparker
May 20 2017 09:03
Hello can I get some help
Johnny
@JohnnyBizzel
May 20 2017 09:03
@punyparker Try the help room
John Otu
@johnotu
May 20 2017 09:03
Yea @punyparker
@JohnnyBizzel This is the "Help" room
Legacy
@punyparker
May 20 2017 09:03
this keeps returning undefined for some reason
@JohnnyBizzel exactly xD
Johnny
@JohnnyBizzel
May 20 2017 09:04
@johnotu This is the "HelpJavaScript" room
Legacy
@punyparker
May 20 2017 09:04
@JohnnyBizzel Javascript. Exactly.
Johnny
@JohnnyBizzel
May 20 2017 09:04
@punyparker is your code doubled or did you paste it twice?
Legacy
@punyparker
May 20 2017 09:05
Wait

function returnLastWord(str) {
var word = str.split(" ");
return word[-1];
}

returnLastWord("Walking on water and developing software from a specification are easy if both are frozen");

this is it
Keeps returning undefined
Johnny
@JohnnyBizzel
May 20 2017 09:06
@punyparker return word[-1]; what is going on here?
:wave: Hello...
@punyparker I presume from your silence, you don't know.
Legacy
@punyparker
May 20 2017 09:11
Sorry, I was afk
it returns the last word in the array.
aurelienmigeot
@aurelienmigeot
May 20 2017 09:11

What's wrong with this ?var processed = 2;

function processArg(num) {
return (7);
}

Johnny
@JohnnyBizzel
May 20 2017 09:13

@punyparker From Mozilla Dev Network...

JavaScript arrays are zero-indexed: the first element of an array is at index 0, and the last element is at the index equal to the value of the array's length property minus 1.

@punyparker return word[-1]; so this is wrong
@aurelienmigeot you always return 7?
Legacy
@punyparker
May 20 2017 09:15
@JohnnyBizzel So I can do return word[word.length - 1];
correct?
Johnny
@JohnnyBizzel
May 20 2017 09:15
@punyparker makes more sense
Legacy
@punyparker
May 20 2017 09:15
Worked! Thanks
How come I've seen [-1] somewhere though?
It usually works
Johnny
@JohnnyBizzel
May 20 2017 09:16
@punyparker you would have to show me that code - I've never seen it.
@aurelienmigeot var processed is never used?
aurelienmigeot
@aurelienmigeot
May 20 2017 09:18
@JohnnyBizzel where should I put it ?
Legacy
@punyparker
May 20 2017 09:18
@JohnnyBizzel Nevermind it's from Python.
Johnny
@JohnnyBizzel
May 20 2017 09:18
@punyparker Ah. Python, yes. I've seen it there!
This is HelpJavaScript ;)
@aurelienmigeot put what?
aurelienmigeot
@aurelienmigeot
May 20 2017 09:19
I can't find the place where i should put var processed in order to use it
Johnny
@JohnnyBizzel
May 20 2017 09:19
@aurelienmigeot You asked what is wrong with this but did not explain what you are doing
aurelienmigeot
@aurelienmigeot
May 20 2017 09:19
this is what i have to do : Call the processArg function with an argument of 7 and assign its return value to the variable processed.
Johnny
@JohnnyBizzel
May 20 2017 09:20
@aurelienmigeot processed = num inside teh function maybe
aurelienmigeot
@aurelienmigeot
May 20 2017 09:21
it doesn't work
Johnny
@JohnnyBizzel
May 20 2017 09:22
@aurelienmigeot it? what is it?
@aurelienmigeot Challenge name?
Ty Tia
@TyTia77
May 20 2017 09:31
@thodorisanta i just finished mine
the tic tac toe minimax algorithm
Spyrantis Theodoros
@thodorisanta
May 20 2017 09:32
@TyTia77 can i check your project?
Ty Tia
@TyTia77
May 20 2017 09:32
its not finished
like the ui and stuff
just the algorithm if you're interested?
Spyrantis Theodoros
@thodorisanta
May 20 2017 09:34
@TyTia77 thats the part that i want to check :)
its at the very bottom
if you can read my code =D
Spyrantis Theodoros
@thodorisanta
May 20 2017 09:36
how can i make player2 to take "what is left" of the arr ?
var arr = [X,O];
var player1 = X;
var player2 = ???
thank you :)
Ty Tia
@TyTia77
May 20 2017 09:36
um
player2 = arr[0];
is that what you're asking
Spyrantis Theodoros
@thodorisanta
May 20 2017 09:38
no. i mean lets assume that player1 is taking randomly a value from the array (either X or O) and i want the player2 to take the other one so if player1 = X; then player2=O;
Ty Tia
@TyTia77
May 20 2017 09:40
player2 = player1 === 'X' ? 'O' : 'X';
is easier i think
theres no reason to have an array just for 2 symbols
aurelienmigeot
@aurelienmigeot
May 20 2017 09:42
@JohnnyBizzel Assignment with a Returned Value
Mahmudul Hasan
@mahmudulhasanjhoony
May 20 2017 09:46
Hi, why it doesn't return the else statement when else condition becomes true ?
image.png
Stratos Iordanidis
@iamstratos
May 20 2017 09:48
@mahmudulhasanjhoony this is not correct, check your if. Try to read the explanation on the left one more time
aurelienmigeot
@aurelienmigeot
May 20 2017 09:53
i managed to do it thank you @JohnnyBizzel
CamperBot
@camperbot
May 20 2017 09:53
aurelienmigeot sends brownie points to @johnnybizzel :sparkles: :thumbsup: :sparkles:
:star2: 1691 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
Stratos Iordanidis
@iamstratos
May 20 2017 09:55
@mahmudulhasanjhoony you got it?
Mahmudul Hasan
@mahmudulhasanjhoony
May 20 2017 10:01
still not.. i m trying
René
@RenevandenHeuvel
May 20 2017 10:02
Hi all, does anyone know the answer to challenge 115?

This is my code:
a = 7;
b = a;

Then I get the answer that b should have a value of 7?

Spyrantis Theodoros
@thodorisanta
May 20 2017 10:09
why do i get an error here?
HUMAN = "X";
COMP = HUMAN == "X" ? "O" : "X";
h1tag
@h1tag
May 20 2017 10:10
@RenevandenHeuvel whats the challenge name?
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 10:11
@thodorisanta What error did you get?
I didn’t get any.
Spyrantis Theodoros
@thodorisanta
May 20 2017 10:14
@ivancsicsmarkus i dont actually get any error but when i try to check COMP's value in the console nothing apears
h1tag
@h1tag
May 20 2017 10:16
@RenevandenHeuvel this part of the solution is right. Make sure you haven't altered anything else. Try reloading the page.
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 10:17
@thodorisanta
Képernyőfotó 2017-05-20 - 12.17.19.png
Spyrantis Theodoros
@thodorisanta
May 20 2017 10:18
:/
i guess codepens fault
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 10:18
@thodorisanta Yes, I think.
@thodorisanta Don’t forget to use var when defining a new variable.
Spyrantis Theodoros
@thodorisanta
May 20 2017 10:19
@ivancsicsmarkus i declared it out of scope
Markus Ivancsics
@ivancsicsmarkus
May 20 2017 10:19
@thodorisanta Okey.
Muhammad Hussain
@ReactorboY
May 20 2017 10:20
help needed in js card counting
Johnny
@JohnnyBizzel
May 20 2017 10:23
@ReactorboY What help
Muhammad Hussain
@ReactorboY
May 20 2017 10:24

var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:  
      count++;
      break;
    case 7:
    case 8:
    case 9:
      count;
      break;

  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
@JohnnyBizzel case 9 count showing error
Keon Samuel
@keonsam
May 20 2017 10:29
what is the website you guys use to get templetes?
Pieter Stokkink
@forkerino
May 20 2017 10:32
Hello boys n girls!
Stratos Iordanidis
@iamstratos
May 20 2017 10:34
@forkerino hii!
Pieter Stokkink
@forkerino
May 20 2017 10:34
@keonsam what kind of templates
?
Stratos Iordanidis
@iamstratos
May 20 2017 10:35
@ReactorboY what do you want the case 9 to do?
Keon Samuel
@keonsam
May 20 2017 10:37
portfolio design .
@forkerino
alpox
@alpox
May 20 2017 10:38
@keonsam i usually dont use any template :D
Pieter Stokkink
@forkerino
May 20 2017 10:38
@keonsam seems like a good opportunity to build something yourself, I think. I don't really use templates unless someone asks me to build a wordpress site.
Pedro Almeida
@pmqa
May 20 2017 10:41
http://jsbin.com/ is really great for developing algorithms and just doodling, anybody else using it often?
Pieter Stokkink
@forkerino
May 20 2017 10:52
@pmqa Not often, I usually use my own computer to these things, although it requires a little more setup.
for simple testing of algo's I use repl.it or pythontutor.com
Pedro Almeida
@pmqa
May 20 2017 11:02
yeah, it does require more setup
but then you’ll never loose anything…. hopefully
Abubakar Sambo
@sastech
May 20 2017 11:03
@ReactorboY i had a bit of a headache before i got through that point myself
@ReactorboY your count there should be += 0. & after all the code at the end, you should have it "return count"
Folkert
@folkert89
May 20 2017 11:08
Hi all, what do i miss here?

Instructions
Assign the value 7 to variable a.

Assign the contents of a to variable b.

// Setup
var a;
var b = 2;

// Only change code below this line
var a = 7;
var b = 7;

Johnny
@JohnnyBizzel
May 20 2017 11:09
@ReactorboY I believe you should count -- in that case.
Stratos Iordanidis
@iamstratos
May 20 2017 11:10
@folkert89 value on a and b are not the same at the moment. also, you dont have to use var again
Folkert
@folkert89
May 20 2017 11:12
thanks stratos, what would you code here?
Stratos Iordanidis
@iamstratos
May 20 2017 11:13
@folkert89 it's on the instructions :P "Assign the contents of a to variable b." -> "Assign ... a to b."
Folkert
@folkert89
May 20 2017 11:14
haha b = a; it works
thanks!
Stratos Iordanidis
@iamstratos
May 20 2017 11:14
@folkert89 ;)
ViralEntity
@ViralEntity
May 20 2017 11:17
ok, I must be really tired and am missing something so simple - why would this return arr.split is not a function?
function mutation(arr) { return arr.split(","); }
DutchGester
@DutchGester
May 20 2017 11:20

i dont understand these assignments

convertToF(0) should return a number
convertToF(-30) should return a value of -22

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

// Only change code above this line
return fahrenheit;

}

// Change the inputs below to test your code
convertToF(30);

Stephen James
@sjames1958gm
May 20 2017 11:21
@ViralEntity split is a string function
ViralEntity
@ViralEntity
May 20 2017 11:21
awww damn I know that.. thanks @sjames1958gm
CamperBot
@camperbot
May 20 2017 11:21
viralentity sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7392 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
May 20 2017 11:21
@DutchGester write one line of code between the comment lines, using the algorithm in the instructions
Those are the results of calling your function with different values
Stephen James
@sjames1958gm
May 20 2017 11:22
@DutchGester
when convertToF(-30) then inside the function the parameter/variable celsius is assigned the value of -30
you should use the celsius variable and the conversion formula to set the provided local variable
Diego Mayer
@Chrono79
May 20 2017 11:22
:wave: @all
DutchGester
@DutchGester
May 20 2017 11:23
like 9/5 + 32 ? @Chrono79
Diego Mayer
@Chrono79
May 20 2017 11:23
@DutchGester you have to use the var fahrenheit and the function parameter celsius too, like @sjames1958gm told you
9/5 +32 is always the same number, and your function returns fahrenheit, so you should set its value before that happens
DutchGester
@DutchGester
May 20 2017 11:24
oooh so instead of (celsius) in function i need to put these number
Diego Mayer
@Chrono79
May 20 2017 11:25
@DutchGester no, you need to write between the comments and you should write celsius there too
Stephen James
@sjames1958gm
May 20 2017 11:25
@DutchGester F = C * 9/5 + 32 - where F and C are replaced by variables in the function
DutchGester
@DutchGester
May 20 2017 11:27
I am really stupid with Javascript, i think this is too hard for beginners
I did
Fahrenheit = Celsius * 9/5 + 32;
below the var fahrenheit between the lines
Diego Mayer
@Chrono79
May 20 2017 11:27
@DutchGester capitalization matters, fahrenheit and Fahrenheit aren't the same var (the same for celsius)
DutchGester
@DutchGester
May 20 2017 11:29
ooh damn, thanks you very much @Chrono79 and @sjames1958gm
CamperBot
@camperbot
May 20 2017 11:29
dutchgester sends brownie points to @chrono79 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4048 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 7393 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Chris Juchtmans
@kjuchtmans
May 20 2017 11:29
Afternoon all :wave:
Diego Mayer
@Chrono79
May 20 2017 11:29
:+1:
Wes
@wesneubeck
May 20 2017 11:32
@DutchGester It is too stupid for beginners, thats why you have to keep doing it. you won't be a beginner of stupid in short time
Stephen James
@sjames1958gm
May 20 2017 11:33
@kjuchtmans :wave:
@DutchGester :+1:
Eric K
@EricK425
May 20 2017 11:34
There is a bug on Make INstances of OBjects with a Cnstructor function
``

``

var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};

// Only change code below this line.
var myCar = new Car();
myCar.whatever = "this";
``

Skander Chouba
@Skanderrr
May 20 2017 11:34
hello
i'm on random quote machine challenge
i have a problem with the button that changes the quote
any help?
Chris Juchtmans
@kjuchtmans
May 20 2017 11:35

re "Random Code Generator" I binned yesterday's code and started all over again.

Question: why is below JS code not showing the data on mouse-click?
If I interpret Chrome's console correctly, it does receive the JSON data and adds this to html content.

Only, nothing displays on click.

JS Code :

  var xhr = new XMLHttpRequest();

  xhr.onload = function() {
    if(xhr.status === 200) {
      responseObject = JSON.parse(xhr.responseText);

      var newContent = '';
      for (var i = 0; i < responseObject.quotes.length; i++) {
        newContent += '<div class = "quote">';
        newContent += responseObject.quotes[i].quote + '<br>';
        newContent += '<p>' + responseObject.quotes[i].author + '</p>';
        newContent += '</div>';
      }
      document.getElementById('message').innerHTML = newContent;
    }
  };

xhr.open('GET', 'http://codepen.io/chrisjuchtmans/pen/OmoaRY.js');
xhr.send(null);

my pen is here: (http://codepen.io/chrisjuchtmans/pen/EWRKaB)
my JSON file is here: (http://codepen.io/chrisjuchtmans/pen/OmoaRY.js)

anyone?
I'm trying not to let Quote Generator occupy my mind day and night, but it..
cheers!

Skander Chouba
@Skanderrr
May 20 2017 11:35
image.png
Stephen James
@sjames1958gm
May 20 2017 11:35
@EricK425 Was the challenge to add a nickname to the object?
@kjuchtmans Why do you have a full HTML page in the html editor?
Eric K
@EricK425
May 20 2017 11:39
@sjames1958gm yes to add a nickname thats a string
Stephen James
@sjames1958gm
May 20 2017 11:39
@EricK425 so you need to add a property nickname - not a property whatever
Chris Juchtmans
@kjuchtmans
May 20 2017 11:40
@sjames1958gm because I couldnt understand the JQuery getJSON approach. And until I do, I thought I try it differently
Eric K
@EricK425
May 20 2017 11:40
@sjames1958gm oh wow..
@sjames1958gm thanks. I need to go to bed and not overlook something so stupid
CamperBot
@camperbot
May 20 2017 11:42
erick425 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7394 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 20 2017 11:42
@kjuchtmans It shows a number of errors in the console, some of which because you have link and script tags
in the HTML editor
But. you also have errors:
Uncaught ReferenceError: responseText is not defined
Uncaught TypeError: Cannot set property 'innerHTML' of null at XMLHttpRequest.xhr.onload
Chris Juchtmans
@kjuchtmans
May 20 2017 11:42
maybe i break this problem down, console error by console error :
  1. my JSON file shows a syntax error at {"quotes": [, says console, the : is wrong here?
Ajith
@ajithvallabai
May 20 2017 11:42
guys i need one help .how to implement output encoding to prevent XSS for sites like personal portfolio ? could any one help me
Stephen James
@sjames1958gm
May 20 2017 11:44
Ajith
@ajithvallabai
May 20 2017 11:45
@sjames1958gm i too read it but should i implement all those rules?
my website contains hyperlinks .it doesnt get any input from user
Stephen James
@sjames1958gm
May 20 2017 11:46
@ajithvallabai The you are probably ok. XSS is really about untrusted data, but if you have no input from the user.
@kjuchtmans Are you using xhr to get the quotes? Or are you including the quotes via script tag?
Chris Juchtmans
@kjuchtmans
May 20 2017 11:48

@kjuchtmans It shows a number of errors in the console, some of which because you have link and script tags
in the HTML editor

should I start over with a barebone HTML file, and try to display my JSON data first? the worry about layout later?

@sjames1958gm I'm trying to use xhr
Ajith
@ajithvallabai
May 20 2017 11:48
Could they access anything through url? @sjames1958gm
Stephen James
@sjames1958gm
May 20 2017 11:48
@kjuchtmans Then remove the json file from the settings inclusion
Chris Juchtmans
@kjuchtmans
May 20 2017 11:48
okay
Stephen James
@sjames1958gm
May 20 2017 11:49
@ajithvallabai If it is a static site, then no?
@kjuchtmans You are including the js file - but it is a just a raw object - which the js parser is not expecting.
Ajith
@ajithvallabai
May 20 2017 11:51
@sjames1958gm i have one doubt if www.example.com is the only page i have , when i type www.example.com/<script>prompt(ndjnd)</script> i am getting "page cannot be displayed" how to prevent this from occuring is it related to XSS
Muhammad Hasham
@MohammadHasham
May 20 2017 11:52
@sjames1958gm can you help me with setState method in react
Stephen James
@sjames1958gm
May 20 2017 11:53
@ajithvallabai The server side would have to handle that. Not sure tags are allowed in URLs regardless
@MohammadHasham I can try
CaptainBoy
@CaptainBoy
May 20 2017 11:53

why am I getting cannot read property of 'length' of undefined : function findLongestWord(str) {
stringLength = 1;
array= str.split(' ');

for(i=0; i<=array.length; i ++){
  arrayStringLength = array[i].length;
  if(stringLength<arrayStringLength){
    stringLength = arrayStringLength;
  }else{}
}

return stringLength;
}

Muhammad Hasham
@MohammadHasham
May 20 2017 11:54
http://codepen.io/Mohammad_Hasham/pen/ybNVzO?editors=0010
Can you tell me that why is the setState method not storing the new values?
@sjames1958gm
Ajith
@ajithvallabai
May 20 2017 11:54
@sjames1958gm thank you
CamperBot
@camperbot
May 20 2017 11:54
ajithvallabai sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7395 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 20 2017 11:54
@CaptainBoy array[array.length] is undefined i<=array.length
CaptainBoy
@CaptainBoy
May 20 2017 11:55
I cannot go array.length ?
Stephen James
@sjames1958gm
May 20 2017 11:56
@MohammadHasham Where are you seeing that the state is not updated?
@CaptainBoy no i < array.length
the indexes are from 0 to array.length - 1
CaptainBoy
@CaptainBoy
May 20 2017 11:56
oh i see
Muhammad Hasham
@MohammadHasham
May 20 2017 11:56
@sjames1958gm i am doing console.log(this.state.userContent) and it shows me message:"" which should have been the input's value
Stephen James
@sjames1958gm
May 20 2017 11:58
@MohammadHasham I put that console.log at the top of render() and it shows it is updated
@MohammadHasham If you put it in the submit() handler then this.state is not updated until that function exits
this.state is not updated immediately on this.setState
Muhammad Hasham
@MohammadHasham
May 20 2017 12:00
i see.
@sjames1958gm Thanks!.Now working.
CamperBot
@camperbot
May 20 2017 12:00
mohammadhasham sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7396 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Muhammad Hasham
@MohammadHasham
May 20 2017 12:00
:+1:
Stephen James
@sjames1958gm
May 20 2017 12:01
@MohammadHasham :+1:
Alesandra
@petraboot
May 20 2017 12:08
Please help me with seek&destroy. I have t filter array in the brackets so it doesn't show arguments (after brackets).
function destroyer(arr) {
  // Remove all the values

var seek = [].slice.call(arr);

  seek.filter( function lookFor(i){
  for (i=1; i < destroyer.length; i++) {
    return arr[i];}  
  }
   );

}
destroyer(["tree", "hamburger", 53], "tree", 53);
Diego Mayer
@Chrono79
May 20 2017 12:11
@petraboot you need to use arguments object
destroyer is your function name
DutchGester
@DutchGester
May 20 2017 12:12

i dont understand this one

var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";

Remove all the backslashes ()
You should have two single quotes ' and four double quotes "

Diego Mayer
@Chrono79
May 20 2017 12:13
@DutchGester do the first step, then change 2 double quotes (think which ones) to single quotes
DutchGester
@DutchGester
May 20 2017 12:13
the first step doesnt work when i delete all the ()
()
( \ )
i remove all the ( \ ) and nothing happens
Diego Mayer
@Chrono79
May 20 2017 12:14
@DutchGester you have to do both for it to work
DutchGester
@DutchGester
May 20 2017 12:14
so i need to replace the ( " ) with ( ' ) ?
Diego Mayer
@Chrono79
May 20 2017 12:14
why are the double quotes escaped in the first place?
DutchGester
@DutchGester
May 20 2017 12:15
uhm
so u can see the sentence with double quotes in a sentence
Diego Mayer
@Chrono79
May 20 2017 12:18
Then which 2 you need to replace qith sibgle quotes when you remove the backslashes?
tpondant
@tpondant
May 20 2017 12:18
Hello everyone
I have trouble finishing one user-story in javascript calculator challenge
everything's working so far, but I don't know how to chain multiple operations
DutchGester
@DutchGester
May 20 2017 12:19
before the htpp: and i dont know @Chrono79
i have now
var myStr = "<a href='http://www.example.com' target=\"_blank\">Link</a>";
but it doenst work
i hate javascript but i need to learn this crap!
Andy
@ajosb
May 20 2017 12:23
You need to replace the double quotes that surround the String with single quotes
Victor Popescu
@VicPopescu
May 20 2017 12:24
@DutchGester string into a string is "this is a string with 'another string inside' and " + a variable + " too"
DutchGester
@DutchGester
May 20 2017 12:24
Yeah i got it thankyou i still dont understand why i need to learn this but yeah
Victor Popescu
@VicPopescu
May 20 2017 12:25
@DutchGester what do you mean?
DutchGester
@DutchGester
May 20 2017 12:25
i just know its very usefull to use javascript but it will take a long time before i can write it in code in my head
yeah it is difficult to follow all of this as a beginner in javscript
html css is fun, but this i dont know
Victor Popescu
@VicPopescu
May 20 2017 12:26
@DutchGester this is a very basic concept
DutchGester
@DutchGester
May 20 2017 12:26
i did something with jquery and i think jquery is so much easier
Pieter Stokkink
@forkerino
May 20 2017 12:27
@DutchGester you don't need to write it in your head, you need to write it on a computer. :P
DutchGester
@DutchGester
May 20 2017 12:27
hahaha
you know what i mean
:smile:
Victor Popescu
@VicPopescu
May 20 2017 12:27
@DutchGester jQuery is Javascript, it's like you learn only to drive one car and if you will get another car you need to learn again
@DutchGester lean Javascript, not jQuery
DutchGester
@DutchGester
May 20 2017 12:28
Oke yeah i will do my best to go through javascript
Victor Popescu
@VicPopescu
May 20 2017 12:29
@DutchGester good luck
Abhishek Tiwari
@fillopfy
May 20 2017 12:29
function titleCase(str) {
  var arr=[];
  var string=[];
  var strr=" ";
  arr=str.split(" ");

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


        newArr[i]=arr.split("");
        newArr[i][0].toUpperCase();

      string=newArr[i].join("");

    }

  strr=string.join(" ");
  return strr;

}

titleCase("I'm a little tea pot");
DutchGester
@DutchGester
May 20 2017 12:29
for now i am gonna take a break and eat something, thanks for the answer guy's @VicPopescu @forkerino @Chrono79
CamperBot
@camperbot
May 20 2017 12:29
dutchgester sends brownie points to @vicpopescu and @forkerino and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 2311 | @forkerino |http://www.freecodecamp.com/forkerino
:cookie: 423 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
:star2: 4049 | @chrono79 |http://www.freecodecamp.com/chrono79
Dustin Reimold
@DustGuppy
May 20 2017 12:29
does anyone know a relatively efficient way to check if a factor is prime in JS?
Abhishek Tiwari
@fillopfy
May 20 2017 12:29
can anyone help
Dustin Reimold
@DustGuppy
May 20 2017 12:30
I know there are advanced things but I'm looking for a fairly simple and not completely slow way to check if a number is prime
I could use a for loop and check to see if division by my iterator == 0 by checking it and every number inbetween but that's super inefficient
@fillopfy what is wrong with your code? don't know? no error message?
Abhishek Tiwari
@fillopfy
May 20 2017 12:34
@DustGuppy it says :string.join is not a function
Ty Tia
@TyTia77
May 20 2017 12:35
@fillopfy u should change the str to all lower or uppercase first
Abhishek Tiwari
@fillopfy
May 20 2017 12:36
@TyTia77 but I have to change the first letter to uppercase only
Ty Tia
@TyTia77
May 20 2017 12:37