These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Aug 2016
llamatarianism
@llamatarianism
Aug 15 2016 00:00
you can sorta read it like english
This is a description of sayHiToGrandma:
  it returns "I can't hear you" if string is lowercase:
    I expect sayHiToGrandma("hello") to equal "I can't hear you!"
  # etc
Ana Benedict
@anabenedict
Aug 15 2016 00:02
@llamatarianism Okay, Im going to write it like in English.. :smile:
ahmed abouhay
@abohay
Aug 15 2016 00:04
function chunkArrayInGroups(arr, size) {
    var newarr =[];
    var slicer=[];
    for ( var i = 0 ;i <= arr.length ;i+size  ){
      slicer = arr.slice(i,i+size);
      newarr.push(slicer);
    }
    return arr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
any one could help @anabenedict @llamatarianism @sjames1958gm
llamatarianism
@llamatarianism
Aug 15 2016 00:05
return arr
Stephen James
@sjames1958gm
Aug 15 2016 00:05
@anabenedict You are supposed to write one function sayHiToGrandma that takes a string and passes the conditions
llamatarianism
@llamatarianism
Aug 15 2016 00:05
you're not doing anything to arr
why would you return arr if you don't do anything to it
Solomon B
@ssbothwell
Aug 15 2016 00:06
i'm looping through a bunch of json objects using getson and a for loop (for the twitch.tv exercise) and appending bits of their data into a global array and then checking the global array in the console and none of the json data has been pushed to the array. i think console.log is executing before the code is finished looping through the json data. how do i make it so my program doesn't continue until the for loop has finished executing?
greg
@wearenotgroot
Aug 15 2016 00:07
@ssbothwell read about asynchronous function
ahmed abouhay
@abohay
Aug 15 2016 00:07
@llamatarianism i have fixed it
Stephen James
@sjames1958gm
Aug 15 2016 00:08
@ssbothwell You could count the requests and the responses
ahmed abouhay
@abohay
Aug 15 2016 00:08
function chunkArrayInGroups(arr, size) {
    var newarr =[];
    var slicer=[];
    for ( var i = 0 ;i <= arr.length ;i+size  ){
      slicer = arr.slice(i,i+size);
      newarr.push(slicer);
    }
    return newarr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
@llamatarianism
@sjames1958gm
llamatarianism
@llamatarianism
Aug 15 2016 00:08
i + size
you're not actually changing i
Stephen James
@sjames1958gm
Aug 15 2016 00:09
@abohay i += size?
Solomon B
@ssbothwell
Aug 15 2016 00:09
@wearenotgroot does this have to do with callbacks?
Stephen James
@sjames1958gm
Aug 15 2016 00:09
@abohay This should be a infinite loop
ahmed abouhay
@abohay
Aug 15 2016 00:09
@sjames1958gm thanks :D
CamperBot
@camperbot
Aug 15 2016 00:09
abohay sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2607 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
greg
@wearenotgroot
Aug 15 2016 00:10
@ssbothwell link you pen or fiddle so we can see what's up
just check the js code. the html is just a static mockup
ahmed abouhay
@abohay
Aug 15 2016 00:13
@sjames1958gm how can i check my code before asking people
Ana Benedict
@anabenedict
Aug 15 2016 00:15
@sjames1958gm thank you again. I keep failling.. i just dont know, simple. : (
@llamatarianism thank you : )
CamperBot
@camperbot
Aug 15 2016 00:15
anabenedict sends brownie points to @sjames1958gm and @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1184 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
:star2: 2608 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
llamatarianism
@llamatarianism
Aug 15 2016 00:15
@ssbothwell yeah, the log is definitely executing before anything gets pushed into the array
Solomon B
@ssbothwell
Aug 15 2016 00:16
yeah, i'm reading http://callbackhell.com/ right now.
llamatarianism
@llamatarianism
Aug 15 2016 00:17
this would be easy enough if it was just one thing
since it's a loop, it's kinda hard
Mostafa Syam
@pro-mos
Aug 15 2016 00:18
guys i'm stuck at smallest common multiple, i pass only 3 tests, tests for [1,13] and more gives infinite loop @_@
llamatarianism
@llamatarianism
Aug 15 2016 00:20
try thinking laterally @ssbothwell
do you actually need to push all that stuff into an array before doing stuff to it?
can't you just do stuff with the data as you receive it?
Solomon B
@ssbothwell
Aug 15 2016 00:21
@llamatarianism is this a weird way to be doing this exercise? my idea was to loop through all the json objects and pull the data i wanted and then insert it all into html
llamatarianism
@llamatarianism
Aug 15 2016 00:21
that's how I did it
it's not really a weird way
Solomon B
@ssbothwell
Aug 15 2016 00:21
yeah thats what i'm realizing
llamatarianism
@llamatarianism
Aug 15 2016 00:21
but it's not a way that fits into the way JS works
Solomon B
@ssbothwell
Aug 15 2016 00:21
i see
well i definitely wanna do things 'the js way' so to speak
llamatarianism
@llamatarianism
Aug 15 2016 00:22
well you're essentially forced to
you can't mix sync and async code in JS
Solomon B
@ssbothwell
Aug 15 2016 00:22
haha
right
llamatarianism
@llamatarianism
Aug 15 2016 00:22
a for loop is synchronous, $.getJSON is async
in order to do only do something when a for loop completes, you'd need a way to mix the two
Solomon B
@ssbothwell
Aug 15 2016 00:23
that makes sense
okay i'll just insert the data into my html template during the loop rather then after
Mostafa Syam
@pro-mos
Aug 15 2016 00:24
function smallestCommons(arr) {
  arr.sort((a,b) => b - a);    // sort array from greatest to smallest.
  var arr2 = [],
      i = arr[0],
      scm, hits = 0;

  // fill arr2 with numbers in range
  while (i >= arr[1]) {        // i missed while loops and decided to use it.
    arr2.push(i);
    i--;
  }
  // scm start from 2 and keep going until hits equalls the length of arr2
  for (scm = 2; ; scm++) {
    // test if scm is dividable by every number in arr2
    for (var j = 0; j < arr2.length; j++) {
      if (scm % arr2[j] === 0) {
        hits += 1;
      }
    }

    if (hits === arr2.length) {
      break;
    } else {
      hits = 0;
    }
  }
  return scm;
}
// cant calculate numbers more than 7 or sometimes 8.
smallestCommons([1,12]);
smallest common multiple , it throws an infinite loop for the last two tests for some reason.
Enrique Alejandro Arzamendi Picazzo
@AleCx4
Aug 15 2016 00:34
Guys
I have no clue where to start qith the Random Quote generator
like
none
Moisés Man
@moigithub
Aug 15 2016 00:37
@pro-mos on that code.. whats the value of i ??
and whats value of arr[1] ??
cuz while (i >= arr[1]) { doesnt seems correct
jamesmillerho
@jamesmillerho
Aug 15 2016 00:37
figured out the other version of permutation
function permutation(str){
    var result = [];
    if (str.length === 1){return str;}
    for (var i=0; i<str.length; i++){
      var first = str[i];
      var other = str.substr(0,i)+str.substr(i+1);
      var temp = permutation(other);
      for (var j=0; j<temp.length; j++){
        result.push(first+temp[j]);
      }
    }
    return result;
  }

  return permutation('abc')
VS
function permutation(str){
    var result = [];
    if (str.length === 1){return str;}
    var temp = permutation(str.substr(1));
    for (var i=0; i<temp.length; i++){
      for (var j=0; j<=temp[i].length; j++){
        result.push(temp[i].substr(0,j)+str[0]+temp[i].substr(j));  
      }
    }
    return result;
  }

  return permutation('abc');
Stephen James
@sjames1958gm
Aug 15 2016 00:42
@pro-mos Possibly start with the largest number and count by the largest number to reduce the number of cycles?
Mostafa Syam
@pro-mos
Aug 15 2016 00:43
@moigithub i = arr[0] ( the biggest number in rage) and arr[1] is the smallest and lasst number in range
Stephen James
@sjames1958gm
Aug 15 2016 00:44
@AleCx4 Maybe start with an array of quotes and how to get them onto the screen with javascript / jquery.
Moisés Man
@moigithub
Aug 15 2016 00:45
@pro-mos soo on this case... smallestCommons([1,12]);
whats i ?? 1 or 12 ?
Enrique Alejandro Arzamendi Picazzo
@AleCx4
Aug 15 2016 00:45
@sjames1958gm That is the easy way :( I actually want to understand how to use API's in Js
Mostafa Syam
@pro-mos
Aug 15 2016 00:45
@moigithub i is 12
Ken Haduch
@khaduch
Aug 15 2016 00:45
@jen-n-taylor - just came back to the computer - you're welcome. I have seen that "undefined" vs. undefined being a problem in the past, not sure if that's what you did, but it is not uncommon for that little slip to happen.
Stephen James
@sjames1958gm
Aug 15 2016 00:46
@AleCx4 If you have done the section on ajax and getJSON, start with simply getting a getJSON response to dump into a HTML element.
@pro-mos You can even start your search with the product of the two largest numbers and increment by that (really cuts down on cycles).
This is due to the fact that the Smallest Common Multiple of two consecutive positive integers is their product
Mostafa Syam
@pro-mos
Aug 15 2016 00:48
@sjames1958gm will try
jamesmillerho
@jamesmillerho
Aug 15 2016 00:49
so the 2nd method runs 120% faster
1st method : 700-800ms
2nd method: 300-350ms.
andersholen94
@andersholen94
Aug 15 2016 00:49
how do I put screenschots in the chat ?
WhisperingTide
@WhisperingTide
Aug 15 2016 00:49

How do I get string.slice() to return the first part of the string?

So if I have var string = "Words or something."

How do I get it to return "Words" instead of "or something." ?

jamesmillerho
@jamesmillerho
Aug 15 2016 00:49
permutation of string length 9
Stephen James
@sjames1958gm
Aug 15 2016 00:50
@WhisperingTide MDN should be able to answer that, slice(0, 1) is the first character
@andersholen94 :point_down:
help format
CamperBot
@camperbot
Aug 15 2016 00:50

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick() at _start_ and _end_ around thecode`.

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

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

Mostafa Syam
@pro-mos
Aug 15 2016 00:51
@sjames1958gm i did that and it works faster i guess, but still the last two tests throw infinite loop, this i believe is a bug or something, because i tested my code on codepen and it works but really really slow
WhisperingTide
@WhisperingTide
Aug 15 2016 00:51
@sjames1958gm
Hmmm, okay, I'll give it another try, for some reason it seems to be returning only the right-hand side of the string.
Yeyo Selso Poche
@Naxell
Aug 15 2016 00:51
someone can explan me Golf Code....
Diego Mayer
@Chrono79
Aug 15 2016 00:53

@Naxell you have to use if/else several times and use the table data

Strokes    Return
1    "Hole-in-one!"
<= par - 2    "Eagle"
par - 1    "Birdie"
par    "Par"
par + 1    "Bogey"
par + 2    "Double Bogey"
>= par + 3    "Go Home!"

When it's not specified use ==, evaluate strokes

Stephen James
@sjames1958gm
Aug 15 2016 00:54
@pro-mos for (scm = arr2[0] * arr2[1]; ; scm += arr2[0] * arr2[1]) { You did this?
you can also start you j for loop at 2 because every number is already checkd for arr2[0] and arr2[1]
These are just small fixes to reduce the number of executions
jamesmillerho
@jamesmillerho
Aug 15 2016 00:54
but it's obvious as the 2nd version is more straightforward: c-> bc,cb, abc,bac,bca
Yeyo Selso Poche
@Naxell
Aug 15 2016 00:54
@Chrono79 ok but i need to assign some value to par and strokes
Diego Mayer
@Chrono79
Aug 15 2016 00:55
@Naxell no, it comes from your function call
golfScore(5, 4);
there par is 5 and strokes is 4
function golfScore(par, strokes) {
Stephen James
@sjames1958gm
Aug 15 2016 00:55
@Naxell No, those are passed into the function through the function parameters.
andersholen94
@andersholen94
Aug 15 2016 00:55
This message was deleted
CamperBot
@camperbot
Aug 15 2016 00:55
:bulb: to format code use backticks! ``` more info
jamesmillerho
@jamesmillerho
Aug 15 2016 00:55
1st version loops more: c->bc , b->cb ==> bc,cb ==> abc,acb /// a->ac, c->ca, etc
Stephen James
@sjames1958gm
Aug 15 2016 00:56
@andersholen94 You return will exit the function on the first loop - need to put that some where with all the other words
and combine for the answer
Yeyo Selso Poche
@Naxell
Aug 15 2016 00:56
@Chrono79 ok...
Mostafa Syam
@pro-mos
Aug 15 2016 00:58
@sjames1958gm that worked like a charm, give me a minute to understand your line of code :D
AFK3000
@AFK3000
Aug 15 2016 01:01
hello
i need help with this exercise
// 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 = 1;

Instructions

Create a variable called myData and set it to equal the first value of myArray using bracket notation.

Diego Mayer
@Chrono79
Aug 15 2016 01:02
@AFK3000 you have to do the same as the example
Use bracket notation to access the value 1 of myArray
AFK3000
@AFK3000
Aug 15 2016 01:02
@Chrono79 ok ill give it a shot
Mostafa Syam
@pro-mos
Aug 15 2016 01:03
@sjames1958gm why you incerment scm += arr2[0] * arr2[1] ? what if the lcm is something other than that
harpreetwasan
@harpreetwasan
Aug 15 2016 01:03
hello guys im stuck with this
error

function myLocalScope() {
'use strict';

myVar = "TRUMP";
console.log(myVar);

}
myLocalScope();

andersholen94
@andersholen94
Aug 15 2016 01:04
@sjames1958gm I just can't seem to find a way to combine them
harpreetwasan
@harpreetwasan
Aug 15 2016 01:04
myVar not defined
Mostafa Syam
@pro-mos
Aug 15 2016 01:04
@harpreetwasan my var seems global not local
harpreetwasan
@harpreetwasan
Aug 15 2016 01:04
any ideas
Diego Mayer
@Chrono79
Aug 15 2016 01:04
write var before myVar @harpreetwasan
Mostafa Syam
@pro-mos
Aug 15 2016 01:04
thx again @sjames1958gm
CamperBot
@camperbot
Aug 15 2016 01:04
pro-mos sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2609 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
harpreetwasan
@harpreetwasan
Aug 15 2016 01:05
@Chrono79 @pro-mos thank you so much
CamperBot
@camperbot
Aug 15 2016 01:05
harpreetwasan sends brownie points to @chrono79 and @pro-mos :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @pro-mos |http://www.freecodecamp.com/pro-mos
:star2: 1820 | @chrono79 |http://www.freecodecamp.com/chrono79
Stephen James
@sjames1958gm
Aug 15 2016 01:10
@pro-mos :+1:
AFK3000
@AFK3000
Aug 15 2016 01:11
// 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 myArray = [1,2,3];
var myData = ourArray[0]; // equals 1
Create a variable called myData and set it to equal the first value of myArray using bracket notation.
The variable myData should equal the first value of myArray.
The data in variable myArray should be accessed using bracket notation.
i cant pass the second one
Vikrant Singh
@VikrantSingh13
Aug 15 2016 01:12
@AFK3000
```
myData = myArray[0];
@AFK3000
myData = myArray[0];
AFK3000
@AFK3000
Aug 15 2016 01:13
@VikrantSingh13 cool thx
CamperBot
@camperbot
Aug 15 2016 01:13
afk3000 sends brownie points to @vikrantsingh13 :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @vikrantsingh13 |http://www.freecodecamp.com/vikrantsingh13
Stephen James
@sjames1958gm
Aug 15 2016 01:14
@anabenedict Did you make it any further with grandma?
andersholen94
@andersholen94
Aug 15 2016 01:28
function titleCase(str) {

  var strSplit = str.toLowerCase().split([" "]);
  var string = "";

  for(i = 0; i < strSplit.length; i++){
    var stringWord =  strSplit[i].charAt(0).toUpperCase() + strSplit[i].slice(1) + " ";

    string += stringWord;
  }
  return string;
}
titleCase("I'm a little tea pot")
this code works, but it won't complete the challenge, why ?
Vikrant Singh
@VikrantSingh13
Aug 15 2016 01:29
@andersholen94 name of the challenge?
Diego Mayer
@Chrono79
Aug 15 2016 01:29
@andersholen94 you're adding a space at the end, don't do that at the last word or either use array and join
andersholen94
@andersholen94
Aug 15 2016 01:30
@VikrantSingh13 Title Case a Sentence
@Chrono79 how do I stop the space at the end then ?
Diego Mayer
@Chrono79
Aug 15 2016 01:31
with an if, or use trim() @andersholen94
Vikrant Singh
@VikrantSingh13
Aug 15 2016 01:31
@andersholen94 use return string.trim(' ');
andersholen94
@andersholen94
Aug 15 2016 01:32
@VikrantSingh13 thank you it worked :)
CamperBot
@camperbot
Aug 15 2016 01:32
andersholen94 sends brownie points to @vikrantsingh13 :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @vikrantsingh13 |http://www.freecodecamp.com/vikrantsingh13
Diego Mayer
@Chrono79
Aug 15 2016 01:33
@VikrantSingh13 @andersholen94 trim doesn't need an argument
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim
andersholen94
@andersholen94
Aug 15 2016 01:33
@Chrono79 thank you :)
CamperBot
@camperbot
Aug 15 2016 01:33
andersholen94 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1821 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 15 2016 01:33
:+1:
Vikrant Singh
@VikrantSingh13
Aug 15 2016 01:34
@Chrono79 it's not like chomp from ruby or strip from python?
Diego Mayer
@Chrono79
Aug 15 2016 01:35
@VikrantSingh13 it only remove spaces, so I think it's not
Vikrant Singh
@VikrantSingh13
Aug 15 2016 01:35
@Chrono79 oh okay thanks!
CamperBot
@camperbot
Aug 15 2016 01:35
vikrantsingh13 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1822 | @chrono79 |http://www.freecodecamp.com/chrono79
Gregory Bilecki
@gbilecki
Aug 15 2016 01:36
can any of you beautiful people help with seek and destroy PL0x?
I m almost done, but I have a small question
Yo tengo una pregunta.
Diego Mayer
@Chrono79
Aug 15 2016 01:37
@gbilecki ask away
Gregory Bilecki
@gbilecki
Aug 15 2016 01:38
ok @Chrono79 ...
heres my code

function destroyer(arr) {

var args = arr.slice.call(arguments, 1);
var newArr = arr.filter(function filt(val) {  


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

if (val === args[i]) {   
      return false;
} else {
      return true;
}
}              
});
return newArr;
}
it works, BUT only removes the first argument
that it finds in the array
and returns the Array, without that element
Diego Mayer
@Chrono79
Aug 15 2016 01:39
@gbilecki generally inside a loop you don't want to return in both if branches, it exits the loop, so the loop only runs once
Does that makes sense to you?
Gregory Bilecki
@gbilecki
Aug 15 2016 01:42
it does, im just trying to think where the loop exits
no spoilers, just analyzing my code at the moment
i knew the loop was exiting prematurely
Diego Mayer
@Chrono79
Aug 15 2016 01:43

@gbilecki

if (val === args[i]) {   
      return false;
} else {
      return true;
}

In both those return, the loop is ended

Gregory Bilecki
@gbilecki
Aug 15 2016 01:47
Eh, this is returning an empty array:
function destroyer(arr) {

var args = arr.slice.call(arguments, 1);
var newArr = arr.filter(function filt(val) {  

for (i=0; i<args.length; i++) {
if (val === args[i]) {   
}
}});
  return newArr;
}
a408335312
@a408335312
Aug 15 2016 01:48
how to deal with the 21 card game?
Diego Mayer
@Chrono79
Aug 15 2016 01:49
@gbilecki what are you doing inside the if now? Nothing, so the filter returns undefined and that is a falsy value, all values are filtered
Gregory Bilecki
@gbilecki
Aug 15 2016 01:49
ah
yes i see
one sec
Stephen James
@sjames1958gm
Aug 15 2016 01:49
@a408335312 The most common method I have see is switch statement.
a408335312
@a408335312
Aug 15 2016 01:50
@sjames1958gm do i need list all the cards?
Stephen James
@sjames1958gm
Aug 15 2016 01:51
@a408335312 Well, not to give too much away - the three cards that don't change count are not needed.
comaeternal
@comaeternal
Aug 15 2016 01:51
function nextInLine(arr, item) {
  // Your code here

  testArr.push(item);



  return testArr.shift(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));
Diego Mayer
@Chrono79
Aug 15 2016 01:51
@a408335312 with switch, yes (except the cards @sjames1958gm mentioned ), with if/else not, a few less
comaeternal
@comaeternal
Aug 15 2016 01:51
how do i get "nextInLine([5,6,7,8,9], 1) should return 5"
Diego Mayer
@Chrono79
Aug 15 2016 01:52
@comaeternal use your function params inside the function
And review how shift works (no need for the argument)
Stephen James
@sjames1958gm
Aug 15 2016 01:52
The instructions are to return the first element and 5 is the first element
@comaeternal Use your parameters (arr, item) in your function defintion
a408335312
@a408335312
Aug 15 2016 01:53
@sjames1958gm k,thanks
Gregory Bilecki
@gbilecki
Aug 15 2016 02:02
@Chrono79 I feel like Im closer, but still getting an empty array...
function destroyer(arr) {

var args = arr.slice.call(arguments, 1);
var newArr = arr.filter(function filt(val) {  


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

if (val === args[i]) {
arr.splice(arr.indexOf(val), 1);                                   
}

}});
  return newArr;
}
Diego Mayer
@Chrono79
Aug 15 2016 02:04
@gbilecki go back to the first version, where you returned in the if and the else
Think when and what you need to return
Gregory Bilecki
@gbilecki
Aug 15 2016 02:05
ok @Chrono79
Luis Amador
@MrLuisAmador
Aug 15 2016 02:05
Why isn't this passing?
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = 4;
  this.seats = 5;
  this.engines = 1;
};

//Try it out here
var myCar = new Car( 3, 1, 2);
Diego Mayer
@Chrono79
Aug 15 2016 02:06
@MrLuisAmador because it doesn't matter which values you call your constructor with, you're not using them inside the function
myCar.wheels is 4 not 3 there
Ademola Adegbuyi
@ooade
Aug 15 2016 02:07
@MrLuisAmador this.wheels should not be hard coded. Pass in wheels
Luis Amador
@MrLuisAmador
Aug 15 2016 02:09
@Chrono79 @marhyorh Going right over my head right now. I don't get it
This the "Make Unique Objects by Passing Parameters to our Constructor" challenge
Diego Mayer
@Chrono79
Aug 15 2016 02:10
@MrLuisAmador look at the code example:
var Car = function(wheels, seats, engines) {
  this.wheels = wheels;
  this.seats = seats;
  this.engines = engines;
};
Luis Amador
@MrLuisAmador
Aug 15 2016 02:11
@Chrono79 , damn it! I see what ya'll meant by hard coded
Feel silly on this one
lol
Ademola Adegbuyi
@ooade
Aug 15 2016 02:11
@MrLuisAmador So you've gotten it now??
Luis Amador
@MrLuisAmador
Aug 15 2016 02:13
@marhyorh @Chrono79, yes. Thank you. I failed to pay attention and realized that I never had assigned the variables.
CamperBot
@camperbot
Aug 15 2016 02:13
mrluisamador sends brownie points to @marhyorh and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1823 | @chrono79 |http://www.freecodecamp.com/chrono79
:cookie: 707 | @marhyorh |http://www.freecodecamp.com/marhyorh
Ademola Adegbuyi
@ooade
Aug 15 2016 02:13
@MrLuisAmador Okay :+1:
WhisperingTide
@WhisperingTide
Aug 15 2016 02:16

function destroyer(arr) {
// Remove all the values
function destroy(x) {
return x == arguments1;

  }

return arr.filter(destroy);
}

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

Hey guys, just toying with the 'Seek and Destroy' challenge. How come that this gives me an empty array, instead of [2,2]? (return 2 == arguments1; returns true...)

Diego Mayer
@Chrono79
Aug 15 2016 02:17
@WhisperingTide arguments inside destroy is not the same as arguments inside destroyer
each function has its own arguments
WhisperingTide
@WhisperingTide
Aug 15 2016 02:18
Ahhh, of course, thank you! :)
Diego Mayer
@Chrono79
Aug 15 2016 02:25
@gbilecki did you solved it?
Gregory Bilecki
@gbilecki
Aug 15 2016 02:25
@Chrono79 -- still working
llamatarianism
@llamatarianism
Aug 15 2016 02:56
@WhisperingTide return x == arguments[1]
this will filter out anything that's not equal to the 2nd argument
which is the opposite of what you want
additionally, you're only checking arguments[1]
what about arguments[2] and arguments[3] and so on?
WhisperingTide
@WhisperingTide
Aug 15 2016 03:01
@llamatarianism Yeah, I was testing with a single argument first, then found a way to generalise, thanks though (Though it was none too happy about me putting a function within a loop, it seemed to work)! :)
CamperBot
@camperbot
Aug 15 2016 03:01
whisperingtide sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1186 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
Diego Mayer
@Chrono79
Aug 15 2016 03:01
@llamatarianism arguments[1] is the index, and arguments[2] is the array inside the filter function, no arguments[3]
llamatarianism
@llamatarianism
Aug 15 2016 03:02
true
I was referring to the arguments to destroyer
Diego Mayer
@Chrono79
Aug 15 2016 03:02
:+1:
Gregory Bilecki
@gbilecki
Aug 15 2016 03:02
@Chrono79 still not functioning correctly however I just wanted to know if I was going in the right direction:
 function destroyer(arr) { 

   var args = arr.slice.call(arguments, 1); 

   var newArr = arr.filter(function filt(val) { 
     for (i=0; i<args.length; i++) { 
       if (val === args[i]) { 
       } 
       } 
         return false;   
   });              
    return newArr; 
 }
Diego Mayer
@Chrono79
Aug 15 2016 03:03
@gbilecki I think the return false should be inside the if, remember that true keeps the value and false filter it
Gregory Bilecki
@gbilecki
Aug 15 2016 03:03
blarg
i thought thats what was making it end early though
i just dont want the effing loop to end early
:(
Diego Mayer
@Chrono79
Aug 15 2016 03:05
@gbilecki well, returning early is not a bad thing if you need to filter that value, when you find a match, you just filter it and follow with the next value
You need to return true if you didn't find a match tho
Gregory Bilecki
@gbilecki
Aug 15 2016 03:05
@Chrono79 thats what i was doing at first, i WAS filtering the value, but my loop was ending before it got to the second argument
Diego Mayer
@Chrono79
Aug 15 2016 03:06
@gbilecki that's why I told you, you don't want to return in the if AND the else, the loop won't run more than once that way
You have to write a return sentence to keep the value, but not inside the loop (like you did now, but false is not the right value there)
Sam Erickson
@samerickson
Aug 15 2016 03:08

How would I go about splitting an element to an array, into another array nestled in the original array?

function titleCase(str) {
  var array = str.split(" ");
  array[0].split();
  return array;
}

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

This doesnt work for some reason. I just want to iterate this once for now. I'll work on adding a loop later.

Vikrant Singh
@VikrantSingh13
Aug 15 2016 03:11
@samerickson challenge name?
Elbert Cortez
@trip16661
Aug 15 2016 03:11
arrayxamarin/xamarin-android@a16673d.split('');
Gregory Bilecki
@gbilecki
Aug 15 2016 03:11
ok @Chrono79 -- tell me this
do i need a return TRUE and a return FALSE for a filter method
thats what im confused about
Elbert Cortez
@trip16661
Aug 15 2016 03:12
@samerickson
array[0].split("");
Diego Mayer
@Chrono79
Aug 15 2016 03:12
@gbilecki yes, true for the values you want to keep, and false for the values you want to filter
jjamesg
@jjamesg
Aug 15 2016 03:12
@samerickson you also arent assigning array[0].split('') to a variable
Elbert Cortez
@trip16661
Aug 15 2016 03:13
i think charAt is better for that
than spliting again the string
Sam Erickson
@samerickson
Aug 15 2016 03:15
function titleCase(str) {
  var array = str.split(" ");
  for(var i in array) {
    array[i] = array[i].split('');
  }
  return array;
}

titleCase("I'm a little tea pot");
Got it! Thanks @trip16661 @jjamesg
CamperBot
@camperbot
Aug 15 2016 03:15
samerickson sends brownie points to @trip16661 and @jjamesg :sparkles: :thumbsup: :sparkles:
:cookie: 438 | @trip16661 |http://www.freecodecamp.com/trip16661
:cookie: 561 | @jjamesg |http://www.freecodecamp.com/jjamesg
Cataloochee
@cataloochee
Aug 15 2016 03:20

I have a random question concerning Regular Expressions in Javascript Basic curriculum. Why is the .length attribute added to the end of a RegEx script? E.G. var string = "For testing purposes only";

var regEx = /for+/gi;

var test = string.match(regEx).length;

From the Regular Expression section in the Basic Javascript curriculum.
Diego Mayer
@Chrono79
Aug 15 2016 03:22
@cataloochee https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
You need to find how many matches are found in that challenge, note that if no matches were found, null.length will give error
Sam Erickson
@samerickson
Aug 15 2016 03:24
Figured out how to do it in one line!
function titleCase(str) {

  return str.toLowerCase().split(' ').map(i => i[0].toUpperCase() + i.substring(1)).join(' ');
}

titleCase("I'm a little tea pot");
Cataloochee
@cataloochee
Aug 15 2016 03:25
@Chrono79 Thanks for the direction to MDN! I just skimmed it to no avail. I understand everything about the code other than the ".length" added to the end of it. Since the RegEx is searching the entire string through the "g", why would it need a .length ?
CamperBot
@camperbot
Aug 15 2016 03:25
cataloochee sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1824 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 15 2016 03:26
@cataloochee it returns an array, so length means how many matches were found
Cataloochee
@cataloochee
Aug 15 2016 03:27
Awesome. Thanks @Chrono79 .
CamperBot
@camperbot
Aug 15 2016 03:27
cataloochee sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: cataloochee already gave chrono79 points
Chris Lacaille
@ChrisL108
Aug 15 2016 03:31
Challenge: Inventory Update ----- Hey guys I'm having trouble understanding why my new array in this gist is returning multiple array objects with the same value when I'm checking with indexOf() === -1 before adding them to the new array. Any help appreciated!
https://gist.github.com/ChrisL108/3870d84745c9aa6fe95745f15ab4aff4
and I just added the else if for calrity.. I know I could just use else
Enrique Alejandro Arzamendi Picazzo
@AleCx4
Aug 15 2016 03:36
@sjames1958gm it was a while ago, but I figured out how to use the parsing needed :) even managed to do so without jquery
Vikrant Singh
@VikrantSingh13
Aug 15 2016 03:38
@ChrisL108 what's the point of having that else if statement? simple else will suffice
llamatarianism
@llamatarianism
Aug 15 2016 03:38
in fact the else if makes it slower
since it'll have to calculate arr1[old].indexOf(arr2[updated][0]) twice
encount
@encount
Aug 15 2016 03:39
Does anyone know why this wont pass the test (titlecase) but each one appears correctly in the console output?
function titleCase(str) {
var ns="";
  var foo = str.split(" ");

  for (var i = 0; i < foo.length; i++) {
    var bar = foo[i];
    var cap = bar.charAt(0).toUpperCase() + bar.slice(1).toLowerCase();
    ns += cap + " "; 
  }

  return ns;
}

titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");
Diego Mayer
@Chrono79
Aug 15 2016 03:39
@encount you add a space at the end (of the whole string), don't do it or use trim()
llamatarianism
@llamatarianism
Aug 15 2016 03:40
@149203 you're using a global variable
that variable doesn't get reset each time you call the function
try using the function 3 times in a row
encount
@encount
Aug 15 2016 03:41
@Chrono79 thanks so much - never would have figured that out!! Driving me mad!
CamperBot
@camperbot
Aug 15 2016 03:41
encount sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1825 | @chrono79 |http://www.freecodecamp.com/chrono79
Chris Lacaille
@ChrisL108
Aug 15 2016 03:41
@VikrantSingh13 read my note..
" and I just added the else if for calrity.. I know I could just use else "
149203
@149203
Aug 15 2016 03:42
@llamatarianism thank you very much where should I put that variable?
CamperBot
@camperbot
Aug 15 2016 03:42
149203 sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1187 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
llamatarianism
@llamatarianism
Aug 15 2016 03:42
inside a function somewhere
for example, you could put it inside flatten
and have flatten return it
comaeternal
@comaeternal
Aug 15 2016 03:42
function nextInLine(arr, item) {
  // Your code here

  testArr.push(item);

  testArr.shift();

  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, 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Vikrant Singh
@VikrantSingh13
Aug 15 2016 03:42
@ChrisL108 lol what does it clarify?
Diego Mayer
@Chrono79
Aug 15 2016 03:43
@comaeternal use arr and item inside your function
testArr is used only in one test
and item is the element added to the array, not the one removed
Vikrant Singh
@VikrantSingh13
Aug 15 2016 03:43
@comaeternal
return testArr.shift();
149203
@149203
Aug 15 2016 03:43
@llamatarianism my only trouble is that flatten is recursive and it will reset the array every time! :)
Vikrant Singh
@VikrantSingh13
Aug 15 2016 03:43
@comaeternal
return arr.shift();
Chris Lacaille
@ChrisL108
Aug 15 2016 03:44
@VikrantSingh13 for people reading through my code.. it doesn't un clarify so im lost? Do you know anything about the issue I stated?
Vikrant Singh
@VikrantSingh13
Aug 15 2016 03:44
@ChrisL108 Well, indexof either returns the index or -1, so the extra else if is redundant and slows the code.
Appreciate it!
Chris Lacaille
@ChrisL108
Aug 15 2016 03:47
@VikrantSingh13 lol I was saying read my next message after I posted the question.it says that I know it's redundant... I'm just trying to figure out what i AM missing. and why array.indexOf() === -1 isn't catching some cases
Vikrant Singh
@VikrantSingh13
Aug 15 2016 03:53
@ChrisL108
try this and tell me what happened
if (arr1[old].indexOf(arr2[updated][1]) !== -1) {
        arr1[old][0] += arr2[updated][0];
same thing for the else if statement replace the 0 with 1
even better replace the else if with just an else
Chris Lacaille
@ChrisL108
Aug 15 2016 03:58
@VikrantSingh13 No that part is working. It's my else-if (or just else lol) statement that is adding duplicates
I could probably just make a new array but I want to know what I'm doing wrong lol
This message was deleted
The else if (arr1[old].indexOf(arr2[updated][0]) === -1) is still executing when it shouldn't be (adding duplicates)
ShaneBenj317
@ShaneBenj317
Aug 15 2016 04:04

Hey guys! Could anyone help me with the challenge Accessing Nested Objects in Javascript? I'm stumped. Here is the code: // Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = "myStorage.gloveboxContents["maps]"; // Change this line

Brett Felts
@brettfelts
Aug 15 2016 04:06
Hey, So I'm working on the exact change algorithm. I'm still in the first part trying to make sure my code returns "insufficient funds" and "closed". I the reduce function on cid returns correctly for most of the tests, but returns 0.01 on one, despite that being less than change.
``function checkCashRegister(price, cash, cid) {
var change = cash - price;
var denomination = [0.01, 0.05, 0.10, 0.25, 1.00, 5.00, 10.00, 20.00, 100.00];
var till = cid.reduce(function(x,y) {
return x + y1;
},0);
if (change === till) {
return 'Closed';
}
if (change < till) {
return 'Insufficient Funds';
}}
checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
Any ideas why?
Vikrant Singh
@VikrantSingh13
Aug 15 2016 04:06
@ChrisL108 in the else if statment :
arr1.push(updated);
llamatarianism
@llamatarianism
Aug 15 2016 04:07
@brettfelts you have to filter out stuff like the hundreds before summing up cid
cuz like
if you owe me $0.50 change
it's impossible to pay that back using anything other than pennies, nickles, dimes and quarters
cuz even if you have a gazillion dollars
you can't pay back exactly $0.50 and no more without denominations that are individually worth less than $0.50
man I suck at explaining :P
@brettfelts essentially, it's impossible to pay back $0.50 with say, hundred dollar bills. so you have to ignore the hundred dollar bills when you're calculating till unless change is greater than 100.
Brett Felts
@brettfelts
Aug 15 2016 04:10
@llamatarianism I think I get what you're saying actually. All i'm doing so far is adding up the total amount, not accounting for the smaller denominations
llamatarianism
@llamatarianism
Aug 15 2016 04:10
yep
as an example:
checkCashRegister(19.50, 20.00, [["PENNY", 0], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 100000]]);
you have way more than $0.50 in the drawer
but you can't pay back exactly $0.50
so you have insufficient funds
encount
@encount
Aug 15 2016 04:11
@ShaneBenj317 you use dot notation to get to the top level objects (car and inside) the [‘glove box’] for inner
Spider
@Spiderixius
Aug 15 2016 04:12
Hey guys, If I wanted to sum consecutive numbers in an array like for example [1, 2, 2, 3, 5, 6, 6, 7] needs to be [1, 4, 3, 5, 12, 7] how can I go around implementing this, any tips?
Brett Felts
@brettfelts
Aug 15 2016 04:13
Thanks @llamatarianism . That gives me an excellent jumping place
CamperBot
@camperbot
Aug 15 2016 04:13
brettfelts sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1189 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
ShaneBenj317
@ShaneBenj317
Aug 15 2016 04:14
@encount Thanks man! That worked.
CamperBot
@camperbot
Aug 15 2016 04:14
shanebenj317 sends brownie points to @encount :sparkles: :thumbsup: :sparkles:
:cookie: 266 | @encount |http://www.freecodecamp.com/encount
llamatarianism
@llamatarianism
Aug 15 2016 04:23
@brettfelts thank you too, cuz in my solution, I kinda figured that out without really understanding it, so you made me have to try and get it :P
CamperBot
@camperbot
Aug 15 2016 04:23
llamatarianism sends brownie points to @brettfelts :sparkles: :thumbsup: :sparkles:
:cookie: 411 | @brettfelts |http://www.freecodecamp.com/brettfelts
Brett Felts
@brettfelts
Aug 15 2016 04:23
Glad I could help
Chris Lacaille
@ChrisL108
Aug 15 2016 04:23
@VikrantSingh13 didn't work
Gregory Bilecki
@gbilecki
Aug 15 2016 04:26
@Chrono79 i took out the else statement --- I still cant figure this out :/
 function destroyer(arr) { 

   var args = arr.slice.call(arguments, 1); 

   var newArr = arr.filter(function filt(val) { 
     for (i=0; i<args.length; i++) { 
       if (val !== args[i]) { 
      return true;
} return false;
     }});           
    return newArr; 
}
Vikrant Singh
@VikrantSingh13
Aug 15 2016 04:26
@ChrisL108 the way you're pushing arr2[updated] is wrong. Since you called for(updated in arr2) update is an array, you can't use it as an index because we are not dealing with JSON.
Gregory Bilecki
@gbilecki
Aug 15 2016 04:26
I also change the true/false
Vikrant Singh
@VikrantSingh13
Aug 15 2016 04:27
@ChrisL108
I tweaked your code and this works fine:
function updateInventory(arr1, arr2) {
  var newitem = true;

  for (var i = 0; i < arr2.length; i++) {
    var updated = arr2[i];
    for (var j = 0; j < arr1.length; j++) {
      var old = arr1[j];
      if (old.indexOf(updated[1]) > -1) {
        old[0] += updated[0];
        newitem = false;
        break;
      } 
    }
    if (newitem){
      arr1.push(updated);
    }
    newitem = true;
  }
  //sorts the array alphabetically 
  return arr1.sort(function(a, b) {
    var itemA = a[1];
    var itemB = b[1];
    return (itemA < itemB) ? -1 : (itemA > itemB) ? 1 : 0;
  }); 
}
John Alcher
@alchermd
Aug 15 2016 04:27
Hey fellas. Can anyone give me a brief overview on how to play audio in javascript? I'm currently doing the simon game project :D
Diego Mayer
@Chrono79
Aug 15 2016 04:29
@gbilecki do you want me to show how it's done?
Robert Richey
@0x0936
Aug 15 2016 04:29
@Spiderixius
var arr = [1, 2, 2, 3, 5, 6, 6, 7]
var result = []

for (var i = 0; i < arr.length; i++) {
  if (arr[i] === arr[i+1] && i+1 < arr.length) {
    result.push(arr[i] + arr[i+1])
    i++
  } else {
    result.push(arr[i])
  }
}

console.log(result) // [1, 4, 3, 5, 12, 7]
Gregory Bilecki
@gbilecki
Aug 15 2016 04:29
@Chrono79 not really -- - its just that i feel like Im doing what you said and its not workin
working*
like i dont have a return with an else
Diego Mayer
@Chrono79
Aug 15 2016 04:30
@gbilecki well, you only need to keep a value if it didn't match the values you need to destroy
Also, you have to write a return inside the if and one outside the loop
Brian
@BrianCodes33
Aug 15 2016 04:30
im having trouble compiling my sass. anyone mind lending a hand?
Gregory Bilecki
@gbilecki
Aug 15 2016 04:31
yeah but @Chrono79 so i DON'T need a false return
Chris Lacaille
@ChrisL108
Aug 15 2016 04:31
@VikrantSingh13 Oh okay thanks
CamperBot
@camperbot
Aug 15 2016 04:31
chrisl108 sends brownie points to @vikrantsingh13 :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @vikrantsingh13 |http://www.freecodecamp.com/vikrantsingh13
Gregory Bilecki
@gbilecki
Aug 15 2016 04:31
@Chrono79 ?
Diego Mayer
@Chrono79
Aug 15 2016 04:32
@gbilecki if the current value of the filter matches a value you want to destroy, you return false
if all the values in the list to destroy don't match the current value of the filter argument, you keep it
Vikrant Singh
@VikrantSingh13
Aug 15 2016 04:32
@ChrisL108 no problem. The code I wrote can be made a lot better. try to clean it up lol
Spider
@Spiderixius
Aug 15 2016 04:33
Thanks @0x0936
CamperBot
@camperbot
Aug 15 2016 04:33
spiderixius sends brownie points to @0x0936 :sparkles: :thumbsup: :sparkles:
:star2: 1658 | @0x0936 |http://www.freecodecamp.com/0x0936
Diego Mayer
@Chrono79
Aug 15 2016 04:34
    for (i=0; i<args.length; i++) { 
      if (val === args[i]) { 
         ... // destroy it, because it matched one of the numbers to destroy
      } 
    }
    ...    //keep it, because it didn't match a value to destroy
@gbilecki
Harindu Dilshan ( Kavinda Pitiduwa Gamage)
@harindu95
Aug 15 2016 04:37
hey guys here is a word cloud i created. http://s.codepen.io/harindu95/debug/QEYqkx
the problem is I don't know how to use frequency to place the words
Gregory Bilecki
@gbilecki
Aug 15 2016 04:37
@Chrono79 --- That worked -- but -- can you tell me what's so special about putting return true; under that last bracket
why cant i put it in the bracket before
Diego Mayer
@Chrono79
Aug 15 2016 04:39
@gbilecki you can only say it's not in the list to destroy after you've checked the whole list, and that's when you finished the loop
before (and that's inside the loop) you only can say it's not equal to the first value you check, and that's not enough
Rita Alfonso
@alfonsotech
Aug 15 2016 04:39
@sjames1958gm Thanks, will try the e.prevdef()...
CamperBot
@camperbot
Aug 15 2016 04:39
alfonsotech sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2611 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Gregory Bilecki
@gbilecki
Aug 15 2016 04:40
so we're only doing one thing in the loop -- checking for false values, correct
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 04:43
Can anyone help me understand why my .getJSON call does not seem to be working. Nothing is printed to the console. http://codepen.io/scabbyjoe/pen/ZOwRAV
Diego Mayer
@Chrono79
Aug 15 2016 04:43
@gbilecki the loop is for checking against a list, if you were to filter values greater than 5 for instance you won't need a loop, you 'll do just:
return val>5
Greg Duncan
@GregatGit
Aug 15 2016 04:46
@diarmuid-murphy try putting this at the end of your api string &callback=?
Gregory Bilecki
@gbilecki
Aug 15 2016 04:47
@Chrono79 -- the loop is only checking for false values in the list --- filter() methos is returning what's true, correct?
Broozius
@Brucius
Aug 15 2016 04:47
random quote generator is hard
:(
Diego Mayer
@Chrono79
Aug 15 2016 04:48
@gbilecki the method keeps the values that returns true and discard the values that returns false (in the function you use inside the filter method)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
Rita Alfonso
@alfonsotech
Aug 15 2016 04:48
@OakerMin :smile:
Broozius
@Brucius
Aug 15 2016 04:48
@alfonsotech is it normal to feel that way
Rita Alfonso
@alfonsotech
Aug 15 2016 04:48
@OakerMin try writing out in regular language the steps that need to happen for the thing to work.
Broozius
@Brucius
Aug 15 2016 04:48
pseudo code isn't it
Chris Lacaille
@ChrisL108
Aug 15 2016 04:49
@diarmuid-murphy I got XMLHttpRequest cannot load https://en.wikipedia.org/w/api.php?action=opensearch&search=&limit=10&namespace=0&format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s.codepen.io' is therefore not allowed access.
Rita Alfonso
@alfonsotech
Aug 15 2016 04:49
It is hard. It's the first zipline, right? SO yeah, it's a leap.
Broozius
@Brucius
Aug 15 2016 04:49
yeah
had a lot of blockers at bonfire too @alfonsotech D:
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 04:50
@GregatGit Unfortunately that doesnt do the trick, I can't seem to run any code inside that getJSON call, even this doesnt work
$.getJSON(apiCall, function(data) {
console.log("NOTHING HAPPENS");
console.log(data);
});
Gregory Bilecki
@gbilecki
Aug 15 2016 04:50
so the loop is there just to return false elements
Rita Alfonso
@alfonsotech
Aug 15 2016 04:50
@OakerMin Yup, I did too. But if it makes you feel better, now looking back those projects that seemed sooooo hard to wrap my head around make total sense now.
Gregory Bilecki
@gbilecki
Aug 15 2016 04:50
yes or no
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 04:50
@ChrisL108 Hmm I don't see that in my console? I'm using FF
Greg Duncan
@GregatGit
Aug 15 2016 04:51
@diarmuid-murphy var apiCall = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + searchQuery + "&limit=10&namespace=0&format=json&callback=?";
Rita Alfonso
@alfonsotech
Aug 15 2016 04:51
I still have to sit down and figure it out, but your understanding will stretch and grow
Broozius
@Brucius
Aug 15 2016 04:51
i see @alfonsotech thanks man
CamperBot
@camperbot
Aug 15 2016 04:51
oakermin sends brownie points to @alfonsotech :sparkles: :thumbsup: :sparkles:
:cookie: 389 | @alfonsotech |http://www.freecodecamp.com/alfonsotech
Rita Alfonso
@alfonsotech
Aug 15 2016 04:52
<--- woman
Emil Aasa
@emilaasa
Aug 15 2016 04:52
Here's a hack: https://crossorigin.me/https://yoururl.here
Rita Alfonso
@alfonsotech
Aug 15 2016 04:52
:smile:
Broozius
@Brucius
Aug 15 2016 04:52
oh oops madam :D
Rita Alfonso
@alfonsotech
Aug 15 2016 04:53
what have you tried, to get started?
Broozius
@Brucius
Aug 15 2016 04:53
just got the UI done and trying to get the api in
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 04:54
@GregatGit Hmm still not allowing me to console.log() the data from the API call
Greg Duncan
@GregatGit
Aug 15 2016 04:56
@diarmuid-murphy its working for me
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 04:59
@GregatGit console.log(data); spits out the object in the console? Are you using the Codepen or running the file locally?
Greg Duncan
@GregatGit
Aug 15 2016 04:59
codepen
Robert Richey
@0x0936
Aug 15 2016 05:00
@Spiderixius another approach, because I found it to be an interesting problem to solve. this has the side effect that when two consecutive numbers are added and form a new consecutive pair - they will continue to be added together. for example, [1, 1, 2] will produce [4]
var arr = [1, 2, 2, 3, 5, 6, 6, 7]
var result = arr.reduce((a, b) => {
  if (a[a.length-1] === b) {
    a.splice(-1, 1, b * 2)
    return a
  }  
  return a.concat(b)
}, [])

console.log(result) // [1, 4, 3, 5, 12, 7]
Greg Duncan
@GregatGit
Aug 15 2016 05:00
@diarmuid-murphy I forked it for now http://codepen.io/gregoverhere/pen/xOrJzq
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 05:01
@GregatGit Hmm that still isnt working for me, the only thing printing to the console is my apiCall string, not the "data" object back from Wikipedia
Greg Duncan
@GregatGit
Aug 15 2016 05:02
@diarmuid-murphy for me I'm getting ["bike", Array[10], Array[10], Array[10]] in the console
Vikrant Singh
@VikrantSingh13
Aug 15 2016 05:03
@diarmuid-murphy check the other chat I posted the tweaked version of your code
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 05:04
@GregatGit wtf, I wonder is some add on blocking something for me
Ekene96
@Ekene96
Aug 15 2016 05:04
Please I need someone to please help me with thsi ... I may know the solution but right am so confuse. Link:
Brett Felts
@brettfelts
Aug 15 2016 05:05
@Ekene96 what kind of trouble are you having with it?
Ekene96
@Ekene96
Aug 15 2016 05:06
I want to convert from celcuis to fahrenheit
or vice versa
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 05:06
@VikrantSingh13 Looking at it now..
Brett Felts
@brettfelts
Aug 15 2016 05:06
What have you tried so far?
the main things to remember are the mathematical order of operations, and that the two variables you need are already declared
Ekene96
@Ekene96
Aug 15 2016 05:12
thanks @VikrantSingh13 . I really appreciate.
CamperBot
@camperbot
Aug 15 2016 05:12
ekene96 sends brownie points to @vikrantsingh13 :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @vikrantsingh13 |http://www.freecodecamp.com/vikrantsingh13
Greg Duncan
@GregatGit
Aug 15 2016 05:12
@diarmuid-murphy I'm using this api https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=bike&callback=? with no problems - I pasted it in yours and nothing.
Helenbella
@Helenbella
Aug 15 2016 05:13

function smallestCommons(arr) {
return arr;
}
smallestcommons([5,1]);

smallestCommons([1,5]);

how do i code this for smallest common multiple?
between 1,5
???
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 05:16
@GregatGit Okay the other api url you are using does indeed seem to be working! Still fiddling around with it here
pauperwithpotential
@pauperwithpotential
Aug 15 2016 05:17
hey guys, i am doing the Profile Lookup challenge for Front End javascript. I cant seem first if statement in my for loop to work. any idea why? it will return "No such contact".

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

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

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

Vikrant Singh
@VikrantSingh13
Aug 15 2016 05:18
@pauperwithpotential use hasOwnProperty(prop)
those brackets/braces can destroy lives :P
pauperwithpotential
@pauperwithpotential
Aug 15 2016 05:19
oh yeah sorry i forgot to correct that but i still get no such contact
Greg Duncan
@GregatGit
Aug 15 2016 05:21
@diarmuid-murphy this shouldn't have apiCall in it the params section $("#searchButton").on("click", function(){
Helenbella
@Helenbella
Aug 15 2016 05:22

function smallestCommons(arr) {
return arr;
}
smallestcommons([5,1]);

smallestCommons([1,5]);
how do i code this for smallest common multiple?
between 1,5
???

Vikrant Singh
@VikrantSingh13
Aug 15 2016 05:22
@about @VikrantSingh13
about @VikrantSingh13
CamperBot
@camperbot
Aug 15 2016 05:22
:cookie: 325 | @vikrantsingh13 |http://www.freecodecamp.com/vikrantsingh13
Brett Felts
@brettfelts
Aug 15 2016 05:22
@Helenbella Look into Euclids algorithm and look up some information about the modulus (%)
Vikrant Singh
@VikrantSingh13
Aug 15 2016 05:22
@pauperwithpotential
this works:
function lookUpProfile(firstName, prop){
  for (var i = 0; i < contacts.length; i++){
    if (contacts[i].firstName == firstName){
      if(contacts[i].hasOwnProperty(prop)){
        return contacts[i][prop];
      } else {
        return "No such property";
      }
    }

  }
  return "No such contact";
}
Brett Felts
@brettfelts
Aug 15 2016 05:23
@Helenbella That one stumped me for a few days.
Helenbella
@Helenbella
Aug 15 2016 05:24
I HAVE BEEN ON IT FOR 2 DAYS NOW @brettfelts
Brett Felts
@brettfelts
Aug 15 2016 05:26
Here's a chunk of my code. It's my first line after the function declaration as well as a comment I wrote to help myself understand it. I'm honestly still trying to work my head around it.
This message was deleted
``for (var i = Math.max(arr[0],arr1); i >= Math.min(arr[0],arr1); i--) {
arr.push(i);
}
/arr.slice(2) will take off the original array values, shortening the loop, reduce will perform Euclid's algorithm over each element in the array. As long as the modulus function is true, for each element in the array a will equal a % b, x will then equal a, and a and b will move down the array. after that, the reduce function will take the greatest common divisor of the elements in the array and return that multiplied by the last element (j) and then use that to divide the next to last(i)/
pauperwithpotential
@pauperwithpotential
Aug 15 2016 05:27
thanks @VikrantSingh13!
CamperBot
@camperbot
Aug 15 2016 05:27
pauperwithpotential sends brownie points to @vikrantsingh13 :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @vikrantsingh13 |http://www.freecodecamp.com/vikrantsingh13
Vikrant Singh
@VikrantSingh13
Aug 15 2016 05:28
@pauperwithpotential no problem. don't just copy paste though, go through the code and try to understand each line, and the overall logic
pauperwithpotential
@pauperwithpotential
Aug 15 2016 05:29
@VikrantSingh13 of course. there's no satisfaction in copying and "passing" without understanding the logic. :+1:
Greg Duncan
@GregatGit
Aug 15 2016 05:32
@diarmuid-murphy obj.query.pages[3973]
pauperwithpotential
@pauperwithpotential
Aug 15 2016 05:33
thanks @revisualize. this is helpful too!
CamperBot
@camperbot
Aug 15 2016 05:33
pauperwithpotential sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 1634 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Aug 15 2016 05:34
@pauperwithpotential I prefer to give people that instead of the answer.
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:45
How do you use a named function instead of an anonymous function in an object
Like if I have a dog object with a bark function, is there another way to declare it besides dog:function (){}
I mean bark:function (){}
Markus Kiili
@Masd925
Aug 15 2016 05:49
@JordanShackelford Do you mean setting a named function as a property value on an object literal?
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:49
Yeah
Markus Kiili
@Masd925
Aug 15 2016 05:50
function myFunction () {
    console.log("test");
}

obj = {
    here : myFunction
}

obj.here(); // "test"
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:50
So I need to write it outside the object!?
Markus Kiili
@Masd925
Aug 15 2016 05:51
@JordanShackelford It is inside the object literal.
Between the brackets.
You can also just make an empty object and add the method with dot or bracket notation.
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:52
Okay I think I understand
Valentin Serra
@Skaiir
Aug 15 2016 05:53
Hey guys, anyone knows how you match pairs of characters in regex?
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:53
If my function was a variable instead of function, the object would be passed value instead of reference, correct?
Valentin Serra
@Skaiir
Aug 15 2016 05:53
[a-z]{2} will match az, looking for something that will match aa, bb, cc, ect...
Markus Kiili
@Masd925
Aug 15 2016 05:56
@JordanShackelford As JS has 1st class functions, there is really no real difference with a named function and a variable with function as a value. So if you did var myFunction = function(){...};, the result would be essentially the same.
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:58
I just read that a function assigned to variable can't be called until the variable is initialized
Diarmuid Murphy
@diarmuid-murphy
Aug 15 2016 05:58
@GregatGit In case you are interested, the issue was todo with my submit button, the form and the js to get the value: http://stackoverflow.com/a/38949426/2466841
Thank you for your help none the less! :)
CamperBot
@camperbot
Aug 15 2016 05:58
diarmuid-murphy sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 737 | @gregatgit |http://www.freecodecamp.com/gregatgit
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:59
All my objects use anonymous functions so I was wondering if that was hurting my performance somehow
Markus Kiili
@Masd925
Aug 15 2016 05:59
@JordanShackelford If you assign a function to a variable, that variable will be initialized. Assigning to a declared variable means initialization.
Jordan Shackelford
@JordanShackelford
Aug 15 2016 05:59
O
@Skaiir try [a-z]([a-z])\1([a-z])\2[a-z]
I'm regex noob but found that on stack overflow
Markus Kiili
@Masd925
Aug 15 2016 06:02
@JordanShackelford If you use the same function many times, you could consider writing a named function.
Valentin Serra
@Skaiir
Aug 15 2016 06:02
@JordanShackelford /([a-z])\1/g actually does the work
@JordanShackelford "\1 matches the same text as most recently matched by the 1st capturing group"
@JordanShackelford Thanks anyways.
CamperBot
@camperbot
Aug 15 2016 06:05
skaiir sends brownie points to @jordanshackelford :sparkles: :thumbsup: :sparkles:
:cookie: 439 | @jordanshackelford |http://www.freecodecamp.com/jordanshackelford
Markus Kiili
@Masd925
Aug 15 2016 06:10
@JordanShackelford Now I got what you were talking about. Yes, function declarations are "hoisted" and assigned functions can only be used only after the assignment. There are a couple of other small differences too.
Markus Kiili
@Masd925
Aug 15 2016 06:17
@JordanShackelford Declared function has a name property (assigned anonymous function doesn't). Declarations cannot be used inside control structures (some weird behaviour can occur if you do). But no fundamental differences.
Suraj Prasad
@suraj18gts
Aug 15 2016 06:18
anyonw knows about the wordline??
Greg Duncan
@GregatGit
Aug 15 2016 06:18
@diarmuid-murphy cool
Suraj Prasad
@suraj18gts
Aug 15 2016 06:19
not word line...it ll be word blank
any one??
anyone knows about word blank??
Rony Vidaur
@RonyVidaur
Aug 15 2016 06:23
@suraj18gts is that a challenge?
Picshulo
@Picshulo
Aug 15 2016 06:23
@suraj18gts Yes, where is your problem?
Suraj Prasad
@suraj18gts
Aug 15 2016 06:24
wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters
whats this??
Picshulo
@Picshulo
Aug 15 2016 06:25
@suraj18gts Do you have any code?
Suraj Prasad
@suraj18gts
Aug 15 2016 06:26
no
i can't get any code
Markus Kiili
@Masd925
Aug 15 2016 06:27
@suraj18gts Function parameters (myNoun, myAdjective, myVerb, myAdverb) will hold those passed words and you should make a long sentence using the function parameters.
Suraj Prasad
@suraj18gts
Aug 15 2016 06:28
how?
Mark Todd
@Knochenmark
Aug 15 2016 06:29
@suraj18gts return ""+myNoun+" "+myAdjective and so on
Suraj Prasad
@suraj18gts
Aug 15 2016 06:30
done
not working
Mark Todd
@Knochenmark
Aug 15 2016 06:34
@suraj18gts link your code
Suraj Prasad
@suraj18gts
Aug 15 2016 06:35
var result = "";
// Your code below this line
result="big dog ran quickly"+ " little cat hit slowly";
// Your code above this line
return result;
}
is this is correct??
Mark Todd
@Knochenmark
Aug 15 2016 06:36
@suraj18gts no you are supposed to use the passed parameters
Suraj Prasad
@suraj18gts
Aug 15 2016 06:38
how??
Mark Todd
@Knochenmark
Aug 15 2016 06:38
@suraj18gts well you could say result = "big dog ran quickly"; but you wouldnt pass the second test so use the parameters like myNoun
@suraj18gts dog is a noun you know :D
actually i saw you wouldnt pass with big dog ran quickly because its "dog big ran quickly"
@suraj18gts start reading the challenge descriptions man :D
Suraj Prasad
@suraj18gts
Aug 15 2016 06:40
+myNoun+" "+myAdjective and so on
this way??
Mark Todd
@Knochenmark
Aug 15 2016 06:40
@suraj18gts try it ;)
and for the future, read more carefully.
Suraj Prasad
@suraj18gts
Aug 15 2016 06:45
result=""+myNoun+" "+myAdjective+" "+myVerb+" "+myAdverb"";
LordYamanouchi
@LordYamanouchi
Aug 15 2016 06:45
Does anyone know what field does in this?
 $.each(result, function(i, field){
            $("div").append(field + " ");
        });
Suraj Prasad
@suraj18gts
Aug 15 2016 06:45
like this??
result=""+myNoun+" "+myAdjective+" "+myVerb+" "+myAdverb"";
Michał
@stegent
Aug 15 2016 06:47

Hi there :) i got stuck on Testing Objects for Properties in JS part. Task is to modify function to test myObj for checkProp with use of .hasOwnProperty. This is my code and if anyone could help me found whre I made mistake:
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

also if someone could tell me how to copy code in more readable way :)
Mark Todd
@Knochenmark
Aug 15 2016 06:49
@suraj18gts did you even run the tests? the last whitespace is not required
@suraj18gts and you should format your code, its hard to read otherwise
@stegent is the "Not Found" part of the test or you are supposed to return a Boolean?
Michał
@stegent
Aug 15 2016 06:50
It is the part of the test
checkObj("gift") should return "pony".
checkObj("pet") should return "kitten".
here are the objectives that my code doesn't complete
Mark Todd
@Knochenmark
Aug 15 2016 06:51
@stegent you are supposed to use bracket notation
@stegent return myObj[checkProp] in your if
return myObj.hasOwnProperty(checkProp) ? myObj[checkProp] : "Not Found";
@stegent might want to have a look into ternary operator too :P
Michał
@stegent
Aug 15 2016 06:53
that worked :D it is weird I tried it few moments ago, but I must have changed. Could you tell me why it must be bracket notation?
Mark Todd
@Knochenmark
Aug 15 2016 06:54
because you are using a variable as property
Markus Kiili
@Masd925
Aug 15 2016 06:54
@stegent The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
Mark Todd
@Knochenmark
Aug 15 2016 06:54
if there would be a object property named checkProp it would return that value :D
if you use the bracket notation it uses the containing string of the variable
Michał
@stegent
Aug 15 2016 06:55
Ok, thank you all for help ;) one more thing: how to paste here code in more readable way?
Markus Kiili
@Masd925
Aug 15 2016 06:55
@stegent So bracket notation is the general access method and dot notation only works in one case.
Michał
@stegent
Aug 15 2016 06:56
btw. so it is better to use bracket notation on daily basis?
Mark Todd
@Knochenmark
Aug 15 2016 06:56
@Masd925 i dont like the "general access method"
@stegent no :D
@stegent you basically use bracket notation if you pass variables or construct the key, or there is a whitespace in the key for example
@stegent if you have information about the property and you want to access the property directly, you use dot notation
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 06:57
@Masd925 Any chance of a short tutorial on your One-liners? Symmetric difference solution is puzzling me. Function .call an .apply arguments are making my head spin.
Suraj Prasad
@suraj18gts
Aug 15 2016 06:58
result=" "+myNoun+" "+myAdjective+" "+myVerb+" "+myAdverb+".";
its working
arif hussain
@arifhussain0
Aug 15 2016 06:58
hello need help with seek and destroy exercise
return arr[0].filter(function(val){
return val!==arguments;
Mark Todd
@Knochenmark
Aug 15 2016 06:58
@stegent i think the freecodecamp editor might even shows you, when you are supposed to use dot notation instead.
@stegent but i might be wrong, could have been another ide too :S
arif hussain
@arifhussain0
Aug 15 2016 06:59
but it says arr[0].filter is not a function
Markus Kiili
@Masd925
Aug 15 2016 06:59
@BenjamWondafrash Some of those solutions have been made mostly for fun, but there certainly is much to learn too. If you tell me what solution it was I can try to explain it.
Mark Todd
@Knochenmark
Aug 15 2016 06:59
@suraj18gts there was a point in the end?
Michał
@stegent
Aug 15 2016 07:01
@Knochenmark it didn't show me this time, but I think I got general idea. I will probably learn it in practice just like in this example.
Mark Todd
@Knochenmark
Aug 15 2016 07:01
@arifhussain0 why arr[0]? just filter arr
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:02
@Masd925 Ahh. It was Symmetric diff. Actually it is not in your repo. It was something you pasted here on the chat.
arif hussain
@arifhussain0
Aug 15 2016 07:02
because arr is an array and its first element is itself an array which needs filtering
Mark Todd
@Knochenmark
Aug 15 2016 07:03
@arifhussain0 lol no? arr is a flat array
arif hussain
@arifhussain0
Aug 15 2016 07:03
@Knochenmark
Markus Kiili
@Masd925
Aug 15 2016 07:03
@BenjamWondafrash You have to post the code because I have bad memory.
Mark Todd
@Knochenmark
Aug 15 2016 07:03
@arifhussain0 destroyer([1, 2, 3, 1, 2, 3], 2, 3) where is the nested array? :D
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:03
@Masd925 I will paste when i get on the desktop.
Markus Kiili
@Masd925
Aug 15 2016 07:04
@arifhussain0 The only parameter arr only catches the first passed argument [1, 2, 3, 1, 2, 3].
arif hussain
@arifhussain0
Aug 15 2016 07:04
but then why the function gets just one input arr??
Mark Todd
@Knochenmark
Aug 15 2016 07:05
@arifhussain0 arr is just a flat arr, the rest of your arguments you have to split into an array
@arifhussain0 var args = [].slice.call(arguments);
args.splice(0,1);
@arifhussain0 the rest is just filtering ;)
Markus Kiili
@Masd925
Aug 15 2016 07:06
@arifhussain0 You can loop the arguments object or do as @Knochenmark told.
arif hussain
@arifhussain0
Aug 15 2016 07:06
could u explain it a bit please?
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:06
@arifhussain0 Every function has an arguments property. You need to look into that.
arif hussain
@arifhussain0
Aug 15 2016 07:06
ok thanks :)
Mark Todd
@Knochenmark
Aug 15 2016 07:06
@arifhussain0 creates an arguments array and throws the first index away, since thats your arr parameter already
Markus Kiili
@Masd925
Aug 15 2016 07:07
@Knochenmark Doing [].slice.call(arguments,1) avoids splicing.
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:09
@Knochenmark General rule. Copy-paste anything @Masd925 says and study that.
arif hussain
@arifhussain0
Aug 15 2016 07:09
just one more adivce.. is it better to use these built in functions for the exercises or do i need to do it using long loopings and iterations on my own?
Markus Kiili
@Masd925
Aug 15 2016 07:10
@arifhussain0 I think you should learn both ways.
arif hussain
@arifhussain0
Aug 15 2016 07:10
because i find it really hard to remember all these built in functions and how they work?
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:10
@arifhussain0 Lot of times the built in functions are just skeletons. They may need loops.
Mark Todd
@Knochenmark
Aug 15 2016 07:11
@BenjamWondafrash you shouldnt follow him blindly :D
Markus Kiili
@Masd925
Aug 15 2016 07:11
@arifhussain0 Built-in functions can lead to easier to read and more compact code. Loops and basic operations are more efficient. So there are places for both ways. A matter of different programming paradigms actually.
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:11
@arifhussain0 Oh you mean like array built-in functions. Sry.
Mark Todd
@Knochenmark
Aug 15 2016 07:12
@arifhussain0 in general the functions in the description just give you a hint, sometimes they are misleading though
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:13
@Knochenmark Yes you should. Good learning experience.
LordYamanouchi
@LordYamanouchi
Aug 15 2016 07:13
Can anyone help with this?
$(".coraline").click(function(){
  var lon = "";
  var lat = "";
  if(navigator.geolocation){     navigator.geolocation.getCurrentPosition(function (position){    
    lon = position.coords.longitude;
    lat = position.coords.latitude;        });
}
  var url = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=f8baf145d3ef928fe6561a3548ce2e55";
$.getJSON(url, function(data){
     $("#position").html(data.main.temp);
     });
});
Liew Xun
@damakuno
Aug 15 2016 07:14
so you're also using the open weather map api
Markus Kiili
@Masd925
Aug 15 2016 07:14
@BenjamWondafrash Stop eating mushroom and listen to @Knochenmark Don't follow anyone's shoe
Liew Xun
@damakuno
Aug 15 2016 07:14
what exactly do you need help with?
Benjam Wondafrash
@BenjamWondafrash
Aug 15 2016 07:15
I am a stalker
Liew Xun
@damakuno
Aug 15 2016 07:15
me too
Mark Todd
@Knochenmark
Aug 15 2016 07:15
@Masd925 good catch though with the call argument ;)
Harrison Freeman
@HarrisonLib
Aug 15 2016 07:42
Vvvvvvvvvvvvvvv www
Xx
BackBencherNewBie
@BackBencherNewBie
Aug 15 2016 07:44
Help Please.
CamperBot
@camperbot
Aug 15 2016 07:44

:point_right: algorithm no repeats please [wiki]

Algorithm No Repeats Please

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: Problem Explanation:

This task requires us to return the number of total permutations of the provided string that don't have repeated consecutive letters. It is to be assumed that all characters in the provided string are each unique. For example, aab should return 2 because it has 6 total permutations (aab, aab, aba, aba, baa, baa), but only 2 of them (aba and aba) don't have the same letter (in this case a) repeating.

To achieve that, we'll have to look at each possible permutation of a string. There are several ways to do that. A common interview question is building a function that collects all permutations of a string. There are several tutorials available on the internet on how to do that.

Potential Methods Used As Solution

Recursive Method

This task can be daunting even after watching a tutorial. To write a recursive solution, you will want to send each new use of the function three inputs:

  1. A new string (or character array) that is being built.
  2. A position in your new string that's going to be filled next.
  3. An idea of what characters (more specifically positions) from the original string have yet to be used.

:pencil: read more about algorithm no repeats please on the FCC Wiki

r2d2
@UsamaHameed
Aug 15 2016 07:46
So are you a newbie back bencher or already a back bencher who is new here?
Just to clear things
BackBencherNewBie
@BackBencherNewBie
Aug 15 2016 07:46
First One

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

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

r2d2
@UsamaHameed
Aug 15 2016 07:47
Is this recursion?
BackBencherNewBie
@BackBencherNewBie
Aug 15 2016 07:48
Yes but till only the array length
r2d2
@UsamaHameed
Aug 15 2016 07:49
You need to use the length of the variable
Not the function
BackBencherNewBie
@BackBencherNewBie
Aug 15 2016 07:49
ok got it right.
thanks @UsamaHameed
CamperBot
@camperbot
Aug 15 2016 07:50
backbenchernewbie sends brownie points to @usamahameed :sparkles: :thumbsup: :sparkles:
:cookie: 466 | @usamahameed |http://www.freecodecamp.com/usamahameed
Michał
@stegent
Aug 15 2016 07:57
JS - Can anyone explain to me when property name should be in "property" and why?
I mean property key
Markus Kiili
@Masd925
Aug 15 2016 07:59
@stegent Object property is a key-value pair, so I don't get your question.
r2d2
@UsamaHameed
Aug 15 2016 07:59
@stegent It is your choice I think.
David Beczuk
@dbeczuk
Aug 15 2016 08:00
Hey people.
can anyone help explaining something to me?
r2d2
@UsamaHameed
Aug 15 2016 08:00
If you want the key to be a string, use "", if not use a number may be etc
@dbeczuk people here will. just ask
Michał
@stegent
Aug 15 2016 08:01
@Masd925 I mean what is the diffrence between:
"key":"value" and key:"value"
David Beczuk
@dbeczuk
Aug 15 2016 08:01
function updateRecords(id, prop, value) {
  if (prop === "" || value === "") {
    return collection;
  } else {
    if (prop === "tracks") {
      if (collection[id].hasOwnProperty(prop)){
        collection[id][prop].push(value);
      } else {
        collection[id][prop] = [];
        collection[id][prop].push(value);
      }
    } else {
      collection[id][prop] = value;
    }
  }
  return collection;
}
Can anyone explain why my function does not evaluate when any of the prop or value is empty?
jamesmillerho
@jamesmillerho
Aug 15 2016 08:01
found a crazy version of permutation
function perm(inputArray){

var result = inputArray.reduce(function permute(res, item, key, arr) {
    return res.concat(arr.length > 1 && arr.slice(0, key).concat(arr.slice(key + 1)).reduce(permute, []).map(function(perm) { return [item].concat(perm); }) || item);
}, []);
    return result;
  }

  perm([1, 2, 3]);
r2d2
@UsamaHameed
Aug 15 2016 08:01
@jamesmillerho what challenge is that?
Markus Kiili
@Masd925
Aug 15 2016 08:02
@stegent JS object literal has that freedom to use quotes on the key if you like. Some keys need them though.
jamesmillerho
@jamesmillerho
Aug 15 2016 08:02
no repeats please @UsamaHameed
Michał
@stegent
Aug 15 2016 08:02
@Masd925 ok, thanks for answer
CamperBot
@camperbot
Aug 15 2016 08:02
stegent sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2294 | @masd925 |http://www.freecodecamp.com/masd925
r2d2
@UsamaHameed
Aug 15 2016 08:02
stuck at that challenge @jamesmillerho
:P
jamesmillerho
@jamesmillerho
Aug 15 2016 08:02
another crazy version:
function permAlone(str,lc) {
  if (str.length===0)
    return 1;
  var res=0;
  for (var i=0; i<str.length; i++)
    if (str[i]!==lc)
      res+=permAlone(str.substring(0,i)+str.substring(i+1),str[i]);
  return res;
}

permAlone('aab');
David Beczuk
@dbeczuk
Aug 15 2016 08:03
@stegent From my recolection a key needs quotes when is not a single word for example "My Key": 123;
Markus Kiili
@Masd925
Aug 15 2016 08:03
@stegent If you have JSON text or string, there you need those quotes.
jamesmillerho
@jamesmillerho
Aug 15 2016 08:03
@UsamaHameed I figured it out after 2 weeks
r2d2
@UsamaHameed
Aug 15 2016 08:04
@jamesmillerho I am trying to make my own permutation function. Half way there. But this is good
David Beczuk
@dbeczuk
Aug 15 2016 08:05
So anyone have an explanation to my problem :P?
Michał
@stegent
Aug 15 2016 08:06
@dbeczuk @Masd925 so for example when i would like to use two word key with space between them, e.g "Key Key"? and when I want to access it I should use brackets e.g. myObj["Key Key"]?
David Beczuk
@dbeczuk
Aug 15 2016 08:06
@stegent yup
r2d2
@UsamaHameed
Aug 15 2016 08:07
@dbeczuk don't see a problem there
where is your collection object?
Markus Kiili
@Masd925
Aug 15 2016 08:07
@stegent Yes, the dot notation only works if the key is a valid JS identifier name, so you need brackets if the key has a space, forbidden characters or starts with a number etc.
David Beczuk
@dbeczuk
Aug 15 2016 08:08
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
r2d2
@UsamaHameed
Aug 15 2016 08:08
Why does FCC keep on resetting my solutions to previous challenges?
David Beczuk
@dbeczuk
Aug 15 2016 08:08
above my function @UsamaHameed
Markus Kiili
@Masd925
Aug 15 2016 08:09
@UsamaHameed Try to enter them from the code portfolio.
Michał
@stegent
Aug 15 2016 08:09
@dbeczuk @Masd925 thanks
CamperBot
@camperbot
Aug 15 2016 08:09
:cookie: 211 | @dbeczuk |http://www.freecodecamp.com/dbeczuk
:warning: stegent already gave masd925 points
stegent sends brownie points to @dbeczuk and @masd925 :sparkles: :thumbsup: :sparkles:
r2d2
@UsamaHameed
Aug 15 2016 08:11
The code portfolio? @Masd925
nvm got it
Markus Kiili
@Masd925
Aug 15 2016 08:11
@UsamaHameed Click your picture on the top right on FCC page.
Louis Johnson
@louisgjohnson
Aug 15 2016 08:12
Ive been asked to do a small task for a job
but I have no idea how to access the api
https://www.object360.net/docs/token

$.ajax({
  'url' : 'https://www.object360.net/token',
  'type' : 'GET',
  'success' : function(data) {
    if (data == "success") {
      alert('request sent!');
    }
  }
});
my error "XMLHttpRequest cannot load https://www.object360.net/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404."
r2d2
@UsamaHameed
Aug 15 2016 08:14
@dbeczuk read the instructions again
If you just want to check if the function is working or not, just do a console.log
@Masd925 found it
Louis Johnson
@louisgjohnson
Aug 15 2016 08:15
can anyone help?
David Beczuk
@dbeczuk
Aug 15 2016 08:16
@UsamaHameed well, thanks I will step back from it and come back to it later. I tried console.log but I can't figure out what I am missing there.
CamperBot
@camperbot
Aug 15 2016 08:16
dbeczuk sends brownie points to @usamahameed :sparkles: :thumbsup: :sparkles:
:cookie: 467 | @usamahameed |http://www.freecodecamp.com/usamahameed
r2d2
@UsamaHameed
Aug 15 2016 08:17
@camperbot hi
No?
Young Mary-Claret Nnenna
@claretyoung20
Aug 15 2016 08:20
this my show local weather project. it showing in my friends laptop but can show in code pen page..
r2d2
@UsamaHameed
Aug 15 2016 08:21
@claretyoung20 what is it showing?
Don't understand your question
Young Mary-Claret Nnenna
@claretyoung20
Aug 15 2016 08:22
it work perfect well on both my phone and friends laptop but doesnot work on my
lapton or on my code pen page
r2d2
@UsamaHameed
Aug 15 2016 08:23
@claretyoung20 It is working for me. What does not work on your laptop?
The whole pen?
Young Mary-Claret Nnenna
@claretyoung20
Aug 15 2016 08:24
it showing only two button on my laptop
jamesmillerho
@jamesmillerho
Aug 15 2016 08:32
it turns out that it is actually a bad code although it looks so compact
// console.time();
function permutation(str){
  return str.split("").reduce(function permute(a,b,c,d){
   return a.concat(d.length>1 && d.slice(0,c).concat(d.slice(c+1)).reduce(permute,   []).map(function(perm){return [b].concat(perm);})||b);},[]).map(function(a){return a.length>1 ?a.join("") :a;});
}

permutation('abcdefghi');
// console.timeEnd();
it takes more than 10 second to calculate the result. Normal code takes only 0.3-0.8 second
a holy 10 second...:)
Louis Johnson
@louisgjohnson
Aug 15 2016 08:34
do these docs make sense to anyone else? https://www.object360.net/docs/token
LaurenCodes
@LaurenCodes
Aug 15 2016 08:34
@pahosler Yes, I think the correct format was {filter:“item1,item2,item3”}
pahosler
@pahosler
Aug 15 2016 08:35
@LaurenCodes hi Lauren, you got it working?
@LaurenCodes I've started to write a nodejs interface to that api, it's fun to play with!
David Beczuk
@dbeczuk
Aug 15 2016 08:39
@louisgjohnson what is the exact task?
Liew Xun
@damakuno
Aug 15 2016 08:48
@dbeczuk he wants to create a page where a user can log in and view the user's details, and log out
I guess?
Louis Johnson
@louisgjohnson
Aug 15 2016 08:49

https://www.object360.net/docs/token
This is a token API that allows you to create, validate and invalidate a user.

The test credentials are:
username: testuser
password: test

Functional requirements:
Ability to login with the test credentials
Display the details of the authenticated user
Ability to logout ( ensure the token has been invalidated )

the task isnt really the issue I just cant seem to get access to the server
@dbeczuk
Michał
@stegent
Aug 15 2016 08:51
I have a problem with Record Collection. I need to access nested objects and I obviously am doing it wrong. If anyone could take a look and tell how I should change it?
``````
masterbunny
@m4sterbunny
Aug 15 2016 08:52

I am in JS Fiddle struggling to fiddle, I want to output the array collections I tried variations on this:

function out()
{
var args = Array.prototype.slice.call(arguments, 0);
document.getElementById('output').innerHTML += args.join(" ") + "\n";
}
out("Hello world!");

// End of test output hello world
// NB has this in HTML <pre id="output"></pre>

console.log(true);

// End of ?? returns true in consol log

var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// end of array

out(collection);

```
This is what I get:
Hello world!
[object Object]

Michał
@stegent
Aug 15 2016 08:52



// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));


// Only change code below this line
function updateRecords(id, prop, value) {

 collection.id.prop.push(value);

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
r2d2
@UsamaHameed
Aug 15 2016 08:53
@stegent whenever using variables, use bracket notation.
pahosler
@pahosler
Aug 15 2016 08:54
@louisgjohnson are you trying to do it via the api? or just in gerneral??? I logged into the server with those creds but not via the api...
Michał
@stegent
Aug 15 2016 08:54
@UsamaHameed like this?
collection[id][prop].push([value]);
Louis Johnson
@louisgjohnson
Aug 15 2016 08:55

@pahosler how did you login?

Im trying to use the api to make a login auth myself

its for a job code test
r2d2
@UsamaHameed
Aug 15 2016 08:55
collection[id][prop].push(value); @stegent
Check using console.log
pahosler
@pahosler
Aug 15 2016 08:56
just went to https://www.object360.net/ and logged in
Andre
@dredamonsta1
Aug 15 2016 08:56
hello world I'm trying to get this
CamperBot
@camperbot
Aug 15 2016 08:56

welcome to FreeCodeCamp @dredamonsta1!

David Beczuk
@dbeczuk
Aug 15 2016 08:56
@stegent let me know if you manage to make it work, I am on the same task and my function does not validate empty values
Michał
@stegent
Aug 15 2016 08:56
@UsamaHameed TypeError: collection[id][prop] is undefined
Louis Johnson
@louisgjohnson
Aug 15 2016 08:56
what did you use for the user name and pw? @pahosler
pahosler
@pahosler
Aug 15 2016 08:57
testuser/test yes...
it's a map
with geolocation
shows my house LOL
David Beczuk
@dbeczuk
Aug 15 2016 08:57
@stegent yes, you will need to check if the property exists with id.hasOwnProperty(prop)
it should return true if the property exists
r2d2
@UsamaHameed
Aug 15 2016 08:57
@stegent that means that key, value pair does not exist
Now, implement the instructions
Andre
@dredamonsta1
Aug 15 2016 08:58
hello world I'm trying to get this manipulate arrays with unshift section done and idk whats off
CamperBot
@camperbot
Aug 15 2016 08:58

welcome to FreeCodeCamp @dredamonsta1!

Andre
@dredamonsta1
Aug 15 2016 08:58

// 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.
myArray.unshift(["paul", 35]);

Louis Johnson
@louisgjohnson
Aug 15 2016 08:58
@pahosler yeah that's an example of what i need to build
pahosler
@pahosler
Aug 15 2016 08:59
@louisgjohnson you need to build the auth api? and the page?
Louis Johnson
@louisgjohnson
Aug 15 2016 09:00
auth api
they just gave me the docs
this is my code

$.get('https://www.object360.net/token', function(data, textStatus)
{
        alert("Done, with the following status: " + textStatus + ". Here is the response: " + data);
});
XMLHttpRequest cannot load https://www.object360.net/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404.
eliecerthoms
@eliecerthoms
Aug 15 2016 09:01
guys , do you know of any good javascript ide where I can test code without using a browser's console?
it's annoying to have to remember to always hit shift + enter for the code not to run.
pahosler
@pahosler
Aug 15 2016 09:02
@eliecerthoms get nodejs installed on your box and use atom.io, that's what I do...
eliecerthoms
@eliecerthoms
Aug 15 2016 09:02
got them both, didn't know you could do that
Dan Couper
@DanCouper
Aug 15 2016 09:02
repl.it. But the browser console is better than anything else in terms of functionality.
pahosler
@pahosler
Aug 15 2016 09:02
@louisgjohnson you prob need to use node... something like...
friscodisco
@friscodisco
Aug 15 2016 09:03
@eliecerthoms have you tried pythontutor.com i use it to watch line by line
LaurenCodes
@LaurenCodes
Aug 15 2016 09:04
This message was deleted
eliecerthoms
@eliecerthoms
Aug 15 2016 09:04
whoa, cool af @friscodisco, thanks
CamperBot
@camperbot
Aug 15 2016 09:04
:cookie: 273 | @friscodisco |http://www.freecodecamp.com/friscodisco
eliecerthoms sends brownie points to @friscodisco :sparkles: :thumbsup: :sparkles:
eliecerthoms
@eliecerthoms
Aug 15 2016 09:04
@pahosler thanks to you too
CamperBot
@camperbot
Aug 15 2016 09:04
eliecerthoms sends brownie points to @pahosler :sparkles: :thumbsup: :sparkles:
:cookie: 344 | @pahosler |http://www.freecodecamp.com/pahosler
pahosler
@pahosler
Aug 15 2016 09:05
@louisgjohnson
const https = require('https');
const url = "https://api.nytimes.com/svc/search/v2/articlesearch.json?api-key=";
const apikey = "api-key";

var q="&q="+process.argv[2];
var fl="&fl=web_url,headline,snippet,multimedia"
var search = url+apikey+q+fl;
var data=[];
https.get(search, (response) => {
  response.setEncoding('utf8');
  response.on('data',(chunk)=>{
    data.push(chunk);

  }).on('end', function(){
    data = (JSON.parse(data));
    console.log(data)
    // data = data.join('');
    data.response.docs.reduce((prev,curr)=>{
      console.log(curr.web_url+'\n',curr.headline.main+'\n',curr.snippet+'\n\n');
    },[]);
  })
});
not exactly, but it should give you an idea...
Louis Johnson
@louisgjohnson
Aug 15 2016 09:05
ill try it
but the weird thing is its for a front end developer job
LaurenCodes
@LaurenCodes
Aug 15 2016 09:06
Need a little regex help! For the following url,
http://yaledailynews.com/blog/2001/02/19/yale-invites-clinton-amid-controversy/
How can I match http://yaledailynews.com/blog/, four numbers, then any character sequence?
I tried http://yaledailynews.com/blog/[\d]{4}[.*] but it wasn’t correct
alhajit21
@alhajit21
Aug 15 2016 09:07
I need help with Escape Sequences in Strings
whats wrong with my code // var myStr = "\ \n \t \r \t";
friscodisco
@friscodisco
Aug 15 2016 09:08
sometimes trying regex in this can be helpful http://www.regextester.com
pahosler
@pahosler
Aug 15 2016 09:08
regex = /http:\/\/yaledailynew\.com\/blog\/\d{4}.*/
Mateusz Szymański
@matszym
Aug 15 2016 09:08
@louisgjohnson acording to the docs, get methods are only for validation of token. Did you create one first, with post method?
pahosler
@pahosler
Aug 15 2016 09:08
maybe???
Louis Johnson
@louisgjohnson
Aug 15 2016 09:09
@matszym nope, how would I do that? :/
pahosler
@pahosler
Aug 15 2016 09:09
maybe was for @LaurenCodes
LaurenCodes
@LaurenCodes
Aug 15 2016 09:09
I will try it out in that site!
pahosler
@pahosler
Aug 15 2016 09:09
@louisgjohnson you can use post also
Michał
@stegent
Aug 15 2016 09:10
@alhajit21 in that challege you got to make sentence just like in example
Mateusz Szymański
@matszym
Aug 15 2016 09:10
@louisgjohnson https://www.object360.net/docs/token
on the top of the page, there is documented api endpoint that accepts post method and 2 parameters, username and password
pahosler
@pahosler
Aug 15 2016 09:10
you need to go through the nodejs exercises, they will help you tremendously and it really doesn't take horribly long
Michał
@stegent
Aug 15 2016 09:10
@alhajit21 so the output of your code looks like this:
FirstLine
\SecondLine\
ThirdLine
Mateusz Szymański
@matszym
Aug 15 2016 09:11
@louisgjohnson first, you create token, by making post request with valid username and password, only then you can use get method and check if token is valid
masterbunny
@m4sterbunny
Aug 15 2016 09:12
can anyone help me fiddle in JS fiddle?
https://jsfiddle.net/m4sterbunny/Le55vfcy/
Michał
@stegent
Aug 15 2016 09:12
@alhajit21 here is text with written escape sentences: " FirstLine newline backslashSecondLine backslash carriage-return ThirdLine"
pahosler
@pahosler
Aug 15 2016 09:12
what's the link @m4sterbunny
nm
LaurenCodes
@LaurenCodes
Aug 15 2016 09:13
@pahosler thank you! that worked, im a total regex noob
CamperBot
@camperbot
Aug 15 2016 09:13
laurencodes sends brownie points to @pahosler :sparkles: :thumbsup: :sparkles:
:cookie: 345 | @pahosler |http://www.freecodecamp.com/pahosler
alhajit21
@alhajit21
Aug 15 2016 09:13
@stegent var myStr = "First \n Second \t \r Third";
masterbunny
@m4sterbunny
Aug 15 2016 09:13
This message was deleted
pahosler
@pahosler
Aug 15 2016 09:13
did it work?? @LaurenCodes
Louis Johnson
@louisgjohnson
Aug 15 2016 09:13
@matszym how would I create a token though?
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "https://www.object360.net/token", true);
xhttp.send();
Liew Xun
@damakuno
Aug 15 2016 09:14
@louisgjohnson did it work
i mean uhhh
Louis Johnson
@louisgjohnson
Aug 15 2016 09:14
im still getting the same error
Mateusz Szymański
@matszym
Aug 15 2016 09:14
@louisgjohnson where are you passing username and password?
Louis Johnson
@louisgjohnson
Aug 15 2016 09:14
how would I pass the username and pw? :/
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:14

// Setup
var myStr = "Jello World";

// Only change code below this line

myStrxamarin/xamarin-android@a16673d = "H"; // Fix Me

Michał
@stegent
Aug 15 2016 09:14
@alhajit21 FirstLine SecondLine etc
Mateusz Szymański
@matszym
Aug 15 2016 09:15
@louisgjohnson
PARAMETERS:

username
    structure:        (string)
    length:            (3 <-> 40)
    validate        required | type:username | user:exists | user:active

password
    structure:        (string)
    length:            (10 <-> 256)
    validate        required | type:password | user_password:match
Liew Xun
@damakuno
Aug 15 2016 09:15
@louisgjohnson front end usually means client side code, which is what you're doing while back end means server side
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:15
How do i paste code in a black box in the chat room?
Liew Xun
@damakuno
Aug 15 2016 09:15
and database
masterbunny
@m4sterbunny
Aug 15 2016 09:15
@pahosler my tiny ambition right now is to be able to output the contents of collection
The closest I have come is getting the console to provide: Object {1245: Object, 2468: Object, 2548: Object, 5439: Object} (I had more data in my array then)
Liew Xun
@damakuno
Aug 15 2016 09:15
so it isn't that weird for your employer to ask you to demonstrate how to use an API
Louis Johnson
@louisgjohnson
Aug 15 2016 09:15
no i know that
but someone was saying I should be using node?
Liew Xun
@damakuno
Aug 15 2016 09:16
@louisgjohnson you mean how to uhhh put your values into the parameters?
Michał
@stegent
Aug 15 2016 09:16
@alhajit21 also remember to use backslash before secondline
Darth Skywalker
@adityaparab
Aug 15 2016 09:16

@CoderJSanchez : if you type

```js
console.log('test');
```

you will see it as

console.log('test');
Louis Johnson
@louisgjohnson
Aug 15 2016 09:16
@matszym how do i pass the parameters in the call though?
@damakuno yes
Michał
@stegent
Aug 15 2016 09:17
@alhajit21 "FirstLine\n\" this how first part should look like
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:17

'''js// Setup
var myStr = "Jello World";

// Only change code below this line

myStr[0] = "H"; // Fix Me'''

CamperBot
@camperbot
Aug 15 2016 09:17
:bulb: to format code use backticks! ``` more info
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:18

```// Setup
var myStr = "Jello World";

// Only change code below this line

myStr[0] = "H"; // Fix Me```

Mateusz Szymański
@matszym
Aug 15 2016 09:18

@louisgjohnson
https://api.jquery.com/jquery.post/

second parametr

const url = "your url";
const data = {
  username: "user",
  password: "password12345678!@#"
}
$.post(url, data);
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:18

```js// Setup
var myStr = "Jello World";

// Only change code below this line

myStrxamarin/xamarin-android@a16673d = "H"; // Fix Me```

Darth Skywalker
@adityaparab
Aug 15 2016 09:18

@CoderJSanchez : you need to type your code on new line after ```js

you can go to new line by hitting shift+enter

Louis Johnson
@louisgjohnson
Aug 15 2016 09:19
thanks @matszym Ill see how i go with that
CamperBot
@camperbot
Aug 15 2016 09:19
louisgjohnson sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 141 | @matszym |http://www.freecodecamp.com/matszym
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:19
ahh, thanks!
Darth Skywalker
@adityaparab
Aug 15 2016 09:19
your closing ``` must also be on new line after your code ends
Mark Adel
@MarkAdell
Aug 15 2016 09:19
What is wrong with my Check for Palindromes problem? Thanks
function palindrome(str) {
  str.toLowerCase();
  var s = "";
  for(var i = 0; i < str.length; i++)
    if(str[i] >= 'a' && str[i] <= 'z' || str[i] >= '0' && str[i] <= '9')
      s += str[i];
  console.log(s);
  for(var y = 0; y < s.length/2; y++)
    if(s[y] != s[s.length-1-y])
      return false;
  return true;
}
palindrome("eye");
Louis Johnson
@louisgjohnson
Aug 15 2016 09:20
Im still getting this though "XMLHttpRequest cannot load https://www.object360.net/docs/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 405."
RIles Le Roy
@iamriles
Aug 15 2016 09:20
could some one help me figure out why my JS isnt updating the page https://codepen.io/Iamriles/pen/xOmZRz?editors=1010
Mateusz Szymański
@matszym
Aug 15 2016 09:20
@louisgjohnson btw, what is this site? I assume to authenticate with username and pasword, you have to create account there first right? Yet there is no account creation form anywhere
its just been given to me as a test
they told me

Could you please build an authentication single page application for the following Service API:
https://www.object360.net/docs/token
This is a token API that allows you to create, validate and invalidate a user.

The test credentials are:
username: testuser
password: test

Functional requirements:
Ability to login with the test credentials
Display the details of the authenticated user
Ability to logout ( ensure the token has been invalidated )

@matszym
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:22
thanks
Darth Skywalker
@adityaparab
Aug 15 2016 09:22
@louisgjohnson : Looks fairly simple :D
Mateusz Szymański
@matszym
Aug 15 2016 09:22
@louisgjohnson So, are you making post request to docs? You should make post request to url specified in documentation, with is I asume
https://www.object360.net/token, not https://www.object360.net/docs/token
Louis Johnson
@louisgjohnson
Aug 15 2016 09:22
@adityaparab I feel like its simple to do but I am having trouble connecting to the api
ive tried both
@matszym
but both return the same error
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:22
// Setup
var myStr = "Jello World";

// Only change code below this line

myStr[0] = "H"; // Fix Me
Liew Xun
@damakuno
Aug 15 2016 09:22
@louisgjohnson probably because you're requesting from a different domain?
Darth Skywalker
@adityaparab
Aug 15 2016 09:23
@louisgjohnson : Are you supposed to build an API or you're jost gonna write a ui code to consume that API?
Louis Johnson
@louisgjohnson
Aug 15 2016 09:23
I just have to user their api
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:23
Shouldnt i just have to change var myStar to "Hello World"?
alhajit21
@alhajit21
Aug 15 2016 09:23
@stegent var myStr = "FirstLine\n\"SecondLine /t \r \t ThirdLine";
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:23
...sorry var myStr
Louis Johnson
@louisgjohnson
Aug 15 2016 09:23
no matter what I do, i get
"XMLHttpRequest cannot load https://www.object360.net/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404."
masterbunny
@m4sterbunny
Aug 15 2016 09:24
@pahosler what the heck?! How do I link you to current Fiddle not the other fork?! I did an update if that helps!
Mark Adel
@MarkAdell
Aug 15 2016 09:24
Thank you I figured out the problem.
Markus Kiili
@Masd925
Aug 15 2016 09:24
@CoderJSanchez Strings are immutable, so you need to construct a new string and assign it to the variable.
Darth Skywalker
@adityaparab
Aug 15 2016 09:24
@CoderJSanchez : Strings are immutable you can't do it that way
@louisgjohnson : Have you tried https://www.object360.net/token?callback=??
Also what are you using for your UI code? jQuery/angular/react?
pahosler
@pahosler
Aug 15 2016 09:24
@m4sterbunny on the right side select add buddy or some such, I pretty much never use fiddle
Louis Johnson
@louisgjohnson
Aug 15 2016 09:24
ill try now
Im supposed to use react
Julio Cesar Sanchez
@CoderJSanchez
Aug 15 2016 09:25
@adityaparab so I would create myStr = "Hello World" right?
Louis Johnson
@louisgjohnson
Aug 15 2016 09:25
but i was just testing the request with jquery @adityaparab
Darth Skywalker
@adityaparab
Aug 15 2016 09:25
@CoderJSanchez : correct!
@louisgjohnson : Yes. if you're using react, you're gonna have to use jquery for ajax anyway
Louis Johnson
@louisgjohnson
Aug 15 2016 09:26
ah okay @adityaparab
Darth Skywalker
@adityaparab
Aug 15 2016 09:26
so just add an additional parameter to your api url called ?callback=? and you should be able to GET the data
pahosler
@pahosler
Aug 15 2016 09:26
@m4sterbunny then you'll need to post the link to me that it gives you
Darth Skywalker
@adityaparab
Aug 15 2016 09:26
@damakuno : I think so
Louis Johnson
@louisgjohnson
Aug 15 2016 09:27
```
```
const url = "https://www.object360.net/token?callback=?";
const data = {
  username: "testuser",
  password: "test"
}
$.post(url, data);
Michał
@stegent
Aug 15 2016 09:27
@alhajit21 var myStr = "FirstLine\n\"SecondLine /t \r \t ThirdLine" - ok so firstly to output backslash you got to make double backslash "\" after second line you only got to make to escpaes - backslash and carriage-return- "\r"
Louis Johnson
@louisgjohnson
Aug 15 2016 09:27
did you mean like that @adityaparab ?
chaitanya ashtekar
@chaitanyaashtekar
Aug 15 2016 09:28
@adityaparab finished your tic tac toe ?
Darth Skywalker
@adityaparab
Aug 15 2016 09:29
Oh! for, POST? I'm afraid that cant be done
@chaitanyaashtekar : I haven't yet
dine with calc
Louis Johnson
@louisgjohnson
Aug 15 2016 09:29
i found this
I think thats what im supposed to use i guess
chaitanya ashtekar
@chaitanyaashtekar
Aug 15 2016 09:29
@adityaparab okay
Darth Skywalker
@adityaparab
Aug 15 2016 09:29
@louisgjohnson : I guess yes
alhajit21
@alhajit21
Aug 15 2016 09:29
@stegent so dont use \t
Darth Skywalker
@adityaparab
Aug 15 2016 09:30
@louisgjohnson : then I'm assuming they have CORS enabled so you dont have to do any pg jsonp settings
Louis Johnson
@louisgjohnson
Aug 15 2016 09:30
still getting this weird error "XMLHttpRequest cannot load https://www.object360.net/api/v1/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."
Darth Skywalker
@adityaparab
Aug 15 2016 09:31
@louisgjohnson Can you show your UI code?
Louis Johnson
@louisgjohnson
Aug 15 2016 09:31
const url = "https://www.object360.net/api/v1/token";
const data = {
  username: "testuser",
  password: "test"
}
$.post(url, data);
but it happens with any ajax request i make
as well as post
and get
Michał
@stegent
Aug 15 2016 09:32
@alhajit21 yes, you should only use three types of escapes: "\", "\n", "\r"; write how it went! ;)

still struggling with Record Collection, can anyone check this out and help to understand what should I do?

 ``` 

// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

collection[id][prop].push(value);

return collection;
}

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

```

Blauelf
@Blauelf
Aug 15 2016 09:35
@stegent Chat will interpret \ as an escape character itself, so either use \\ to represent a single \, or use backticks to inline code \\
Michał
@stegent
Aug 15 2016 09:35
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

collection[id][prop].push(value);

return collection;
Blauelf
@Blauelf
Aug 15 2016 09:36
@stegent That push statement only works as specified if prop is "tracks", value is not "", and collection[id][prop] is an array. It should only be run if all three are met.
You'll need three if/else (or equivalent code) for that one.
cuongss98
@cuongss98
Aug 15 2016 09:37
hello everyone..can u tell me "studlyCapVar should use camelCase in both declaration and assignment sections." mean what I can do ?
masterbunny
@m4sterbunny
Aug 15 2016 09:37
@pahosler You edited -right? But I lost my hello world!
Michał
@stegent
Aug 15 2016 09:38
@Blauelf how should I change it?
Darth Skywalker
@adityaparab
Aug 15 2016 09:39
@louisgjohnson : I don't know why you're getting that Error, when I run it locally, I am allowed to make that cross domain call
import React from 'react';
import { render } from 'react-dom';
import $ from 'jquery';

class App extends React.Component {

    componentDidMount(){
        const url = "https://www.object360.net/api/v1/token";
        const data = { username: "testuser", password: "test" }
        $.post(url, data);
    }

  render() {
    return (
      <div>
        Lets Check
      </div>
    )
  }
}

render(<App/>, document.querySelector("#app"));
Blauelf
@Blauelf
Aug 15 2016 09:39
@stegent Add a few tests. For example, if value is empty string, remove the property using the delete operator. Nothing else to test for, if value is empty string, delete. Then have another if in its else path.
Louis Johnson
@louisgjohnson
Aug 15 2016 09:40
@adityaparab so its my computer not the server?
Michał
@stegent
Aug 15 2016 09:40
and what in case that prop is "artist">
?
Darth Skywalker
@adityaparab
Aug 15 2016 09:40
@louisgjohnson : Not sure what it is.
Louis Johnson
@louisgjohnson
Aug 15 2016 09:41
but you can access it right? @adityaparab
Darth Skywalker
@adityaparab
Aug 15 2016 09:41
@louisgjohnson : To make it even stricter I used with Chrome and Safari and their API has CORS enabled. So you should be able to do it
Yeah. I am able to see the request going through
Blauelf
@Blauelf
Aug 15 2016 09:41

@stegent That should be subject to the second if in that chain, in that case it's a simple assignment, so second test should handle whether prop unequals "tracks" (using unequal here makes the if-elseif chain look more flat)

Another way would be using complex conditions combined using &&.

Louis Johnson
@louisgjohnson
Aug 15 2016 09:42
well im just glad I know it works, im gonna play around with a few things and see if I can get a fix happening @adityaparab
why does this shit have to happen when time is of importance xD
alhajit21
@alhajit21
Aug 15 2016 09:42
@stegent thanks I passed it now