These are chat archives for FreeCodeCamp/HelpJavaScript

25th
May 2017
john94
@lpy1994
May 25 2017 00:00
//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 lookUp(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
 if(contacts[i].hasOwnProperty(["firstName"])&&contacts[i].hasOwnProperty(prop)&&contacts[i]["firstName"]==firstName){
                   return contacts[i][prop];
               }else if(contacts[i].hasOwnProperty(prop)){
                   return   "No such contact";
               }else if(contacts[i].hasOwnProperty(["firstName"])){
                return "No such property";
               }
 }

// Only change code above this line
}

// Change these values to test your function
lookUp("Sherlock", "likes");
yjxhome
@yjxhome
May 25 2017 00:01
it in my compute is ok, but it err on the webpage
Xarri Jorge
@xarrijorge
May 25 2017 00:01
Keon Samuel
@keonsam
May 25 2017 00:02
@yjxhome your first if statement condition is wrong.
Xarri Jorge
@xarrijorge
May 25 2017 00:02
@ankerpeet i would use filter or assign to an empty if length is longer.
yjxhome
@yjxhome
May 25 2017 00:02
^-^
Keon Samuel
@keonsam
May 25 2017 00:03
firstName parameter is actually a name
not a property.
yjxhome
@yjxhome
May 25 2017 00:04
Thanks a lot guys!
moshe18
@moshe18
May 25 2017 00:04
Can anyone explain why I'm getting this I,'m A L,i,t,t,l,e T,e,a P,o,t
function titleCase(str) {
  var arr = str.split(" ");
  for (i = 0; i < arr.length; i++) {
    var temp = arr[i].split("");
    temp[0] = temp[0].toUpperCase();
    arr[i] = temp;
  }
  return arr.join(" ");
}

titleCase("I'm a little tea pot");
Frank McCroy
@fmccroy
May 25 2017 00:04
My For loop never advanced, the return statements kept cutting it short.. a ton of console.log statements helped me figure out the problems
Keon Samuel
@keonsam
May 25 2017 00:05
.split("")
john94
@lpy1994
May 25 2017 00:05
join("")
@moshe18
tawares07
@tawares07
May 25 2017 00:05
Hi guys! It´s me again =/. How can I add a new value ?
var myMusic = [
{
"artist": "Billy Joel","A-ha"
"title": "Piano Man","Take on me"
"release_year": 1973, 1985
"formats": [
"CS",
"8T",
"LP" ],["CS","LP"]
"gold": true
}
// Add record here
];
Manish Giri
@Manish-Giri
May 25 2017 00:05
add a , and add the second object after it
moshe18
@moshe18
May 25 2017 00:05
@lpy1994 how should I split and join every character
Manish Giri
@Manish-Giri
May 25 2017 00:05
myMusic is an array, that contains one object now
@tawares07
Xarri Jorge
@xarrijorge
May 25 2017 00:06
@moshe18 you are joining at empty space. join at every character ""
Manish Giri
@Manish-Giri
May 25 2017 00:06
@tawares07 ["CS","LP"] - see how this array has 2 elements, separated by ,
moshe18
@moshe18
May 25 2017 00:07
@kodinglife join(" ") i think just adds a space between every word of the original array after it is already capitalized
tawares07
@tawares07
May 25 2017 00:07
@Manish-Giri Like this: var myMusic = [
{
"artist": ["Billy Joel","A-ha"]
"title": ["Piano Man","Take on me"]
"release_year": [1973, 1985]
"formats": [
"CS",
"8T",
"LP" ],["CS","LP"]
"gold": true
}
Manish Giri
@Manish-Giri
May 25 2017 00:08
there's a comment
// Add record here
your second object goes after that
don't modify the existing object
@tawares07
moshe18
@moshe18
May 25 2017 00:08
@kodinglife var temp = arr[i].split(""); The problem has to be somewhere here
Xarri Jorge
@xarrijorge
May 25 2017 00:08
@moshe18 Naa. join("") joins the array at every character where as join(" ") joins the array at empty space
talshir
@talshir
May 25 2017 00:08

Looking for some help... why doesn't this code work? What am I missing?

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

// Only change code below this line
lookup = {
alpha: "Adams",
bravo: "Boston",
charlie: "Chicago",
delta: "Denver",
echo: "Easy",
foxtrot: "Frank"
};

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

tawares07
@tawares07
May 25 2017 00:09
@Manish-Giri I saw that but everytime there was a sintaxe error. I wiil try again! =)
Manish Giri
@Manish-Giri
May 25 2017 00:09
@talshir you're not assigning anything to result
moshe18
@moshe18
May 25 2017 00:10
@kodinglife I,'mAL,i,t,t,l,eT,e,aP,o,t Fine I followed your instructions but this is what I got
Manish Giri
@Manish-Giri
May 25 2017 00:10
you need to lookup the value of the property val from the lookup object and assign to result
@talshir
Xarri Jorge
@xarrijorge
May 25 2017 00:11
@moshe18 sorry, but when an array is joined the commas are removed. why are yours still there?
moshe18
@moshe18
May 25 2017 00:13
@kodinglife yeah, thats what I'm wondering
tawares07
@tawares07
May 25 2017 00:13

@Manish-Giri And now? var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here

{
"artist": "Aha",
"title": "Take on me",
"release_year": 1985,
"formats": [
"CS",
"8T",
"LP" ],
}

];

Does anybody could help me? On "Manipulating Complex Objects"
Gena
@genacatharine
May 25 2017 00:16
im confused what this task is asking about changing order of statements in function, i cant seem to return less than 5 statement

function orderMyLogic(val) {
if (val < 10) {
return "Less than 10";
} else if (val < 5) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}

// Change this value to test
orderMyLogic(4);

Zattara
@vpenha
May 25 2017 00:16
I am doing the Check for Palindromes, I keep on coming up with the error "Object doesn't support property or method 'reverse':
this is my code so far:
function palindrome(str) {
var palindrome = (str.toLowerCase().replace(/[\s#$%&*_^~@!'),.]/g, ''));
var reversed = str.reverse();
return true;
abraham anak agung
@padunk
May 25 2017 00:16
@moshe18 you have two .split("")
Zattara
@vpenha
May 25 2017 00:16
why is .reverse() not working?
if I figure that out, I will go ahead and use if statements
but, it's not working =(
abraham anak agung
@padunk
May 25 2017 00:17
@vpenha .reverse is not for string
Zattara
@vpenha
May 25 2017 00:17
@padunk how would you use .reverse in this case?
abraham anak agung
@padunk
May 25 2017 00:18
@vpenha you have to split the string first. .reverse is for array
Gena
@genacatharine
May 25 2017 00:18
can someone advise on Logical Order in If Else Statements
Zattara
@vpenha
May 25 2017 00:18
such as: var reversed = str
str.reverse()?
abraham anak agung
@padunk
May 25 2017 00:20
@vpenha you have to use str.split(' ') before you can reverse it
@genacatharine 4 is less than 10, when your if statement met the return on val<10 then it will exit the function
Gena
@genacatharine
May 25 2017 00:22
ok
thanks @padunk
CamperBot
@camperbot
May 25 2017 00:22
genacatharine sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @padunk |http://www.freecodecamp.com/padunk
Manish Giri
@Manish-Giri
May 25 2017 00:22
@tawares07 missed the ,
told you that like twice
odm275
@odm275
May 25 2017 00:23
does anyone know how to solve search and destroy?
t0cc
@t0cc
May 25 2017 00:23
tawares07: "Billy Joel" is an awesome choice ... Especially "Downeaster Alexa" :)
Manish Giri
@Manish-Giri
May 25 2017 00:23
@odm275 you could use indexOf() to check if an element is present
odm275
@odm275
May 25 2017 00:24
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
the input 2,3 doesn't make it into the function
function destroyer(arr) {
even if i add parameters
some tests require me different number of parameters
Manish Giri
@Manish-Giri
May 25 2017 00:24
use arguments
joy33joy
@joy33joy
May 25 2017 00:24
In Computer Science a queue is an abstract Data Structure where items are kept in order. New items can be added at the back of the queue and old items are taken off from the front of the queue.
Can anybody explain what this is trying to teach me in
Stand in Line Challenge?
odm275
@odm275
May 25 2017 00:24
tests from free code camp that is
Manish Giri
@Manish-Giri
May 25 2017 00:25
@joy33joy you need to add something to the end of the array arr and then remove and return it's first element.
use arguments
@odm275
odm275
@odm275
May 25 2017 00:26
@kodinglife @Manish-Giri thanks, i see now
CamperBot
@camperbot
May 25 2017 00:26
odm275 sends brownie points to @kodinglife and @manish-giri :sparkles: :thumbsup: :sparkles:
:cookie: 439 | @kodinglife |http://www.freecodecamp.com/kodinglife
:star2: 5640 | @manish-giri |http://www.freecodecamp.com/manish-giri
Elias Grey
@eliasgrey
May 25 2017 00:26

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

}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

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

Help!
Declare a local variable myVar inside myLocalScope. Run the tests and then follow the instructions commented out in the editor.
Diego Mayer
@Chrono79
May 25 2017 00:27
@eliasgrey try refrshing the browser
Elias Grey
@eliasgrey
May 25 2017 00:28
I did. Nothing

function myLocalScope() {
'use strict';

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

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

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

Diego Mayer
@Chrono79
May 25 2017 00:28
@eliasgrey the console.log line you should delete is the one outside the function
You should both declare and initialize the var inside the function, use var keyword for that
joy33joy
@joy33joy
May 25 2017 00:28
@Manish-Giri I don't get what the end of the array means. Does it means ([2],1) like this? What is the point of doing this? Also how do you remove?
Elias Grey
@eliasgrey
May 25 2017 00:29
@Chrono79 I did and it says myVar is not defined.

function myLocalScope() {
'use strict';

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

Gena
@genacatharine
May 25 2017 00:30
can someone please explain what the test is for and where we can see what is displayed after it's test
Diego Mayer
@Chrono79
May 25 2017 00:30
@eliasgrey write var myVar... inside the function
@genacatharine No clue what you're talking about
Elias Grey
@eliasgrey
May 25 2017 00:31
@Chrono79
function myLocalScope() {
'use strict';
var="myVar";
Diego Mayer
@Chrono79
May 25 2017 00:31
@eliasgrey no, that's not what I told
var myVar = "somevalue";
Elias Grey
@eliasgrey
May 25 2017 00:31
@Chrono79 SyntaxError: unexpected token
like inside parenthesis?
Diego Mayer
@Chrono79
May 25 2017 00:32
var is a keyword, myVar should be the var name and use any value you want
Elias Grey
@eliasgrey
May 25 2017 00:34
@Chrono79
function myLocalScope() {
'use strict';
var Myvar="1";
Drew
@Duffelbag
May 25 2017 00:34
hihihi, question on the Madlibs, uncertain with what to start using the wordBlanks beginning strings.
Elias Grey
@eliasgrey
May 25 2017 00:34
like this?
Diego Mayer
@Chrono79
May 25 2017 00:34
@eliasgrey capitalization matters, myVar is not the same as Myvar, didn't you see that in a previous challenge?
Duffy125
@Duffy125
May 25 2017 00:34
var myStr="\n\\\r"; myStr should have encoded text with the proper escape sequences and no spacing. can you spot what I'm missing on these Escape sequences in strings
Elias Grey
@eliasgrey
May 25 2017 00:35
@Chrono79 I got it. Thank you for your help!
CamperBot
@camperbot
May 25 2017 00:35
eliasgrey sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4106 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 25 2017 00:35
@Duffelbag read mad libs link, review Constructing strings with variables
@Duffy125 use the last line as a template, your string should have FirstLine, etc. too
Drew
@Duffelbag
May 25 2017 00:36
@Chrono79 Thanks m8, will check it out
CamperBot
@camperbot
May 25 2017 00:36
duffelbag sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4107 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 25 2017 00:36
:+1:
Cynwenn
@Cynwenn
May 25 2017 00:38
Okay not sure what's wrong with my codes tonight ugh. Could someone please let me know why this one won't run? https://codepen.io/dev999/pen/aWMZpe
Okay not sure what's wrong with my codes tonight ugh. Could someone please let me know why this one won't run? https://codepen.io/dev999/pen/aWMZpe
tawares07
@tawares07
May 25 2017 00:38
@Manish-Giri yeah. The f... , =/ Thanks for your attention!
CamperBot
@camperbot
May 25 2017 00:38
tawares07 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5641 | @manish-giri |http://www.freecodecamp.com/manish-giri
Diego Mayer
@Chrono79
May 25 2017 00:39
@Cynwenn click console, bottom left corner
Manish Giri
@Manish-Giri
May 25 2017 00:39
@Cynwenn did you see the console
Cynwenn
@Cynwenn
May 25 2017 00:40
@Manish-Giri @Chrono79 I did but for some reason it's not displaying anything. Starting to think it's my computer
@Manish-Giri @Chrono79 I did but for some reason it's not displaying anything. Starting to think it's my computer
joy33joy
@joy33joy
May 25 2017 00:41

function nextInLine(arr, item) {
  // Your code here
  [arr],1;
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
I have no idea how to add the number to the end of the array, and remove the first element of array.
Gena
@genacatharine
May 25 2017 00:41
can someone tell me if im on the right path for golf code

function golfScore(par, strokes) {
// Only change code below this line
if (stroke == 1) {
return "Hole-in-one!";
}
else if (stroke<= par-2)
return "Eagle";
}
else if (stroke== par-1) {
return "Birdie";
}
else if (stroke == par) {
return "Par";
else if (stroke == par + 1) {
return "Bogey";
}
else if (stroke == par + 2) {
return "Double Bogey";
else if (stroke >= par + 3) {
return "Go Home!";
}
else {
return "Change Me";
}
// Only change code above this line
}

// Change these values to test
golfScore(5, 4);

Joseph
@revisualize
May 25 2017 00:41
@joy33joy Okay. Let's work through it.
Manish Giri
@Manish-Giri
May 25 2017 00:41
@Cynwenn click the "console" tab on codepen
Joseph
@revisualize
May 25 2017 00:41
@joy33joy How do you add anything to the end of an array?
Manish Giri
@Manish-Giri
May 25 2017 00:41
@genacatharine looks right
Cynwenn
@Cynwenn
May 25 2017 00:42
@Manish-Giri @Chrono79 It /was/ my computer. thanks
CamperBot
@camperbot
May 25 2017 00:42
cynwenn sends brownie points to @manish-giri and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4108 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 5642 | @manish-giri |http://www.freecodecamp.com/manish-giri
joy33joy
@joy33joy
May 25 2017 00:42
@revisualize was is [arr]+=[]?
Joseph
@revisualize
May 25 2017 00:42
@joy33joy Nope.
joy33joy
@joy33joy
May 25 2017 00:42
@revisualize .unshift()?
Cynwenn
@Cynwenn
May 25 2017 00:43
@joy33joy arr.push(item); arr.shift();
Joseph
@revisualize
May 25 2017 00:43
@joy33joy Where does .unshift() add an element.
@Cynwenn That is in no way helpful but, whatever.
@joy33joy
Manipulate Arrays With push()
Manipulate Arrays With pop()
Manipulate Arrays With shift()
Manipulate Arrays With unshift()
joy33joy
@joy33joy
May 25 2017 00:44
@revisualize so unshift in at the front, and push is at the end so...
Joseph
@revisualize
May 25 2017 00:44
@joy33joy correct.
Gena
@genacatharine
May 25 2017 00:45
can someone tell me what to do with the end of the code where it says '// Change these values to test
golfScore(5, 4);'
there seems to be a test on end of each task
not sure what to do w/it
Joseph
@revisualize
May 25 2017 00:45
@genacatharine that is the function call.
@genacatharine You can change the arguments of the function call to match the values for the tests that you want to run.
Gena
@genacatharine
May 25 2017 00:46
i understand that just wondering if i should be looking elsewhere when its called
Xarri Jorge
@xarrijorge
May 25 2017 00:46
@genacatharine Just leave it or change the values in () to tests work
Cynwenn
@Cynwenn
May 25 2017 00:46
@revisualize Hope you're deriving pleasure from criticizing other people trying to help
Gena
@genacatharine
May 25 2017 00:46
hm ok
Manish Giri
@Manish-Giri
May 25 2017 00:46
@genacatharine if your code is right, just hit "run tests"
Joseph
@revisualize
May 25 2017 00:46
@Cynwenn I understand that you're trying to help. However, Studies have shown that giving people answers to problems instills an illusionary sense of learning. Because, it only puts information into short-term memory. Of which people think they are learning. Only through a little struggle and repetition that the human brain puts things into long-term memory. I don't know what your end goal. I don't know if you want to do this as a personal project, hobby, or if you want to move into industry. Because of this, I strongly feel that working with people to allow them to solve problems on their own is a far better outcome than giving away answers. But, others clearly don't agree with my methods for helping people learn.
joy33joy
@joy33joy
May 25 2017 00:47
than can you do [arr].push(banana).shift()
Joseph
@revisualize
May 25 2017 00:47
@joy33joy No.

@joy33joy If you have

var arr = [1,2,3];

then you do
[arr]
What is that?

[[1,2,3]]
joy33joy
@joy33joy
May 25 2017 00:48
Yep
arr.push(banana) would be
[[1,2,3,banana]]
moshe18
@moshe18
May 25 2017 00:49
@padunk well that is to first get the words from the string and then each word I split also to change the first letter to a capital
Joseph
@revisualize
May 25 2017 00:50
@joy33joy Doing [arr].push("banana"); would be [ [1,2,3] , "banana" ]
moshe18
@moshe18
May 25 2017 00:50
@padunk that is why the first one is split(" ") and the second is split("")
Joseph
@revisualize
May 25 2017 00:50
@joy33joy You can't arr.push(banana) if the variable banana is not declared.
joy33joy
@joy33joy
May 25 2017 00:51
function nextInLine(arr, item) {
  // Your code here
  [arr].push("banana");
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Still no change... hmm
I thought [array] was the array thing
So [].push(1)?
Joseph
@revisualize
May 25 2017 00:52
@joy33joy Why do you keep putting arr inside of another array ([ ])?
moshe18
@moshe18
May 25 2017 00:53

@padunk Ah! I just figured it out!

function titleCase(str) {
  str = str.toLowerCase();
  var arr = str.split(" ");
  for (i = 0; i < arr.length; i++) {
    var temp = arr[i].split("");
    temp[0] = temp[0].toUpperCase();
    arr[i] = temp.join("");
  }
  return arr.join(" ");
}
titleCase("I'm a little tea pot");

Notice the temp.join("")

abraham anak agung
@padunk
May 25 2017 00:54
@moshe18 cool, is it working?
moshe18
@moshe18
May 25 2017 00:55
@padunk Yes! On to the next challenge
abraham anak agung
@padunk
May 25 2017 00:55
@moshe18 happy coding then :)
Joseph
@revisualize
May 25 2017 00:55
@joy33joy With the "nvm" ... I take it you gave up?
@joy33joy Look, variables hold values.
joy33joy
@joy33joy
May 25 2017 00:56
Oh so I need to declare the arr!
wow that's a lot I will try to read those
Joseph
@revisualize
May 25 2017 00:56
@joy33joy If you are doing var myArr = [1,2,3];
It is
@joy33joy If you want to add the number 4 to the end of myArr you just need to do myArr.push(4)
@joy33joy arr is a parameter

@joy33joy Stand In Line is a CheckPoint where you're supposed to:
Write a function nextInLine which has two parameters
an array (arr) and a number (item).
That part has been done for you here:

function nextInLine(arr, item) { }

With that function declaration you have a function name of nextInLine. You have two parameters arr which represents an array passed into the function and item that represents a number passed to the function.
A few example function calls:

nextInLine([4,3,2] , 1) the values passed to arr is [4,3,2] and the value passed to item is 1

nextInLine([2,4,6,8] , 10) ... arr is [2,4,6,8] & item is 10

nextInLine([2,3,5,7,11] , 13) ... arr is [2,3,5,7,11] & item is 13 (first 5 and 6th prime numbers)

nextInLine([] , 0) ... arr is [] & item is 0

var myArr = [1,3,5,7]; nextInLine(myArr , 9) ... arr is [1,3,5,7] a copy of the value of the global variable myArr & item is 9

Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Again the two parameters for the nextInLine function are arr & item.

Per the instructions: Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.

You need to add the number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr).

Then you need to have your function return the removed element from the array arr.

abraham anak agung
@padunk
May 25 2017 00:58
wow very detail explanation @revisualize nice!
Joseph
@revisualize
May 25 2017 00:59
@padunk I'm lazy. I already had it typed up.
abraham anak agung
@padunk
May 25 2017 01:00
@revisualize hahaha... but this is cool, this Stand in Line is one of the most confusing for me too
ROBUSTO8
@ROBUSTO8
May 25 2017 01:00
hey guys, im tinkering with the local weather map challenge and trying to see if i succeeded in getting the latitude and longitude in my code and trying to show it in HTML but, its not working can anyone tell me why? codepen: https://codepen.io/ROBUSTO/pen/Wjaqab
Joseph
@revisualize
May 25 2017 01:01
@padunk It's confusing for a lot of people because FreeCodeCamp doesn't really cover the details of function declaration, parameters, function calls and how to work with function arguments.
ROBUSTO8
@ROBUSTO8
May 25 2017 01:01
im trying to show the latitude where "City here, country here" is..
Greg Duncan
@GregatGit
May 25 2017 01:02
@ROBUSTO8 failure is not defined
joy33joy
@joy33joy
May 25 2017 01:02
I think I am getting confused because I really don't know arguments and parameters. I gotta learn those stuff in other way.. thing is I don't know how
Joseph
@revisualize
May 25 2017 01:02
@joy33joy Okay. Let's learn that.
youngalps
@youngalps
May 25 2017 01:02
var a = b;
?
a should be assigned to b with =
abraham anak agung
@padunk
May 25 2017 01:03
@revisualize yes, that is why i think that they need to learn somewhere else too but still doing challenge in fcc. i learn it in w3school and codeacademy
joy33joy
@joy33joy
May 25 2017 01:03
I heard that argument is something like result thing... thuu
youngalps
@youngalps
May 25 2017 01:03
As a fluent c++ write i cant even get past this.
oml
Joseph
@revisualize
May 25 2017 01:03
@joy33joy Do you have some time to answer a few questions?
Zekalo
@Zekalo
May 25 2017 01:03
@youngalps Shouldn't b be in enclosed with " ?
joy33joy
@joy33joy
May 25 2017 01:04
Definitely
Zekalo
@Zekalo
May 25 2017 01:04
"b"
youngalps
@youngalps
May 25 2017 01:04
it is
ROBUSTO8
@ROBUSTO8
May 25 2017 01:04
@GregatGit ohhh got it thanks
CamperBot
@camperbot
May 25 2017 01:04
robusto8 sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 852 | @gregatgit |http://www.freecodecamp.com/gregatgit
youngalps
@youngalps
May 25 2017 01:04
not the solution
Joseph
@revisualize
May 25 2017 01:04
@joy33joy Let's say I have this code:
function addThree(num) { }
Zekalo
@Zekalo
May 25 2017 01:04
@youngalps You sent var a = b, it should be var a = "b" thought?
youngalps
@youngalps
May 25 2017 01:04
i have
var a = "b";
still no fixo
joy33joy
@joy33joy
May 25 2017 01:04
@revisualize Yep
So parameter is something inside of () like f(x)?
Joseph
@revisualize
May 25 2017 01:04
@youngalps That's backwards.
@joy33joy In the function declaration of function addThree (num) { You see that there is a parameter defined of num
youngalps
@youngalps
May 25 2017 01:05
var "a" = b?
Greg Duncan
@GregatGit
May 25 2017 01:05
@ROBUSTO8 i deleted failure and it worked
Joseph
@revisualize
May 25 2017 01:05
@youngalps How do you assign the value of 7 to a variable num? ... var num = 7;
Now if you want you can use a variable to store values.
Like in mathmatics. num + 3 = 10 What is the value of num?
var x = num + 3; ... That outputs 10
So, you can do several things with variables. But, you need to understand that variables hold values and variables can be used with other variables.
So, how do you assign the value of 5 to a variable x? ... x = 5; (Which is also overwriting the previous value of 10 from above.
How do you assign the value of x to a variable y?
Look at the way things are written. var y = x;
How do you assign the value of 42 to a variable answer? ... What is the answer?
Variables hold values. Just understand that.
ROBUSTO8
@ROBUSTO8
May 25 2017 01:05
@GregatGit yeah i defined failure and it worked too
youngalps
@youngalps
May 25 2017 01:05

// Setup
var a;
var b = 2;

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

it says dont change the top
Joseph
@revisualize
May 25 2017 01:06
@youngalps Remove the var b=7;
youngalps
@youngalps
May 25 2017 01:06
a should have a value of 7
b should have a value of 7
Joseph
@revisualize
May 25 2017 01:06
@youngalps Quotes define strings.

@joy33joy So, when we make the function call of:

addThree(10);

You're calling the function addThree You're also passing a value 10 as an argument.

@joy33joy So, again...
In the function declaration of function addThree (num) { You see that there is a parameter defined of num
When we do addThree(10) then the value of the parameter num is passed the argument value of ... 10

@joy33joy If you then make another function call..

addThree(39);

You can use the same function to follow the operation:
When we do addThree(39) then the value of the parameter num is passed the argument value of ... 39

If you make the function call of addThree(21) the value of num inside the function is 21.
If you make the function call of addThree(1000) the value of num inside the function is 1000.
If you make the function call of addThree(123456) the value of num inside the function is 123456.
@joy33joy That's with 1 function and 1 parameter
joy33joy
@joy33joy
May 25 2017 01:08
So num is the variable that has not been declared by specific number, and argument is like 39 in addThree(39) right?
num=parameter?
OMG You explained too good. I gotta copy all the things you wrote and read in seperate doc.
Joseph
@revisualize
May 25 2017 01:09
@joy33joy Correct num would be a parameter.

@joy33joy Another example of this:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

You can use the fName and uName parameters just like a variable inside of your function.

Duffy125
@Duffy125
May 25 2017 01:10
var myStr="FirstLine\n\secondLine\\rThirdLine";
myStr should have encoded text with the proper escape sequences and no spacing.
what am i missing
Joseph
@revisualize
May 25 2017 01:10
@Duffy125 second
@Duffy125 Second
Duffy125
@Duffy125
May 25 2017 01:11
thank you
joy33joy
@joy33joy
May 25 2017 01:13
function nextInLine(arr, item){
return arr.shift()+ item.shift()
no that doesn't make any sense
Joseph
@revisualize
May 25 2017 01:13
@joy33joy Are things making more sense
item is a number
You can't do array methods on a number.
joy33joy
@joy33joy
May 25 2017 01:14
I wonder how I can make parameter ([],1) into 1
Do I have to infer a secrete rule?
Joseph
@revisualize
May 25 2017 01:14
@joy33joy Follow the order of operations.
@joy33joy First you have to add the number (item) to the end of the array (arr).
joy33joy
@joy33joy
May 25 2017 01:15
return shift.([1,2,3,4,5],1)
but those are numbers
Joseph
@revisualize
May 25 2017 01:15
Then you have to remove the first element from the array (arr) and return that element.
@joy33joy There are no "secret" rules.
@joy33joy You keep changing lines upwards. I don't read lines upwards.
You're confusing the hell out of me.
Manish Giri
@Manish-Giri
May 25 2017 01:17
lol
Conor Murphy
@cmurphy580
May 25 2017 01:17
hey i'm working on my website here. And I wanted to add this 'mousemove' effect where a row of circles follows the mouse, but i can 't get it work, other than for a split second. here's the codepen, and its the last segment of JS. Let me know if you have any ideas on how to fix it
https://codepen.io/cmurphy580/pen/ygaWbG
joy33joy
@joy33joy
May 25 2017 01:18
sry. Tho [arr,item].shift() doesn't make any sense. or Does it?
Joseph
@revisualize
May 25 2017 01:18
@joy33joy Are you trying to do everything in 1 line?
Frank McCroy
@fmccroy
May 25 2017 01:19
arr.shift() will take the first item off from the beginning of the array
Joseph
@revisualize
May 25 2017 01:19
@joy33joy If you are trying to solve this challenge with 1 line of code. DON'T!

The push() method adds one or more elements to the end of an array and returns the new length of the array.

The pop() method removes the last element from an array and returns that element.

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

The shift() method removes the first element from an array and returns that element.

joy33joy
@joy33joy
May 25 2017 01:19
This message was deleted
Joseph
@revisualize
May 25 2017 01:19
@joy33joy What does .unshift() do?
joy33joy
@joy33joy
May 25 2017 01:20
oh nvm it does adding
so it is shift
chameleon07
@chameleon07
May 25 2017 01:21
```
Masaki
@masaki1223
May 25 2017 01:21

 XMLHttpRequest cannot load https://api.darksky.net/forecast/ba****3154ce00000052a/3**.709,****9.7186. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.
How can I fix Access control allow origin?
Joseph
@revisualize
May 25 2017 01:21
@joy33joy How do you add a number (item) to the end of an array (arr)?
chameleon07
@chameleon07
May 25 2017 01:21
function mutation(arr) {

  arr[0] = arr[0].toLowerCase().split("").sort();
  arr[1] = arr[1].toLowerCase().split("").sort();

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

 for (j = 0; j < arr[i].length; j++){
   if (arr[i][j] == arr[i][j - 1]){
     arr[i] = arr[i].join("").replace(arr[i][j], "");
   }
   else { arr[i] = arr[i].join("");}
 } 
}

  if (arr[0] == arr[1]){
    return true;
  }
  else {return false;}

}

mutation(["Mary", "Aarmy"]);
Joseph
@revisualize
May 25 2017 01:21
@masaki1223 CORS
joy33joy
@joy33joy
May 25 2017 01:22
item=item + 1 because it is number?
fx
Joseph
@revisualize
May 25 2017 01:22
@joy33joy No.
@joy33joy There is nothing in the instructions that says to add 1 to the number (item).
chameleon07
@chameleon07
May 25 2017 01:23
Why do I get TypeError: arr[i].join is not a function?
Frank McCroy
@fmccroy
May 25 2017 01:23
You are trying to add an item to the array, so which of the 4 operations that Joseph listed above will do that?
To the END of the array
joy33joy
@joy33joy
May 25 2017 01:23
pop!
Manish Giri
@Manish-Giri
May 25 2017 01:23
@chameleon07 is arr[i] an array?
Joseph
@revisualize
May 25 2017 01:23
@joy33joy No.
Frank McCroy
@fmccroy
May 25 2017 01:24
Pop takes it off the end
chameleon07
@chameleon07
May 25 2017 01:26
@Manish-Giri Yep
image.png
Joseph
@revisualize
May 25 2017 01:28

@joy33joy Let me ask a side question.

var num = 10;
var myArr = [2,4,6,8];

How do you add num to the end of myArr?

joy33joy
@joy33joy
May 25 2017 01:30
myArr = myArr.unshift(10);
Joseph
@revisualize
May 25 2017 01:30
@joy33joy No
@joy33joy END
@joy33joy The answer is myArr.push(num);
@joy33joy num holds the value 10
joy33joy
@joy33joy
May 25 2017 01:31
myArr = myArr.push(num)
Jessica Connor
@JessConn
May 25 2017 01:31
I need help with json. How do I add multiple data sets in one array?
joy33joy
@joy33joy
May 25 2017 01:31
yep
Joseph
@revisualize
May 25 2017 01:31
@joy33joy No.
joy33joy
@joy33joy
May 25 2017 01:31
oh i don't need myArr=?
Joseph
@revisualize
May 25 2017 01:32
@joy33joy Because .push() returns the new length of the arry.
So...
chameleon07
@chameleon07
May 25 2017 01:32
@Manish-Giri I replaced the first else statement with a return statement to show
joy33joy
@joy33joy
May 25 2017 01:32
you mean to make [2,4,6,8,10] not [2,4,6,8],10 right
Joseph
@revisualize
May 25 2017 01:32
@joy33joy myArr = myArr.push(num) .. Adds the value of num to the end of the array ... The new .length of the array is 5 ... so that is assigning the value 5 to the variable myArr
abraham anak agung
@padunk
May 25 2017 01:33
@chameleon07 you are working with one dimensional array. why you use arr[i][j]
Joseph
@revisualize
May 25 2017 01:33
@joy33joy It should be [2,4,6,8,10] after the .push()
Roly desouza
@rolydesouza
May 25 2017 01:34
please help #173 this is what i got
joy33joy
@joy33joy
May 25 2017 01:34
myArr =myArr.push(num)
Roly desouza
@rolydesouza
May 25 2017 01:34

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

return (testArr,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, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Joseph
@revisualize
May 25 2017 01:34
@joy33joy That doesn't work.

@rolydesouza @rolydesouza

Stand In Line is a CheckPoint where you're supposed to:
Write a function nextInLine which has two parameters
an array (arr) and a number (item).
That part has been done for you here:

function nextInLine(arr, item) { }

With that function declaration you have a function name of nextInLine. You have two parameters arr which represents an array passed into the function and item that represents a number passed to the function.
A few example function calls:

nextInLine([4,3,2] , 1) the values passed to arr is [4,3,2] and the value passed to item is 1

nextInLine([2,4,6,8] , 10) ... arr is [2,4,6,8] & item is 10

nextInLine([2,3,5,7,11] , 13) ... arr is [2,3,5,7,11] & item is 13 (first 5 and 6th prime numbers)

nextInLine([] , 0) ... arr is [] & item is 0

var myArr = [1,3,5,7]; nextInLine(myArr , 9) ... arr is [1,3,5,7] a copy of the value of the global variable myArr & item is 9

Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Again the two parameters for the nextInLine function are arr & item.

Per the instructions: Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.

You need to add the number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr).

Then you need to have your function return the removed element from the array arr.

chameleon07
@chameleon07
May 25 2017 01:35
@padunk Ahhh so thats where I messed up... Thank you! :D
CamperBot
@camperbot
May 25 2017 01:35
chameleon07 sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 327 | @padunk |http://www.freecodecamp.com/padunk
chameleon07
@chameleon07
May 25 2017 01:37
@padunk Hmmm actually... nope i dont get it yet... The idea is to split the characters and iterate through them one by one and if the previous character is the same as the next, one of the characters will be removed
abraham anak agung
@padunk
May 25 2017 01:40
@chameleon07 ok. so you have two arrays to compare. [ 'a', 'm', 'r', 'y' ] and [ 'a', 'a', 'm', 'r', 'y' ] right?
chameleon07
@chameleon07
May 25 2017 01:41
@padunk yep
Roly desouza
@rolydesouza
May 25 2017 01:41
thanks joseph
abraham anak agung
@padunk
May 25 2017 01:42
chameleon07
@chameleon07
May 25 2017 01:43
@padunk Okie I try that then thank you
CamperBot
@camperbot
May 25 2017 01:43
chameleon07 sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:warning: chameleon07 already gave padunk points
Dovydas Stirpeika
@Giveback007
May 25 2017 01:48
hey there, so I am having an optimization problem with the tic tac toe
anyone willing to help?
Dovydas Stirpeika
@Giveback007
May 25 2017 01:53
Capture.PNG
the tic tac toe AI correcly assessed the best move to take
but it ran trough 362,000 grid posibilities
which on a slower computer takes a whole minute to decide which is the best move to take.
Victor Romero
@vromero2017
May 25 2017 01:55
hi all, I am stuck here on JavaScrip
var myStr = "Firstline\n\SecondLine\ThirdLine\r"; // Change this line
myStr should have encoded text with the proper escape sequences and no spacing.
I don't understand very well the question I guess
Dovydas Stirpeika
@Giveback007
May 25 2017 01:55
how can I optimize it so it would take a lot less time
Joseph
@revisualize
May 25 2017 01:59
@vromero2017 Youreorder is incorrect.
Dovydas Stirpeika
@Giveback007
May 25 2017 01:59
@vromero2017 you need to use \r for every new line
Joseph
@revisualize
May 25 2017 02:00
@vromero2017 You didn't write "FirstLine" correctly and you're escaping the carriage-return out of order.
Dovydas Stirpeika
@Giveback007
May 25 2017 02:01
@revisualize hey could you help me with optimising the tic-tac-toe ai?
Joseph
@revisualize
May 25 2017 02:01
@Giveback007 Nope.
Dovydas Stirpeika
@Giveback007
May 25 2017 02:01
:(
Joseph
@revisualize
May 25 2017 02:01
@vromero2017 You have to assign 'FirstLine newline backslash SecondLine backslash carriage-return ThirdLine' to the variable myStr.
But, You have to replace the escape words with the proper escape sequences. (And per the instructions: remove all spaces.)
How do you escape a newline? With: \n
How do you escape a backslash? With: \\
How do you escape a carriage-return? With \r
@Giveback007 I can't help you with something that I haven't done nor understand.
Dovydas Stirpeika
@Giveback007
May 25 2017 02:03
i understand
Zattara
@vpenha
May 25 2017 02:04

Hello!
anyone knows how I can remove the '-' from my array?
I have the following code:
function palindrome(str) {
{var palindrome = (str.toLowerCase().replace(/[\s#$%&_^()~@!/\:'),.]/g, ''));
var arr = str.split("");
var reverseArr = arr.reverse();
var joinArr = reverseArr.join("").replace(/[\s#$%&
_^-~@()\/:!'),.]/g, '').toLowerCase();

//if (joinArr === palindrome) {
//return true;}

//else {
//return false;}
return joinArr;
}}

palindrome("0_0 (: /-\ :) 0-0");

I have to remove the '-' from the str

Joseph
@revisualize
May 25 2017 02:05
@vpenha I think you should change your thought process a little.
Zattara
@vpenha
May 25 2017 02:05
@revisualize should I just not reverse it?
this is for the check for palindromes case
Joseph
@revisualize
May 25 2017 02:05
@vpenha You have to reverse it.
@vpenha You have to remove all non-alphanumeric characters.. Right?
Zattara
@vpenha
May 25 2017 02:06
yes
Joseph
@revisualize
May 25 2017 02:06
@vpenha So, why not just keep all alphanumeric characters and remove everything not an alphanumeric character?
Zattara
@vpenha
May 25 2017 02:07
yes!!! :)
thanks @revisualize !
CamperBot
@camperbot
May 25 2017 02:07
vpenha sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4002 | @revisualize |http://www.freecodecamp.com/revisualize
Victor Romero
@vromero2017
May 25 2017 02:07
Checking on it @revisualize
Zattara
@vpenha
May 25 2017 02:08
@revisualize I can just use the \W :)
@revisualize I have been looking at this code for hours...haha
Joseph
@revisualize
May 25 2017 02:09
@vpenha WHat is \W?
Zattara
@vpenha
May 25 2017 02:09
@revisualize \W is the equivalent of [^0-9a-zA-Z_] - it includes the underscore character. To also remove underscores use e.g.:
input.replace(/[^0-9a-z]/gi, '')
Joseph
@revisualize
May 25 2017 02:09
@vpenha Did you just answer your own question?
Zattara
@vpenha
May 25 2017 02:10
@revisualize , well you help! a lot!
@revisualize I was stuck in that mental process, that did not check if there was a way already in javescript to do that...
Peter Kay
@deuscode
May 25 2017 02:12
function diffArray(arr1, arr2) {
  var newArr = [];

    for (var i = 0; i < arr1.length; i++) {
      for (var j = 0; j < arr2.length; j++) {

        if (arr2.indexOf(arr1[i]) === -1) {
        newArr.push(arr1[i]);
        } else if (arr1.indexOf(arr2[j]) === -1) {
        newArr.push(arr2[j]);
        }
      }
    }
  return newArr;
}

diffArray([], [1, 2, 3, 4, 5]);
So I am doing the Diff Two Arrays algorithm challenge and am getting an error on the last two arrays. Can someone point me in the right direction on solving this? Thanks!
Victor Romero
@vromero2017
May 25 2017 02:14
Got it, Thank you @revisualize and @Giveback007
CamperBot
@camperbot
May 25 2017 02:14
vromero2017 sends brownie points to @revisualize and @giveback007 :sparkles: :thumbsup: :sparkles:
:cookie: 308 | @giveback007 |http://www.freecodecamp.com/giveback007
:star2: 4003 | @revisualize |http://www.freecodecamp.com/revisualize
Stephen James
@sjames1958gm
May 25 2017 02:16
@deuscode You probably should split into two seperate loops - if one array is empty you will never loop
Peter Kay
@deuscode
May 25 2017 02:17

function diffArray(arr1, arr2) {
  var newArr = [];

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

        if (arr2.indexOf(arr1[i]) === -1) {
        newArr.push(arr1[i]);
        }
    }
    for (var j = 0; j < arr2.length; j++) {
        if (arr1.indexOf(arr2[j]) === -1) {
        newArr.push(arr2[j]);
        }
      }

  return newArr;
}

diffArray([], [1, 2, 3, 4, 5]);
hey this worked
Thanks @sjames1958gm
CamperBot
@camperbot
May 25 2017 02:17
deuscode sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7455 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Peter Kay
@deuscode
May 25 2017 02:18
I still don't understand why it wouldn't loop
shouldn't the else if go through?
Austin
@werewolfred
May 25 2017 02:19
hi I'm having an issue understanding the instructions from the challenge stand in line, am I applying .shift and .unshift to item or am I adding array to item in a way that applies qeue?
joy33joy
@joy33joy
May 25 2017 02:19

How to return the element that was removed?

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

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

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

doesn't work for me

Joseph
@revisualize
May 25 2017 02:19
@joy33joy You're removing the first element twice.
@joy33joy You should just have 1 .shift() and it should be the returned one.
joy33joy
@joy33joy
May 25 2017 02:21
Butarr.push(item); arr.shift();
return arr; still wrong
Joseph
@revisualize
May 25 2017 02:21
@joy33joy Because now you're not returning the element removed.
joy33joy
@joy33joy
May 25 2017 02:21
oh
OH MY GOD I passed it!
@revisualize Thank you sooooo much you are my savior
CamperBot
@camperbot
May 25 2017 02:22
joy33joy sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4004 | @revisualize |http://www.freecodecamp.com/revisualize
joy33joy
@joy33joy
May 25 2017 02:22
You helped me to understand many things
Joseph
@revisualize
May 25 2017 02:23
@joy33joy Does it all make sense?
joy33joy
@joy33joy
May 25 2017 02:23
@revisualize YES it DOES!!!
Now Im boasted
Dovydas Stirpeika
@Giveback007
May 25 2017 02:24
nwm
Peter Kay
@deuscode
May 25 2017 02:24
@sjames1958gm oh I see it now... derp... because of the for loop i =0 it wouldn't loop
Zachary David Saunders
@ZacharyDavidSaunders
May 25 2017 02:30

Hello. I am again working on my node CLI app and I have a question about using encryption in node. If I was to utilize a private key for encryption and decryption, how do I store the file in my npm module, without making it accessible to everyone who downloads my module?

In git, I can use .gitignore, but I belive that a similar approach won’t work with npm, as the user needs all of the files to use the app.

Here is a screenshot that further highlights my question:

Screen Shot 2017-05-24 at 7.22.20 PM.jpg
Anker
@ankerpeet
May 25 2017 02:34
function largestOfFour(arr) {
  //declare variables
  var newArr = [];
  //for loop to cycle through arrays
  for (var i = 0; i < arr.length; i++) { 
  for (var j = 0; j < arr[i].length; j++) { 
   newArr.push(arr[i][j].sort(function(a, b){return a - b;}));    
    }   return newArr;
  }
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
i keep getting an error that arr[i][j].sort is not a function
Moisés Man
@moigithub
May 25 2017 02:36
@ankerpeet sort only works on arrays
what arrr[i][j] returns ???
Thomas Magnus
@tmag298
May 25 2017 02:36
I desperately need guidance on this challenge: https://tinyurl.com/lsvsc9u
Please!
Anker
@ankerpeet
May 25 2017 02:37
@moigithub thank you. I'll change some things and try again :)
CamperBot
@camperbot
May 25 2017 02:37
ankerpeet sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3259 | @moigithub |http://www.freecodecamp.com/moigithub
Claudio Restifo
@Marmiz
May 25 2017 02:39

@tmag298 read the instruction carefoully:

he nextInLine function should then return the element that was removed.

You need to add the number first; then return only the removed one

Thomas Magnus
@tmag298
May 25 2017 02:40
^^ This is very good instruction
thankyou @Marmiz
CamperBot
@camperbot
May 25 2017 02:41
tmag298 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 887 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
May 25 2017 02:43
@tmag298 :+1: happy coding
Thomas Magnus
@tmag298
May 25 2017 02:44
@Marmiz but wait why isn't the return statement jsut arr.pop() then??
Rick Riggs
@wikiwiggs
May 25 2017 02:44
I have a quick question regarding the projects. Who looks at them?
Moisés Man
@moigithub
May 25 2017 02:45
@tmag298 what arr.pop() does??
Thomas Magnus
@tmag298
May 25 2017 02:45
@wikiwiggs You can make a post in the form about them if you like. No real authority checks to see if you have finished them.
@moigithub it takes the last value in an array and assigns the value to a new variable
Claudio Restifo
@Marmiz
May 25 2017 02:45
@tmag298 because pop removes the last element. There's another method for the first one ^^
Thomas Magnus
@tmag298
May 25 2017 02:46
^^ okay word
Rick Riggs
@wikiwiggs
May 25 2017 02:47
@tmag298 OK, I just really struggled with the twitch project, and for the life of me couldn't get one feature of the user story's implemented, so I just submitted it anyway.
Claudio Restifo
@Marmiz
May 25 2017 02:47
@wikiwiggs I think there's a team that reviews them when the time is right
Rick Riggs
@wikiwiggs
May 25 2017 02:47
@Marmiz I have four more projects, and then I'm up to get my front end cert.
Claudio Restifo
@Marmiz
May 25 2017 02:47
@wikiwiggs it's probably easier to ask for help on that specific feature :)
Thomas Magnus
@tmag298
May 25 2017 02:48
Wait! How is this answer not just arr.shift() ? Do I have to use two separate functions?
Cesar Fernandez
@Diamond713
May 25 2017 02:48
How do you add this "$(document).ready(function() {"
To the beginning of the script element?
Rick Riggs
@wikiwiggs
May 25 2017 02:48
@tmag298 that's the beginning of the array, not the end
Claudio Restifo
@Marmiz
May 25 2017 02:48
@tmag298 you have to add the number the the array first. Then return the first element removed
Aizaz Shahid
@aizazshahid
May 25 2017 02:49
@Diamond713 didn't i tell you ?
Moisés Man
@moigithub
May 25 2017 02:49
@tmag298 instructions says...
add item to the end of the array then...
remove and return the first element removed
Claudio Restifo
@Marmiz
May 25 2017 02:49
read the instructions~
Thomas Magnus
@tmag298
May 25 2017 02:49
@wikiwiggs but I need to take the element off the beginning
Rick Riggs
@wikiwiggs
May 25 2017 02:49
@Marmiz I was not getting the 404, because I was never getting to the user's channel
@tmag298 then use shift()
Claudio Restifo
@Marmiz
May 25 2017 02:50

@wikiwiggs

I was never getting to the user's channel

So how were you able to see who was on line?

Rick Riggs
@wikiwiggs
May 25 2017 02:50
@tmag298
shift() & unshift() work on the left side of the array.
pop() & push() work on the right side
@Marmiz Yes
Cesar Fernandez
@Diamond713
May 25 2017 02:51
@aziz shahid. Is not working
Rick Riggs
@wikiwiggs
May 25 2017 02:51
@Marmiz Here's the codepen if you want to see what is happening.
http://codepen.io/wikiwiggs/pen/ZKPQeQ?editors=1010
Aizaz Shahid
@aizazshahid
May 25 2017 02:54
<html>
<head>
    .....
<script>
$(document).ready( function() { 
   // all js goes here
} );
</script>
</head>

<body> ....
@Diamond713
Cesar Fernandez
@Diamond713
May 25 2017 02:56
Ok got it thanks
Claudio Restifo
@Marmiz
May 25 2017 02:58
@wikiwiggs I'm curious about the wikiwiggs request. What's that?
afaik the twitch API has https://api.twitch.tv (or something similar) as an endpoint
Rick Riggs
@wikiwiggs
May 25 2017 02:58
@Marmiz That's my channel
Claudio Restifo
@Marmiz
May 25 2017 03:00
@wikiwiggs and what's your channel instructed to do when received a request?
Francis Ngo
@francisngo
May 25 2017 03:00
hey guys how do you countchars using a while loop and slice method?
Rick Riggs
@wikiwiggs
May 25 2017 03:00
@Marmiz oh you mean the wikiwiggs.com request?
Claudio Restifo
@Marmiz
May 25 2017 03:00
@wikiwiggs yep
Aizaz Shahid
@aizazshahid
May 25 2017 03:01
@francisngo what do you mean by countchars ?
Francis Ngo
@francisngo
May 25 2017 03:01
function countChars(string, character){
  var count = 0;
  var charCount = 0;
  while(count < string.length){
    string.slice(0, 1);
    if(character === string.slice(0, 1)){
      charCount += 1;
    }
    count += 1;
  }
  return charCount;
}

console.log(countChars("doggie", "g"));
Rick Riggs
@wikiwiggs
May 25 2017 03:01
@Marmiz yeah I setup a backend, so I can authenticate my api client-id with less issues
Francis Ngo
@francisngo
May 25 2017 03:01
sorry count characters*
Aizaz Shahid
@aizazshahid
May 25 2017 03:02
@francisngo you have already a property for that string.length is it a task ?
Francis Ngo
@francisngo
May 25 2017 03:03
while the count is less than the length of string i want to slice each character off until its empty
Claudio Restifo
@Marmiz
May 25 2017 03:03
@francisngo just so you know, there's an easy method to split a string into an array:
var str = "test"
var splitted = str.split('')
//splitted ['t', 'e', 's', 't']
Francis Ngo
@francisngo
May 25 2017 03:03
i want to find the character while slicing and count the time it shows up while slicing
Aizaz Shahid
@aizazshahid
May 25 2017 03:03
but slice will return the new string so store it into string = ...
if you don't modify the string then every time you get the same character
Francis Ngo
@francisngo
May 25 2017 03:05
function countChars(string, character){
  var count = 0;
  var charCount = 0;
  while(count < string.length){
    var str = string.slice(0, 1);
    if(character === str){
      charCount += 1;
    }
    count += 1;
  }
  return charCount;
}
Claudio Restifo
@Marmiz
May 25 2017 03:06
@wikiwiggs unfortunately your backend is been blocked due to being on an http endpoint while codepen is on a https
Rick Riggs
@wikiwiggs
May 25 2017 03:06
@francisngo I don't believe this will work
Moisés Man
@moigithub
May 25 2017 03:06
@francisngo check slice syntax mdn.io/slice
WHAT those 2 numbers mean ?? ie str.slice(0,1)
Aizaz Shahid
@aizazshahid
May 25 2017 03:06
well it will also not works :) you need index numbers, for loop is good here
Francis Ngo
@francisngo
May 25 2017 03:06
oh wait i think a light bulb just turned on in my head
Aizaz Shahid
@aizazshahid
May 25 2017 03:06
like .slice(i, i+1)
Francis Ngo
@francisngo
May 25 2017 03:07
im supposed to use while
Aizaz Shahid
@aizazshahid
May 25 2017 03:07
and store it into temporary variable not string, sorry for that !
Rick Riggs
@wikiwiggs
May 25 2017 03:07
@francisngo you can split('')
Francis Ngo
@francisngo
May 25 2017 03:07
i have been able to solve it with a for loop and object
function countChars(string, character) {
  var count = {};
  for(var i = 0; i < string.length; i++){
    if(!count[string[i]]){
      count[string[i]] = 1;
    } else {
      count[string[i]] += 1;
    }
  }
  return count[character];
}
but i am trying to solve this with while loop and slice method
Rick Riggs
@wikiwiggs
May 25 2017 03:08
@Marmiz I thought you could bring codepen out of https, if you just removed it from the address???
Aizaz Shahid
@aizazshahid
May 25 2017 03:08
ok good, its upto you how to solve that challenge !
Francis Ngo
@francisngo
May 25 2017 03:08
ive been stuck on how to for awhile
Claudio Restifo
@Marmiz
May 25 2017 03:09
@wikiwiggs yes you can. I was just giving you feedback :)
Francis Ngo
@francisngo
May 25 2017 03:09
something in my brain isnt clicking
Aizaz Shahid
@aizazshahid
May 25 2017 03:09
@francisngo you made your count an object ? but you need an integer variable to count the number of places of that character?
Francis Ngo
@francisngo
May 25 2017 03:09
nevermind that solution...
Rick Riggs
@wikiwiggs
May 25 2017 03:10
@Marmiz Oh, ok. Any thoughts on the 404 user story?

@Marmiz the user story is as follows:

User Story: I will see a placeholder notification if a streamer has closed their Twitch account (or the account never existed). You can verify this works by adding brunofin and comster404 to your array of Twitch streamers.

Claudio Restifo
@Marmiz
May 25 2017 03:12
@wikiwiggs I should see what your "api" returns since it's in fact that that's making the request
Rick Riggs
@wikiwiggs
May 25 2017 03:14
you can console.log(data), console.log(data2) & console.log(data3) as these are the three returns of my server.
Claudio Restifo
@Marmiz
May 25 2017 03:14
@wikiwiggs I'll give it a look
Rick Riggs
@wikiwiggs
May 25 2017 03:14
@Marmiz me too.
@Marmiz Lines 84, 85, 86
Mario A. Carlos
@MarioC3
May 25 2017 03:16
Hello Guys. Hope everyone is doing ok today.
I'm currently stuck in Chunky Monkey
This is my code:

function chunkArrayInGroups(arr, size) {
  // Break it up.
  var tempArray = [];
  arr.forEach(function(element){
    tempArray.push(arr.splice(0, size));
  });

return tempArray;

}

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3);
Aizaz Shahid
@aizazshahid
May 25 2017 03:18
@MarioC3 you should avoid to iterate through each element of that array !
Mario A. Carlos
@MarioC3
May 25 2017 03:18
Why though?
Aizaz Shahid
@aizazshahid
May 25 2017 03:18
while and for will works fine here.
because you have to make groups of that arr as per size.
Mario A. Carlos
@MarioC3
May 25 2017 03:19
In my mind if they iterate until there is nothing left of the array, wouldn't that return nicely?
Aizaz Shahid
@aizazshahid
May 25 2017 03:19
but splice returns the new array !
correct me if i am wrong ?
Mario A. Carlos
@MarioC3
May 25 2017 03:19
right but it's pushing it to the new tempArray variable..
Aizaz Shahid
@aizazshahid
May 25 2017 03:20
and also you are getting the array from zero means, from first element at every time
Mario A. Carlos
@MarioC3
May 25 2017 03:21
right...
so...
Aizaz Shahid
@aizazshahid
May 25 2017 03:21
i think if you just remove the elements from the original one arr then it can be work
Mario A. Carlos
@MarioC3
May 25 2017 03:21
I'm removing them
Aizaz Shahid
@aizazshahid
May 25 2017 03:22
where ?
Mario A. Carlos
@MarioC3
May 25 2017 03:22
because I'm using splice and not slice
Aizaz Shahid
@aizazshahid
May 25 2017 03:22
splice change the original one ?
Mario A. Carlos
@MarioC3
May 25 2017 03:22
Yep.
Aizaz Shahid
@aizazshahid
May 25 2017 03:23
oh then it will ok !
Mario A. Carlos
@MarioC3
May 25 2017 03:23
image.png
Aizaz Shahid
@aizazshahid
May 25 2017 03:23
but what if it has less then 3 element remaining ?
Mario A. Carlos
@MarioC3
May 25 2017 03:23
That's where I'm stuck
Aizaz Shahid
@aizazshahid
May 25 2017 03:24
well you can use a logic there like:
if ( arr.length < size ) then .....just push the whole array
Ogundele Olumide
@Lumexralph
May 25 2017 03:24
@MarioC3 it's not a good idea to mutate an array when looping through it
Mario A. Carlos
@MarioC3
May 25 2017 03:25
what do you mean @Lumexralph ?
oh I see what you're saying
why not?
Aizaz Shahid
@aizazshahid
May 25 2017 03:25
@Lumexralph but he is trying his own algortihm and that is good for him
Ogundele Olumide
@Lumexralph
May 25 2017 03:26
@MarioC3 splice mutates an array, be very careful with that when you're looping through the array
@forwebtech i understand
Mario A. Carlos
@MarioC3
May 25 2017 03:26
Is that like JS Best preactices?
I'm still last! :(
lost*
Ogundele Olumide
@Lumexralph
May 25 2017 03:31
@MarioC3 i think it's a good programming suggestion, you can put holes in your array doing that or have a sparse array which will give you a different behaviour. You can still use methods like splice just know what's happening
Mario A. Carlos
@MarioC3
May 25 2017 03:31
Oh I get it.
Going on with this solution
Joseph
@revisualize
May 25 2017 03:32
Hi
Mario A. Carlos
@MarioC3
May 25 2017 03:32
Shouldn't the conditional iterate 3 times?
Kelechi Chinaka
@ke1echi
May 25 2017 03:32
how do i return a negative value makeNegative(1); // return -1
Claudio Restifo
@Marmiz
May 25 2017 03:32

@wikiwiggs I think you should check your api response.
Twitch, when a user does not exist return a

{
  "error":"Not Found",
  "status":404,
  "message":"Channel 'user_to_test' does not exist"
}

Your API for the comster404 does not provide any response.
While for all the other channel theres' a response.

You should probably tell your API that in case there's an error should still send a response back.

To see this inspect the network request :)

Mario A. Carlos
@MarioC3
May 25 2017 03:33
It only iterates 2 times and then it stops and goes directly to return tempArray... why?
Manish Giri
@Manish-Giri
May 25 2017 03:33
@kelechichinaka 0 minus the number?
Mario A. Carlos
@MarioC3
May 25 2017 03:34
Someone?
Joseph
@revisualize
May 25 2017 03:34
What if the num is -1 and you do 0 - -1?
Mario A. Carlos
@MarioC3
May 25 2017 03:35
@revisualize you have help me before...
Aizaz Shahid
@aizazshahid
May 25 2017 03:35
@MarioC3 i think the problem is that you are also iterating through the arr @Lumexralph is right there !
Kelechi Chinaka
@ke1echi
May 25 2017 03:35
i dont understand @Manish-Giri
Mario A. Carlos
@MarioC3
May 25 2017 03:35
Want to help me?
Joseph
@revisualize
May 25 2017 03:35
I am on a bus right now.
Aizaz Shahid
@aizazshahid
May 25 2017 03:35
@MarioC3 you have to make a for loop instead using that forEach
Mario A. Carlos
@MarioC3
May 25 2017 03:35
Ok.
Manish Giri
@Manish-Giri
May 25 2017 03:35
@kelechichinaka how much is 0 - 1?
Mario A. Carlos
@MarioC3
May 25 2017 03:35
I just want to understand the why?
Aizaz Shahid
@aizazshahid
May 25 2017 03:35
because you are also iterating through the arr
Mario A. Carlos
@MarioC3
May 25 2017 03:36
right
Aizaz Shahid
@aizazshahid
May 25 2017 03:36
so when you are cutting down it i think the size will gets ambiguous to forEach
Kelechi Chinaka
@ke1echi
May 25 2017 03:36
-1 @Manish-Giri
Aizaz Shahid
@aizazshahid
May 25 2017 03:36
@kelechichinaka yes !
Manish Giri
@Manish-Giri
May 25 2017 03:36
so there's your answer
@kelechichinaka
Mario A. Carlos
@MarioC3
May 25 2017 03:37
so First interaction it will take [0,1,2] and assign it to tempArray, and array is [3,4,5,6]
Kelechi Chinaka
@ke1echi
May 25 2017 03:37
ok..pls throw some light on it @Manish-Giri
Ogundele Olumide
@Lumexralph
May 25 2017 03:37
@MarioC3 just like this is what I came up with, try if it works, used the second parameter index and used modulo
Manish Giri
@Manish-Giri
May 25 2017 03:37
what light?
it's just math.
Ogundele Olumide
@Lumexralph
May 25 2017 03:37
@MarioC3
arr.forEach(function(element, index){
    if(index % size === 0) {
    tempArray.push(arr.slice(index, index + size));
Mario A. Carlos
@MarioC3
May 25 2017 03:37
second iteration it will take [3,4,5] and assign it to tempArray, and array is [6]
and shouldnt the thrid interaction take the remaining 6 and assign it that 6 to Temparray?
Zachary Orona-Calvert
@TheTRUEHoohah
May 25 2017 03:37
hey guys how would i make elements randomly light up in JS
i'm doing the simon says challenge
Aizaz Shahid
@aizazshahid
May 25 2017 03:38
@MarioC3 logically yes but i think it has its own algorithm to iterate that's why.
Ogundele Olumide
@Lumexralph
May 25 2017 03:38
@Manish-Giri @kelechichinaka @revisualize Good Morning
Manish Giri
@Manish-Giri
May 25 2017 03:38
@TheTRUEHoohah you could store the elements in an array
use a random number to pick an element from the array
@Lumexralph :wave:
Zachary Orona-Calvert
@TheTRUEHoohah
May 25 2017 03:38
okay @Manish-Giri then use math.random
Aizaz Shahid
@aizazshahid
May 25 2017 03:38
you are also changing it so as i said size will not be the same
Thomas Magnus
@tmag298
May 25 2017 03:38
With If statements, is the first return statement always a return statement for the "true" result and the second for the "false" result
?
Zachary Orona-Calvert
@TheTRUEHoohah
May 25 2017 03:39
then increase the count with count++?
Aizaz Shahid
@aizazshahid
May 25 2017 03:39
@tmag298 yes !
Ogundele Olumide
@Lumexralph
May 25 2017 03:39
@Manish-Giri how's thesis?
Kelechi Chinaka
@ke1echi
May 25 2017 03:39
:wave: @Lumexralph morning bro
Thomas Magnus
@tmag298
May 25 2017 03:39
@forwebtech thanks
CamperBot
@camperbot
May 25 2017 03:39
tmag298 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 588 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
May 25 2017 03:39
@tmag298 second one is else or else if, for the false ones
Manish Giri
@Manish-Giri
May 25 2017 03:40
@Lumexralph back and forth between the official docs and SO
:weary:
Rick Riggs
@wikiwiggs
May 25 2017 03:41
@Marmiz I will see what I can do on that front, thanks for the pointer.
CamperBot
@camperbot
May 25 2017 03:41
wikiwiggs sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 888 | @marmiz |http://www.freecodecamp.com/marmiz
Ogundele Olumide
@Lumexralph
May 25 2017 03:41
@Manish-Giri :joy:
@MarioC3 seen it?
Mario A. Carlos
@MarioC3
May 25 2017 03:42
Yeah...
Ogundele Olumide
@Lumexralph
May 25 2017 03:42
@MarioC3 did it work for you?
Mario A. Carlos
@MarioC3
May 25 2017 03:42
I still want to understand why the forEach()
Kelechi Chinaka
@ke1echi
May 25 2017 03:42
hows it been @Lumexralph
Mario A. Carlos
@MarioC3
May 25 2017 03:42
function ignores my last iteration
Ogundele Olumide
@Lumexralph
May 25 2017 03:43
@MarioC3 did it solve the problem first?
Mario A. Carlos
@MarioC3
May 25 2017 03:43
I haven't implemet it
I kinda want to use my own code
Ogundele Olumide
@Lumexralph
May 25 2017 03:44
@kelechichinaka been good bro, about submitting the application
Claudio Restifo
@Marmiz
May 25 2017 03:44

@wikiwiggs if that was a node, when parsing the response should able to see that the twitchTV just send back a 404 and still send a repsonse

if (req.status === 404) res.status(200).json({user: 'no exist'}

(dumb example)
Still seems your API doesn't handle this case

Ogundele Olumide
@Lumexralph
May 25 2017 03:44
@MarioC3 i used your code
Rick Riggs
@wikiwiggs
May 25 2017 03:44
@Marmiz unfortunately it is a PHP backend
Claudio Restifo
@Marmiz
May 25 2017 03:45
@wikiwiggs do the same in PHP :)
cannot help with that. php is not my bread and butter
Rick Riggs
@wikiwiggs
May 25 2017 03:45
shouldn't a try/catch do the trick?
Claudio Restifo
@Marmiz
May 25 2017 03:46
@wikiwiggs in theory all you have to do is instruct your end to handle 404 response and still send back a response :)
Kelechi Chinaka
@ke1echi
May 25 2017 03:47
ok.. @Lumexralph
Rick Riggs
@wikiwiggs
May 25 2017 03:47
@Marmiz I'm just not sure how to do that, because I'm using php's file_get_contents() function. That's how I'm successfully retrieving the json
Masaki
@masaki1223
May 25 2017 03:47
How can I fix CORS issue?
Thien VoMinh
@thienvm
May 25 2017 03:51
"myVar = myVar should be changed " I do not understand. who can help me?
Ogundele Olumide
@Lumexralph
May 25 2017 03:51
@MarioC3 only thing I avoided doing was mutating the array you're iterating through, so used slice then i used the second parameter of the callback which takes index, if you'll be chunking the array according to size, means the index is a multiple of the size and I used modulo to get that and sliced starting from the index and ending at index + size.... worked here it might still fail a test or not, that's why I said you try it....it's your code bro
@thienvm are you on increment operation?
Claudio Restifo
@Marmiz
May 25 2017 03:53
@wikiwiggs unfortunately cannot help in php. But at least I've (hopefully) found the problem from now on cannot be of much help :/
Ogundele Olumide
@Lumexralph
May 25 2017 03:53
@MarioC3 so yours probably didn't do what you wanted cos of splice which changed the initial array
Claudio Restifo
@Marmiz
May 25 2017 03:54
@wikiwiggs i'd start to see if get_content return something with the 404. and if so...what?

@MarioC3 give a deep read at foreach. If you modify the array some element will be skipped:

he range of elements processed by forEach() is set before the first invocation of callback. Elements that are appended to the array after the call to forEach() begins will not be visited by callback. If the values of existing elements of the array are changed, the value passed to callback will be the value at the time forEach() visits them; elements that are deleted before being visited are not visited. If elements that are already visited are removed (e.g. using shift()) during the iteration, later elements will be skipped - see example below.

And that's the case.
your function is skipping both the 3 and 6 iteration.
try a console.log(element) to see it

siva prasad
@sivaprasad92
May 25 2017 03:58
how can i use increment to this code
Ogundele Olumide
@Lumexralph
May 25 2017 03:58
@sivaprasad92 use what?
siva prasad
@sivaprasad92
May 25 2017 03:59
var myVar = 87;
increment operator to the above code
Mario A. Carlos
@MarioC3
May 25 2017 04:00
Thanks @Marmiz! That's exactly what I was asking!
CamperBot
@camperbot
May 25 2017 04:00
marioc3 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 889 | @marmiz |http://www.freecodecamp.com/marmiz
Ogundele Olumide
@Lumexralph
May 25 2017 04:00
@sivaprasad92
let a = 1;
//using post-increment operator
a++; //2, increases a by 1  just like  a = a + 1
@MarioC3 :joy:
Mario A. Carlos
@MarioC3
May 25 2017 04:01
I didn't understand forEach!
Claudio Restifo
@Marmiz
May 25 2017 04:01
@MarioC3 I like the idea of recurive function, but you cannot use a forEach on an element that's changing.
I'd rather use a while (eg: while arr.length // iterate and modify array).
Rick Riggs
@wikiwiggs
May 25 2017 04:01
@Marmiz That's all I'm doing is setting the file_get_contents(my API call) to a variable and echoing that back out to the client
@Marmiz So it is just returning nothing, or not returning at all.
Ogundele Olumide
@Lumexralph
May 25 2017 04:02
@MarioC3 okay.... so it all still went on the fact that forEach or not, becareful about mutating an array you're looping through, maybe avoid it
Claudio Restifo
@Marmiz
May 25 2017 04:03
@MarioC3 for each apply a callback function to each element of the array. But mid execution you change it.
If this was C with some pointer you'd probably just segmented it :)
Mario A. Carlos
@MarioC3
May 25 2017 04:03
@Marmiz So for this problem, and my code:

function chunkArrayInGroups(arr, size) {
  // Break it up.
  var tempArray = [];
  arr.forEach(function(element){
    tempArray.push(arr.splice(0, size));
  });

return tempArray;

}

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3);
I need to figure another conditional then...
like while
correct?
Ogundele Olumide
@Lumexralph
May 25 2017 04:04
@MarioC3 you can still use your code
Claudio Restifo
@Marmiz
May 25 2017 04:04
@MarioC3 there are many more solution. Just hope you saw the flaws in the logic you implemented
Mario A. Carlos
@MarioC3
May 25 2017 04:04
Yessssss!!!!
Thanks
Huzzzaaaaahhhh
I understand it!
evaparicio
@evaparicio
May 25 2017 04:05

Hi guys i have a question. I'm working on making a mad lib sentence in freecodecamp.com, but its not working D: can someone help please? this is what i have now.​
2
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
3
var result = "";
4
// Your code below this line
5

6
var myStr = "The " + myAdjective +", ugly" +myNoun + "jumped and " +myVerb+ "to its home.";
7

8

9
// Your code above this line
10
return result;
11
}
12

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

Mario A. Carlos
@MarioC3
May 25 2017 04:05
I know there are a lot of solutions
Thanks @Lumexralph for providing one
CamperBot
@camperbot
May 25 2017 04:05
marioc3 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1810 | @lumexralph |http://www.freecodecamp.com/lumexralph
Joseph
@revisualize
May 25 2017 04:05
@evaparicio You need spaces between all of the words.
Claudio Restifo
@Marmiz
May 25 2017 04:05
@wikiwiggs probably, have you console.log the echo?
Ogundele Olumide
@Lumexralph
May 25 2017 04:05
@evaparicio you need to put spaces between your strings
Joseph
@revisualize
May 25 2017 04:06
@evaparicio "The " + myAdjective +", ugly" +myNoun ... You're missing spaces.
Mario A. Carlos
@MarioC3
May 25 2017 04:06
I just wanted to understand why my solution wasn't working and why `forEach' skipped the last iteration.
Turns out, you were right @Marmiz
Joseph
@revisualize
May 25 2017 04:06
@evaparicio Also, you shouldn't be assigning the value to myStr you need to assign it to result you're returning result
Mario A. Carlos
@MarioC3
May 25 2017 04:06
If I used splice I just needed the conditional to return true and I was golden.
This is my last solution:
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var tempArray = [];
  while(arr.length){
    tempArray.push(arr.splice(0, size));
  }

return tempArray;

}

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3);
and voila.... It work like a charm
evaparicio
@evaparicio
May 25 2017 04:07
oh... ok let me try. thank you
Claudio Restifo
@Marmiz
May 25 2017 04:07
@MarioC3 :+1: :sparkles: this makes way more sense ^^
(mainly because I've suggested it :P)
Mario A. Carlos
@MarioC3
May 25 2017 04:07
Lol
Thanks!
Thanks for making it understand
me*
Now to the next one!
Anker
@ankerpeet
May 25 2017 04:30
so
so im trying to get this to loop
```
im tring to get this output, but with loops. Any tips of where to start. I'm just having trouble how to structure the loops properly .
function largestOfFour(arr) {
  //declare variables
  var firstArr = arr[0];
  var secondArr = arr[1]; 
  var thirdArr = arr[2];
  var fourthArr = arr[3]; 
  //sort
  firstArr.sort(function(a, b){return b - a;});
  secondArr.sort(function(a, b){return b - a;});
  thirdArr.sort(function(a, b){return b - a;});
  fourthArr.sort(function(a, b){return b - a;});

  var finalArr = [firstArr[0], secondArr[0], thirdArr[0], fourthArr[0]];

  return finalArr;

}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Augusto
@hackedWifi
May 25 2017 04:34
Can anyone explain why does this regExp insert and space once it has found its matches
I am confused about this str = str.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();
Markus Ivancsics
@ivancsicsmarkus
May 25 2017 04:36
@ankerpeet
function largestOfFour(arr) {
  var largest = function(a, b){return b - a;}
  for (var i = 0; i < arr.length; i++) {
     arr[i].sort(largest);
  }
  var finalArr = [arr[0][0], arr[1][0], arr[2][0], arr[3][0]];
  return finalArr;
}

@hackedWifi

  "$1 $2"

there’s ^^ a space.

Augusto
@hackedWifi
May 25 2017 04:39
I was confused about that @ivancsicsmarkus . I was not understandig what the $1 $2 was doing. Now it is clear
danghv
@danghv
May 25 2017 04:41
someone plz helps me out:

function golfScore(par, strokes) {
// Only change code below this line
if(strokes == 1){
return "Hole-in-one!";
}
else if(strokes <=(par-2)){
return "Egale";
}
else if(strokes == (par -1)){
return "Birdie";
}
else if(strokes == par){
return "Par";
}
else if(strokes == (par+1)){
return "Bogey";
}
else if(strokes == (par +2)){
return "Double Bogey";
}
else{
return "Go Home!";
}
return "Change Me";
// Only change code above this line
}

// Change these values to test
golfScore(5, 2);

still got this: golfScore(4, 2) should return "Eagle"
Mike Hernandez
@nandez678
May 25 2017 04:42
Did anyone else have trouble with the Convert Celsius to Fahrenheit challenge. I went to GitHub and found a solution, but I was (am) lost!
Markus Ivancsics
@ivancsicsmarkus
May 25 2017 04:42
@hackedWifi Could you please give me brownie points?
Claudio Restifo
@Marmiz
May 25 2017 04:43
@nandez678 what confuses you? Also as much as you are frustrated try to come up with your solution.
And in case you end up looking at someone else's... then go back an try to see where you got stuck
Augusto
@hackedWifi
May 25 2017 04:44
No @ivancsicsmarkus lol. Thanks
CamperBot
@camperbot
May 25 2017 04:44
hackedwifi sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:cookie: 518 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
Ogundele Olumide
@Lumexralph
May 25 2017 04:44
@danghv I think there's a typo here return "Egale"; should be Eagle
Mykel Pyles
@Crim5onx
May 25 2017 04:44
I am having trouble with the Escape Sequences. Why is the code not accepting this:
var myStr= "Firstline \n \Secondline\ \r Thridline";
Claudio Restifo
@Marmiz
May 25 2017 04:44
@danghv watch out for spelling:
return "Egale";
Mykel Pyles
@Crim5onx
May 25 2017 04:44
var myStr= "Firstline \n \Secondline\ \r Thridline";
Ogundele Olumide
@Lumexralph
May 25 2017 04:45
@nandez678 where're you lost?
Mykel Pyles
@Crim5onx
May 25 2017 04:45
It is cutting out the double back slashes around the secondline for some reason
Claudio Restifo
@Marmiz
May 25 2017 04:45
@Crim5onx aren't you supposed to return some backslash as well?
Ogundele Olumide
@Lumexralph
May 25 2017 04:45
@Crim5onx FirstLine check the L make sure it's caps
danghv
@danghv
May 25 2017 04:46
@Lumexralph @Marmiz thanks
CamperBot
@camperbot
May 25 2017 04:46
danghv sends brownie points to @lumexralph and @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1811 | @lumexralph |http://www.freecodecamp.com/lumexralph
:cookie: 890 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
May 25 2017 04:46
also mind capitalization, if I recall is FirstLine
Ogundele Olumide
@Lumexralph
May 25 2017 04:46
@Crim5onx eliminate any space between your string too
@danghv :+1:
Mykel Pyles
@Crim5onx
May 25 2017 04:47
var myStr= "FirstLine\n\SecondLine\\rThridLine";
So why won't chat show my double backslashes?
Ogundele Olumide
@Lumexralph
May 25 2017 04:47
@Crim5onx gitter eats it up :smile:
Mike Hernandez
@nandez678
May 25 2017 04:48
@Marmiz I just didnt know where to begin. with the function and return and convertToF(celsius). I googled it, tried to see if I could figure it out in this Jon Duckett Book....Im new to all this.
Ogundele Olumide
@Lumexralph
May 25 2017 04:48
@Crim5onx put the code between 2 backticks ```
@nandez678 do you understand the construct of a function and how it works?
Mike Hernandez
@nandez678
May 25 2017 04:49
@Lumexralph no. I think thats my biggest problem.
Mykel Pyles
@Crim5onx
May 25 2017 04:49
var myStr= "FirstLine\n\\SecondLine\\\rThridLine";
Ogundele Olumide
@Lumexralph
May 25 2017 04:50
@nandez678 why don't you try this link if it'll help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions
Claudio Restifo
@Marmiz
May 25 2017 04:51
@Crim5onx lgtm. try refreshing the page if not passing :)
Ogundele Olumide
@Lumexralph
May 25 2017 04:51
@Crim5onx ThirdLine not ThridLine
Claudio Restifo
@Marmiz
May 25 2017 04:51
woops! :D
@Lumexralph hawk eye!
Ogundele Olumide
@Lumexralph
May 25 2017 04:52
@Marmiz :joy:
Mike Hernandez
@nandez678
May 25 2017 04:52
@Lumexralph I see its coming up in the next course. object oriented...functions .. thanks for the link. I will check it out.
CamperBot
@camperbot
May 25 2017 04:52
nandez678 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1812 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
May 25 2017 04:53
@nandez678 all the best
Mykel Pyles
@Crim5onx
May 25 2017 04:53
@Lumexralph @Marmiz Thank you. Who knew it was a spelling error that would be my downfall
CamperBot
@camperbot
May 25 2017 04:53
crim5onx sends brownie points to @lumexralph and @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 891 | @marmiz |http://www.freecodecamp.com/marmiz
:star2: 1813 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ayush Bahuguna
@relentless-coder
May 25 2017 04:54
is anyone here into chai mocha testing??
Mike Hernandez
@nandez678
May 25 2017 04:55
@Lumexralph I keep thinking / hoping if I read it and re-read it and watch videos and re-read it that it will sink in . :)
Daniel Zeff
@Diesirae9
May 25 2017 04:55
more of an americano fan ;) @relentless-coder
lol
Abhishek Tiwari
@fillopfy
May 25 2017 04:55
@fillopfy
is there any restriction on strings to be entered in an array in javascript of codepen
it is saying, unexpected string
Ayush Bahuguna
@relentless-coder
May 25 2017 04:56
@Diesirae9 you keep it up. :+1:
Claudio Restifo
@Marmiz
May 25 2017 04:56
@relentless-coder Did some. Not an expert by any means.
@fillopfy how's your array?
Ayush Bahuguna
@relentless-coder
May 25 2017 04:57
describe('join team test', () => {
    let team = {};
    let id;
    let user = {};
    let team_id;
    let userId;
    beforeEach(() => {
        team.Name = "Kake Da Dhaba";
        team.address = "Chor Gali";
        Team.create(team, (err, createTeam) => {
            const str = createTeam.Name.replace('\s', '').slice(-3).split('').map(el => el.toUpperCase()).join('') + extract(createTeam._id);
            createTeam.teamId = str;
            createTeam.TeamMembers = [];
            createTeam.save();
            id = createTeam._id;
            team_id = createTeam.teamId;
        })

        user.name = "Chacha Dhacha";

    })

    afterEach(()=>{
        User.remove();
        Team.remove();
    })

    it('should be an actual user', ()=>{
         User.create(user, (err, createUser)=>{
            userId = createUser._id;
            createUser.team = team_id;
        should.exist(userId);

        })
    })

    it('should attach a user to a team', function(done){
        this.timeout(10000);
         User.create(user, (err, createUser)=>{
            userId = createUser._id;
            createUser.team = team_id;
            Team.findOne({teamId: team_id}, (err, foundTeam)=>{
            foundTeam.TeamMembers.push(createUser._id);
            foundTeam.save((err, savedTeam)=>{
            const length = savedTeam.TeamMembers.length;
               const index = savedTeam.TeamMembers.indexOf(createUser._id);
               index.should.equal(length - 1);
            })
        })

    })
    done();

    })
})
@Marmiz
Abhishek Tiwari
@fillopfy
May 25 2017 04:57
@Marmiz its an array of quotes
it is saying, unexpected string
Ayush Bahuguna
@relentless-coder
May 25 2017 04:57
@Marmiz my second test won't pass.
Abhishek Tiwari
@fillopfy
May 25 2017 04:58
var quotes=[
 " Don't cry because it's over, smile because it happened. ― Dr. Seuss"
  "Be yourself, everyone else is already taken. - Oscar Wilde"
"Two things are infinite the universe and human stupidity and I'm not sure about the universe. ― Albert Einstein"
  "Be who you are and say what you feel, because those who mind don't matter, and those who matter don't mind. ― Bernard M. Baruch”
  "A room without books is like a body without a soul. ― Marcus Tullius Cicero"
 "You only live once, but if you do it right, once is enough. ― Mae West"
  "Be the change that you wish to see in the world. ― Mahatma Gandhi"
  "In three words I can sum up everything I've learned about life: it goes on. ― Robert Frost"
  "If you want to know what a man's like, take a good look at how he treats his inferiors, not his equals. ― J.K. Rowling"
  "No one can make you feel inferior without your consent. ― Eleanor Roosevelt, This is My Story"
  "Darkness cannot drive out darkness: only light can do that. Hate cannot drive out hate: only love can do that. ― Martin Luther King Jr."

];
Claudio Restifo
@Marmiz
May 25 2017 04:59
@fillopfy the , comma to separate element
Abhishek Tiwari
@fillopfy
May 25 2017 04:59
@fillopfy codepen is saying : Unexpected String
@Marmiz ahh...i really forgot to to do that, I was just copying quotes one after other from google
Claudio Restifo
@Marmiz
May 25 2017 05:00
@relentless-coder what error (if any) is throwing?
Abhishek Tiwari
@fillopfy
May 25 2017 05:02
@Marmiz even after comma, it is saying:Unexpected token illegal
Ayush Bahuguna
@relentless-coder
May 25 2017 05:02
@Marmiz expected 0, actual -1
nevermind, I was expecting wrong thing.
valeria vicuña
@vale99nadin
May 25 2017 05:04
can you give me the code for Profile Lookup? I've got stuck there D:
Claudio Restifo
@Marmiz
May 25 2017 05:05
@fillopfy since you copied from google, may be some char that is invisible but get parsed into JS as well. Make sure there are no extra characters and the string are exactly as you expect
@relentless-coder :+1:
Abhishek Tiwari
@fillopfy
May 25 2017 05:06
@Marmiz okay, let me type them and try again
MissLisaMN
@MissLisaMN
May 25 2017 05:40
i am in the exercise "Check for Palindromes" and my code works for all but 2 of the tests. Can someone point me to what my code is missing please?
function palindrome(str) {
var newStr = str.replace(/[^0-9a-z]/gi, "");
var anotherStr = newStr.toLowerCase().split('').reverse().join('');
if (anotherStr === newStr){
return true;
} else {
return false;
}
}
palindrome("eye");
the 2 it doesnt work for has commas and a period, maybe that is something?
palindrome("eye") should return a boolean.
palindrome("eye") should return true.
palindrome("_eye") should return true.
palindrome("race car") should return true.
palindrome("not a palindrome") should return false.
palindrome("A man, a plan, a canal. Panama") should return true.
palindrome("never odd or even") should return true.
palindrome("nope") should return false.
palindrome("almostomla") should return false.
palindrome("My age is 0, 0 si ega ym.") should return true.
palindrome("1 eye for of 1 eye.") should return false.
palindrome("00 (: /-\ :) 0-0") should return true.
palindrome("five|\
/|four") should return false.
the * ones are the ones that fail...
oh wait * made it italic from the first to 2nd one...
*facepalm
Anker
@ankerpeet
May 25 2017 05:43
@MissLisaMN instead of splitting it, reversing it, then joining it back together, use the filter() function while it is still in an array state to try and filter out those symbols you dont want. Then join it back to a string.
keep what you have, you just need to add a filter() function before the join() function
MissLisaMN
@MissLisaMN
May 25 2017 05:49
thank you @ankerpeet however it doenst work after that addition, should I put anything in the ()?
CamperBot
@camperbot
May 25 2017 05:49
misslisamn sends brownie points to @ankerpeet :sparkles: :thumbsup: :sparkles:
:cookie: 253 | @ankerpeet |http://www.freecodecamp.com/ankerpeet
Anker
@ankerpeet
May 25 2017 05:50
@MissLisaMN the filter funtion will be set up something like this;
var filterArr = newArray.filter(function(val) {
    return val != "*" && val != " " && val != "_";
  });
@MissLisaMN basically start listing any symbol you do not want to appear in the new filtered array
the code i just sent you would create an array that eliminates all *, spaces, and _
so you just need to add more != which is not equal to and then in "" add the symbol
Markus Kiili
@Masd925
May 25 2017 05:55
@MissLisaMN First replace and lowercase. Then compare that string with the reversed one.
So the problem is that newStr is not lowercased there.
Bharathiraja
@bharathi04
May 25 2017 06:13
Hi!, anyone please help me to solve "Stand in Line" topic in javascript
Markus Kiili
@Masd925
May 25 2017 06:13
@bharathi04 Sure.
What have you done so far?
Bharathiraja
@bharathi04
May 25 2017 06:15
@Masd925 Thank you. I can't able to understand the concept
CamperBot
@camperbot
May 25 2017 06:15
bharathi04 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4136 | @masd925 |http://www.freecodecamp.com/masd925
Bharathiraja
@bharathi04
May 25 2017 06:15
can you able to review it
Markus Kiili
@Masd925
May 25 2017 06:15
@bharathi04 You need to use two of the array methods you just learned, and use them on arr and item.
Bharathiraja
@bharathi04
May 25 2017 06:17
@Masd925 Yes of course push() and shift(). But can't able to solve the second and third hint
Markus Kiili
@Masd925
May 25 2017 06:17
@bharathi04 Yes. You only need two lines of code here. First uses push and second uses return and shift.
Bharathiraja
@bharathi04
May 25 2017 06:18

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,5)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Markus Kiili
@Masd925
May 25 2017 06:18
@bharathi04 Don'
Don't use testArr.
It is only for FCC tests on your function.
Use arr and item. They are the function parameters that hold the array and number from the function call.
Bharathiraja
@bharathi04
May 25 2017 06:20
Oh! k k, i try this now. Thank you
@Masd925 Sorry, i can't able solve it
can't able to solve it
Markus Kiili
@Masd925
May 25 2017 06:25
@bharathi04 First push item to arr.
Bharathiraja
@bharathi04
May 25 2017 06:25
arr.push(item);
Is this right?

function nextInLine(arr, item) {
// Your code here
arr = [5,6,7,8,9];
arr.push(item);
arr.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,5)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 3));
console.log(nextInLine(arr[2], 1));

nextInLine([2], 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
After nextInLine(testArr, 10), testArr[4] should be 10
h1tag
@h1tag
May 25 2017 06:29
@bharathi04 no, you have to return the item that was removed/shifted. Not the one that was added/pushed
Bharathiraja
@bharathi04
May 25 2017 06:40
@h1tag Thank you. What is the use of "testArr", Why should that used.
CamperBot
@camperbot
May 25 2017 06:40
bharathi04 sends brownie points to @h1tag :sparkles: :thumbsup: :sparkles:
:cookie: 797 | @h1tag |http://www.freecodecamp.com/h1tag
h1tag
@h1tag
May 25 2017 06:42
@bharathi04 to test ur solution/code
Bharathiraja
@bharathi04
May 25 2017 06:42
k how do i pass the arr(array)
h1tag
@h1tag
May 25 2017 06:43
@bharathi04 like you pass any other parameter
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr,5)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 3));
console.log(nextInLine(arr[2], 1));
^ it's already used passed here to test your solution
Bharathiraja
@bharathi04
May 25 2017 06:44
console.log(nextInLine(arr[2], 1));
if i use this code, their was an error will shows
arr is not defined
h1tag
@h1tag
May 25 2017 06:44
@bharathi04 yes, of course, you have to define it first
Anker
@ankerpeet
May 25 2017 06:45
function truncateString(str, num) {
  //variables
  var length = num - 3;
  var lengthLess3 = num;
  var dots = "...";
  var newStr = "";
  //slice string when num is 3 or less
  if (num <= 3) {
  newStr = str.slice(0, lengthLess3);
  return newStr + dots;  
  }
  //slice string normal
  newStr = str.slice(0, length);
  return newStr + dots;
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
this seems to not work on 2 of the test strings.
any suggestions?
Bharathiraja
@bharathi04
May 25 2017 06:46
already i was defined it inside the function, then how access outside of it
Manish Giri
@Manish-Giri
May 25 2017 06:47
@bharathi04 when you call a function, you have to provide it an array
arr is not defined anywhere outside the function
hence the error.
Bharathiraja
@bharathi04
May 25 2017 06:48
how i would solve it
@Manish-Giri Here the conditions where i have to solve nextInLine([2], 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
After nextInLine(testArr, 10), testArr[4] should be 10
Manish Giri
@Manish-Giri
May 25 2017 06:49
show your code
Bharathiraja
@bharathi04
May 25 2017 06:50

function nextInLine(arr, item) {
// Your code here
arr = [5,6,7,8,9];
arr.push(item);
arr.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,5)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
console.log(nextInLine(arr[2],5));

Manish Giri
@Manish-Giri
May 25 2017 06:50
@bharathi04 why are you doing this? arr = [5,6,7,8,9];
Bharathiraja
@bharathi04
May 25 2017 06:50
i'm just tried... sry
jmariomejiap
@jmariomejiap
May 25 2017 06:51
@Masd925 hi markus. are you around?
Bharathiraja
@bharathi04
May 25 2017 06:51
@Manish-Giri May i know the correct way to solve the probem
problem
Manish Giri
@Manish-Giri
May 25 2017 06:53
@bharathi04 delete that line first
@bharathi04 next thing you need to do is return what you get from here - arr.shift();
Bharathiraja
@bharathi04
May 25 2017 06:54
i'm already deleted the arr[] and returned the item like return item;
is that wrong
Blauelf
@Blauelf
May 25 2017 06:56
Happy Towel day everyone :)
Manish Giri
@Manish-Giri
May 25 2017 06:56
dude
@bharathi04 next thing you need to do is return what you get from here - arr.shift();
is this the same as return item?
@Blauelf same to you :smile:
jmariomejiap
@jmariomejiap
May 25 2017 06:57

hey guys. I have been working on my "sum all primes" algorithm. but im still having troubles.


function sumPrimes(num) {
  var composite = [];
  var primes = [];
  var total = 0;

  for (var twos = 4; twos <= num; twos += 2) {
    composite.push(twos);
  }
  for (var threes = 6; threes <= num; threes += 3) {
    composite.push(threes);
  }

  for (var five = 10; five <= num; five += 5) {
    composite.push(five);
  }

  for (var seven= 14; seven <= num; seven += 7) {
    composite.push(seven);
  }

  for (var elevens = 11; elevens <= num; elevens += 11) {
    composite.push(elevens);
  }

  for (var it = 2; it <= num; it++) {
    if (composite.indexOf(it) === -1) {
      primes.push(it);
      total += it;
    }    
  }
  return total;
}

sumPrimes(977);

my implementation fails to create primes after 169.
any ideas? I am trying to use https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Bharathiraja
@bharathi04
May 25 2017 06:59
Thank you all guys!
Finally i done it
ozmusicman
@ozmusicman
May 25 2017 07:02
Hi Everyone, i'm new to freeCodeCamp and I just got stuck in the 'Escape Sequences in Strings' section. Specifically "myStr should have encoded text with the proper escape sequences and no spacing."
my code is here -
var myStr = "\"FirstLine\"\n\\"SecondLine\"\\r\"ThirdLine\""; // Change this line
lagasi
@lagasi
May 25 2017 07:03
@jmariomejiap That's because your composites only go up to multiples of 11
@jmariomejiap 13*13 = 169
jmariomejiap
@jmariomejiap
May 25 2017 07:03
@lagasi ok... please bare with me... i love coding so much but math as never been my cup of tea.
aaaaaa... ok I should implement that in another loop.
tahashin
@tahashinegp
May 25 2017 07:04

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.

var newArray = oldArray.filter(function(val){
return val > 5 ;
});

lagasi
@lagasi
May 25 2017 07:05
@jmariomejiap This method requires you to generate composites of multiples up to sqrt(n)
tahashin
@tahashinegp
May 25 2017 07:05
You should have filtered out all values from the array that are greater than 5.
it should work isnt it?
in console it shoiwng 6,7,8,910
but it s showing cross in "You should have filtered out all values from the array that are greater than 5."
lagasi
@lagasi
May 25 2017 07:06
@jmariomejiap Take a look at the pusedo code and try to implement that: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Pseudocode
tahashin
@tahashinegp
May 25 2017 07:08
why it is swhoing wrong?
Dan Couper
@DanCouper
May 25 2017 07:10
@tahashinegp the filter keeps values that the callback function returns true for. So in your function you are saying keep values greater than 5, whereas you want to say keep values less than 5
  • less than 6, or less than or equal to 5, sorry
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:11

function convertToF(celsius) {
  var fahrenheit;
  // Only change code below this line
  var celcius;
fahrenheit = celcius * 9/5  +32;

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

// Change the inputs below to test your code
convertToF(30);
is this code alright?
jmariomejiap
@jmariomejiap
May 25 2017 07:12
@lagasi I think I am finally getting it. thank you sooooo much for helping me out.
CamperBot
@camperbot
May 25 2017 07:12
jmariomejiap sends brownie points to @lagasi :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @lagasi |http://www.freecodecamp.com/lagasi
Dan Couper
@DanCouper
May 25 2017 07:13
You don't need var celcius, celcius is already there (as the argument to the function). If you leave it there it means you're redeclaring a variable called celcius with no value defined, which you don't want
@saifsmailbox98
Jacky
@skywards1910
May 25 2017 07:14
@saifsmailbox98 remove var celcisus; line
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:14
ReferenceError: celcius is not defined
I get this error without
var celcius;
Dan Couper
@DanCouper
May 25 2017 07:15
celsius
Not celcius
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:15
oh shit
Xarri Jorge
@xarrijorge
May 25 2017 07:15
@saifsmailbox98 celsius is mispelled
Dan Couper
@DanCouper
May 25 2017 07:15
😁
Xarri Jorge
@xarrijorge
May 25 2017 07:15
@saifsmailbox98 Language :laughing:
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:15
@DanCouper , @kodinglife thanks
CamperBot
@camperbot
May 25 2017 07:15
saifsmailbox98 sends brownie points to @dancouper and @kodinglife :sparkles: :thumbsup: :sparkles:
:cookie: 732 | @dancouper |http://www.freecodecamp.com/dancouper
:cookie: 441 | @kodinglife |http://www.freecodecamp.com/kodinglife
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:16
@skywards1910 thanks
CamperBot
@camperbot
May 25 2017 07:16
saifsmailbox98 sends brownie points to @skywards1910 :sparkles: :thumbsup: :sparkles:
:cookie: 168 | @skywards1910 |http://www.freecodecamp.com/skywards1910
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:20
what is the function of carriage return?
```
\r carriage return
\r
Anker
@ankerpeet
May 25 2017 07:21
function chunkArrayInGroups(arr, size) {
  //variables
  var firstArr = [];
  var secondArr = [];
  var finalArr = [];
  //slice array
  firstArr = arr.slice(0, size);
  secondArr = arr.slice(size, size * 2);
  finalArr.push(firstArr, secondArr);
  return finalArr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
any ideas on how to loop this so that it can create more than just 2 arrays?
Markus Kiili
@Masd925
May 25 2017 07:27
@ankerpeet You could loop arr indices with increment i+=size and then push slices of arr into the result array. Just figure out the slice indices.
Hisham Mubarak
@HishamMubarak
May 25 2017 07:27
Hi, I am now working on a password form. Whenever I submit the form, it checks if both passwords match, if they do, alerts passwords match and submits the form. When the passwords don't match, the form is still submitting! How do I make it to submit only when both the password fields are same. Below is the link to the my code
https://gist.github.com/HishamMubarak/a253b76cd948bc35ab08df3449867313
Ken Haduch
@khaduch
May 25 2017 07:27
@saifsmailbox98 - carriage return probably goes back to old manual typewriters where as you typed, the "carriage " that held the paper shifted across until you used the full width of the paper, then you had to manually return the carriage to the start. It is probably not really useful these days, but you'll come across it in some computer languages or O/S as a line terminator character.
Ken Haduch
@khaduch
May 25 2017 07:33
You can google that for a variety of answers
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:40
Whatis the problem with this code?
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line

result=myAdjective+myNoun+myVerb+myAdverb;
  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
Calvin
@oakypokey
May 25 2017 07:41
You need spaces @saifsmailbox98
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:41
okay
Calvin
@oakypokey
May 25 2017 07:41
currently your string looks like bigdogranquickly
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:41
let me try
oh yes
Xarri Jorge
@xarrijorge
May 25 2017 07:42
@oakypokey Not required
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:42
@oakypokey @khaduch thanks guys
CamperBot
@camperbot
May 25 2017 07:42
saifsmailbox98 sends brownie points to @oakypokey and @khaduch :sparkles: :thumbsup: :sparkles:
:cookie: 250 | @oakypokey |http://www.freecodecamp.com/oakypokey
:star2: 2912 | @khaduch |http://www.freecodecamp.com/khaduch
Calvin
@oakypokey
May 25 2017 07:44
Also, does anyone know why I need to add the +1 to arr.length on line 20?
function mutation(arr) {
  arr[0]=arr[0].toLowerCase();arr[1]=arr[1].toLowerCase();
  var test ='';
  var compare1 = '';
  var compare2 = '';

  if (arr[0].length > arr[1].length){
    compare1 = arr[1];
    compare2 = arr[0];
  } else if (arr[0].length < arr[1].length){
    compare1 = arr[0];
    compare2 = arr[1];
  } else {
    compare1 = arr[1];
    compare2 = arr[0];
  }


  for(var i = 0; i < arr.length + 1; i++){
    if (compare2.indexOf(compare1[i]) === -1){
      return false;
    }
  } return true;
}

mutation(["hello", "hey"]);
I only managed to get it by messing about, but I’d like to know the theory?
sunil
@usunil0
May 25 2017 07:46
hey everybody i was using this api http://www.recipepuppy.com/about/api/ to create a project but there is some problem i cant find this is my code
$.getJSON('http://www.recipepuppy.com/api/?i=onions,garlic&q=omelet&p=3',function(data){
  console.log(data);
})
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:46
@oakypokey
for(var i = 0; i <= arr.length; i++)
try this
Xarri Jorge
@xarrijorge
May 25 2017 07:47
@oakypokey You logic call for check on the length of the array which is two in this case. if you use less then 2, the loop runs once, using lenght +1 = 2 +1, which is 3 so the loops runs twice. less than three. it would also work it you used <= arr.length.
Calvin
@oakypokey
May 25 2017 07:47
@saifsmailbox98 The code works— it’s just I don’t know why it works haha
xyedabz
@xyedabz
May 25 2017 07:47
how to remove non-alphanumeric characters ?
Calvin
@oakypokey
May 25 2017 07:47
ahhh thanks @kodinglife
CamperBot
@camperbot
May 25 2017 07:47
oakypokey sends brownie points to @kodinglife :sparkles: :thumbsup: :sparkles:
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:47

WORD
0123

i goes for all indices

CamperBot
@camperbot
May 25 2017 07:47
:cookie: 442 | @kodinglife |http://www.freecodecamp.com/kodinglife
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:48
but it should be less than the length
should i give u an example?
Calvin
@oakypokey
May 25 2017 07:48
Oh i see what you did in your code @saifsmailbox98 thank you
CamperBot
@camperbot
May 25 2017 07:48
oakypokey sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 174 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Calvin
@oakypokey
May 25 2017 07:49
yeah i see i was missing the last letter
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:49
@oakypokey you're welcome
yes
Check out my Tribute Page
Makopa
@makopa
May 25 2017 07:51
Im trying to learn ES6 arrow function. but why i get error of object property of undefine in this line of codes
var myObject = {
  num1: 3,
  adder: (num2) => this.num1+num2
};


console.log(myObject.adder(2));
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:51
please help me in removing that grey bar from the photo caption
Lenarey S. Torririt
@Lengzki
May 25 2017 07:52

How will I convert Celsius to Fahrenheit ?
This is the current code:
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

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

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

Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:53
F=9/5 *C+32
Lenarey S. Torririt
@Lengzki
May 25 2017 07:53
@saifsmailbox98 yeah I know that but how should I code it?
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:54
@Lengzki assign 9/5*celsius +32 to fahrenheit
Lenarey S. Torririt
@Lengzki
May 25 2017 07:54
@saifsmailbox98 oh, thanks.
CamperBot
@camperbot
May 25 2017 07:54
lengzki sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 175 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:54
@Lengzki you are welcome
sunil
@usunil0
May 25 2017 07:55
anybody to help me out with my code
Saif Ur Rahman
@saifsmailbox98
May 25 2017 07:56
@usunil0 whats your code?
Claudio Restifo
@Marmiz
May 25 2017 07:56
@saifsmailbox98 that's the margin that comes from the h4. simply give it a margin-bottom: 0
Jan Arvin Lapuz
@jarvipuz
May 25 2017 07:56

Hi everyone,

Just want to ask for help regarding the below code. The nextInLine function takes an array and a number. It adds the number to the end of the array, then removes the first element of array. Then it returns the element that was removed. There are 4 test cases, I am not getting the 1st one:

nextInLine([], 1) should return 1 <---- shouldn't the output be [] instead of 1?
nextInLine([2], 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
After nextInLine(testArr, 10), testArr[4] should be 10

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

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Claudio Restifo
@Marmiz
May 25 2017 07:56
or make the whole image div with a white background
sunil
@usunil0
May 25 2017 07:56

@saifsmailbox98 i was using this api http://www.recipepuppy.com/about/api/ to create a project but there is some problem i cant find this is my code

$.getJSON('http://www.recipepuppy.com/api/?i=onions,garlic&q=omelet&p=3',function(data){
  console.log(data);
})

the data is not console logging