These are chat archives for FreeCodeCamp/HelpJavaScript

30th
Apr 2017
c0d0er
@c0d0er
Apr 30 2017 00:00
@TylerMoeller thanks
CamperBot
@camperbot
Apr 30 2017 00:00
c0d0er sends brownie points to @tylermoeller :sparkles: :thumbsup: :sparkles:
:star2: 1519 | @tylermoeller |http://www.freecodecamp.com/tylermoeller
enoatarisolo
@enoatarisolo
Apr 30 2017 00:01
Can anyone help me with escape sequences in strings?
Here is my code:
'var myStr = 'FirstLine"n\"\Second Line\"\r\"ThirdLine\"\'; // Change this line'
Argh it didn't send right
Brittany Rutherford
@brittanyrutherford
Apr 30 2017 00:11
if node uses commonjs module format, how come are we able to use es2015 module formats in node? r commonjs module format and es2015 integrated at some level?
Anupta Islam
@noopta
Apr 30 2017 00:12
can someone help me with the create a madlibs challenge on javascript
this is my code so far

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
myNoun = wordBlanks[wordBlanks.length-4];
myAdjective = wordBlanks[wordBlanks.length-3];
myVerb = wordBlanks[wordBlanks.length-2];
myAdverb= wordBlanks.length[0];
result = "Today, my " + myNoun + " looked very " + myAdjective + "and " + myVerb + myAdverb;

// Your code above this line
return result;
}

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

rn im unable to get the words from the wordBlanks at the bottom, to appear in my sentence
Vamp
@the-vampiire
Apr 30 2017 00:18
when your function is called it is being passed 4 arguments. inside your function all you need to do is set the variable names in place
what you are currently doing is assuming that the function is being passed an array, instead they are 4 separate arguments
myNoun = wordBlank[wordBlanks.length-4] 
// assumes wordBlanks is being passed an array whose first element is ‘myNoun’

// myNoun is already being passed individually. so just remove the top half of your code and leave result as is

alternatively if you’d like to keep the declarations youve made on the top half of your code you can add this above

var wordBlanks = [myNoun, myAdjective, myVerb, myAdverb];

now this will be consistent with your array index approach to defining the variables.

But as I said this is doing double work. The variable already exist individually. Just showing this part for completion’s sake

@noopta
grfraser
@grfraser
Apr 30 2017 00:25
im learning React right now, is it worth it?
Manisha Chhibber
@Manisha11sep
Apr 30 2017 00:31
Hello guys..while solving "Where do i Belong" algorithm challenge...i am facing an issue.. My array is not sorting
all test cases are passing except one

function getIndexToIns(arr, num) {
// Find my place in this sorted array.
// arr.sort();
var index=-1;
for(var i=0; i<arr.length; i++) { if(arr[i]>=num)
{
index=i;
break;
}

}
if(index==-1)
{
index=arr.length;
}
return index;
}

getIndexToIns([2, 20, 10], 35);

Corey Pennington
@JuiceyDuecy
Apr 30 2017 00:32
you have arr.sort commented out
@Manisha11sep
remove your //
Manisha Chhibber
@Manisha11sep
Apr 30 2017 00:36
Yeah.. I removed that all test cases are passing except getIndexToIns([5, 3, 20, 3], 5) should return 2.
Gulsvi
@gulsvi
Apr 30 2017 00:37

@Manisha11sep a compare function is needed when sorting.

var scores = [1, 10, 21, 2]; 
scores.sort(); // [1, 10, 2, 21]
// Note that 10 comes before 2,
// because '10' comes before '2' in Unicode code point order.

For numbers, you would do something like the following to sort ascending:

arr.sort(function (a, b) {
  return a - b;
});

Examples above from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

[5, 3, 20, 3].sort() would result in [20,3,3,5]
Manisha Chhibber
@Manisha11sep
Apr 30 2017 00:38
let me try
awesome...Thank you @SkyCoder01
CamperBot
@camperbot
Apr 30 2017 00:39
manisha11sep sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1227 | @skycoder01 |http://www.freecodecamp.com/skycoder01
RonnyNovik
@RonnyNovik
Apr 30 2017 00:46
Hey can someone tell me why jquery misplacing my element?
$('.blackbox').show('clip', { direction: 'horizontal' }, 500);

div.blackbox{
display:none;
width:100%;
height:50%;
background:rgba(0, 0, 0,0.7);
padding-bottom: 150px;

}

Chris
@bestintown23
Apr 30 2017 00:51
what could prevent my page from having the overflow? I have to scroll to see my footer. when I would just like it on the bottom of the page without scrolling. Thanks. http://codepen.io/bestintown23/pen/ybyOqb
Anupta Islam
@noopta
Apr 30 2017 01:04
@the-vampiire what do you mean remove top half? theres a section im not allwoed to delete to complete the challenge
Vamp
@the-vampiire
Apr 30 2017 01:05
read what I said and you should understand what I am talking about
if not then you need to review the lessons before this challenge
@bestintown23
.foot{
  color:white;
  font-size:20px;
  position:fixed;
  bottom: 0px;
}
@bestintown23 for future reference you will et more help on front end questions in FCC/HelpFrontEnd. this chat is for javascript related questions
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:11
Hello
I am working on the profile lookup asisgnment
function lookUpProfile(firstName, prop){
// Only change code below this line
for ( var i = 0; i < contacts.length; i++) {
if (contacts[i].hasOwnProperty(firstName)) {
return contacts[i][prop];
}
else{
return "No such contact";
}
}
}
what is wrong with this ?
Vamp
@the-vampiire
Apr 30 2017 01:12
when a return statement is reached in a loop the loop exits at that point whether it has reached its condition or not
function lookUpProfile(firstName, prop){
// Only change code below this line
  for ( var i = 0; i < contacts.length; i++) {
if (contacts[i].hasOwnProperty(firstName)) {
  return contacts[i][prop];
}
else{
return "No such contact";
}
     }


    }
Simeon
@SimeonCodes
Apr 30 2017 01:13
^^ and its only getting to the first entry
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:13
lol so it is a nested loop
Vamp
@the-vampiire
Apr 30 2017 01:13
meaning if you are looking for a contact that is not found in the first iteration of the loop it will hit that return statement and exit beore proceeding to the following loops / contacts
no it isnt
not the way you’ve written it at least
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:14
so I have to use something else at the return statement
Vamp
@the-vampiire
Apr 30 2017 01:14
no
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:15
I am not even close ?
Vamp
@the-vampiire
Apr 30 2017 01:15
what I said is that if a return statement is reached in your loop it will kick out of the loop at that point
looks close to me
walk through your loop mentally. try for i = 0, does it do what you expect? what if you are looking for a contact beyond i = 0? what happens when the loop goes through iteration 0 and hits the return statement (because you arent looking for contact[0])?
does it ever make it to contact[1]?
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:18
nope it returns with no such contact every single time
Vamp
@the-vampiire
Apr 30 2017 01:19
exactly
suppose you are looking for contact[1] aka i = 1.
you begin your loop for contact[0] aka i = 0
you do not find the contact you want
you hit your else statement
you hit a return statement
your loop breaks and never makes it to i = 1 or beyond.
how are you going to solve this dilemma
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:21
I want the loop to iterate until it has its own property
= == true
is it a while loop ? :D
Vamp
@the-vampiire
Apr 30 2017 01:22
you need to consider 2 checks:
1) does the firstName property of contact[i] match the firstName passed into your function
2, pass) does the contact[i] have the property ‘prop’ passed into your function
2, fail) does the NEXT contact match (aka repeat this process)
function lookUpProfile(firstName, prop){

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

    }

}
this much is correct
Simeon
@SimeonCodes
Apr 30 2017 01:25
bonfire
cbot
CamperBot
@camperbot
Apr 30 2017 01:25
you called?
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:26
so this one is not ?
if (contacts[i].hasOwnProperty(firstName)) {
return contacts[i][prop];
Vamp
@the-vampiire
Apr 30 2017 01:27
no
this much is correct
function lookUpProfile(firstName, prop){

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

    }

}
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:30
@the-vampiire thanks, I will re-learn the whole chapter
CamperBot
@camperbot
Apr 30 2017 01:30
jasoncorp84 sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 329 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:31
maybe that will help
Vamp
@the-vampiire
Apr 30 2017 01:31
maybe
i think what is more important is to think about what is being asked
I detailed your plan in 3 steps
hekri-d
@hekri-d
Apr 30 2017 01:32
@JasonCorp84 if I may suggest you don't go through the whole chapter again. Ask google for what you want to do you'll learn more that way
Vamp
@the-vampiire
Apr 30 2017 01:32
if (contacts[i].hasOwnProperty(firstName)) {
  return contacts[i][prop];
}

// this line says if contacts[i] has a property called firstName return that contacts’ property ‘prop’
// your check before returning the prop should be does this contact have a property called ‘prop’ if so return it
why not use hasOwnProperty to see if is has the property you are looking for?
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:34
nice I think I got it now
Ronique Ricketts
@RoniqueRicketts
Apr 30 2017 01:34
I need help with my code. its flex-box related
Csaba Balogh
@JasonCorp84
Apr 30 2017 01:34
lets see
Ronique Ricketts
@RoniqueRicketts
Apr 30 2017 01:34
Vamp
@the-vampiire
Apr 30 2017 01:35
is knowing whether a contact has the property firstName useful to you? no
knowing whether a contact has a property prop is useful
knowing whether a particular contact’s property firstName MATCHES the firstName you are looking for is useful.
@RoniqueRicketts you will get more help for css / html help in FCC/HelpFrontEnd
this is chat for javascript questions
Ronique Ricketts
@RoniqueRicketts
Apr 30 2017 01:35
@the-vampiire thanks
CamperBot
@camperbot
Apr 30 2017 01:35
roniquericketts sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 330 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Simeon
@SimeonCodes
Apr 30 2017 01:43
@JasonCorp84 theres also more to the answer than you were outputting
snoudin
@snoudin
Apr 30 2017 01:52

Stand in Line
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.

Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.

nextInLine([], 1) should return 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
item = arr.shift();
arr.push(item);
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));

function nextInLine(arr, item) {
// Your code here
item = arr.shift();
arr.push(item);
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));

help, please
Matt
@mdmpdx
Apr 30 2017 01:53
help please... "Using Objects for Lookups" lesson
barki mustapha
@barkinet
Apr 30 2017 01:55

<?xml version="1.0" encoding="UTF-8"?>

<Workspace version = "1.0">
<FileRef location = "self:sudo.xcodeproj">
</FileRef>
</Workspace>

Matt
@mdmpdx
Apr 30 2017 01:56
 function phoneticLookup(val) {
  var result = "";

  var lookup = {
   "alpha": "Adams",
   "bravo": "Boston",
   "charlie": "Chicago",
   "delta": "Denver",
   "echo": "Easy",
   "foxtrot": "Frank"
 };

result = lookup[val]; 

  return result;
}

phoneticLookup(lookup.charlie);
i can't seem to figure out what's wrong here... i get this error in Console: "ReferenceError: lookup is not defined"
Simeon
@SimeonCodes
Apr 30 2017 02:00
@mdmpdx technically the lookup variable isnt global, so cant be called outside of the function
nheyse89
@nheyse89
Apr 30 2017 02:02
can you help me with the Stand in Line page?
I cant figure out where I went wrong

~~
function nextInLine(arr, item) {
// Your code here
arr.shift(0);
arr.push(item);

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

Matt
@mdmpdx
Apr 30 2017 02:02
@SimeonCodes ahhh, thank you! I got it working by just swapping to "charlie" instead of lookup.charlie
CamperBot
@camperbot
Apr 30 2017 02:02
mdmpdx sends brownie points to @simeoncodes :sparkles: :thumbsup: :sparkles:
:cookie: 437 | @simeoncodes |http://www.freecodecamp.com/simeoncodes
nheyse89
@nheyse89
Apr 30 2017 02:02
also, how do I past the code in as a block format without a simple copy and paste
Simeon
@SimeonCodes
Apr 30 2017 02:02
@mdmpdx yea that would do it
Rogue Coder
@RogueRaider
Apr 30 2017 02:03

Hi team, I have a noob question. I need a second counter in my for loop so I have made a this```

function palindrome(str) {
str.toLowerCase();
var strChars = str.replace(/[^a-z]/g, "");
//onsole.log(strChars);

var j = strChars.length;
console.log(j);
for (i = 0; i < strChars.length; i++) {
console.log(strChars[i] + " and " + strChars[j]);
if (strChars[i] == strChars[j]) {
j--;
} else {
return false;
}
}

return true;
}

palindrome("eye");
var code = "formatted";
```

I can't access the var j inside the for loop.....
Simeon
@SimeonCodes
Apr 30 2017 02:04
@nheyse89 you dont need a 0 in the brackets of shift
@RogueRaider try changing str.toLowerCase(); to str = str.toLowerCase();
barki mustapha
@barkinet
Apr 30 2017 02:07

Get the badge by copying the relevant snippet below and replacing "name" with the name of your package.

HTML:

<img src="https://snyk.io/package/npm/name/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/package/npm/name style="max-width:100%;">
Markdown:

Known Vulnerabilities
Analytics

c0d0er2
@c0d0er2
Apr 30 2017 02:07

Can somebody please help me with Selecting from many options with Switch Statements in JavaScript? Here is my code:

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

  switch (val) {
    case "alpha":
      console.log("alpha");
      break;
    case "beta":
      console.log("beta");
      break;
    case "gamma":
      console.log("gamma");
      break;
    case "delta":
      console.log("delta");
      break;
  }

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

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

Here is the link: https://www.freecodecamp.com/challenges/selecting-from-many-options-with-switch-statements

Simeon
@SimeonCodes
Apr 30 2017 02:08
@c0d0er2 you need to change your cases to numbers
and then assign the answer to its output
Rogue Coder
@RogueRaider
Apr 30 2017 02:09
@SimeonCodes thanks that's a nice touch, doesn't solve my problem though. I'm able to access strChars[i] with no problems. However strChars[j] is always coming back undefined. Console.log(j) is returning the correct value for j.
CamperBot
@camperbot
Apr 30 2017 02:09
rogueraider sends brownie points to @simeoncodes :sparkles: :thumbsup: :sparkles:
:cookie: 438 | @simeoncodes |http://www.freecodecamp.com/simeoncodes
Heathercoraje
@Heathercoraje
Apr 30 2017 02:09
Hello everyone
Simeon
@SimeonCodes
Apr 30 2017 02:10
@RogueRaider yes j will always equal its length
Heathercoraje
@Heathercoraje
Apr 30 2017 02:10
I am doing a kata. Can anyone give me a hand
wittyfans
@wittyfans
Apr 30 2017 02:10
hello
Simeon
@SimeonCodes
Apr 30 2017 02:10
so calling strChars[j] will always be too short for things like eye, but j-1 might work
c0d0er2
@c0d0er2
Apr 30 2017 02:10
@SimeonCodes I just did it and it did not work here is my code:
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line

  switch (val) {
    case 1:
      console.log("alpha");
      break;
    case 2:
      console.log("beta");
      break;
    case 3:
      console.log("gamma");
      break;
    case 4:
      console.log("delta");
      break;
  }

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

// Change this value to test
caseInSwitch(1);
Heathercoraje
@Heathercoraje
Apr 30 2017 02:11
function mixFruit(arr) {
let fruits = [['banana', 'orange', 'apple', 'lemon', 'grapes'],
                 ['avocado', 'strawberry', 'mango']];


    let sum = arr.reduce((a, x) => a + ((fruits[0].hasOwnProperty(x)) ? 5 : (fruits[1].hasOwnProperty(x)) ? 7 : 9), 0);    
   return Math.round(sum / arr.length);
}
mixFruit(['mango', 'banana', 'watermelon']);
Simeon
@SimeonCodes
Apr 30 2017 02:11
@c0d0er2 you have to assign answer = in every case of switch
Rogue Coder
@RogueRaider
Apr 30 2017 02:11
@SimeonCodes var j = strChars.length -1;
solved the problem
Heathercoraje
@Heathercoraje
Apr 30 2017 02:11
the test arr should return 7 then but it returns 9 :(
What am I missing?
wittyfans
@wittyfans
Apr 30 2017 02:12
@c0d0er2 can send you question link?
Simeon
@SimeonCodes
Apr 30 2017 02:12
sorry i dont know es6
wittyfans
@wittyfans
Apr 30 2017 02:13
@c0d0er2 your answer is empty ,your do not give it a value
c0d0er2
@c0d0er2
Apr 30 2017 02:14
@SimeonCodes I did that again but it still didn't work. Here is my code:
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line

  switch (val) {
    case answer = 1:
      console.log("alpha");
      break;
    case answer = 2:
      console.log("beta");
      break;
    case answer = 3:
      console.log("gamma");
      break;
    case answer = 4:
      console.log("delta");
      break;
  }

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

// Change this value to test
caseInSwitch(1);
snoudin
@snoudin
Apr 30 2017 02:14
can u help me with Stand in Line test
Gulsvi
@gulsvi
Apr 30 2017 02:15
@Heathercoraje What are the instructions for the kata?
Heathercoraje
@Heathercoraje
Apr 30 2017 02:15
@SkyCoder01
Simeon
@SimeonCodes
Apr 30 2017 02:16
@c0d0er2
 case 4:
  answer = "delta"
      console.log("delta");
      break;
Heathercoraje
@Heathercoraje
Apr 30 2017 02:16

Jumbo Juice makes a fresh juice out of fruits of your choice. Jumbo Juice charges $5 for regular fruits and $7 for special ones. Regular fruits are banana, orange, apple. Special ones are avocado, strawberry and mango. Others fruits that are not listed are also available upon request. Those extra special fruits cost $9 per each. The price of a cup of juice is the mean of price of chosen fruits. In case of decimal number (ex. $5.99), output should be the nearest integer.

Example

['mango', 'banana', 'avocado'] //the price of this juice should is 7+5+7/3 = $6($6.333333...)

wittyfans
@wittyfans
Apr 30 2017 02:16
  case 1:
      console.log("alpha");
      answer = "alpha";
Simeon
@SimeonCodes
Apr 30 2017 02:17
@Heathercoraje id nearly write out the ternry statement in a else if format to see where its wrong
wittyfans
@wittyfans
Apr 30 2017 02:17
shloud add break!
c0d0er2
@c0d0er2
Apr 30 2017 02:17
@SimeonCodes Thanks! :smiley:
CamperBot
@camperbot
Apr 30 2017 02:17
c0d0er2 sends brownie points to @simeoncodes :sparkles: :thumbsup: :sparkles:
:cookie: 439 | @simeoncodes |http://www.freecodecamp.com/simeoncodes
Heathercoraje
@Heathercoraje
Apr 30 2017 02:17
true.
nheyse89
@nheyse89
Apr 30 2017 02:17
how would I go about pasting a block of code in that box format?
Gulsvi
@gulsvi
Apr 30 2017 02:18
You'll also want to use .includes() or .indexOf() instead of .hasOwnProperty() @Heathercoraje
Heathercoraje
@Heathercoraje
Apr 30 2017 02:18
@SkyCoder01
Gulsvi
@gulsvi
Apr 30 2017 02:18
At least, I haven't seen hasOwnProperty used to test the value of an array, only for objects {}
wittyfans
@wittyfans
Apr 30 2017 02:19
@nheyse89 paste to where?
Heathercoraje
@Heathercoraje
Apr 30 2017 02:19
@SkyCoder01 I actually saw a clever solution of another warrior
let sum = arr.reduce((a, x) => a + ((fruits[0].indexOf(x.toLowerCase()) !== -1)
 ? 5 : (fruits[1].indexOf(x.toLowerCase()) !== -1) ? 7 : 9), 0);
then I don't understand what does indexOf(x) !== -1
what is -1 there?
Gulsvi
@gulsvi
Apr 30 2017 02:20
-1 means it doesn't exist
nheyse89
@nheyse89
Apr 30 2017 02:20
@wittyfans i think i figured it out....maybe
Heathercoraje
@Heathercoraje
Apr 30 2017 02:20
@SkyCoder01 but in that case why not hasOwnProperty? :9
Gulsvi
@gulsvi
Apr 30 2017 02:21
Because hasOwnProperty looks for a property of an object, not for an element in an array
nheyse89
@nheyse89
Apr 30 2017 02:21

``` function nextInLine(arr, item) {
// Your code here
arr.shift(0);
arr.push(item);

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

@wittyfans ok still not working. i tried the 3 backticks then shift + enter
Ralem Eomhd
@Korrah
Apr 30 2017 02:22
 function nextInLine(arr, item) {
  // Your code here
  arr.shift(0);
  arr.push(item);

  return arr;  // 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));
@nheyse89 You need those backticks after the last line too
stunpop
@stunpop
Apr 30 2017 02:22
hi anyone there to help with escape sequence in strings please?
Shripe
@Shripe
Apr 30 2017 02:23
Having issues with Stand in Line as well, it seems
wittyfans
@wittyfans
Apr 30 2017 02:23
your should write two ```,one top ,one bottom
@nheyse89
stunpop
@stunpop
Apr 30 2017 02:23
i do not know why there is an error?
var myStr; "FirstLine\n\SecondLine\n\ThirdLine";
nheyse89
@nheyse89
Apr 30 2017 02:23
function nextInLine(arr, item) {
  // Your code here
  arr.shift(0);
  arr.push(item);

  return arr;  // 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));
Shripe
@Shripe
Apr 30 2017 02:23
function nextInLine(arr, item) {
  // Your code here

  testArr.push(item);
  var nextInLine = testArr.shift();
  return nextInLine;  // Change this line
}

// Test Setup
var testArr = [5,6,7,8,9];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
nheyse89
@nheyse89
Apr 30 2017 02:23
ok so i removed the "0" in arr.shift and its still not working
Heathercoraje
@Heathercoraje
Apr 30 2017 02:24
@SkyCoder01 If the let is an object, will it work?
Shripe
@Shripe
Apr 30 2017 02:24
All requirements are checked off except nextInLine([5,6,7,8,9], 1) should return 5
And yet in the test return area, it shows a return of 5
Gulsvi
@gulsvi
Apr 30 2017 02:24
@Heathercoraje No, let is similar to var an object is like:
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};
Heathercoraje
@Heathercoraje
Apr 30 2017 02:25
such as
```
var fruits = {
'banana' : 5,
'mango': 7};
Ralem Eomhd
@Korrah
Apr 30 2017 02:25
@stunpop Look more into what an escape sequence is, more specifically, what the double \ is doing
Gulsvi
@gulsvi
Apr 30 2017 02:25
Yes, @Heathercoraje like that
Heathercoraje
@Heathercoraje
Apr 30 2017 02:25
I mean, @SkyCoder01 then If the var is object,
hasOwnProperty should work, right
Gulsvi
@gulsvi
Apr 30 2017 02:26
fruits is the object in that case, var is a keyword
but yes, you could do fruits.hasOwnProperty('banana') and expect to get true from that
Ralem Eomhd
@Korrah
Apr 30 2017 02:26
@stunpop In other words, how can we display a "\"? If we ONLY use a single \ in our code, then the computer won't actually display a \
Heathercoraje
@Heathercoraje
Apr 30 2017 02:27
@SkyCoder01 I see
stunpop
@stunpop
Apr 30 2017 02:27
@Korrah I am not sure I underdtand?
var myStr; "FirstLine\n\SecondLine\n\ThirdLine";
more like this?
oops
I meant;
var myStr; "FirstLine\n\SecondLine\n\ThirdLine";
Heathercoraje
@Heathercoraje
Apr 30 2017 02:27
@SkyCoder01 but then I need to give classify fruits by 2 types of prices so array would be better, i guess
Ralem Eomhd
@Korrah
Apr 30 2017 02:27
@stunpop You're still only using single \ there. What does a double \ do?
Gulsvi
@gulsvi
Apr 30 2017 02:28
You can do it either way - it looks like the other answer you saw definitely uses an array though
stunpop
@stunpop
Apr 30 2017 02:28
ugh it keeps deleting my double "\"
Ralem Eomhd
@Korrah
Apr 30 2017 02:28
var myStr; "\FirstLine\n\SecondLine\n\ThirdLine";
ah I see
var myStr; "FirstLine\\n\SecondLine\n\ThirdLine";
Heathercoraje
@Heathercoraje
Apr 30 2017 02:29
@SkyCoder01 True. I am actually making the kata.
Ralem Eomhd
@Korrah
Apr 30 2017 02:29
@stunpop surround the code you're writing in this chat with three ```
Heathercoraje
@Heathercoraje
Apr 30 2017 02:29
wanted to see which code'd be better
barki mustapha
@barkinet
Apr 30 2017 02:29
var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp"));
var user = await github.User.Get("half-ogre");
Console.WriteLine(user.Followers + " folks love the half ogre!");
Gulsvi
@gulsvi
Apr 30 2017 02:31

@Heathercoraje I think an array is easiest, personally.

  let fruits = [
    ["banana", "orange", "apple"],
    ["avocado", "strawberry", "mango"]
  ];

If the fruit isn't listed, $9, if the fruit is in the second array, $7, else $5.

stunpop
@stunpop
Apr 30 2017 02:31
oh ok thanks @Korrah
'''var myStr; "FirstLine\n\SecondLine\n\ThirdLine";'''
CamperBot
@camperbot
Apr 30 2017 02:31
stunpop sends brownie points to @korrah :sparkles: :thumbsup: :sparkles:
:cookie: 186 | @korrah |http://www.freecodecamp.com/korrah
stunpop
@stunpop
Apr 30 2017 02:31
:(
Gulsvi
@gulsvi
Apr 30 2017 02:32
But avocado juice, I have to say, seems a little odd
Guess it's something to try
Daniel Molina
@Molina92
Apr 30 2017 02:32
Hi! good night, hope that u're ok! Can someone help me? :D
Ralem Eomhd
@Korrah
Apr 30 2017 02:32
@stunpop Oh not quite, those were single quote marks you used. ''' vs ``` can be found above your TAB key (assuming you're on a standard US Keyboard?)
CamperBot
@camperbot
Apr 30 2017 02:32
:bulb: to format code use backticks! ``` more info
Heathercoraje
@Heathercoraje
Apr 30 2017 02:33
@SkyCoder01 haha You want it with Banana
Damien
@DubbDevs
Apr 30 2017 02:33
I'm working with Data structures and the Queue nextInLine problem and I'm thoroughly confused
stunpop
@stunpop
Apr 30 2017 02:33
@Korrah I am using mac
Ralem Eomhd
@Korrah
Apr 30 2017 02:33
@stunpop What key is directly above your TAB key?
stunpop
@stunpop
Apr 30 2017 02:34
§ and 1
Gulsvi
@gulsvi
Apr 30 2017 02:35
Okay, maybe I'll try it :)
stunpop
@stunpop
Apr 30 2017 02:35
think itis cmd 'return' will try now
var myStr; "FirstLine\n\SecondLine\n\ThirdLine";
nope!
lol
Rogue Coder
@RogueRaider
Apr 30 2017 02:35

function palindrome(str) {
  str = str.toLowerCase();
  var strChars = str.replace(/[^a-z]/g, "");
  console.log(strChars);

  var j = strChars.length - 1;  

  for (i = 0; i <= strChars.length - 1; i++) {    
    console.log(strChars[i] + " and " + strChars[j]);
    if (strChars[i] == strChars[j]) {
      console.log(i) ;
      j--;
    } else {
      console.log("F");
      return false;
    }
  }
  console.log("T");
  return true;
}


palindrome("1 eye for of 1 eye.");
Ralem Eomhd
@Korrah
Apr 30 2017 02:35
@stunpop Okay, I think I know what your keyboard layout is like. What's the key to the left of Z?
stunpop
@stunpop
Apr 30 2017 02:36
how are pople including the actual sceenpic
Simeon
@SimeonCodes
Apr 30 2017 02:36
need more regex @RogueRaider
stunpop
@stunpop
Apr 30 2017 02:36
var myStr; "FirstLine\n\\SecondLine\n\\ThirdLine";
yay! oh god finally!
Ralem Eomhd
@Korrah
Apr 30 2017 02:36
There you go
Gulsvi
@gulsvi
Apr 30 2017 02:36
``` (shift + enter for a new line)
code goes here (shift + enter for another new line)
```
Tyler Bernath
@tbtree55
Apr 30 2017 02:37

The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.

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

need ehlp please
stunpop
@stunpop
Apr 30 2017 02:37
@Korrah does this make sense?
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";
Daniel Molina
@Molina92
Apr 30 2017 02:37
@tbtree55 what do you need? i passed out that challenge
Tyler Bernath
@tbtree55
Apr 30 2017 02:38

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);

it has to convert from C to F
Ralem Eomhd
@Korrah
Apr 30 2017 02:38
@stunpop That should work, does it pass you?
stunpop
@stunpop
Apr 30 2017 02:39
it just did but honestly I am not sure why I needed the \r carriage return lol
i was juts thinking of \n
Sandesh Shrestha
@UnovaXan
Apr 30 2017 02:39
@tbtree55 use the celsius variable to get the fahrenheit
fahrenheit = (celsius * 9/5 ) + 32
Gulsvi
@gulsvi
Apr 30 2017 02:39
@tbtree55 It's going to look a bit like algebra
Tyler Bernath
@tbtree55
Apr 30 2017 02:40
@UnovaXan @SkyCoder01 thanks .. had it as fahrenheit = ((celsius 9/5 ) + 32) instead of (celsius 9/5 ) + 32
CamperBot
@camperbot
Apr 30 2017 02:40
tbtree55 sends brownie points to @unovaxan and @skycoder01 :sparkles: :thumbsup: :sparkles:
:cookie: 282 | @unovaxan |http://www.freecodecamp.com/unovaxan
:star2: 1229 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Rogue Coder
@RogueRaider
Apr 30 2017 02:41

function palindrome(str) {
  str = str.toLowerCase();
  var strChars = str.replace(/[^a-z]/g, "");
  console.log(strChars);

  var j = strChars.length - 1;  

  for (i = 0; i <= strChars.length - 1; i++) {    
    console.log(strChars[i] + " and " + strChars[j]);
    if (strChars[i] == strChars[j]) {
      console.log(i) ;
      j--;
    } else {
      console.log("F");
      return false;
    }
  }
  console.log("T");
  return true;
}


palindrome("1 eye for of 1 eye.");
Hi team this function is passing all tests in 240 except for the "1 eye for of 1 eye." test.
According to the test parameters, this test should return false.
However with my code removing spaces numbers and punctuation, I am left with "eyeforofeye" which is a palindrome.
Am I missing something in the logic here?
Shripe
@Shripe
Apr 30 2017 02:42
function nextInLine(arr, item) {
  // Your code here

  testArr.push(item);
  var nextInLine = testArr.shift();
  return nextInLine;  // Change this line
}

// Test Setup
var testArr = [5,6,7,8,9];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
At a loss here... All tests check out except the one I input into the test setup. nextInLine([5,6,7,8,9], 1) should return 5, and in the return box it does.
Ralem Eomhd
@Korrah
Apr 30 2017 02:42
@stunpop If you're curious what carriage return is: http://stackoverflow.com/questions/1761051/difference-between-n-and-r
Manish Giri
@Manish-Giri
Apr 30 2017 02:42
@Shripe function nextInLine(arr, item) {
what is the use of arr here then?
since you're not using it anywhere.
Shripe
@Shripe
Apr 30 2017 02:43
Ah. It started me off with testArr as the array name in the rest of the code
So that's confusing
stunpop
@stunpop
Apr 30 2017 02:44
ok not crystal clear but sort of enough for now :)
Shripe
@Shripe
Apr 30 2017 02:44
Oh... I think I get what you mean.
Manish Giri
@Manish-Giri
Apr 30 2017 02:44
what you should work with is what's passed in to your code
that's arr
Shripe
@Shripe
Apr 30 2017 02:44
Yep.
Vignettes
@Vignettes
Apr 30 2017 02:44

`function truncateString(str, num) {

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

truncateString("A-tisket a-tasket A green and yellow basket", 11);
`
I am confused why this would return "A-tisket..." shouldn't it return 8 characters before the "..." so it would in theory have a space between the words and the ellipses?

ugh formatting let me repeat that, sorry.

```function truncateString(str, num) {

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

truncateString("A-tisket a-tasket A green and yellow basket", 11);
```
I am confused why this would return "A-tisket..." shouldn't it return 8 characters before the "..." so it would in theory have a space between the words and the ellipses?

still the same... I apologize
Shripe
@Shripe
Apr 30 2017 02:45
thanks @Manish-Giri
CamperBot
@camperbot
Apr 30 2017 02:45
shripe sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5341 | @manish-giri |http://www.freecodecamp.com/manish-giri
Vignettes
@Vignettes
Apr 30 2017 02:45
function truncateString(str, num) {

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

truncateString("A-tisket a-tasket A green and yellow basket", 11);
I am confused why this would return "A-tisket..." shouldn't it return 8 characters before the "..." so it would in theory have a space between the words and the ellipses?
Rogue Coder
@RogueRaider
Apr 30 2017 02:51
@Vignettes str.length is indexed from 1, str.slice is indexed from 0. Hence you don't get the space :)
Armanis22
@Armanis22
Apr 30 2017 02:53
I am in the middle of the basic algorithm scripting and do they mostly expect for loops and if logic? I did the fibinacci recursively because I knew it, and I could have done a couple others recursuvely, but is it just totally fine to do these with basic tools? feels a little like cheating
Vamp
@the-vampiire
Apr 30 2017 02:54
you can solve it any way you like as long as it is dynamic, and you didnt cheat / copy code.
stunpop
@stunpop
Apr 30 2017 03:00
just got stuck on Appending Variables to strings
var someAdjective = "Hard!";
var myStr = "Learning to code is ";
ourStr += someAdjective;
anyone can help please?
Ralem Eomhd
@Korrah
Apr 30 2017 03:01
@stunpop look at how you're naming your variables there
stunpop
@stunpop
Apr 30 2017 03:02
hmmm
Ralem Eomhd
@Korrah
Apr 30 2017 03:02
There should only be two variables, not three, and you created a third variable by mistake
stunpop
@stunpop
Apr 30 2017 03:02
oh!
var someAdjective = "Hard!"; var myStr = "Learning to code is "; myStr += someAdjective;
?
Ralem Eomhd
@Korrah
Apr 30 2017 03:03
Yeah try that
stunpop
@stunpop
Apr 30 2017 03:03
yep works
thanks again - dumb mistakes :(
not sure I will ever get this stuff properly
Vignettes
@Vignettes
Apr 30 2017 03:05
@RogueRaider Thank you, I assumed all counts started from the 0 index.
CamperBot
@camperbot
Apr 30 2017 03:05
:cookie: 242 | @rogueraider |http://www.freecodecamp.com/rogueraider
vignettes sends brownie points to @rogueraider :sparkles: :thumbsup: :sparkles:
Ralem Eomhd
@Korrah
Apr 30 2017 03:05
even the most experienced programmers aren't immune to that, we're human after all. The cool thing as humans, the more we make similar mistakes, the more we're able to spot them more easily or know what went wrong and why. Just takes time and practice
stunpop
@stunpop
Apr 30 2017 03:06
yep will try and stay focused and positive - thanks @Korrah
CamperBot
@camperbot
Apr 30 2017 03:06
stunpop sends brownie points to @korrah :sparkles: :thumbsup: :sparkles:
:warning: stunpop already gave korrah points
Ralem Eomhd
@Korrah
Apr 30 2017 03:06
Indeed! And you're welcome. ^^
Eduar Tua
@eduartua
Apr 30 2017 03:12
Guys in the challenge Mutations:
Mutations
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
Do I have to use toLowerCase method?
Daniel Molina
@Molina92
Apr 30 2017 03:13
@eduartua can u send me the link?
@Molina92
Christopher McCormack
@cmccormack
Apr 30 2017 03:21
@eduartua when testing equality of strings, ensuring they are the same case is always required
> 'a' == 'A'
false
> 'a' === 'A'
false
Eduar Tua
@eduartua
Apr 30 2017 03:22
thank you @cmccormack I'll check it
CamperBot
@camperbot
Apr 30 2017 03:22
eduartua sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 461 | @cmccormack |http://www.freecodecamp.com/cmccormack
Pagnito
@Pagnito
Apr 30 2017 03:23

i think i understand how this code works, but i dont understand exctly
```function steamrollArray(arr){
var result =[];
var b;
while(arr.length > 0){
b = arr.shift();
if(!Array.isArray(b)){
result.push(b);
} else {
arr = b.concat(arr);
console.log(arr);
}
}

return result;
}

steamrollArray([1, [2], [3, [[4]]]]);

what i dont understand is

else {
arr = b.concat(arr);
console.log(arr);
}
```
wouldnt that concat the nested array back in? how do the the nestd arrays get unraveled i guess if thats the right word

Zack Vizirov
@Intellektual
Apr 30 2017 03:24

// Setup
var a;
var b = 2;

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

what am i doing wrong
a should be assigned to b with =
Pagnito
@Pagnito
Apr 30 2017 03:24

i think i understand how this code works, but i dont understand exctly

function steamrollArray(arr){
  var result =[];
  var b;
  while(arr.length > 0){
     b = arr.shift();
    if(!Array.isArray(b)){
      result.push(b);
    }  else {
     arr = b.concat(arr);
      console.log(arr);
    }
  }

  return result;
}

steamrollArray([1, [2], [3, [[4]]]]);

what i dont understand is

else {
     arr = b.concat(arr);
      console.log(arr);
    }

wouldnt that concat the nested array back in? how do the the nestd arrays get unraveled i guess if thats the right word

Zack Vizirov
@Intellektual
Apr 30 2017 03:25

// Setup
var a;
var b = 2;

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

a should be assigned to b with =
h1tag
@h1tag
Apr 30 2017 03:28
@Intellektual why are you doing b=7 then a=b (this is redundant)? + a should be assigned to b, not the reverse
Zack Vizirov
@Intellektual
Apr 30 2017 03:31
thanks
Christopher McCormack
@cmccormack
Apr 30 2017 03:31
@Pagnito it looks like it continually concatenates arrays until that index in arr no longer contains an array
Ramana reddy MV
@Ramanareddymv
Apr 30 2017 03:32
image.png
Christopher McCormack
@cmccormack
Apr 30 2017 03:32
@Ramanareddymv you may be missing a space in the first string
Ramana reddy MV
@Ramanareddymv
Apr 30 2017 03:33
@cmccormack yeaH THANKS
CamperBot
@camperbot
Apr 30 2017 03:33
ramanareddymv sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 462 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Apr 30 2017 03:33
@Pagnito that's actually a good example of something you can work out on paper, and once you get a good hang on the concept it will help enormously on other tasks
Pagnito
@Pagnito
Apr 30 2017 03:35
@cmccormack yea i think i got that part, i just dont understand the details, of how it does it
Christopher McCormack
@cmccormack
Apr 30 2017 03:35
@Pagnito work it through one variable at a time, write down what is stored in each and change it as necessary
Pagnito
@Pagnito
Apr 30 2017 03:35
@cmccormack when it concats the one that didnt pass the test, is it somehow not an array anymore
ive went over it like shit load of times, i just know there is a understanding im missing of how one ofthe methods work
Christopher McCormack
@cmccormack
Apr 30 2017 03:36
you're basically starting the array over again, so the first value may no longer be an array after you concatenate
Pagnito
@Pagnito
Apr 30 2017 03:37
yea thats the part i dont get
how come its no longer an array?
like i was saying, i get its logic, i just dont understand what allows that logic to work
Christopher McCormack
@cmccormack
Apr 30 2017 03:38
@Pagnito again, you gotta walk it through one loop at a time. After the first loop, you end up with something like this:
> var arr = [3, [[4]]]
undefined
> var b = [2]
undefined
> arr = b.concat(arr);
[ 2, 3, [ [ 4 ] ] ]
ignore the undefined
but now see how the first value is no longer an array, just a number in an array
Pagnito
@Pagnito
Apr 30 2017 03:39
so techincally, the four get concatted twice?
Christopher McCormack
@cmccormack
Apr 30 2017 03:40
@Pagnito yes, as it will be an array in the loop twice, I believe
Pagnito
@Pagnito
Apr 30 2017 03:40
ooh yea i forgot that concat doesnt insert the element!
lol
man, imm telling, i was lookin at this code for hours lol, felt rly stupid
i could understand that how the loop worked and everything, but i i didnt put the pieces together that concat, concats i guess
if thats how i say it
Christopher McCormack
@cmccormack
Apr 30 2017 03:42
yup just flattens two into one
Pagnito
@Pagnito
Apr 30 2017 03:42
so u were saying, understanding this code wil help alot in the future? kinda curious, if u dont mind tellin me more
Christopher McCormack
@cmccormack
Apr 30 2017 03:43
@Pagnito not this code specifically, but walking through the logic will help you make more concise code because you'll have a better understanding of what the code can do
Pagnito
@Pagnito
Apr 30 2017 03:43
ooh ok
Christopher McCormack
@cmccormack
Apr 30 2017 03:43
Recursive functions are also great learning tools
they can be really hard for humans to process in their heads, but if you work it out it starts to make sense
Pagnito
@Pagnito
Apr 30 2017 03:44
what does recurisve mean
Christopher McCormack
@cmccormack
Apr 30 2017 03:44
an expression in a function that calls the function it's in
Pagnito
@Pagnito
Apr 30 2017 03:44
meaning that the loop keeps going over and over
Christopher McCormack
@cmccormack
Apr 30 2017 03:44
nope
recursive functions should always have a base case that stops it
Pagnito
@Pagnito
Apr 30 2017 03:45
so the part that keeps calling it the if statement?
Christopher McCormack
@cmccormack
Apr 30 2017 03:45
otherwise it will run forever, as well as fill up the stack
Pagnito
@Pagnito
Apr 30 2017 03:45
i mean while
arr.length>0
Christopher McCormack
@cmccormack
Apr 30 2017 03:45
sorry didn't mean to confuse - the function we've been walking through is not a recursive function
Pagnito
@Pagnito
Apr 30 2017 03:45
oh ok
Christopher McCormack
@cmccormack
Apr 30 2017 03:46
but this exercise can be done with a recursive function as well and it may make more sense
Pagnito
@Pagnito
Apr 30 2017 03:46
yea i was lookin over some other functions that do the same thing, and they called them recursive
Christopher McCormack
@cmccormack
Apr 30 2017 03:46
function steamrollArray(arr) {
  var newArr = [];

  for (var i = 0; i < arr.length; i++){
    if (Array.isArray(arr[i])){
      var temp = steamrollArray(arr[i]);
      newArr = newArr.concat(temp);
    } else {
      newArr.push(arr[i]);
    }
  }
  return newArr;
}
Pagnito
@Pagnito
Apr 30 2017 03:46
ok yea, that confuses me
Christopher McCormack
@cmccormack
Apr 30 2017 03:46
see how if the first conditional is an Array, it calls the steamrollArray from within the same function
Pagnito
@Pagnito
Apr 30 2017 03:47
yea
Christopher McCormack
@cmccormack
Apr 30 2017 03:47
yup, but again once you walk it through step by step and learn to understand it, it can definitely help you write more interesting code
Pagnito
@Pagnito
Apr 30 2017 03:47
k, gonna do that now
Christopher McCormack
@cmccormack
Apr 30 2017 03:47
shortest path algorithms and stuff like that tend to use recursive algorithms
at least some of the one's I have seen
Pagnito
@Pagnito
Apr 30 2017 03:48
tho, what happens when the function gets called like that. it just wont click in my head right now
does it start the loop over?
Christopher McCormack
@cmccormack
Apr 30 2017 03:48
think of it as a stack, you add new work to the stack until you hit the base case, then go back down the stack until you go back up the stack again if needed
again, it's hard to fully process in our heads, but if you write it out it starts to make sense
Pagnito
@Pagnito
Apr 30 2017 03:49
k
Pagnito
@Pagnito
Apr 30 2017 03:55
i dont get, tho, it concats the function call to the newArr, thats rly unfamiliar to me
@cmccormack
Christopher McCormack
@cmccormack
Apr 30 2017 03:56
@Pagnito I'll be honest, I wrote it and I would still have to go back and look at it for a bit to see how it works :) recursive functions are rarely intuitive
Pagnito
@Pagnito
Apr 30 2017 03:56
yea lol, shit is breakin my head right now, cuz i dunno hat happens by concatting the call
youtube to the rescue, but yea thanks @cmccormack
CamperBot
@camperbot
Apr 30 2017 03:58
pagnito sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 463 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Apr 30 2017 03:58
@Pagnito haha gl
Pagnito
@Pagnito
Apr 30 2017 03:58
thnx hehe
the concept itself sounds pretty cool tho, lol i dunno why but when the explanation is verbalized i think of the matrix
@cmccormack
Christopher McCormack
@cmccormack
Apr 30 2017 03:59
@Pagnito just think about it concatenating the return from the call, not the call itself, and the return is return newArr;
Jor
@joreyesl
Apr 30 2017 04:00
@Pagnito you're concatenating the array that is returned from the call
Christopher McCormack
@cmccormack
Apr 30 2017 04:00
haha
Jor
@joreyesl
Apr 30 2017 04:00
jinx
Pagnito
@Pagnito
Apr 30 2017 04:00
@cmccormack ok, ima go over it again
@joreyesl thanks as well
CamperBot
@camperbot
Apr 30 2017 04:01
pagnito sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 807 | @joreyesl |http://www.freecodecamp.com/joreyesl
Christopher McCormack
@cmccormack
Apr 30 2017 04:01
In Matrix multiplication, divide and conquer algorithms use recursion, so you're not too far off :D
@joreyesl haha
Pagnito
@Pagnito
Apr 30 2017 04:02
@cmccormack sweet lol
Jor
@joreyesl
Apr 30 2017 04:02
@Pagnito recursion is a concept that gets many ppl stump when they are first learning it. But once you get it, it will be as simple as writing a loop
Pagnito
@Pagnito
Apr 30 2017 04:02
@joreyesl sweet
so it calls the function and basically restarts the function?
but the newArr still having the first element alrdy in it
Christopher McCormack
@cmccormack
Apr 30 2017 04:04
Think of it as going to a whole new function, that will eventually peak and return at some point
that peak is the base case where it will return usually
so in the end your concatenating an array that was concatenated with another array in a recursive call that was concatenated with another array in a recursive call... and so on
Pagnito
@Pagnito
Apr 30 2017 04:06
that sounds like a tongue twister to me right now lol
except its twisting my brain
im read that over a few tims
ima watch a video on recursive function real quick brb
Christopher McCormack
@cmccormack
Apr 30 2017 04:08
I'm not joking at all when I say write it down, it's how I learned it. Once you see how the data starts returning from the recursive calls and combining to form your solution it will make more sense
yeah that's a good idea
Pagnito
@Pagnito
Apr 30 2017 04:08
k got u
Damien
@DubbDevs
Apr 30 2017 04:15
Hi I'm currently working on javascript and having a tough time with the functions
I've made it as far as the "stand in line"
Christopher McCormack
@cmccormack
Apr 30 2017 04:15
@DubbDevs sure what's the issue?
Damien
@DubbDevs
Apr 30 2017 04:16
I need to add a number to the end of the array and remove a number at the beginning if I understand the directions correctly
Christopher McCormack
@cmccormack
Apr 30 2017 04:17
correct
Damien
@DubbDevs
Apr 30 2017 04:17
I see the function that was created nextInLine
i understand the 2 parameters arr and item
beyond that i feel a bit lost where to start
Christopher McCormack
@cmccormack
Apr 30 2017 04:19

Do you remember these exercises?

Manipulate Arrays With push
Manipulate Arrays With pop
Manipulate Arrays With shift
Manipulate Arrays With unshift

two of those will be very useful for this project, I would recommend reading each one again
Damien
@DubbDevs
Apr 30 2017 04:19
ohhhhh yeaahhhhh
thanks!
Christopher McCormack
@cmccormack
Apr 30 2017 04:20
np
Sergii
@Doomkrat
Apr 30 2017 04:25
hi, guys
var myStorage = {
  "car": {
    "inside": {
      "glove_box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents;  
gloveBoxContents = myStorage.car.inside.glove_box;//
Use dot and bracket notation to access myStorage
where?
can you help me please
Christopher McCormack
@cmccormack
Apr 30 2017 04:27
@Doomkrat did you change myStorage? I believe it had a space in "glove box"
@Doomkrat because it has a space, you cannot use dot notation, so you'll have to use bracket notation
Sergii
@Doomkrat
Apr 30 2017 04:34
ok
yep, you right
@cmccormack thanks
CamperBot
@camperbot
Apr 30 2017 04:35
doomkrat sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 464 | @cmccormack |http://www.freecodecamp.com/cmccormack
Liz
@Eliz964
Apr 30 2017 04:39
So I'm getting a potential infinite loop at line 13 and I have no idea why:
function sumPrimes(num) {
  var answer = 0;
  var array = [];
  function isPrime(test) {
    for(i = 2; i < test; i++) {
      if(test%i === 0 && (test > 2)) {
        return false;
      }
    }
    return true;
  }
  for(i = 0; i < num; i++) {
    if(isPrime(i)) {
      answer = answer + i;
      array.push(i);
    }
  }
  return answer;
}
I was sent here from the general FreeCodeCamp help chat because they didn't know.
Jianhao Tan
@jaanhio
Apr 30 2017 04:44
var quoteContainer = document.getElementById("#quoteText");
var authorContainer = document.getElementById("#quoteAuthor");

var quoteButton = document.getElementById("#quoteButton");
var tweetButton = document.getElementById("#tweetButton");

quoteButton.addEventListener("click", function (){
  var ourRequest = new XMLHTTPRequest();
  ourRequest.open('GET', 'http://api.forismatic.com/api/1.0/?method=getQuote&key=457654&format=jsonp&lang=en&jsonp=quotedata');
  ourRequest.onload = function quotedata(data){
    quoteContainer.text = data.quoteText;
    authorContainer.text = data.quoteAuthor;
  };
});
may i know which part did i get wrong?
Christopher McCormack
@cmccormack
Apr 30 2017 04:45
@Eliz964 hmm I'm not seeing it yet
@Eliz964 which line is 13 for you?
Jianhao Tan
@jaanhio
Apr 30 2017 04:45
should i be retrieving using json or jsonp?
Liz
@Eliz964
Apr 30 2017 04:46
@cmccormack if(isPrime(i))
Christopher McCormack
@cmccormack
Apr 30 2017 04:48
@jaanhio I would suggest jsonp, but usually the format is json and you use callback=?
but read the api docs for clarification
Jianhao Tan
@jaanhio
Apr 30 2017 04:50
@cmccormack then when should i be using jsonp?
i thought jsonp is used for cases where the data is not stored on similar server
Christopher McCormack
@cmccormack
Apr 30 2017 04:51
@Eliz964 add var before i in your loop declarations, you have a scope issue
Liz
@Eliz964
Apr 30 2017 04:52
what does "scope issue" mean?
Christopher McCormack
@cmccormack
Apr 30 2017 04:52
@jaanhio it's used to get around CORS issues. If you're not having them, then you can use JSON
Jianhao Tan
@jaanhio
Apr 30 2017 04:52
@cmccormack i see. how will i know if im having CORS issues?
Christopher McCormack
@cmccormack
Apr 30 2017 04:53
@Eliz964 you're using the same ivariable in both loops. In order to make both i variables 'different', you'll need to declare the variable again in the new scope
Liz
@Eliz964
Apr 30 2017 04:53
Ah, ok, I just changed the 2nd loop to use 'j' instead and it works.
Christopher McCormack
@cmccormack
Apr 30 2017 04:53
well for one thing you won't get a response, but you'll see an error in the console as well
@Eliz964 yup that will work as well
Liz
@Eliz964
Apr 30 2017 04:54
Thanks @cmccormack
CamperBot
@camperbot
Apr 30 2017 04:54
eliz964 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 465 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Apr 30 2017 04:54
@Eliz964 np
Brittany Rutherford
@brittanyrutherford
Apr 30 2017 04:58
if const means u can't change the variable after it's declared, how could I change objects after they are declared with const?
const s = {
init : () => { 
    console.log('init');
}
}

s.newvalue = 5; //worked
doesn't const mean the variable was locked and can't be changed anymore?
i could also do s.init = 0 .. and it will override the declared function
Christopher McCormack
@cmccormack
Apr 30 2017 05:01
const means it cannot be changed to a new reference, but you're just modifying the object that the const s is referring to
@brittanyrutherford try making a new object, then assigning s to that object
Jor
@joreyesl
Apr 30 2017 05:03
@brittanyrutherford const only affects the variable, as @cmccormack mentioned the object being referenced can still be changed. If you want prevent an object from being mutated, you have to use Object.freeze()
Christopher McCormack
@cmccormack
Apr 30 2017 05:04
@joreyesl that's cool wasn't aware of that
Pagnito
@Pagnito
Apr 30 2017 05:04
i was wondering, if building a desktop app that would basically interact with other apps, would that mean i would need a permission from those other app companies to ineract with them?
Christopher McCormack
@cmccormack
Apr 30 2017 05:05
@Pagnito You can lookup RPC and see if the apps have hooks for it
Pagnito
@Pagnito
Apr 30 2017 05:06
@cmccormack thanks
CamperBot
@camperbot
Apr 30 2017 05:06
pagnito sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 466 | @cmccormack |http://www.freecodecamp.com/cmccormack
Jor
@joreyesl
Apr 30 2017 05:09
@cmccormack yea theres so many little things that I wasnt aware of in JS
Brittany Rutherford
@brittanyrutherford
Apr 30 2017 05:10
thanks @cmccormack @joreyesl
CamperBot
@camperbot
Apr 30 2017 05:10
brittanyrutherford sends brownie points to @cmccormack and @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 808 | @joreyesl |http://www.freecodecamp.com/joreyesl
:cookie: 467 | @cmccormack |http://www.freecodecamp.com/cmccormack
Brittany Rutherford
@brittanyrutherford
Apr 30 2017 05:10
@joreyesl how did u know about the Object.freeze() .. a book?
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:10
@Pagnito sure permission except the company don't put any
@joreyesl The semi-boss :smiling_imp:
jhobotuck
@jhobotuck
Apr 30 2017 05:12
Hit a bit of roadblock on Return Largest Numbers in Array. If some reason the if statement is not filtering the largest number of the array. Could use a fresh pair of eyes.

function largestOfFour(arr) {

  var value = 0;
  var largest = 0;
  var test = 0;
  var result = [];

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

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

    value = arr[i][j];

       if (value > largest) {
            largest = value;


       }

    return largest;
  }

}

}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Jor
@joreyesl
Apr 30 2017 05:13
@brittanyrutherford It actually mentions that very scenario that you asked about in the docs for const and mentions using Object.freeze().
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:13
@jhobotuck you need to resetlargest for every iteration of the sub-array
Brittany Rutherford
@brittanyrutherford
Apr 30 2017 05:14
got u @joreyesl
Jor
@joreyesl
Apr 30 2017 05:14
@Lumexralph ggm :smiling_imp: :bow:
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:14
@joreyesl Morning S-Boss :bow:
Jor
@joreyesl
Apr 30 2017 05:16
@brittanyrutherford ya the docs are a good reference. It's a good place to start when encountering a new feature of JS.
@Lumexralph thats @Manish-Giri , he is the sgm :smiling_imp:
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:18
@joreyesl nah..... he's the ggggggggggm :smiling_imp:
@joreyesl how're you?
Jor
@joreyesl
Apr 30 2017 05:18
@Lumexralph i'm doing good, hbu?
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:19
@joreyesl travelled home been afk.....
Jor
@joreyesl
Apr 30 2017 05:19
how was the trip
jhobotuck
@jhobotuck
Apr 30 2017 05:20
@Lumexralph I see the value of doing so however I have not been to return the largest value into codelargestcode. I get 4 which is the first value in the array

function largestOfFour(arr) {

  var value = 0;
  var largest = 0;
  var test = 0;
  var result = [];

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

    largest = 0;

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

      value = arr[i][j];

      if (value > largest) {
        largest = value;
      }

    return largest;
    }
  }
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:20
@joreyesl just got a breather this morning, the trip was cool... driving all the way from state to state
Damien
@DubbDevs
Apr 30 2017 05:21
@cmccormack are you still here?
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:21
@jhobotuck you need to push largest into the result array in your outer loop
Jor
@joreyesl
Apr 30 2017 05:21
@jhobotuck you dont want to have return largest there, instead you should push that to the array result and then return that ouside of the loops
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:22
@jhobotuck cos if you return largest you'll be returning just 1 value and it'll stop the loop and exit the function
Jor
@joreyesl
Apr 30 2017 05:22
@Lumexralph nice, how long was the drive?
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:22
@joreyesl how's life with software development?
I'm not yet in the field but trying to make the switch
jhobotuck
@jhobotuck
Apr 30 2017 05:23
Ohhhhh!!! Of course! It exits the first loop.
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:23
@joreyesl like 2 hrs
jhobotuck
@jhobotuck
Apr 30 2017 05:23
Thanks @Lumexralph and @joreyesl
CamperBot
@camperbot
Apr 30 2017 05:23
jhobotuck sends brownie points to @lumexralph and @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 809 | @joreyesl |http://www.freecodecamp.com/joreyesl
:star2: 1609 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:24
@jhobotuck :+1:
Jor
@joreyesl
Apr 30 2017 05:24
@Lumexralph been kinda lazy in learning lately, but thinking of getting serious. Have a list of books that I want to study, just need the motivation to start lol
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:24
@joreyesl working on my calculator and I've not found time to finish it.....
Jor
@joreyesl
Apr 30 2017 05:25
@Lumexralph ah i need to start mine yet lol
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:26
@joreyesl the set-back we have as humans is we can't multi-task, so it's one event after the other or pause one continue the other and the event paused will be in our memory stack with a label when we're ready to continue
@joreyesl it's interesting working without eval
Jor
@joreyesl
Apr 30 2017 05:27
@Lumexralph lmao yea, or the garbage collector comes and removes that event if we take too long :laughing:
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:27
@joreyesl :joy:
@joreyesl which books have you got lined up?
Jor
@joreyesl
Apr 30 2017 05:33
@Lumexralph pretty standard I'd say
YDKJS, Eloquent JS, JS Allonge
Ogundele Olumide
@Lumexralph
Apr 30 2017 05:34
@joreyesl very good book YDKJS...... maybe i'll give eloquent another chance didn't like it
@joreyesl JS Allonge ? heard of it but can't remember the book
Jor
@joreyesl
Apr 30 2017 05:35
@Lumexralph yea @forkerino suggested it. Seems to be in a functional style of programming. which is something I'm also interested in.
Jason Shoemaker
@kutsuya1
Apr 30 2017 05:55
anyone like Head First JS?
Ogundele Olumide
@Lumexralph
Apr 30 2017 06:08
@kutsuya1 seen the book but not read it
Jor
@joreyesl
Apr 30 2017 06:14
same
Also want to read the Art of Computer Programming. Should be an easy read ;)
Ogundele Olumide
@Lumexralph
Apr 30 2017 06:21
not heard of the book
Markus Ivancsics
@ivancsicsmarkus
Apr 30 2017 06:23
@kutsuya1 That’s great. I liked Javascript the definitive too.
Sergii
@Doomkrat
Apr 30 2017 06:40
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
Rahul Tiwari
@invinciblycool
Apr 30 2017 06:42
@Doomkrat edit:product+=(i*j);
Sergii
@Doomkrat
Apr 30 2017 06:43
how?
Rahul Tiwari
@invinciblycool
Apr 30 2017 06:44
There's a syntax error there on line number 7.
Jor
@joreyesl
Apr 30 2017 06:44
@Doomkrat you want to access the element at index i and j, not multiple i * j together
Rahul Tiwari
@invinciblycool
Apr 30 2017 06:44
Change product=+(i*j); to product+=(i*j);
Sergii
@Doomkrat
Apr 30 2017 06:44
@invinciblycool already did
Ogundele Olumide
@Lumexralph
Apr 30 2017 06:45
@Doomkrat product *= sub-array elements
Rahul Tiwari
@invinciblycool
Apr 30 2017 06:46
Change it to product*=arr[j];
Jor
@joreyesl
Apr 30 2017 06:47

@Doomkrat suppose we want to sum elements of an array. You would do

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

i'm summing the elements. What you are doing is more like sum += i, i.e. summing the indices.

Sergii
@Doomkrat
Apr 30 2017 06:54
still don't get it
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

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

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

     product*=(arr[i]*arr[j]);
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Sergii
@Doomkrat
Apr 30 2017 07:02
or
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

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

    product*=arr[i];   

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

     product*=arr[j];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
stravel611
@stravel611
Apr 30 2017 07:18
arr[i] is an array
Markus Ivancsics
@ivancsicsmarkus
Apr 30 2017 07:24
@Doomkrat arr[i][j] in the inner loop!
@Doomkrat
for (var i = 0; i < arr.length; i++)  {
    for (var j = 0; j < arr[i].length; j++)  {
      product *= arr[i][j];
    }
}
Jianhao Tan
@jaanhio
Apr 30 2017 07:28
how do i get around this?
Refused to execute script from 'http://api.forismatic.com/api/1.0/?method=getQuote&key=457654&format=jsonp&lang=en&jsonp=jQuery321008318690596484335_1493537162063' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
i tried declaring dataType as jsonp
but still doesnt work
Markus Ivancsics
@ivancsicsmarkus
Apr 30 2017 07:30
@jaanhio I would use $.getJSON(url, function(data) { ... });
@jaanhio It works for jsonp too.
@jaanhio Are you using an external js file?
Jianhao Tan
@jaanhio
Apr 30 2017 07:32
function getQuote(){


  $.ajax({
    type: "GET",
    url: "http://api.forismatic.com/api/1.0/?method=getQuote&key=457654&format=jsonp&lang=en&jsonp=?",
    dataType: "jsonp",
    cache: true,
    crossDomain: true,
    mimeType: "application/javascript",
    beforeSend: function(){
      $("#quoteText").html("Loading...");
      $("#quoteAuthor").hide();
    },
    success: function(data){
      $("#quoteAuthor").show();
      $("#quoteText").html('"'+data.quoteText+'"');
      $("#quoteAuthor").html("<em>" + "-" +data.quoteAuthor+"</em>");
    },
    error: function(){
      console.log("error retrieving data");
    }
  });
};
it worked fine for Safari, but not Chrome
based on the code above, what changes can i make to make it work on Chrome?
Markus Ivancsics
@ivancsicsmarkus
Apr 30 2017 07:35
@jaanhio I think if you should add &callback= to the end of the url.
@jaanhio But I always used $.getJSON to avoid these cross-browser bugs.
Jianhao Tan
@jaanhio
Apr 30 2017 07:40
@ivancsicsmarkus you mean like this?
http://api.forismatic.com/api/1.0/?method=getQuote&key=457654&format=jsonp&lang=en&jsonp=?&callback=
Nirvana-zsy
@Nirvana-zsy
Apr 30 2017 07:57
js正则替换string 怎么做到替换式保持原单词的大小写
is somebody here??????
ok......I'll left
Ryan Nelson
@iamryandnelson
Apr 30 2017 08:05
For my Twitch.tv project I can't get my OFFLINE button to work properly. Can anyone help? This should work!! http://codepen.io/iamryandnelson/pen/vmXzXz
Idowu Wasiu
@Hoxtygen
Apr 30 2017 08:07
hello people
got a lil problem that needs solving
rugano
@rugano
Apr 30 2017 08:11
function largestOfFour(arr){
//You can do this
sum = arr;
var largestNum = sum;
for(var i = 0;i < arr.length;i++){
if(largestNum == arr[i][0] + arr[i][1] + arr[i][2] + arr[i][3]){
sum += arr[i];
}
}
return sum;
}
largestOfFour([[4,5,1,3],[13,27,18,26],[32,35,37,39],[1000,1001,857,1]]);
how can i correct this?
Jianhao Tan
@jaanhio
Apr 30 2017 08:13
@rugano why are summing them up?
rugano
@rugano
Apr 30 2017 08:14
@jaanhio to get largest array of numbers,how should i do?
Jianhao Tan
@jaanhio
Apr 30 2017 08:15
@rugano its asking for largests numbers in each of the array
@rugano it should return [5,27,39,1001]
rugano
@rugano
Apr 30 2017 08:17
@jaanhio i have tried several ways without success,so what i s the correct way of doing it?
@jaanhio my problem is figuring how to arrange that code
How do i make it return [5,27,39,1001] ?
Kismet
@kizmat
Apr 30 2017 08:23
nodejs 6 vs 7? Anyone have an opinion on which to use? or resources that explain why someone might want to choose current over stable?
Jianhao Tan
@jaanhio
Apr 30 2017 08:24
@rugano you can try creating a loop to access each of the arrays within the array
then within each of the arrays, use a sort function to arrange it from smallest to largest
then push the largest number to an empty array
Ryan Nelson
@iamryandnelson
Apr 30 2017 08:28
@iamryandnelson Nvm, got it :)
Kismet
@kizmat
Apr 30 2017 08:29

the answer to my question: http://stackoverflow.com/questions/37532655/why-is-node-js-v4-4-5-recommended-over-v6-2-0-for-most-users

Incase anyone else was wondering the same thing. Different versions but the same logic/reasons apply

Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:07
hi im having trouble with the stand in line challenge, im not sure what to do. how do i add a number to the end of the array and then remove the first element of it?
knecka
@knecka
Apr 30 2017 09:08
remember about push() and (shift) methods
as well as pop() and unshift()
shift() *
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:09
i think so, yeah, it takes away values after something has occured
shift, that is, unshift does the opposite
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:16
so i need to write the function using push(), shift(), pop() and unshift() functions?
knecka
@knecka
Apr 30 2017 09:20
exactly. when you have an i.e. array = [1, 2, 3], array.pop(4) will add 4 at the end of the array and you have array = [1, 2, 3, 4] as a result
you use pop(), shift() and unshift() the same way
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:21
and array.shift(0) will remove the first number?
knecka
@knecka
Apr 30 2017 09:22
that's right
it removes the number and returns it, so while removing, you can store it in another variable (if you don't want to 'lose' it)
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:25
ok i got that, what i dont get is what number I should 'pop'? tough challenge hmm
thanks @knecka btw
CamperBot
@camperbot
Apr 30 2017 09:26
dubsteppa4life sends brownie points to @knecka :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @knecka |http://www.freecodecamp.com/knecka
knecka
@knecka
Apr 30 2017 09:27
no problem :D don't worry about pop() and unshift() now, from what I see in the challenge description you only need push() and shift() for this
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:28
is there a way to use push() to add the last number plus 1? I tried finalnum and lastnum but neither worked
rugano
@rugano
Apr 30 2017 09:29
function largestOfFour(arr){
//You can do tnis !
var ar = [ ];
var largestNum = arr;
for(var i = 0;i < arr.length;i++){
if(largestNum == arr[i][0] + arr[i][1] + arr[i][2] + arr[i][3]){

var smallestToLargest = arr.sort();
ar.push(largestNum);
}
}
return ar;
}
largestOfFour([[4,5,1,3],[13,27,18,26],[32,35,37,39],[1000,1001,857,1]);
i keep on failing at this,how do i correct ?
knecka
@knecka
Apr 30 2017 09:34
@Dubsteppa4Life you can always array.push(number+1), if you i.e. have number 5, but want to add 6 to the array. not sure if it is what you asked for though
rugano
@rugano
Apr 30 2017 09:35
@Dubsteppa4Life like this: arr.push(lastnum,1)
flansolo
@flansolo
Apr 30 2017 09:35
@rugano
function largestOfFour(arr) {
  // You can do this!
  let myArr = [];

  for(let x = 0; x < arr.length; x++){
     myArr.push(Math.max.apply(Math, arr[x]));  
  }
  return myArr;
}
knecka
@knecka
Apr 30 2017 09:35
rugano I believe you need to approach this challenge in a different way, by comparing numbers you have in array to check which one is the biggest
@flansolo I believe it's better to give tips instead of ready solution, since you can find solutions online anyway :)
flansolo
@flansolo
Apr 30 2017 09:36
yeah i agree was just lazy
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:36
hmm it says lastnum is not defined but ill number+1
flansolo
@flansolo
Apr 30 2017 09:36
sorry :P
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:37
*try number+1
seemed to have worked with arr.push((arr[4])+1) but I dont know how to modify the return line? im so hopeless haha
Jor
@joreyesl
Apr 30 2017 09:40
@Dubsteppa4Life you shouldn't need to add a number +1. You will be given 2 parameters, arr and num. You need to .push() the value of num to the array arr. Then you need to .shift() the first element of arr and return that.
flansolo
@flansolo
Apr 30 2017 09:41
ty @joreyesl
CamperBot
@camperbot
Apr 30 2017 09:41
flansolo sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 810 | @joreyesl |http://www.freecodecamp.com/joreyesl
flansolo
@flansolo
Apr 30 2017 09:41
lots more cookies now i see
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:42
thanks @joreyesl but the parameter num seems to be undefined? do i need to define it as num=arr[4]?
CamperBot
@camperbot
Apr 30 2017 09:42
dubsteppa4life sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 811 | @joreyesl |http://www.freecodecamp.com/joreyesl
Jor
@joreyesl
Apr 30 2017 09:42
@flansolo ty, not much more than last time lol
CamperBot
@camperbot
Apr 30 2017 09:42
joreyesl sends brownie points to @flansolo :sparkles: :thumbsup: :sparkles:
:warning: @flansolo's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
flansolo
@flansolo
Apr 30 2017 09:43
lol
Kuba Michalski
@kubami9
Apr 30 2017 09:43
Hello all!
Could you help me, how to grab those 2 parameters after an array in Seek and Destroy challenge in basic algorithm scripting? arr argument grabs only an array
Jor
@joreyesl
Apr 30 2017 09:44
@Dubsteppa4Life oh my bad, the parameters are arr and item
@flansolo you should link your account :p
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:45
oh yeah that seems to have worked arr.push(item) ty
Jor
@joreyesl
Apr 30 2017 09:45
@Dubsteppa4Life :thumbsup:
rugano
@rugano
Apr 30 2017 09:45
@Dubsteppa4Life what does the question say?
Pieter Stokkink
@forkerino
Apr 30 2017 09:45
@kubami9 you can use the arguments object for that. There should be a link in the instructions.
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:46
"Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed."
flansolo
@flansolo
Apr 30 2017 09:46
@joreyesl i will eventually. :D
byNio
@byNio
Apr 30 2017 09:47
anyone can help with profile lookup challenge? I got stuck there. Thanks.
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:47

my code atm

just stuck at return

arr.push(item);
arr.shift(0);
return item;

Kuba Michalski
@kubami9
Apr 30 2017 09:48
@forkerino Ohh okay, silly me, it's working now, thank you! :smile: :+1:
CamperBot
@camperbot
Apr 30 2017 09:48
kubami9 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2027 | @forkerino |http://www.freecodecamp.com/forkerino
rugano
@rugano
Apr 30 2017 09:48
@Dubsteppa4Life would be better if you posted the code that you wrote but never worked.that way,you learn,but there are many ways of learnig
knecka
@knecka
Apr 30 2017 09:48
you have to return the element that you removed with shift() method, not the item you were pushing. and +1 to what @rugano wrote
Pieter Stokkink
@forkerino
Apr 30 2017 09:48
@kubami9 :+1:
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:49
yeah true i forgot to write the code in here
return arr.unshift(0) then?
knecka
@knecka
Apr 30 2017 09:49
try it! I think it should work
Jor
@joreyesl
Apr 30 2017 09:50
@Dubsteppa4Life .unshift() adds the argument to the beginning of the array. you want to remove. so you need .shift()
Pieter Stokkink
@forkerino
Apr 30 2017 09:50
This message was deleted
@knecka unshift adds to the array.
knecka
@knecka
Apr 30 2017 09:50
whoops, didn't notice that, sorry for confusion
Pieter Stokkink
@forkerino
Apr 30 2017 09:50
and it returns a number
Jor
@joreyesl
Apr 30 2017 09:51
ok @forkerino is here. I can go take a break :)
Pieter Stokkink
@forkerino
Apr 30 2017 09:51
hold your horses
off an on
studying in bits and pieces in between
and I should write some code.
Jor
@joreyesl
Apr 30 2017 09:52
:laughing:
knecka
@knecka
Apr 30 2017 09:52
I always mix shift() and unshift() because for me UNshift sounds more like something that removes an element :worried:
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:52
it does, true.
Pieter Stokkink
@forkerino
Apr 30 2017 09:52
@knecka we all make well-intentioned mistakes.
that is the perfect metaphor for coding
:laughing:
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:54
ty @rugano and ty @forkerino
CamperBot
@camperbot
Apr 30 2017 09:54
dubsteppa4life sends brownie points to @rugano and @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 240 | @rugano |http://www.freecodecamp.com/rugano
:star2: 2028 | @forkerino |http://www.freecodecamp.com/forkerino
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:55

so this is still currently my code arr.push(item);
arr.shift(0);
return arr.unshift();

i know i should get to the conclusion myself but i think in this case i just dont get it...

oh and ty @knecka
CamperBot
@camperbot
Apr 30 2017 09:55
dubsteppa4life sends brownie points to @knecka :sparkles: :thumbsup: :sparkles:
:warning: dubsteppa4life already gave knecka points
Jor
@joreyesl
Apr 30 2017 09:56
you are still returning .unshift(), you should be returning arr.shift()
Pieter Stokkink
@forkerino
Apr 30 2017 09:56
@Dubsteppa4Life .shift() doesn't require an argument. It does return the element it removes, which is your return value. So return the result of arr.shift()
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:57
I wrote return arr.shift() but now none of the tests are passed
Jor
@joreyesl
Apr 30 2017 09:57
you should only be .shift() 1 time, if you do it in the line before and in the return, then you end up removing 2 elements
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 09:58

ah yes thank you so much,

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

return arr.shift(); // Change this line
}

finally worked

didnt realize that return also executes the fucntion
thank you everyone!!!
and sry for spamming...
Pieter Stokkink
@forkerino
Apr 30 2017 10:02
@Dubsteppa4Life I didn't see any spam... What is happening is that the expression to the right of return will be evaluated and then it will be returned. So arr.shift is performed and the return value takes it place, which is then in turn returned by your function.
rugano
@rugano
Apr 30 2017 10:03
@flansolo thanks
CamperBot
@camperbot
Apr 30 2017 10:03
rugano sends brownie points to @flansolo :sparkles: :thumbsup: :sparkles:
:warning: @flansolo's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 10:03
oh i see ty @forkerino
CamperBot
@camperbot
Apr 30 2017 10:03
dubsteppa4life sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: dubsteppa4life already gave forkerino points
Jianhao Tan
@jaanhio
Apr 30 2017 10:04
function getQuote(){


  $.ajax({
    type: "GET",
    url: "http://api.forismatic.com/api/1.0/?method=getQuote&key=457654&format=jsonp&lang=en&jsonp=?",
    dataType: "jsonp",
    cache: true,
    crossDomain: true,
    mimeType: "application/javascript",
    beforeSend: function (){
      $("#quoteText").html("Loading...");
      $("#quoteAuthor").hide();
    },
    success: function (data){
      $("#quoteAuthor").show();
      $("#quoteText").html('"'+data.quoteText+'"');
      $("#quoteAuthor").html("<em>" + "-" +data.quoteAuthor+"</em>");
    },
    error: function(){
      console.log("error retrieving data");
    }
  });
};
may i know how can i use callback function on this?
Pieter Stokkink
@forkerino
Apr 30 2017 10:06
@jaanhio your success and error functions are the callbacks (in the case of data coming back or an error respectively)
Teo
@Teo03
Apr 30 2017 10:06

can someone help? '''function golfScore(par, strokes) {
// Only change code below this line
if(strokes = 1) {
return "Hole-in-one!";
}
else if(strokes <= par - 2) {
return "Eagle";
}
else if(strokes = par - 1){
return "Birdie";
}
else if(strokes = par){
return "Par";
}
else if(strokes = par - 1){
return "Bogey";
}
else if(strokes = par + 2){
return "Double Bogey";
}
else{
return "Go Home!";
}

}

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

CamperBot
@camperbot
Apr 30 2017 10:06
:bulb: to format code use backticks! ``` more info
Pieter Stokkink
@forkerino
Apr 30 2017 10:06
@Teo03 your first if sets strokes to 1
use === for comparison
you do the same in a couple other places.
Teo
@Teo03
Apr 30 2017 10:07

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

}

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

IS this ok?
Jianhao Tan
@jaanhio
Apr 30 2017 10:08
@forkerino ok. then how can i resolve this error on chrome?
Refused to execute script from 'http://api.forismatic.com/api/1.0/?method=getQuote&key=457654&format=jsonp&lang=en&jsonp=jQuery32104226152045092493_1493546830880' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Pieter Stokkink
@forkerino
Apr 30 2017 10:08
@Teo03 don't change <=, =>, < and >
Jianhao Tan
@jaanhio
Apr 30 2017 10:08
it worked fine on Safari but i can’t get it to work on chrome
Teo
@Teo03
Apr 30 2017 10:09

if(strokes === 1) {
return "Hole-in-one!";
}
else if(strokes <= par - 2) {
return "Eagle";
}
else if(strokes === par - 1){
return "Birdie";
}
else if(strokes === par){
return "Par";
}
else if(strokes === par - 1){
return "Bogey";
}
else if(strokes === par + 2){
return "Double Bogey";
}
else{
return "Go Home!";
}

}

// Change these values to test
golfScore(4, 5);
Is this good? @forkerino

Pieter Stokkink
@forkerino
Apr 30 2017 10:10
@Teo03 the bogey needs par + 1, but other than that it looks good at first glance.
Teo
@Teo03
Apr 30 2017 10:10
@forkerino Thanks a lot
CamperBot
@camperbot
Apr 30 2017 10:10
teo03 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2029 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Apr 30 2017 10:10
you're welcome
Jianhao Tan
@jaanhio
Apr 30 2017 10:11
@forkerino could you advise me on this? i have trying to make it work on Chrome but kept returning the same error :worried:
Pieter Stokkink
@forkerino
Apr 30 2017 10:11
@jaanhio do you have a link to your codepen?
Jianhao Tan
@jaanhio
Apr 30 2017 10:12
@forkerino i am doing this on atom
Pieter Stokkink
@forkerino
Apr 30 2017 10:13
ok. @jaanhio, I'm not entirely sure what is going on, because you specify the mimetype to be js rather than text/html.
@jaanhio let's see if I can find something in the docs.
"i can feel the love i want, i can feel the love i need, but it's never gonna come the way i am. could i change it if i wanted? can i rise above the flood? will it wash out in the water, or is it always in the blood?"
Pieter Stokkink
@forkerino
Apr 30 2017 10:15
@jaanhio can you try removing &jsonp=? from the end of your url?
I just read that $.ajax automatically appends something like that when the dataType is jsonp
if that doesn't work, try commenting out your mimeType in the settings.
I'm not sure on how it works, but this is what I would try.
Lola
@smokingboudicca
Apr 30 2017 10:19
is there a glossary of terms? I don't know what 'initialize a variable' means, among many, maaaany other things and scrolling around for definitions takes a lot of time
kickkick479
@kickkick479
Apr 30 2017 10:19
Hi, guys.
Pieter Stokkink
@forkerino
Apr 30 2017 10:21
@smokingboudicca I don't know of any glossary, but initialize means you assign a value to a variable when you declare it.
var a = 0 declares a and initializes it to 0
@kickkick479 :wave:
Lola
@smokingboudicca
Apr 30 2017 10:21
thanks @forkerino !
CamperBot
@camperbot
Apr 30 2017 10:21
smokingboudicca sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2030 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Apr 30 2017 10:22
@smokingboudicca most of these terms are explained in any JS book for beginners.
Jianhao Tan
@jaanhio
Apr 30 2017 10:22
@forkerino thank you for the suggestion, i will try it later as I'm not at my desk now. I think i tried removing &jsonp=? and i couldn't retrieve the data
CamperBot
@camperbot
Apr 30 2017 10:22
jaanhio sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2031 | @forkerino |http://www.freecodecamp.com/forkerino
Angelos Arnis
@pixelsign
Apr 30 2017 10:23
have you ever tried to assign an "enter" key to an event, to submit a form?
Jianhao Tan
@jaanhio
Apr 30 2017 10:23
@forkerino it's really puzzling why it works in Safari but not on chrome
AMANDEEP
@Amandeep1998
Apr 30 2017 10:23

function bouncer(arr) {
// Don't show a false ID to this bouncer.
var result= arr.filter(check);
return result;

}

function check(arr){
return arr!== undefined && arr!== false && arr!== "";

}
bouncer([7, "ate", "", false, 9]);
what i am doing wrong

Pieter Stokkink
@forkerino
Apr 30 2017 10:24
@pixelsign if the form is inside <form> tags, enter should automatically submit the form. Otherwise, you would have to set up an event listener that listens for a 'keypress' event and check to see if the key pressed was the enter key.
@jaanhio yeah, welcome to coding.
Angelos Arnis
@pixelsign
Apr 30 2017 10:25
Yeah I Tried to do something like that @forkerino but no success. Trying to subscribe emails to Mailchimp
Pieter Stokkink
@forkerino
Apr 30 2017 10:25
@jaanhio did you try searching stack overflow for 'jQuery .ajax call JSONP error on Chrome' ?
@pixelsign show some code.
Angelos Arnis
@pixelsign
Apr 30 2017 10:26
Pieter Stokkink
@forkerino
Apr 30 2017 10:26
@Amandeep1998 there are a few more falsy values that you need to filter out. NaN is one of them and the checking should be a little bit different.
Lola
@smokingboudicca
Apr 30 2017 10:27
var global = myGlobal;


function fun1() {
  // Assign 5 to oopsGlobal Here

}

// Only change code above this line
function fun2() {
  var output = "";
  if (typeof myGlobal != "undefined") {
    output += "myGlobal: " + myGlobal;
  }
  if (typeof oopsGlobal != "undefined") {
    output += " oopsGlobal: " + oopsGlobal;
  }
  console.log(output);
}
TCzechowski
@TCzechowski
Apr 30 2017 10:27
Guys, I have a table that loads the contend from JSON file, and I have couple functions (filtering by input, sorting, and pagination). When I wrote filtering and sorting everything was fine, but when I call pagination function, the filtering and sorting stops working. Anyone got any idea on why it doesn't work?
Pieter Stokkink
@forkerino
Apr 30 2017 10:27
@pixelsign When I hit enter there, it works.
Lola
@smokingboudicca
Apr 30 2017 10:27
how do I initialize myGlobal with a value of 10?
TCzechowski
@TCzechowski
Apr 30 2017 10:27
var myGlobal = 10?
Angelos Arnis
@pixelsign
Apr 30 2017 10:27
There is an animation that for now shows success no matter what. :P
TCzechowski
@TCzechowski
Apr 30 2017 10:28
anyone? :(
Lola
@smokingboudicca
Apr 30 2017 10:29
@TCzechowski thanks!!
CamperBot
@camperbot
Apr 30 2017 10:29
smokingboudicca sends brownie points to @tczechowski :sparkles: :thumbsup: :sparkles:
:warning: @tczechowski's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Pieter Stokkink
@forkerino
Apr 30 2017 10:30
@pixelsign I like the graph in the background, super nice effect! Are you sure the form method should be 'get' ?
@TCzechowski hard to say without seeing the code
Angelos Arnis
@pixelsign
Apr 30 2017 10:31
@forkerino Both post and get do not work :(
TCzechowski
@TCzechowski
Apr 30 2017 10:32
@forkerino well, I can paste you the code, but its like 130 lines long, so Idk if you want to read that lol
Pieter Stokkink
@forkerino
Apr 30 2017 10:34
@TCzechowski can you be more precise about the problem? What happens when pagination is called?
Teo
@Teo03
Apr 30 2017 10:35

Can someone help here?
// Setup
function abTest(a, b) {
// Only change code below this line
if( a, b < 0){
return undefined;
}

// Only change code above this line

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

// Change values below to test your code
abTest(2,8);
//
abTest(-2,2) should return undefined.

Pieter Stokkink
@forkerino
Apr 30 2017 10:35
@pixelsign I suggest you pop over to mailchimp and double check there on how to embed the code.
Angelos Arnis
@pixelsign
Apr 30 2017 10:36
@forkerino thanks!
CamperBot
@camperbot
Apr 30 2017 10:36
pixelsign sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2032 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Apr 30 2017 10:36
@Teo03 that will only check if b is less than zero.
@pixelsign wish I could help you better...
Angelos Arnis
@pixelsign
Apr 30 2017 10:37
It's fine, it is just something beyond my skillset yet :P
Pieter Stokkink
@forkerino
Apr 30 2017 10:37
@Teo03 you need to use the logical operator for 'or' and compare both params to zero individually.
Teo
@Teo03
Apr 30 2017 10:37
@forkerino Thanks :)
CamperBot
@camperbot
Apr 30 2017 10:37
teo03 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: teo03 already gave forkerino points
Pieter Stokkink
@forkerino
Apr 30 2017 10:37
@pixelsign that's how we grow.
:+1:
Manuchehr Muhidinov
@manucher17
Apr 30 2017 10:37
hey, guys
function mutation(arr) { //if arr[1] is in arr[0] 
  let newArr = [] ; 
  let str; 

  newArr = arr; 
  str = newArr.join(' ').toLowerCase(); 
  console.log(str); 

}

//should return false cuz there's no "y" in arr[i]
console.log(mutation(["helLo", "hEy"]));
TCzechowski
@TCzechowski
Apr 30 2017 10:38
@forkerino Well, when pagination is called it paginates total of 12 rows into 3 pages with 5 rows each, but then my filtering and sorting functions don't work (there are no errors in console whatsoever). I don't know how to be more precise. It feels like the pagination function is not dynamic, but Idk how to turn it into dynamic
Pieter Stokkink
@forkerino
Apr 30 2017 10:38
@manucher17 hey! what's your approach for the challenge?
@TCzechowski does it sort/filter the first page or nothing at all?
TCzechowski
@TCzechowski
Apr 30 2017 10:40
nothing at all. I even tried to put console.log("working"); inside sorting function and filtering function, but it doesn't appear in the console.
Manuchehr Muhidinov
@manucher17
Apr 30 2017 10:40
@forkerino I thought to turn my array into string and then somehow work it . But I have no idea now. Maybe I should use methods of an array?
Pieter Stokkink
@forkerino
Apr 30 2017 10:41
@manucher17 well, you have two strings in the array, you need to check each letter in the second string, to see if it is in the first string. There is no need to make one long string out of it (but lowercasing both is a good idea).
@TCzechowski does your pagination function change the DOM?
TCzechowski
@TCzechowski
Apr 30 2017 10:42
it does.
Pieter Stokkink
@forkerino
Apr 30 2017 10:43
@TCzechowski that's where I would start looking for bugs.
Manuchehr Muhidinov
@manucher17
Apr 30 2017 10:44
@forkerino the thing is I don't know how to compare each letter
Pieter Stokkink
@forkerino
Apr 30 2017 10:45
@manucher17 how would you normally go over each element of an array or each letter of a string?
Manuchehr Muhidinov
@manucher17
Apr 30 2017 10:45
@forkerino with loop
Pieter Stokkink
@forkerino
Apr 30 2017 10:45
yes!
@manucher17 so create a loop to go over the second string.
write that and come back.
Manuchehr Muhidinov
@manucher17
Apr 30 2017 10:46
@forkerino ok, thanks
CamperBot
@camperbot
Apr 30 2017 10:46
manucher17 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2033 | @forkerino |http://www.freecodecamp.com/forkerino
Lola
@smokingboudicca
Apr 30 2017 10:50
```
function myLocalScope() {
  'use strict';


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

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);
this is the local scopes and functions challenge and I am not sure what I am supposed to write here
Plean
@geart891
Apr 30 2017 10:50
Hey, can you guys please explain to me how this function work?
function(a){ [1,2,3,4,5].indexOf(a)===-1};
Keon Samuel
@keonsam
Apr 30 2017 10:51
which part how function works or how indexOf works?
Plean
@geart891
Apr 30 2017 10:52
@keonsam how indexOf work
Teo
@Teo03
Apr 30 2017 10:52
Can someone help I don't know what is wrong here
function cc(card) {
  // Only change code below this line
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break:
    case 7:
    case 8:
    case 9:
      count = 0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
      break;
  }
  if(count >= 1){
    return count + "Bet";
  } else {
    return count + "Hold";
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Keon Samuel
@keonsam
Apr 30 2017 10:52
there is a thing called docs
Stephen James
@sjames1958gm
Apr 30 2017 10:53
@Teo03 your output is 5Bet not 5 Bet
Lola
@smokingboudicca
Apr 30 2017 10:53
?
Teo
@Teo03
Apr 30 2017 10:53
@sjames1958gm I changet still doesen't work
Stephen James
@sjames1958gm
Apr 30 2017 10:54
@Teo03 What are you doing when case 7,8,9?
Keon Samuel
@keonsam
Apr 30 2017 10:54
" Bet"
Manuchehr Muhidinov
@manucher17
Apr 30 2017 10:54
function mutation(arr) { //if arr[1] is in arr[0] 
  let newArr = [] ; 
  let str; 

  newArr = arr; 
  str = newArr[0].toLowerCase(); 
  str2 = newArr[1].toLowerCase(); 

  for(let i = 0; i < str.length; i++) {
      if() {
        console.log(); 
    }
  }
}

//should return false cuz there's no "y" in arr[i]
console.log(mutation(["helLo", "hEy"]))
Stephen James
@sjames1958gm
Apr 30 2017 10:55
@Teo03 Count Change is 0 when 7,8,9 - not set count to zero
Lola
@smokingboudicca
Apr 30 2017 10:55
I don't understand
Keon Samuel
@keonsam
Apr 30 2017 10:55
should be count +=0;
Teo
@Teo03
Apr 30 2017 10:55
@sjames1958gm @keonsam thanks :smile:
CamperBot
@camperbot
Apr 30 2017 10:55
:cookie: 349 | @keonsam |http://www.freecodecamp.com/keonsam
teo03 sends brownie points to @sjames1958gm and @keonsam :sparkles: :thumbsup: :sparkles:
:star2: 7034 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 30 2017 10:56
@manucher17 You should probably loop over str2 and check if each letter is in str
Lola
@smokingboudicca
Apr 30 2017 10:57
um, my question... can anyone help me with this challenge?
Keon Samuel
@keonsam
Apr 30 2017 10:58
read the challenge over and over until you get it.
Stephen James
@sjames1958gm
Apr 30 2017 10:59
@smokingboudicca You are supposed to define myVar as a local variable inside the function.
Then there will be an error because of the last console.log
then you remove that and it passes
Pieter Stokkink
@forkerino
Apr 30 2017 11:00
@manucher17 in your loop you can use .indexOf to check if the current letter is in the first string. And as Stepehn pointed out, you need to loop over str2.
kickkick479
@kickkick479
Apr 30 2017 11:01
@smokingboudicca
  1. Declare a local variable myVar inside myLocalScope.
  2. Run the tests . This run fails.
  3. Finally, comment out or remove the console.log(myVar);
kreuel
@kreuel
Apr 30 2017 11:03
hi guys, got stuck here on Title Case a Sentence. I managed to update all the first letter of the word to UpperCase, but in the final output it is showing the whitespace in the closing double quotes. I tried to use the function replace but this not resolve the issue. Any workaround on this?
blob
thanks in advance
kickkick479
@kickkick479
Apr 30 2017 11:04
@kreuel You don't need double quotes in the output, I guess.
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 11:05

Need help with the Golf Code challenge, my code being:

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

return "Change Me";
// Only change code above this line
}

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

Pieter Stokkink
@forkerino
Apr 30 2017 11:05
@kreuel also, you can .trim a string to remove the last space.
@Dubsteppa4Life = is assignment, === is comparison
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 11:05
how do I format it to be shown as code in here btw?
Pieter Stokkink
@forkerino
Apr 30 2017 11:05
'''
CamperBot
@camperbot
Apr 30 2017 11:05
:bulb: to format code use backticks! ``` more info
Pieter Stokkink
@forkerino
Apr 30 2017 11:05
@Dubsteppa4Life click more info ^^
kickkick479
@kickkick479
Apr 30 2017 11:05
'''
CamperBot
@camperbot
Apr 30 2017 11:05
:bulb: to format code use backticks! ``` more info
kreuel
@kreuel
Apr 30 2017 11:05
hi @Pieter, already tried it but did not work also
kickkick479
@kickkick479
Apr 30 2017 11:06
@forkerino ^That is useful to teach the triple backtick function :smile:
Pieter Stokkink
@forkerino
Apr 30 2017 11:06
@kreuel .trim doesn't work after adding the "s, which you don't have to do
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 11:06
oh ok so on all the "strokes=" I should write "strokes===" instead?
Pieter Stokkink
@forkerino
Apr 30 2017 11:06
@Dubsteppa4Life yes
Manuchehr Muhidinov
@manucher17
Apr 30 2017 11:06
@forkerino
if(~str2.indexOf(str)) //something like this?
Alexander Køpke
@alexanderkopke
Apr 30 2017 11:07
@kreuel where did you put the trim ?
kreuel
@kreuel
Apr 30 2017 11:07
hi @kickkick479 , if i remove the double quote it will output a single line sentence without any space in between words.
Pieter Stokkink
@forkerino
Apr 30 2017 11:07
@Dubsteppa4Life what happens now is that you overwrite the strokes in your first if.
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 11:07
oh i see
kreuel
@kreuel
Apr 30 2017 11:08
@alexanderkopke, i insert it in the last variable
Pieter Stokkink
@forkerino
Apr 30 2017 11:08
@manucher17 you need to reverse str and str2, and put an index on str2, to just check the current letter
@kreuel show what you got now
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 11:08
in the else if (strokes<===(par-2)) it shows me an error, how come?
oh and ty @forkerino
CamperBot
@camperbot
Apr 30 2017 11:08
dubsteppa4life sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2034 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Apr 30 2017 11:09
@Dubsteppa4Life you don't have to change <=, =>, < or >
kickkick479
@kickkick479
Apr 30 2017 11:09
@kreuel Really so ? Your code inserted white space after evoerwords, as strUpperCase += brabara + " ";
Dubsteppa4Life
@Dubsteppa4Life
Apr 30 2017 11:10
oh sweet, now it correct, thanks!
*it's
kreuel
@kreuel
Apr 30 2017 11:11
@kickkick479 i inserted the white space in order to have a space in between the words when it loop. do you have any alternative?
kickkick479
@kickkick479
Apr 30 2017 11:11
@kreuel The problem is the last white space of the output. So modify your code like return tempResult.trim();
stelarossa
@stelarossa
Apr 30 2017 11:11

hi all,if somebody could help me with this,im a little bit stuck :)
https://www.freecodecamp.com/challenges/golf-code my code looks like function golfScore(par, strokes) {
// Only change code below this line
if (strokes == 1) {
return "Hole-in-one!";
} else if (strokes <= par - 2) {
return "Eagle";
} else if (strokes <= par - 1) {
return "Birdie";
} else if (strokes == par) {
return "Par";
} else if (strokes >= par + 1 && strokes < par + 2) {
return "Bogey";
} else if (strokes >= par + 2 && strokes < par + 3) {
return "Double Bougey";
} else if (strokes >= par + 3) {
return "Go Home";
}

return "Change Me";
// Only change code above this line
} why it whant pass?To mee the logic seems ok...

kickkick479
@kickkick479
Apr 30 2017 11:12
@kreuel Another solution is to use an array and push everywords. Finnaly join the array with white spaces. I used that.
Pieter Stokkink
@forkerino
Apr 30 2017 11:12
@stelarossa Go Home! exclamation !
@stelarossa and spelling error in Double Bogey
stelarossa
@stelarossa
Apr 30 2017 11:12
ok,thanks :)
kickkick479
@kickkick479
Apr 30 2017 11:12
lol
Pieter Stokkink
@forkerino
Apr 30 2017 11:13
@stelarossa this else if (strokes >= par + 2 && strokes < par + 3) can also be just else if (strokes == par +2)
stelarossa
@stelarossa
Apr 30 2017 11:13
thanks @kreuel @forkerino
CamperBot
@camperbot
Apr 30 2017 11:13
stelarossa sends brownie points to @kreuel and @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 243 | @kreuel |http://www.freecodecamp.com/kreuel
:star2: 2035 | @forkerino |http://www.freecodecamp.com/forkerino
kreuel
@kreuel
Apr 30 2017 11:14
@kickkick479 i tried inserting the trim in the return value but did not remove the whitespace. will try to push the value inside an array
jimmynelsondavid
@jimmynelsondavid
Apr 30 2017 11:14

hi guys , I got stuck here

<input type="text" placeholder="cat photo URL">

<form action="/submit-cat-photo">
</form>

Nest your text input element within a form element

heroiczero
@heroiczero
Apr 30 2017 11:14
@jimmynelsondavid put your <input> between the <form> tags
Lola
@smokingboudicca
Apr 30 2017 11:14
am I supposed to declare the variable where it says 'use strict'?
```
Pieter Stokkink
@forkerino
Apr 30 2017 11:15
@smokingboudicca on the line below it
kickkick479
@kickkick479
Apr 30 2017 11:15
@kreuel Can you share your code? Paste this window.
Lola
@smokingboudicca
Apr 30 2017 11:15
@forkerino thanks!!
CamperBot
@camperbot
Apr 30 2017 11:15
smokingboudicca sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: smokingboudicca already gave forkerino points
Pieter Stokkink
@forkerino
Apr 30 2017 11:15
@smokingboudicca 'use strict' is a command to JS, to be extra strict with your code.
Manuchehr Muhidinov
@manucher17
Apr 30 2017 11:15
@forkerino
I did it!!! thank you)
function mutation(arr) { //if arr[1] is in arr[0] 
  let newArr = [];
  let str, result, position;

  newArr = arr;
  str = newArr[0].toLowerCase();
  str2 = newArr[1].toLowerCase();

  position = 0;
  for (let i = 0; i < str2.length; i++) {
    if (~str.indexOf(str2[i])) {
      position++;
    }

  }

  return position === str2.length;
}
//should return false cuz there's no "y" in arr[i]
console.log(mutation(["helLo", "hE"]));
CamperBot
@camperbot
Apr 30 2017 11:15
manucher17 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: manucher17 already gave forkerino points
Lola
@smokingboudicca
Apr 30 2017 11:15
sounds harsh
kreuel
@kreuel
Apr 30 2017 11:15

@kickkick479 function titleCase(str) {
var newTitle = [];
var strUpperCase = "";
var tempResult = "";
var temp = [];
var test = "";

//insert the string in to Array
newTitle = str.split(" ");

//loop the array values
for (var i = 0; i < newTitle.length; i++){

//get the first letter and convert it to UpperCase
//this will generate S A S then get the remaining substring in the Array and convert it LowerCase
strUpperCase += newTitle[i].charAt(0).toUpperCase() + newTitle[i].substring(1).toLowerCase() +" ";
//remove the ending comma
//finalResult = strUpperCase.replace(/,\s*$/, ""); 
tempResult = '"' + strUpperCase + '"';
//temp = tempResult.split(" ");  
//test = 

}
return tempResult.trim();
}

titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");

Pieter Stokkink
@forkerino
Apr 30 2017 11:16
@manucher17 I think you can safely remove the ~, I don't know what it does there.
kreuel
@kreuel
Apr 30 2017 11:16
@kickkick479
Pieter Stokkink
@forkerino
Apr 30 2017 11:16
@smokingboudicca lol
kreuel
@kreuel
Apr 30 2017 11:16

function titleCase(str) {
var newTitle = [];
var strUpperCase = "";
var tempResult = "";
var temp = [];
var test = "";

//insert the string in to Array
newTitle = str.split(" ");

//loop the array values
for (var i = 0; i < newTitle.length; i++){

//get the first letter and convert it to UpperCase
//this will generate S A S then get the remaining substring in the Array and convert it LowerCase
strUpperCase += newTitle[i].charAt(0).toUpperCase() + newTitle[i].substring(1).toLowerCase() +" ";
//remove the ending comma
//finalResult = strUpperCase.replace(/,\s*$/, ""); 
tempResult = '"' + strUpperCase + '"';
//temp = tempResult.split(" ");  
//test = 

}
return tempResult.trim();
}

titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");

Pieter Stokkink
@forkerino
Apr 30 2017 11:17
@kreuel don't add '"'s to your string.
kickkick479
@kickkick479
Apr 30 2017 11:17
"""
'''
CamperBot
@camperbot
Apr 30 2017 11:17
:bulb: to format code use backticks! ``` more info
kickkick479
@kickkick479
Apr 30 2017 11:17
@forkerino tempResult = strUpperCase ; Only that change is needed.
Manuchehr Muhidinov
@manucher17
Apr 30 2017 11:18
blob
@forkerino it will not work
jimmynelsondavid
@jimmynelsondavid
Apr 30 2017 11:18
@heroiczero please how?
kickkick479
@kickkick479
Apr 30 2017 11:18
@kreuel Sorry not forkerino . That was for kreuel.
kreuel
@kreuel
Apr 30 2017 11:18
@kickkick479 @forkerino how should add the double quote at the final result?
heroiczero
@heroiczero
Apr 30 2017 11:18

@jimmynelsondavid

<form>
    <input>
</form>

like this

kickkick479
@kickkick479
Apr 30 2017 11:19
@kreuel we don't need that.
Alexander Køpke
@alexanderkopke
Apr 30 2017 11:19
@kreuel it already is a string
TCzechowski
@TCzechowski
Apr 30 2017 11:20
How to write an IF statement that checks if there is already an element in the DOM?
kreuel
@kreuel
Apr 30 2017 11:20
@kickkick479 @alexanderkopke @forkerino thanks guys, it is resolve after i remove the "" in my string.
CamperBot
@camperbot
Apr 30 2017 11:20
kreuel sends brownie points to @kickkick479 and @alexanderkopke and @forkerino :sparkles: :thumbsup: :sparkles:
Alexander Køpke
@alexanderkopke
Apr 30 2017 11:20
@kreuel tempResult = strUpperCase; is sufficient. And then your return tempResult.trim(); should work
CamperBot
@camperbot
Apr 30 2017 11:20
:cookie: 335 | @kickkick479 |http://www.freecodecamp.com/kickkick479
:star2: 2036 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 1336 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
Alexander Køpke
@alexanderkopke
Apr 30 2017 11:21
@kreuel awesome.. good work! :)
kreuel
@kreuel
Apr 30 2017 11:21
thanks
Pieter Stokkink
@forkerino
Apr 30 2017 11:21
@manucher17 aah, ok, I just never saw the ~operator used like that before. You can do str.indexOf(str2[i])== -1 to check if the letter is not in the string.
that's the most common way
or >= 0 to see if it is there.
TCzechowski
@TCzechowski
Apr 30 2017 11:22
I meant something like if (<button> doesn't exist in the DOM) { make button } else { skip };
how to write that IF statement?
if (<button> doesn't exist in the DOM)
this part
Manuchehr Muhidinov
@manucher17
Apr 30 2017 11:23
@forkerino yeah, you're right. The article in Russian says to remember
"if(~str.indexOf(str2[i]))" as a chunk "if it's found"
Pieter Stokkink