These are chat archives for FreeCodeCamp/HelpJavaScript

2nd
Mar 2017
Chris Jantzen
@XXiphias
Mar 02 2017 00:00
I think someone is having a stroke...
Pieter Stokkink
@forkerino
Mar 02 2017 00:00
@moigithub is that your cat typing?
Moisés Man
@moigithub
Mar 02 2017 00:00
jgvbngcngbvghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
hjkgohyjjjjjjkkkkkkk
Chris Jantzen
@XXiphias
Mar 02 2017 00:00
@only1dallas That looks fine. What issue are you having?
eyesore-
@eyesore-
Mar 02 2017 00:01
@JSchock16 You dont really have to worry about refs and pointers in this. With that being said I only know pointers from Go which I think handles them the same as C++. Far as scope goes you want to use let and const instead of var. Const whenever you are using a variable that isnt going to change type. Let will create a new scope even within a for loop which var does not.
Jeff
@JSchock16
Mar 02 2017 00:01
my goal is to learn javascript to replace c++ through html blocks with node.js just trying to get aquainted with the language is the a global scope identifier?
Pieter Stokkink
@forkerino
Mar 02 2017 00:01
@JSchock16 JS doesn't have pointers. All objects and arrays are reference types. Scope is something that whole books have been written about, best one imo this & Object prototype by Kyle Simpson (free to read on github)
only1dallas
@only1dallas
Mar 02 2017 00:02
@XXiphias it's telling me that gloveBoxContents is undefined :(
Chris Jantzen
@XXiphias
Mar 02 2017 00:02
Whats the object look like @only1dallas ?
only1dallas
@only1dallas
Mar 02 2017 00:02

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

// Only change code below this line

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

@XXiphias I'm prob missing something.. not sure. need a little help
Chris Jantzen
@XXiphias
Mar 02 2017 00:03
ah.. @only1dallas you want to do ["glove box"]
or change that inside the object to glove_box
eyesore-
@eyesore-
Mar 02 2017 00:03
@only1dallas You have glove box in one place and g"glove_box" somewhere else
Pieter Stokkink
@forkerino
Mar 02 2017 00:03
@JSchock16 global scope in the browser is the window object
Chris Jantzen
@XXiphias
Mar 02 2017 00:03
glove box != glove_box
only1dallas
@only1dallas
Mar 02 2017 00:04
good deal. Thanks!
Chris Jantzen
@XXiphias
Mar 02 2017 00:04
@JSchock16 if you want to learn more about js scope, this and the next 2 lessons after it might be worth going through: https://beta.freecodecamp.com/en/challenges/es6/explore-problems-with-the-var-keyword
eyesore-
@eyesore-
Mar 02 2017 00:05
@JSchock16 let and const > var
Jeff
@JSchock16
Mar 02 2017 00:05
@forkerino thank you man gunna findout for overloading and if globals can be manipulated inside function
CamperBot
@camperbot
Mar 02 2017 00:05
jschock16 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 1302 | @forkerino |http://www.freecodecamp.com/forkerino
Jeff
@JSchock16
Mar 02 2017 00:05
ooo const are here too?
Chris Jantzen
@XXiphias
Mar 02 2017 00:05
yes, but only in ES6
so only up-to-date browsers
eyesore-
@eyesore-
Mar 02 2017 00:06
Yup! Use those bad boys for objects and functions (which technically are also objects)
Yeah, if you use ES6 make sure to use Babel or the like.
Jeff
@JSchock16
Mar 02 2017 00:07
mobile at ES6?
Steven
@Ironwrangler
Mar 02 2017 00:07

i am not getting this i have tried it 5 different ways.
// Example
var changed = 0;

function change(num) {
return (num + 5) / 3;
}

changed = change(10);

// Setup
var processed = 0;

function processArg(num) {
return (num + 3) / 5;
}

// Only change code below this line
var processed = process(2);

function processedArg(num) {
return (2 + 5);

Pieter Stokkink
@forkerino
Mar 02 2017 00:08
You can see all browser support on the docs of the relevant syntax @JSchock16
at MDN
LaconicLuchador
@LaconicLuchador
Mar 02 2017 00:08
When returning object properties, is there a difference between like return contacts[i][prop] and return contacts[i].prop; I think that I'm confusing myself between bracket and dot notation but am not sure...
Pieter Stokkink
@forkerino
Mar 02 2017 00:09
yes @LaconicLuchador
eyesore-
@eyesore-
Mar 02 2017 00:09
@JSchock16 For the most part yes, but to be sure use Babel to transpile
Pieter Stokkink
@forkerino
Mar 02 2017 00:09
@LaconicLuchador better use brackets if you work with variable names or object keys that have spaces in them.
Jeff
@JSchock16
Mar 02 2017 00:09
bookmarked! @forkerino can you link me a source on babel? I have no context
Pieter Stokkink
@forkerino
Mar 02 2017 00:09
@LaconicLuchador .prop is equivalent to ["prop"]
Jeff
@JSchock16
Mar 02 2017 00:10
@eyesore- that was for you too
eyesore-
@eyesore-
Mar 02 2017 00:11
Their site has good information https://babeljs.io/ when you use frameworks like React and Angular it's a good idea to run them through Babel or Buble when compiling.
@Ironwrangler What is the prompt?
Pieter Stokkink
@forkerino
Mar 02 2017 00:12
That's all folks, I'm going to sleeeeeeeeep.
forkerino @forkerino wanders of into Dreamtime
Pieter Stokkink
@forkerino
Mar 02 2017 00:12
:sleeping:
LaconicLuchador
@LaconicLuchador
Mar 02 2017 00:12
@forkerino oh, okay thanks! G'night
CamperBot
@camperbot
Mar 02 2017 00:12
laconicluchador sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 1303 | @forkerino |http://www.freecodecamp.com/forkerino
Chris Jantzen
@XXiphias
Mar 02 2017 00:13
nn @forkerino :)
Rico042002
@rico042002
Mar 02 2017 00:15
Need some serious help! anybody down for helping me with a simple array manipulation function?
PM me
Mac
@itchick85
Mar 02 2017 00:16
Compound Assignment With Augmented Addition
eyesore-
@eyesore-
Mar 02 2017 00:16
@rico042002 sup
Mac
@itchick85
Mar 02 2017 00:16
var += 3;
var += 17;
var += 12;
var += 7
Johnny
@JohnnyBizzel
Mar 02 2017 00:16
@itchick85 what var are you declaring?
Mac
@itchick85
Mar 02 2017 00:16
what wrong with thisCompound Assignment With Augmented Addition
Chris Jantzen
@XXiphias
Mar 02 2017 00:17
also no semicolon on the last. but that might just be a copy/paste miss
Gulsvi
@gulsvi
Mar 02 2017 00:18
@itchick85 you need a variable to assign the new number to
john94
@lpy1994
Mar 02 2017 00:22
guys, can I use indexof() in a 2d array?
eyesore-
@eyesore-
Mar 02 2017 00:22
@lpy1994 What do you mean by 2d array?
john94
@lpy1994
Mar 02 2017 00:22
I am doing the FCC challenge called inventory update.
@eyesore- ```
Johnny
@JohnnyBizzel
Mar 02 2017 00:23
@lpy1994 which indexof? indexOf?
john94
@lpy1994
Mar 02 2017 00:23
@JohnnyBizzel yeah sir
flyingstone2
@flyingstone2
Mar 02 2017 00:24

Why isn't my code passing? if (myObj.hasOwnProperty === true) {return checkProp;} {
return myObj[checkProp];}

return "Not found";

}
// Test your code by modifying these values
checkObj("house");
This is what it tells me SnytaxError:Illegal return statement.and checkObj("house") should return "Not Found

Gulsvi
@gulsvi
Mar 02 2017 00:24
@lpy1994 No, you cannot do indexOf on 2D arrays
john94
@lpy1994
Mar 02 2017 00:24
@SkyCoder01 yeah I figured, tried so many times
ObjectiveCFido
@ObjectiveCFido
Mar 02 2017 00:25
@forkerino If you're still there, Stack Overflow helped and the solution was what you said remove the () from the namesdefine function call. However, they had me write it as a function which call all of the functions at once like this:
    document.getElementById('sbm').onclick = function() {
        namesdefine();
        seat(document.getElementsByClassName('a').value);
        check();
        changeHTML();
    }
john94
@lpy1994
Mar 02 2017 00:27
@SkyCoder01 this one looks solid, lets see if it can solve my problem ;) thx
CamperBot
@camperbot
Mar 02 2017 00:27
lpy1994 sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:cookie: 394 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Gulsvi
@gulsvi
Mar 02 2017 00:27
@lpy1994 Depending on how complex the array is, you could do something like this:
var arr = [[3, 9], [5, 2]]
console.log(arr.toString().split(',').indexOf('2')); // 3
Miguel-Castrejon
@Miguel-Castrejon
Mar 02 2017 00:28
Alright whats going on in here? I've been working on it for the past 20 mins... can't get it to work.```

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

//testing.....
/*console.log(firstName + " t = " + contacts[i][firstName] + " \n" + prop + " t = " + contacts[i][prop]);*/

}
}

return contacts[index][""+prop];

// Only change code above this line
}```

Chris Jantzen
@XXiphias
Mar 02 2017 00:31
@Miguel-Castrejon Your first if statement, if(firstName != contacts[i].firstName){. The first time the loop runs, if that gets called you will return with "no such contact" immediately. So if the very first item in the array is not = to firstName you will immediately get that
so you are only checking the fisrt item in the array
Steven
@Ironwrangler
Mar 02 2017 00:31
ty @eyesore-
CamperBot
@camperbot
Mar 02 2017 00:31
ironwrangler sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 49 | @eyesore- |http://www.freecodecamp.com/eyesore-
Chris Jantzen
@XXiphias
Mar 02 2017 00:31
or object. whatever contacts is
john94
@lpy1994
Mar 02 2017 00:31
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];
@SkyCoder01 there are the ones that I am working on
if they have the same string, then i need to add the number relatively to the one in the curInv
Miguel-Castrejon
@Miguel-Castrejon
Mar 02 2017 00:33
@XXiphias .... how dumb I am... thanks. I suppose I can make a boolean and set it to true if the contact is found. same for the property.
CamperBot
@camperbot
Mar 02 2017 00:33
miguel-castrejon sends brownie points to @xxiphias :sparkles: :thumbsup: :sparkles:
:cookie: 372 | @xxiphias |http://www.freecodecamp.com/xxiphias
Chris Jantzen
@XXiphias
Mar 02 2017 00:33
Ya, use a flag. That's a good idea :)
john94
@lpy1994
Mar 02 2017 00:33
if different, then add the whole array into the curInv.
Gulsvi
@gulsvi
Mar 02 2017 00:34
@lpy1994 That looks like an algorithm I haven't gotten to yet :) fun problem though, I'll let you know if I figure something out
john94
@lpy1994
Mar 02 2017 00:36
@SkyCoder01 inventory update is the name of the challenge.
Chris Jantzen
@XXiphias
Mar 02 2017 00:37
ah.. thats one of the advanced algorithms
those were fun to do
john94
@lpy1994
Mar 02 2017 00:37
@XXiphias :(
Chris Jantzen
@XXiphias
Mar 02 2017 00:37
i think for that I used nested for loops
eyesore-
@eyesore-
Mar 02 2017 00:37
Has anyone in here used webassembly? I know it's pretty new tech. I was just wondering.
I need help with my random quote machine .
Chris Jantzen
@XXiphias
Mar 02 2017 00:38
@lpy1994 Why the sad face? THey're fun and challenging! :D
Savour it ;)
john94
@lpy1994
Mar 02 2017 00:38
@XXiphias hate to be stuck all the time..
Jason Luboff
@JLuboff
Mar 02 2017 00:39
@TSIIAM I'm not sure your question...but right off the bat, I wouldn't use append. I would use .html instead so that it replaces the last quote instead of appending it below
Miguel-Castrejon
@Miguel-Castrejon
Mar 02 2017 00:40
@XXiphias The flag did the trick, thanks again.
CamperBot
@camperbot
Mar 02 2017 00:40
miguel-castrejon sends brownie points to @xxiphias :sparkles: :thumbsup: :sparkles:
:warning: miguel-castrejon already gave xxiphias points
Chris Jantzen
@XXiphias
Mar 02 2017 00:40
no worries. glad you got it sorted :)
@lpy1994 just have to break them down into small steps. And if you get stuck, google! stackoverflow has answers for everything :)
Alvaromesa
@TSIIAM
Mar 02 2017 00:42
@JLuboff Yes I am looking to change the append and make it random, thanks for the input
CamperBot
@camperbot
Mar 02 2017 00:42
tsiiam sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1007 | @jluboff |http://www.freecodecamp.com/jluboff
john94
@lpy1994
Mar 02 2017 00:42
@XXiphias I know how it should be solved, but don’t know exactly how. lmao
Chris Jantzen
@XXiphias
Mar 02 2017 00:42
haha thats ok :P trial and error
twlst
@twlst
Mar 02 2017 00:45
Hey I’m on the Sum All Primes algorithm and my code works for inputting 10 but not for 977. I based the sieve of eratosthenes on Wiki’s pseudocode.
'esversion: 6';

function sumPrimes(num) {
  //using sieve of eratosthenes to solve

  var primes = [];
  var limit = Math.sqrt(num);
  var tempPrimes = [];
  var sum = 0;

  for (var i = 0; i < num; i++) {
    primes.push(true);
  }

  //removes multiples of primes
  for (i = 2; i <= limit; i++) {
    if(primes[i]) {
      for (var x = i * i; x < num; x += i) {
        primes[x] = false;
      }
    }
  }

  //replaces boolean values with numbers
  for (i = 2; i < num; i++) {
    if(primes[i]) {
      tempPrimes.push(i);
    }
  }

  //adds elements together
  sum = tempPrimes.reduce((a, b) => a + b, 0);
  return sum;
}
Chris Jantzen
@XXiphias
Mar 02 2017 00:46
have you tested what it outputs when you input 977?
twlst
@twlst
Mar 02 2017 00:46
Yeah it’s about 300 off but I can get the exact number in a sec.

"sumPrimes(977) should return 73156”

it outputs 72179.

Chris Jantzen
@XXiphias
Mar 02 2017 00:50
Do other high numbers have a similar issue?
if it's looping a lot of times it could be a rounding issue
you could add a console.log into one of your loops and actually watch the number increment to see whats going wrong
twlst
@twlst
Mar 02 2017 00:52
I just checked for 100 and it outputs correctly but I’ll try adding a console log for tempPrimes to see if it’s missing a few numbers.
Chris Jantzen
@XXiphias
Mar 02 2017 00:53
good plan
eyesore-
@eyesore-
Mar 02 2017 00:58
Anyone need help?
twlst
@twlst
Mar 02 2017 00:59
I figured out the problem. 977 itself is a prime number and it’s not being added to the array in the first for loop.
Chris Jantzen
@XXiphias
Mar 02 2017 01:00
ah.. there you go :)
nice work
Pamela
@pamela113
Mar 02 2017 01:07
code not working

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
myNoun= "dog";
myAdjective="big";
myVerb="ran";
myAdverb="quickly";

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

// Change the words here to test your function
wordBlanks("cat", "little", "hit", "slowly");

eyesore-
@eyesore-
Mar 02 2017 01:08
@pamela113 what is the prompt?
twlst
@twlst
Mar 02 2017 01:09
Your variables shouldnt be in quotations @pamela113
You also don’t have to assign the input variables to different strings because when you call the functions, they are defined there. ex: myNoun = “cat” via the “wordBlanks(“cat”, …)"
Rachel Wilson
@razzlepdx
Mar 02 2017 01:12
hi guys! super beginner question here: I'm working on the Factorialize a Number algorithm. So far, I have taken the (num) input and used a while loop and decrement to create an array containing each number between num and 0. I'm a little stuck on the next step and just wanted to get confirmation that I am on the right track?
eyesore-
@eyesore-
Mar 02 2017 01:13
@razzlepdx that sounds right. Could you post your code?
Travis Martin
@marti2221
Mar 02 2017 01:14
I could use some help following the basic code for the mutations algorithm. Im having trouble understanding why if the test and target variables are switched in the loop, it doesn't work...

function mutation(arr) {

var test = arr[1].toLowerCase();
var target = arr[0].toLowerCase();

for (i=0;i<test.length;i++) {
if (target.indexOf(test[i]) < 0)
return false;
}
return true;
}

CamperBot
@camperbot
Mar 02 2017 01:15
razzlepdx sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 50 | @eyesore- |http://www.freecodecamp.com/eyesore-
eyesore-
@eyesore-
Mar 02 2017 01:16
That looks good :+1:
twlst
@twlst
Mar 02 2017 01:16
@razzlepdx imo you’re making it more complicated than it needs to be but it should work.
eyesore-
@eyesore-
Mar 02 2017 01:17
@razzlepdx There is no need for the array to do the problem, but as a brute force solution it will work.
Rachel Wilson
@razzlepdx
Mar 02 2017 01:18
ahh, ok. I will see if I can come up with something else then. Thank you again @eyesore- and @twlst for the feedback
CamperBot
@camperbot
Mar 02 2017 01:18
razzlepdx sends brownie points to @eyesore- and @twlst :sparkles: :thumbsup: :sparkles:
:cookie: 335 | @twlst |http://www.freecodecamp.com/twlst
:warning: razzlepdx already gave eyesore- points
eyesore-
@eyesore-
Mar 02 2017 01:20
@marti2221 where are you switching them?
Travis Martin
@marti2221
Mar 02 2017 01:21

i switched them only in the for loop so it became

for (i=0;i<target.length;i++) {
if (test.indexOf(target[i]) < 0)
return false;
}

twlst
@twlst
Mar 02 2017 01:23
@marti2221 it doesn’t work because you’re checking to see if the test is inside the target, not the other way around.
Jim Carroll
@pulamusic
Mar 02 2017 01:23
Need some help. My switch statement here shows an error that the break is inaccessible after return. Not sure what this means.

function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (answer) {
case 1 === "a":
return "apple";
break;
case 2 === "b":
return "bird";
break;
case 3 === "c":
return "cat";
break;
default:
return "stuff";
}

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

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

Travis Martin
@marti2221
Mar 02 2017 01:23
because i was having trouble figuring out why we didnt have to specify testing the smallest string with the largest
eyesore-
@eyesore-
Mar 02 2017 01:23
@marti2221 That is because you want to traverse the test instead of the target. If the test is longer than target then you aren't checking all the values.
Kang Chen
@kangchen
Mar 02 2017 01:25
var isPrime = function(n) {
    for(let j=2; j<n; j++){
        if(n%j===0) return false; 
    }
    return true;
};

var sumPrimes = function(n) {
    let total = 0;
    for(let i=2; i<=n; i++){
        if(isPrime(i)){
            total += i;
        }        
    }
    return total;
};
Travis Martin
@marti2221
Mar 02 2017 01:25
why does the code work if the 2nd string is longer than the first?
eyesore-
@eyesore-
Mar 02 2017 01:26
@marti2221 It will work, but you have to traverse through the second string opposed to the first string.
@marti2221 so your loop has to be test.length opposed to target.length
Travis Martin
@marti2221
Mar 02 2017 01:28
yes but the only difference between the two is that one is assigned to the first string and the other to the second. How does the code still work when we dont know which of those strings is longer
eyesore-
@eyesore-
Mar 02 2017 01:29
@marti2221 It doesn't matter which is longer as long as you are traversing through the second string. I was just using your variable names as examples.
Travis Martin
@marti2221
Mar 02 2017 01:30
so the first string MUST traverse through the second??\
eyesore-
@eyesore-
Mar 02 2017 01:31
@marti2221 basically what you are doing in traversing through the second string and checking if the first string contains the character you are on.
Travis Martin
@marti2221
Mar 02 2017 01:33
ok I see. I think I was confused about how the indexOf() method actually works
eyesore-
@eyesore-
Mar 02 2017 01:35
@marti2221 it's cool. I understand. If you are still confused shoot me a PM
Kang Chen
@kangchen
Mar 02 2017 01:36
function diffArray(arr1, arr2) {
  var newArr = [];
  for(let i=0; i<arr2.length; i++){
    let idx = arr1.indexOf(arr2[i]);
      if(idx<0)
          newArr.push(arr2[i]);
      else
          arr1.splice(idx,1); 
  }
  newArr.push(...arr1);
  return newArr;
}
ESLMiguel
@ESLMiguel
Mar 02 2017 01:40
@ESLMiguel
Any feedback on what I have so far for my wiki app? Next step is adding in the actual search code with a animated box of search results which will open below the two boxes that are in the middle now
I have terrible design sense, so any comments would be appreciated
http://codepen.io/nthd3gr33/pen/vxLjyz
Ross
@staadecr
Mar 02 2017 01:42
I’m just learning JS. If someone could help me figure out what’s wrong, I’d appreciate it. https://gist.github.com/staadecr/e8f2515e47f75fa102da8e01c94464f0 I need the labels to switch and the calculation to perform correctly. Totally stuck here.
Miguel-Castrejon
@Miguel-Castrejon
Mar 02 2017 01:45
I'm passing most of the tests but 2 that contain some numbers... what am I doing wrong?

function palindrome(str) {
// Good luck!
var str2 = str.replace(/[^a-zA-Z0-9]/g, "").replace(/\s+/g, '').toLowerCase();
var reversedString = str.split("").reverse().join("").replace(/[^a-zA-Z ]/g, "").replace(/\s+/g, '').toLowerCase();

if(( str.replace(/[^a-zA-Z0-9]/g, "").replace(/\s+/g, '').toLowerCase()) === reversedString){
return true;
}else{
return false;
}
}

Carlos
@Mahajinn
Mar 02 2017 01:45
If i declare a variable inside a function but outside of a switch, will it work in the switch?
the switch is inside of the function
eyesore-
@eyesore-
Mar 02 2017 01:46
@Mahajinn Yes.
Carlos
@Mahajinn
Mar 02 2017 01:46
ty sir
eyesore-
@eyesore-
Mar 02 2017 01:46
No problem.
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 01:46

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

return item * arr[0]; // 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));
How do I combine the .push and the .shift? I need to have my item argument added to the end of my arr argument and I need the first element of my arr argument to be removed. Everything is working except the first element isnt being removed. The challenge is "Stand in Line".

Kang Chen
@kangchen
Mar 02 2017 01:47
Search and Replace
function myReplace(str, before, after) {
  let idx = str.indexOf(before);
  let strAfter = after.substr(1);
  after=(before[0].charCodeAt(0)<97)?after[0].toUpperCase():after[0].toLowerCase();
  after+=strAfter;
  str = str.replace(before,after);
  return str.trim();
}
Pamela
@pamela113
Mar 02 2017 01:47
now I'm getting the error dog is not defined

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
myNoun= dog;
myAdjective= big;
myVerb= ran;
myAdverb= quickly;

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

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

eyesore-
@eyesore-
Mar 02 2017 01:47
@SirUlrichVonLiechenstein arr.push(item).shift
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 01:47
@eyesore- thank you
CamperBot
@camperbot
Mar 02 2017 01:47
:cookie: 51 | @eyesore- |http://www.freecodecamp.com/eyesore-
sirulrichvonliechenstein sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
eyesore-
@eyesore-
Mar 02 2017 01:48
@SirUlrichVonLiechenstein no problem!
@SirUlrichVonLiechenstein another thing is that you have to do shift()
@pamela113 you have quotes in the wrong places.
@pamela113 when you do myNoun = dog you are telling myNoun to go look for another variable named dog. To assign the string dog to myNoun you need to do myNoun = 'dog'
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 01:50
@eyesore- like this? console.log(arr.push(item) .shift());
eyesore-
@eyesore-
Mar 02 2017 01:51
@SirUlrichVonLiechenstein yes
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 01:53
@eyesore- it's telling me there is an error with that line. It's telling me it's not a function
eyesore-
@eyesore-
Mar 02 2017 01:54
@SirUlrichVonLiechenstein I'm sorry, that is incorrect. It wont chain. What are you trying to do? Do you have to console.log it?
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 01:55
@eyesore- I'm trying to add item to the end of arr and remove the first element of arr. I do not have to console.log it
eyesore-
@eyesore-
Mar 02 2017 01:56
@SirUlrichVonLiechenstein Oh, then just just write each of them on their own line.
@SirUlrichVonLiechenstein methods like .map .join .reduce you can chain together.
Joseph
@revisualize
Mar 02 2017 01:58
hey
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 01:58
@eyesore- arr.push(item); // Your code here
arr.shift(); like this? It messed up the rest of my code.
Joseph
@revisualize
Mar 02 2017 01:58
@pamela113 WHy are you overwriting your parameters with variables that don't exist? Also, You have your parameters as strings.
@pamela113 Why did you turn your parameters in to strings?
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 01:59
This is the Stand in Line challenge @eyesore-
AJ
@DracIdea
Mar 02 2017 01:59

Hey guys, can you see why this won't work properly?
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here

myObj.hasOwnProperty(checkProp);

if ("true"){
return myObj[checkProp];

}

if ("false"){
return "Not Found";
}

}

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

Pamela
@pamela113
Mar 02 2017 02:00
@revisualize I'm not sure what you mean? Isn't what I should do with the wordblanks?
Joseph
@revisualize
Mar 02 2017 02:00
@DracIdea "true" is always true

@pamela113 Gist by revisualize / FreeCodeCamp - Word_Blanks.js
The function declaration was set up as... function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) giving the function name as wordBlanks and with four parameter of myNoun, myAdjective, myVerb and myAdverb.
There is more that I could go into (if you want I can) but, I'll sum it up with:
Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Here's an example of this:

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

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

AJ
@DracIdea
Mar 02 2017 02:00
@revisualize true is always true?
Joseph
@revisualize
Mar 02 2017 02:00
@DracIdea No. "true" is always true
Kang Chen
@kangchen
Mar 02 2017 02:01
Pamela, you shouldn't put quotation on parameters (it will be a string if you do), just concatenate the parameters. That's what you make a mistake.
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";  
  result = myAdjective + ' ' + myNoun + ' ' + myVerb + ' ' + myAdverb;
  return result;
}
Joseph
@revisualize
Mar 02 2017 02:01
@kangchen Do NOT give away answers.
@kangchen You need to EXPLAIN WHY that is the answer.
eyesore-
@eyesore-
Mar 02 2017 02:01
@SirUlrichVonLiechenstein Sorry, I got confused. The prompt is asking you to push the item into arr and return the first item.
quicksilver774
@quicksilver774
Mar 02 2017 02:01
im on the find the longest word in a string challenge and i cannot find the answer to this thing
Kang Chen
@kangchen
Mar 02 2017 02:02
ok, my bad
quicksilver774
@quicksilver774
Mar 02 2017 02:02
i have 2 nested for loops!

function findLongestWord(str) {
var arr = str.split(" "); // returns an array
console.log(arr); // displays the array
var largestStr;

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

for (var j = 1; j <= arr.length; j++){

  if (arr[i].length >= arr[j].length){
      largestStr = arr[i].length;
    }
else if (arr[i].length <= arr[j].length){
   largestStr = arr[j].length;
}

}
}
return largestStr;
}

findLongestWord("The quick brown fox jumped over the lazy dog");

Joseph
@revisualize
Mar 02 2017 02:02
@kangchen Now explain it. Because giving away answer doesn't instill learning. People think it does but, it doesn't.
eyesore-
@eyesore-
Mar 02 2017 02:02
@SirUlrichVonLiechenstein
function nextInLine(arr, item) {
  arr.push(item)
  return arr.shift()
}
Joseph
@revisualize
Mar 02 2017 02:03
Everyone that gives away answers better be able to explain the answer because THAT is what will help instill learning.
You're doing the person a disservice by giving them answers to challenges.
AJ
@DracIdea
Mar 02 2017 02:03
@revisualize oh ok, that helped I think, but it still won't actually return "Not Found"
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 02:04
@eyesore- Thank you! that worked
CamperBot
@camperbot
Mar 02 2017 02:04
sirulrichvonliechenstein sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:warning: sirulrichvonliechenstein already gave eyesore- points
Joseph
@revisualize
Mar 02 2017 02:04
@DracIdea Look the method .hasOwnProperty() returns a boolean.. true or false that... is what should be inside of your if condition.
eyesore-
@eyesore-
Mar 02 2017 02:04
@SirUlrichVonLiechenstein That makes sense right? If you need me to explain anything please let me know.
Joseph
@revisualize
Mar 02 2017 02:05
@DracIdea if conditional statements get triggered when the condition is true
Pamela
@pamela113
Mar 02 2017 02:05
@kangchen Thank you!
CamperBot
@camperbot
Mar 02 2017 02:05
pamela113 sends brownie points to @kangchen :sparkles: :thumbsup: :sparkles:
:warning: @kangchen's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 02:05
@eyesore- That makes sense. I got confused by one of the demands so I had return = arr[0] * item
Joseph
@revisualize
Mar 02 2017 02:05
@pamela113 You really really really need to understand how and why that lesson works like that.
Pamela
@pamela113
Mar 02 2017 02:07
@revisualize Yes, I do. I want to move forward but want to understand what I'm doing.
AJ
@DracIdea
Mar 02 2017 02:07

@revisualize Im sorry, but I'm still not following completely
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here

myObj.hasOwnProperty(checkProp);

if (true){
return myObj[checkProp];

}

if (false){
return "Not Found";
}

}

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

I removed the "" from the true and false
eyesore-
@eyesore-
Mar 02 2017 02:08
@SirUlrichVonLiechenstein oh, okay. Makes sense. Unfortunately that wouldn't work because you are multiplying the first array element with item which would just be a number unassociated with the prompt.
AJ
@DracIdea
Mar 02 2017 02:08
and i feel like ive tried every conceivable combination of if conditions
Ty N.
@mynameislink
Mar 02 2017 02:09
Holy dammit I am losing my f*ing mind
eyesore-
@eyesore-
Mar 02 2017 02:09
@DracIdea your if statement is always being fired. True is a boolean so it does not need quotes.
Joshua
@SirUlrichVonLiechenstein
Mar 02 2017 02:09
@eyesore- Yeah, it worked for two of the results I needed which is why I didn't realize thats what I needed to change.
Ty N.
@mynameislink
Mar 02 2017 02:09
Someone PLEASE tell me wtf I'm doing wrong here.

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

I have tried at least 30 different variations of how to make this code work, and...NOTHING.
Joseph
@revisualize
Mar 02 2017 02:11
@mynameislink You're not supposed to console.log. You're supposed to return
@mynameislink Switch cases don't take conditionals.
eyesore-
@eyesore-
Mar 02 2017 02:12
@DracIdea Like @revisualize was saying .hasOwnProperty will return a boolean so you want to use that as a conditional
Joseph
@revisualize
Mar 02 2017 02:12
@DracIdea having myObj.hasOwnProperty(checkProp); outside of the if condition does nothing.
Kang Chen
@kangchen
Mar 02 2017 02:12
@mynameislink you need to review your switch case statement, here is the link https://www.w3schools.com/js/js_switch.asp that can help you out
AJ
@DracIdea
Mar 02 2017 02:14
@revisualize @eyesore- OK, I'll try to get it into the if condition correctly
eyesore-
@eyesore-
Mar 02 2017 02:14
@revisualize can you elaborate on switch cases not being conditionals? I would argue that they are a giant else if
You don't do a boolean expression
eyesore-
@eyesore-
Mar 02 2017 02:15
@revisualize I understand switch statements and how to use them. I think I misunderstood your statement.
Joseph
@revisualize
Mar 02 2017 02:16
You do not need to do answer === 1 in a switch case
eyesore-
@eyesore-
Mar 02 2017 02:16
@revisualize Yup! I definitely did (: Sorry.
Joseph
@revisualize
Mar 02 2017 02:16
Also. because answer is already setup as ""
It will never be 1
Unless answer is changed.
Ty N.
@mynameislink
Mar 02 2017 02:17
@revisualize case statements for some reason will not accept a return before a break statement here
Joseph
@revisualize
Mar 02 2017 02:17
@mynameislink Show me.
The return statement ends function execution and specifies a value to be returned to the function caller.
eyesore-
@eyesore-
Mar 02 2017 02:18
@DracIdea When doing if statements you don't want to do if (true) you want to put something in there to evaluate or else you might as well just write the code with a conditional since it will always run
Joseph
@revisualize
Mar 02 2017 02:18
So, it technically is breaking the switch
along with the whole function.
Ty N.
@mynameislink
Mar 02 2017 02:20
switch (val) {
case answer === 1:
return "alpha";
break;
! Unreachable 'break' after 'return'
AJ
@DracIdea
Mar 02 2017 02:20
@eyesore- So if statements aren't the way to tackle this challenge then?
Joseph
@revisualize
Mar 02 2017 02:20
@mynameislink Again.
@mynameislink case answer === 1: is wrong
Ty N.
@mynameislink
Mar 02 2017 02:20
@revisualize And according to the rules, you need to have at least 3 break statements
Joseph
@revisualize
Mar 02 2017 02:20
@mynameislink answer is ""
Also, that is not how case's work.
It's just case 1:
Flamorus
@Flamorus
Mar 02 2017 02:21
if anyone could explain what "should have encoded text" is in this then thanks. https://www.freecodecamp.com/challenges/escape-sequences-in-strings
eyesore-
@eyesore-
Mar 02 2017 02:21
@DracIdea It is. You could do something like if ( obj.hasProperty... ) {} so on.
Joseph
@revisualize
Mar 02 2017 02:21
@Flamorus You have to assign 'FirstLine newline backslash SecondLine backslash carriage-return ThirdLine' to the variable myStr.
But, You have to replace the escape words with the proper escape sequences. (And per the instructions: remove all spaces.)
How do you escape a newline?
How do you escape a backslash?
How do you escape a carriage-return?
Flamorus
@Flamorus
Mar 02 2017 02:22
k
AJ
@DracIdea
Mar 02 2017 02:23
test
Ty N.
@mynameislink
Mar 02 2017 02:23

@revisualize Okay. Did your method. Same error. Unreachable 'break' after 'return'.

switch (answer) {
case 1:
return "alpha";
break;
case 2:
return "beta";
break;
case 3:
return "gamma";
break;
case 4:
return "delta";
break;

Nvm I figured it out anyway
Joseph
@revisualize
Mar 02 2017 02:27
@mynameislink Why did you change your switch condition?
@mynameislink The return statement ends function execution and specifies a value to be returned to the function caller.
AJ
@DracIdea
Mar 02 2017 02:28
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here

 if (myObj.hasOwnProperty("checkProp") = true){

   return myObj.(checkProp);
 }

 if (myObj.hasOwnProperty("checkProp") = false){

   return "Not Found";
 }


}

// Test your code by modifying these values
checkObj("pet");
Joseph
@revisualize
Mar 02 2017 02:29
@DracIdea remove the .() That isn't correct
AJ
@DracIdea
Mar 02 2017 02:29
so this is what i came up with; still no worky
Ty N.
@mynameislink
Mar 02 2017 02:29
@revisualize I changed it at the end to fix it by switching it back to the 'val' parameter which made more sense
eyesore-
@eyesore-
Mar 02 2017 02:29
@DracIdea myobj.hasOwnProperty() will already return a boolean
Joseph
@revisualize
Mar 02 2017 02:29
@DracIdea How do you access an object property using a variable?
@DracIdea = is assignment
@DracIdea Quotes define strings
eyesore-
@eyesore-
Mar 02 2017 02:30
@DracIdea Also, you don't want to check if it has the property checkProp you want to check if it has whatever checkProp represents.
David Amanze
@GodKingShogun
Mar 02 2017 02:30
anyone still up that can help
Joseph
@revisualize
Mar 02 2017 02:30
"checkProp" vs checkProp
David Amanze
@GodKingShogun
Mar 02 2017 02:31
i got a challenge right bu i do not understand why it is right lol
AJ
@DracIdea
Mar 02 2017 02:31
So youre saying I should assign the result of the .hasOwnProperty to a var, then use the var in the if statement?
David Amanze
@GodKingShogun
Mar 02 2017 02:31
so i have this as one of my if statements in a loop
for (var i=1; i<str.length; i++){
    if (i===str.length-1) {
      return undefined;
    }
eyesore-
@eyesore-
Mar 02 2017 02:32
@DracIdea no need to assign. Just leave if ( myObj.hasOwnProperty(checkProp) )
David Amanze
@GodKingShogun
Mar 02 2017 02:32
and in the param i am giving "abce". shouldn't it return undefined. it is returning d
eyesore-
@eyesore-
Mar 02 2017 02:33
@DracIdea myObj.hasOwnProperty(checkProp) will come back with true or false (a boolean)
Adam VanZuiden
@adamvz
Mar 02 2017 02:33
I have been working this over all day and racking my brain when not in front of my computer....what am I doing wrong.

function destroyer(arr) {
  // Remove all the values
  function seeker(num) {
    return num == this;
  }
  var args = arguments.length;
  for (var i = 1; i < args; i++) {
    var arg = arguments[i];
    arr = arguments[0].filter(seeker[arg]);
   }
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
David Amanze
@GodKingShogun
Mar 02 2017 02:33
i am on the missing letter challenge
this is the rest of my code
function fearNotLetter(str) {

  for (var i=1; i<str.length; i++){
    if (i===str.length-1) {
      return undefined;
    }
    else if (str.charCodeAt(i-1)!=str.charCodeAt(i)-1){
        return String.fromCharCode(str.charCodeAt(i)-1);
        } else if (str.charCodeAt(i+1)!=str.charCodeAt(i)+1){
      return String.fromCharCode(str.charCodeAt(i)+1);
        } 
  }
  return str.length;
}
RyanADesigns
@RyanADesigns
Mar 02 2017 02:33
Hellur, was wondering I fi could get some help with "manipulating complex objects" lesson
David Amanze
@GodKingShogun
Mar 02 2017 02:34
@adamvz what are you supposed to do
Adam VanZuiden
@adamvz
Mar 02 2017 02:35
use the arguments preceding the array to filter them out of the array
quicksilver774
@quicksilver774
Mar 02 2017 02:35
anyone knowledgeable in JS logic?
Im trying to get an if else statment inside 2 nested for loops right
Adam VanZuiden
@adamvz
Mar 02 2017 02:35
I am trying to avoid putting the seeking arguments in their own seperate array
quicksilver774
@quicksilver774
Mar 02 2017 02:35

function findLongestWord(str) {
var arr = str.split(" "); // returns an array
console.log(arr); // displays the array
var largestStr;

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

for (var j = 1; j <= arr.length; j++){

  if (arr[i].length >= arr[j].length){
      largestStr = arr[i].length;
    }
else if (arr[i].length <= arr[j].length){
   largestStr = arr[j].length;
}

}
}
return largestStr;
}

findLongestWord("The quick brown fox jumped over the lazy dog");

Joseph
@revisualize
Mar 02 2017 02:37
@quicksilver774 try using www.pythontutor.com/javascript.html to visualize your code.
This message was deleted
eyesore-
@eyesore-
Mar 02 2017 02:37
@quicksilver774 By using two loops you are making the problem much more difficult then it has to be.
Joseph
@revisualize
Mar 02 2017 02:37
@quicksilver774 You'll see that you really do NOT need a second for loop.
eyesore-
@eyesore-
Mar 02 2017 02:38
@quicksilver774 after splitting the string you may want to look at something like reduce
quicksilver774
@quicksilver774
Mar 02 2017 02:38
i cant see how it will work any other way,
David Amanze
@GodKingShogun
Mar 02 2017 02:39
@revisualize joseph can you scroll up and read my question
quicksilver774
@quicksilver774
Mar 02 2017 02:41
@eyesore- Thanks! Ill take a look into it!
CamperBot
@camperbot
Mar 02 2017 02:41
quicksilver774 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 52 | @eyesore- |http://www.freecodecamp.com/eyesore-
AJ
@DracIdea
Mar 02 2017 02:42

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

function checkObj(checkProp) {
// Your Code Here

if (myObj.hasOwnProperty(checkProp)){

return myObj.checkProp;
}

return "Not Found";

}

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

eyesore-
@eyesore-
Mar 02 2017 02:42
@quicksilver774 No problem.
AJ
@DracIdea
Mar 02 2017 02:42
Is this more along the right lines?
eyesore-
@eyesore-
Mar 02 2017 02:42
@DracIdea When using variable to look up properties in objects make sure to do bracket notation
Joseph
@revisualize
Mar 02 2017 02:43
@DracIdea Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
@GodKingShogun I haven't solved that lesson
AJ
@DracIdea
Mar 02 2017 02:44
@eyesore- @revisualize Thanks guys, that worked.
CamperBot
@camperbot
Mar 02 2017 02:44
dracidea sends brownie points to @eyesore- and @revisualize :sparkles: :thumbsup: :sparkles:
:cookie: 53 | @eyesore- |http://www.freecodecamp.com/eyesore-
:star2: 3387 | @revisualize |http://www.freecodecamp.com/revisualize
eyesore-
@eyesore-
Mar 02 2017 02:45
Is freecodecamp big on semicolons? I haven't really done many of the lessons.
Joseph
@revisualize
Mar 02 2017 02:45
@eyesore- JavaScript needs semicolons
eyesore-
@eyesore-
Mar 02 2017 02:46
@revisualize that is very incorrect sir. The only time it is absolutely necessary is when your line starts with ( which is rare.
@revisualize Javascript has ASI
Joseph
@revisualize
Mar 02 2017 02:47
It is a syntax error if you don't have a ; terminator
AJ
@DracIdea
Mar 02 2017 02:47
Sometimes I feel like we aren't given enough info to figure out some of these challenges on our own. Could just be me. Either way, It's a good thing you guys are here. cheers
Kang Chen
@kangchen
Mar 02 2017 02:48
@DracIdea you need to passing in the key not the value of key
```
checkObj('gift')
eyesore-
@eyesore-
Mar 02 2017 02:48
@revisualize it's a linter style preference, but they are not necessary. Here are some examples. http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding http://inimino.org/~inimino/blog/javascript_semicolons
Joseph
@revisualize
Mar 02 2017 02:48
@eyesore- Look you're going to argue that because of the ASI you're not required to have ;s ... However that through process is WRONG.
Unless you're comfortable writing incorrect code that adds overhead by relying on the ASI.
Then.. Well... You do you.
Not having a ; is a syntax issue.
eyesore-
@eyesore-
Mar 02 2017 02:50
@revisualize If you prefer using them then just say that, but to say that semicolons are a necessity in JS is incorrect.
Joseph
@revisualize
Mar 02 2017 02:50
And to correct the syntax issue the ASI will try to correct the error by doing ASI.
@eyesore- It is technically incorrect syntax to not have a ;
Gulsvi
@gulsvi
Mar 02 2017 02:50

@revisualize Is more like Google: https://google.github.io/styleguide/javascriptguide.xml?showone=Semicolons#Semicolons

Relying on implicit insertion can cause subtle, hard to debug problems. Don't do it. You're better than that.

eyesore-
@eyesore-
Mar 02 2017 02:50
@revisualize If I write console.log('Hello world!') or console.log('Hello world!); neither would fail.
Joseph
@revisualize
Mar 02 2017 02:51
@eyesore- Because of ASI
eyesore-
@eyesore-
Mar 02 2017 02:51
@revisualize It's a style preference not a necessity.
Joseph
@revisualize
Mar 02 2017 02:51
It is a syntax error.
WRONG
eyesore-
@eyesore-
Mar 02 2017 02:51
ASI will happen no matter what.
David Amanze
@GodKingShogun
Mar 02 2017 02:51
@revisualize str.length-1 should return 3 if str is "abcd" right
Joseph
@revisualize
Mar 02 2017 02:51
It is a syntax error .. ASI will try to automatically insert a semicolon to correct the error.
It is a syntax error.
It just doesn't report a syntax error because of ASI
Automatic Semicolon Insertion
@eyesore- Look, this was brought up in two talks that I attended with Kyle Simpson.
Bryan Reese
@breese8009
Mar 02 2017 02:53
why is it not good to use prevent.default in production code.
Joseph
@revisualize
Mar 02 2017 02:53
Anyhow.
Bryan Reese
@breese8009
Mar 02 2017 02:54
?
Joseph
@revisualize
Mar 02 2017 02:54
I'm at an event. I want to focus on this event.
Flamorus
@Flamorus
Mar 02 2017 02:54
I don't understand what it means by it should contain all passed in words
eyesore-
@eyesore-
Mar 02 2017 02:54
@revisualize Have fun. Good debate.
Edgar Pan
@edgaryp
Mar 02 2017 03:01
function pairwise(arr, arg) {
  var test = arr.reduce(function(acc, cur, index, array) {
    array.forEach(function(element) {
      if (cur + element === arg) {
        acc.push([cur, element]); 
      }
    });
    return acc;
  }, []);
  return test;
}

pairwise([1,4,2,3,0,5], 16);
Don't know what I have down wrong with my code, can anybody help?
Adam VanZuiden
@adamvz
Mar 02 2017 03:02
Has anyone had a algorithm challenge that won't pass even though it's satisfying the requirements?
eyesore-
@eyesore-
Mar 02 2017 03:04
If anyone is more curious about the semicolon debate please read this article http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding
Ryhu
@Ryhu
Mar 02 2017 03:05
can someone help me on my code? my ajax will run outside of a function, but gives me errors once inside a function
Adam VanZuiden
@adamvz
Mar 02 2017 03:11
ok this challenge won't pass and I can't figure what's going on with it. I am satisfying the requirements as far as I can tell and it's giving the expected answers. But I am still met with failing conditions on each of the testing conditions

function destroyer(arr) {
  // Remove all the values
  function seeker(num) {
    return num !== this;
  }
  var product = arguments[0];
  var args = arguments.length;
  for (var i = 0; i < args; i++) {
    product = product.filter(seeker, arguments[i]);
   }
  return product;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
//destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3);
//destroyer([3, 5, 1, 2, 2], 2, 3, 5);
//destroyer(["tree", "hamburger", 53], "tree", 53);
//destroyer([2, 3, 2, 3], 2, 3);
winer110
@winer110
Mar 02 2017 03:18
blob
where is wrong?
Usman Akram
@usmanakram1996
Mar 02 2017 03:24
hey there
hgilghk
@hgilghk
Mar 02 2017 03:24
@winer110 check the " '
Usman Akram
@usmanakram1996
Mar 02 2017 03:24
blob
hgilghk
@hgilghk
Mar 02 2017 03:24
it's confusing but be sharp about it
Usman Akram
@usmanakram1996
Mar 02 2017 03:25
i want 4 in newArr how the function should be ?
plz help
Edgar Pan
@edgaryp
Mar 02 2017 03:29
@usmanakram1996 did you screenshot this from FCC?
Stephan Sharps
@ssharps711
Mar 02 2017 03:29
Guys. Help.
I just found out my IQ is lot lower than I thought it was.
Usman Akram
@usmanakram1996
Mar 02 2017 03:31
yes
@edgaryp
@ssharps711 agreed dude :( same here
Stephan Sharps
@ssharps711
Mar 02 2017 03:33
@usmanakram1996 Thanks
CamperBot
@camperbot
Mar 02 2017 03:33
ssharps711 sends brownie points to @usmanakram1996 :sparkles: :thumbsup: :sparkles:
:warning: @usmanakram1996's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Usman Akram
@usmanakram1996
Mar 02 2017 03:35
@edgaryp plz help ?
Andrew Nichols
@frenata
Mar 02 2017 03:38
@ssharps711 Not sure we can help with that. :/
Stephan Sharps
@ssharps711
Mar 02 2017 03:39
Gonna off myself. Hopefully next life I won't be black and dumb.
Edgar Pan
@edgaryp
Mar 02 2017 03:40
@usmanakram1996 you would want to use return in the function rather then console.log
Andrew Nichols
@frenata
Mar 02 2017 03:48
@ssharps711 On the off chance you aren't trolling: being alive is good, you should stay that way. Programming is hard, not everyone can do it.
Re: semicolons
Explicit is better than implicit. ASI was a mistake (unless they went whole hog like Go).
NaveenRathor
@NaveenRathor
Mar 02 2017 03:55
golfScore(4, 2) should return "Eagle"
golfScore(5, 2) should return "Eagle"
any body can help
my code is here

function golfScore(par, strokes) {
// Only change code below this line
if (par < 5 || strokes > 1){
return "Hole-in-one!";
}else if (par < 4 || strokes > 2){
return "Eagle";
}else if (par < 4 || strokes > 3){
return "Birdie";
}

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

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

eyesore-
@eyesore-
Mar 02 2017 03:57
@NaveenRathor that is never going to return 'Birdie'
NaveenRathor
@NaveenRathor
Mar 02 2017 03:58
@eyesore- sorry it should return eagle
but it's not return eagle
Andrew Nichols
@frenata
Mar 02 2017 03:58
You may need to review the rules of golf (at least to the extent it matters for this exercise...)
eyesore-
@eyesore-
Mar 02 2017 03:59
@frenata My argument was that saying semicolons are a necessity is an incorrect statement. If you want to code with semicolons that's cool, but you shouldn't make the statement to fear them and that you always need them.
Andrew Nichols
@frenata
Mar 02 2017 04:00
I agree that not including them is not illegal syntax.
eyesore-
@eyesore-
Mar 02 2017 04:00
@NaveenRathor what is it returning?
arturoc921
@arturoc921
Mar 02 2017 04:00

function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
  arr[1] = arr[1].toLowerCase();
  var str = arr[1].split('');
  for (var i=0;i < arr.length; i++){
    return arr[0].indexOf(str[i]) !== -1;
  }
}

mutation(["hello", "hey"]);
I think I'm close on this one. Anyone know what I can add or change to the code? one test case to go
NaveenRathor
@NaveenRathor
Mar 02 2017 04:00
only "Hole-in-one!"
eyesore-
@eyesore-
Mar 02 2017 04:02
@NaveenRathor because of your || statement. You are saying par < 5 or strokes > 1
Andrew Shieh
@andrewlikes
Mar 02 2017 04:02

We have an array of objects representing different people in our contacts lists.

A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"


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


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

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

// Only change code above this line
}

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

function is giving me a random property when called..

Andrew Nichols
@frenata
Mar 02 2017 04:02
I'm not convinced that embracing the badly designed parts of JS is a good idea though. Understand those parts? Yes.
eyesore-
@eyesore-
Mar 02 2017 04:02
@frenata arr.length is 2
Sorry wrong @
@arturoc921 arr.length is 2
Manish Giri
@Manish-Giri
Mar 02 2017 04:03
@andrewlikes else; is wrong syntax
NaveenRathor
@NaveenRathor
Mar 02 2017 04:04
@eyesore- so what should i do
ESLMiguel
@ESLMiguel
Mar 02 2017 04:05
Looking for feedback/suggestions on my wiki app before moving on. Next step is adding in the actual search code with a box of search results which will open below the two boxes that are in the middle now. Any comments would be appreciated
http://codepen.io/nthd3gr33/pen/vxLjyz
badalsaibo
@heyDante
Mar 02 2017 04:05
@ESLMiguel damn, loved it :+1:
arturoc921
@arturoc921
Mar 02 2017 04:06
@eyesore- not sure I understand
ESLMiguel
@ESLMiguel
Mar 02 2017 04:06
@heyDante do you think the animations are smooth enough?
Andrew Shieh
@andrewlikes
Mar 02 2017 04:06
@Manish-Giri thx
CamperBot
@camperbot
Mar 02 2017 04:06
andrewlikes sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4539 | @manish-giri |http://www.freecodecamp.com/manish-giri
eyesore-
@eyesore-
Mar 02 2017 04:06
@NaveenRathor Well I believe that a hole in one is just 1 stroke. You are saying that it is greater than 1
Andrew Shieh
@andrewlikes
Mar 02 2017 04:06
i also figured it out, I put the return in the wrong block
Manish Giri
@Manish-Giri
Mar 02 2017 04:07
yes
eyesore-
@eyesore-
Mar 02 2017 04:08
@NaveenRathor as far as the other ones I don't know golf rules.
Andrew Nichols
@frenata
Mar 02 2017 04:08
@ESLMiguel focusing on the input box once the user clicks the search button is a no brainer
badalsaibo
@heyDante
Mar 02 2017 04:08
@ESLMiguel yes its subtle. I bet this is still in beta though.
Andrew Nichols
@frenata
Mar 02 2017 04:09
I shouldn't have to click "search" then also click to start typing
ESLMiguel
@ESLMiguel
Mar 02 2017 04:09
@frenata ok i will code that in before moving on
@frenata thank you
CamperBot
@camperbot
Mar 02 2017 04:09
eslmiguel sends brownie points to @frenata :sparkles: :thumbsup: :sparkles:
:cookie: 455 | @frenata |http://www.freecodecamp.com/frenata
ESLMiguel
@ESLMiguel
Mar 02 2017 04:09
@heyDante and you :smirk_cat:
Andrew Nichols
@frenata
Mar 02 2017 04:09
No problem, just a small usability thing.
ESLMiguel
@ESLMiguel
Mar 02 2017 04:09
@heyDante thanks
CamperBot
@camperbot
Mar 02 2017 04:09
eslmiguel sends brownie points to @heydante :sparkles: :thumbsup: :sparkles:
:cookie: 498 | @heydante |http://www.freecodecamp.com/heydante
Cristian
@cristianalmanzar
Mar 02 2017 04:09
I need help
Gilbert Gaviola
@singleparin
Mar 02 2017 04:10
me too
eyesore-
@eyesore-
Mar 02 2017 04:10
@cristianalmanzar sup
ESLMiguel
@ESLMiguel
Mar 02 2017 04:10
@frenata yeah i worked on this til 4am so i forgot basic stuff like that
Cristian
@cristianalmanzar
Mar 02 2017 04:10
Find the Length of a String
CamperBot
@camperbot
Mar 02 2017 04:10
find the length of a string
nothing found
Gilbert Gaviola
@singleparin
Mar 02 2017 04:10
what am I missing here?
Cristian
@cristianalmanzar
Mar 02 2017 04:10
Find the Length of a String
CamperBot
@camperbot
Mar 02 2017 04:10
find the length of a string
nothing found
Cristian
@cristianalmanzar
Mar 02 2017 04:10
exc. 145
ESLMiguel
@ESLMiguel
Mar 02 2017 04:10
@frenata how long have you been coding, if you dont mind me asking?
badalsaibo
@heyDante
Mar 02 2017 04:10
@ESLMiguel I'm working on the Random Quote Machine. Just completed the front-end part :smile:
Gilbert Gaviola
@singleparin
Mar 02 2017 04:10
var myStr ="FirstLine\n\SecondLine\r\ThirdLine";
ESLMiguel
@ESLMiguel
Mar 02 2017 04:10
@heyDante nice!
Andrew Nichols
@frenata
Mar 02 2017 04:11
It's funny, I see everyone build design/look first and then functionality...
I always build functionality and then add styling.
But I guess it's the nature of different personalities.
Cristian
@cristianalmanzar
Mar 02 2017 04:11
Who helps me ?
eyesore-
@eyesore-
Mar 02 2017 04:11
@cristianalmanzar Have you seen .length before?
Cristian
@cristianalmanzar
Mar 02 2017 04:11
yup
lastNameLenght = lastName.leng
eyesore-
@eyesore-
Mar 02 2017 04:12
@cristianalmanzar That is all you need to do.
Cristian
@cristianalmanzar
Mar 02 2017 04:12
lastNameLenght = lastName.lenght;
ESLMiguel
@ESLMiguel
Mar 02 2017 04:12
@frenata function is more important than form, we newbies are just fascinated by all the shiny stuff lol
badalsaibo
@heyDante
Mar 02 2017 04:12
@singleparin see how to add backslash on the table they provided
Cristian
@cristianalmanzar
Mar 02 2017 04:12
but is says : You should be getting the length of lastName by using .length like this: lastName.length.
eyesore-
@eyesore-
Mar 02 2017 04:12
Send me your code.
Andrew Nichols
@frenata
Mar 02 2017 04:13
You should have seen my minimally functional wiki project with zero styling. ;)
Cristian
@cristianalmanzar
Mar 02 2017 04:13

@eyesore- // Example
var firstNameLength = 0;
var firstName = "Ada";

firstNameLength = firstName.length;

// Setup
var lastNameLength = 8;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLenght = lastName.lenght;

eyesore-
@eyesore-
Mar 02 2017 04:13
@cristianalmanzar you have length spelt wrong.
ESLMiguel
@ESLMiguel
Mar 02 2017 04:13
@frenata haha nice
AKCore
@AKCore
Mar 02 2017 04:14
I has a question. On Returning Boolean Values from Functions
I am supposed to remove the if statements. And I think i am misunderstading the challenge
eyesore-
@eyesore-
Mar 02 2017 04:14
@AKCore I'll help you.
Andrew Nichols
@frenata
Mar 02 2017 04:14
How long have I been coding? is a tricky question. Probably the first time I took it seriously was working with html/css and VBasic back in ~1999?
AKCore
@AKCore
Mar 02 2017 04:14

```function isLess(a, b) {
// Fix this code
return a===b;
}

// Change these values to test
isLess(10, 15);```

Cristian
@cristianalmanzar
Mar 02 2017 04:14
but continius saying that: You should be getting the length of lastName by using .length like this: lastName.length.
badalsaibo
@heyDante
Mar 02 2017 04:14
@frenata I like to keep things minimal too!
Gilbert Gaviola
@singleparin
Mar 02 2017 04:14
Thank you @heyDante
CamperBot
@camperbot
Mar 02 2017 04:14
singleparin sends brownie points to @heydante :sparkles: :thumbsup: :sparkles:
:cookie: 499 | @heydante |http://www.freecodecamp.com/heydante
AKCore
@AKCore
Mar 02 2017 04:14

Since === returns true or false, we can return the result of the comparison:

function isEqual(a,b) {
return a === b;
}

Andrew Nichols
@frenata
Mar 02 2017 04:14
But I haven't necessarily spent all those intervening years dedicated to coding.
AKCore
@AKCore
Mar 02 2017 04:15
OHHH i misread it
nevermind lol
ESLMiguel
@ESLMiguel
Mar 02 2017 04:15
@frenata oh wow, makes sense. you went pretty in depth about for loops yesterday, seemed like you have a lot of knowledge
eyesore-
@eyesore-
Mar 02 2017 04:15
@AKCore Cool!
Andrew Nichols
@frenata
Mar 02 2017 04:16
Less than I'd like.
eyesore-
@eyesore-
Mar 02 2017 04:16
@cristianalmanzar after fixing the typo you still get those errors?
Cristian
@cristianalmanzar
Mar 02 2017 04:16
@eyesore- ohhhhh i found my error
@eyesore- lastNameLenght += lastName.length;
is in that way
eyesore-
@eyesore-
Mar 02 2017 04:17
You shouldn't have to do that. I just passed it without +=

@cristianalmanzar ```
// Example
var firstNameLength = 0;
var firstName = "Ada";

firstNameLength = firstName.length;

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLength = lastName.length;
```

Cristian
@cristianalmanzar
Mar 02 2017 04:20
@eyesore- this one works too

var firstNameLength = 0;
var firstName = "Ada";

firstNameLength = firstName.length;

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLength += lastName.length;

eyesore-
@eyesore-
Mar 02 2017 04:20
@cristianalmanzar Yeah, it's basically the same thing. As long as you know the difference between them.
Andrew Nichols
@frenata
Mar 02 2017 04:20
@ESLMiguel
http://wiki-minimal.frenata.net/ My first commit from as soon as I had all the functionality working.
eyesore-
@eyesore-
Mar 02 2017 04:20
@cristianalmanzar as in the difference between = and +=
ESLMiguel
@ESLMiguel
Mar 02 2017 04:21
@frenata now THAT is minimal
:clap:
Nadia
@nadiaschutz
Mar 02 2017 04:23
var code = "formatted";
Cristian
@cristianalmanzar
Mar 02 2017 04:23
@eyesore- I don't understand to much english that's why i get stuck and when it told me that lastNameLength should be equal to eight i understand to set the value of xdd
Andrew Nichols
@frenata
Mar 02 2017 04:23
But I don't think there's anything wrong with doing design first! Especially if that's what interests/excites you.
Cristian
@cristianalmanzar
Mar 02 2017 04:23
@eyesore- Thanks for your help
CamperBot
@camperbot
Mar 02 2017 04:23
cristianalmanzar sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 55 | @eyesore- |http://www.freecodecamp.com/eyesore-
eyesore-
@eyesore-
Mar 02 2017 04:24
@cristianalmanzar Oh, that's totally fine. I just asked in case you wanted more explaination :smile:
Nadia
@nadiaschutz
Mar 02 2017 04:24

hi guys, should i use if/else statement in this problem ?

NuPack is responsible for taking existing products and repackaging them for sale at electronic stores like Best Buy. Companies will phone up NuPack, explain the process and NuPack needs to quickly give them an estimate of how much it will cost. Different markups to the job:

  • Without exception, there is a flat markup on all jobs of 5%
  • For each person that needs to work on the job, there is a markup of 1.2%

Markups are also added depending on the types of materials involved:

  • If pharmaceuticals are involved, there is an immediate 7.5% markup
  • For food, there is a 13% markup
  • Electronics require a 2% markup
  • Everything else, there is no markup

Another system calculates the base price depending on how many products need to be repackaged. As such, the markup calculator should accept the initial base price along with the different categories of markups and calculate a final cost for a project.

The flat markup is calculated first and then all other markups are calculated on top of the base price plus flat markup.

Example 1:

Input:  $1,299.99, 3 people, food
Output: $1,591.58
Andrew Nichols
@frenata
Mar 02 2017 04:25
@nadiaikon This looks like some kind of school assignment.
Cristian
@cristianalmanzar
Mar 02 2017 04:25
@eyesore- this is your real account cuz you alredy done 10 exerc. xd ?
eyesore-
@eyesore-
Mar 02 2017 04:25
Trying to get us to do her homework.
Nadia
@nadiaschutz
Mar 02 2017 04:25
@frenata yep. thats why i am asking if i need to use if/else statment
@eyesore- i am not
Andrew Nichols
@frenata
Mar 02 2017 04:26
I mean...if/else will show up in probably 95% of non-trivial programs.
eyesore-
@eyesore-
Mar 02 2017 04:26
@cristianalmanzar I'll be honest. I haven't really done many exercises here. haha I just come to help.
Cristian
@cristianalmanzar
Mar 02 2017 04:26
@eyesore- give that mn a cookie xd
Nadia
@nadiaschutz
Mar 02 2017 04:26
@eyesore- if i tried someone to do it, i wouldn't ask this way
Cristian
@cristianalmanzar
Mar 02 2017 04:27
I have to spend more time is FCC is an amazig plataform
Nadia
@nadiaschutz
Mar 02 2017 04:28
@frenata thanks
CamperBot
@camperbot
Mar 02 2017 04:28
nadiaikon sends brownie points to @frenata :sparkles: :thumbsup: :sparkles:
:cookie: 456 | @frenata |http://www.freecodecamp.com/frenata
eyesore-
@eyesore-
Mar 02 2017 04:28
@nadiaikon I was just kidding. You could do a switch or if/else
badalsaibo
@heyDante
Mar 02 2017 04:28
@eyesore- give that mn a cookie xd
Andrew Nichols
@frenata
Mar 02 2017 04:28
@nadiaikon It's possible to go out of your way to avoid using if/else. But shrug
Nadia
@nadiaschutz
Mar 02 2017 04:28
@eyesore- what is switch ?
Cristian
@cristianalmanzar
Mar 02 2017 04:29
Guys what do you think abour Ryzen ?
achudoz
@achudoz
Mar 02 2017 04:30
Hi, my code for lowest common multiple of a range is almost done, in the sense that I reliably get the LCM for any two numbers, however I am struggling with the loop that goes through the array (it's 5am here) 4/5 tests return correct answer, but the one below returns LCM of over three billion while it should be only about 360k. Can you see what's wrong with it?
function smallestCommons(arr) {
  var newArr = [];
for (var i=Math.min.apply(null, arr); i<=Math.max.apply(null, arr); i++) {
      newArr.push(i);
    }

function gcd(x, y) { // GREATEST COMMON DIVISOR - functional
  var accumulator = [];
   while (x%y !== 0) {  
    r = x % y;
    x = y;
    y = r; //undeclared variable apparently ok
   } accumulator.push(r);
   return accumulator;
 } 

function lcm(a, b) { // LOWEST COMMON MULTIPLE - functional
  return (a*b)/gcd(a, b);
  } 

var result = newArr[0]; //LOOP THROUGH RANGE - BROKEN
for (var j=1; j<newArr.length; j++) {  
  result = lcm(result,newArr[j]);
  console.log(j + " " + result);
}
  return result;
}


smallestCommons([1, 13]);
Nadia
@nadiaschutz
Mar 02 2017 04:30
@eyesore- thanks! i forgot about that totally !
CamperBot
@camperbot
Mar 02 2017 04:30
nadiaikon sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 56 | @eyesore- |http://www.freecodecamp.com/eyesore-
achudoz
@achudoz
Mar 02 2017 04:31
oh and I know the code is a bit messy and can be made much simpler. I just like to have it broken up in parts to see each component in its entirety
eyesore-
@eyesore-
Mar 02 2017 04:31
@nadiaikon No problem! There's a couple ways you could do it. If I may suggest I think the most practical way would be an object with the markups.
// i.e.
let markup = {
  ...
  food : 0.13
  ...
}
Andrew Nichols
@frenata
Mar 02 2017 04:32
@achudoz Breaking things into parts like that is a good thing.
Nadia
@nadiaschutz
Mar 02 2017 04:32
@eyesore- oh ..have not seen it yet anywhere on FCC
eyesore-
@eyesore-
Mar 02 2017 04:33
@nadiaikon Those dots are just placeholders. Don't use that. haha
Nadia
@nadiaschutz
Mar 02 2017 04:33
@eyesore- c'mon , stop kidding me here ))
eyesore-
@eyesore-
Mar 02 2017 04:34
@nadiaikon Sorry, I didn't want to write all the categories.
Andrew Nichols
@frenata
Mar 02 2017 04:35
@achudoz Are you saying that you can get the LCM for any two numbers, but not for an array of n numbers?
Nadia
@nadiaschutz
Mar 02 2017 04:35
@eyesore- no i got you.....dots are important in coding ...
achudoz
@achudoz
Mar 02 2017 04:36
@frenata yeah. when I bypass the loop and just return lcm(x, y), the returned LCM is correct.
Andrew Nichols
@frenata
Mar 02 2017 04:37
Is the range being generated correctly?
Nadia
@nadiaschutz
Mar 02 2017 04:37
good night everyone
achudoz
@achudoz
Mar 02 2017 04:37
@frenata That's why I think the mistake is in the loop. I mean I haven't tried every possible combination of two numbers. yes, the array is generated correctly
Chris Jantzen
@XXiphias
Mar 02 2017 04:39
dots are important in coding! Especially now in es6 :D
...
eyesore-
@eyesore-
Mar 02 2017 04:40
Love those spread operators.
Chris Jantzen
@XXiphias
Mar 02 2017 04:40
yes. super handy
achudoz
@achudoz
Mar 02 2017 04:42
@frenata oh wait, I just tried calculating the thing manually and there seems to be some sort of error. hmm
eyesore-
@eyesore-
Mar 02 2017 04:42
Yeah, specially in Redux
Anyone need help?
Andrew Nichols
@frenata
Mar 02 2017 04:42
@achudoz Yeah I'm messing with it and I think your lcm is broken in some way.
for (var j=1; j<newArr.length; j++) {
    let old = result;
  result = lcm(result,newArr[j]);
  console.log("lcm of " + old + " and " + newArr[j] + " is " + result);
}
I rewrote your loop as such for better inspection on what's happening.
achudoz
@achudoz
Mar 02 2017 04:44
@frenata the lcm formula is pretty straightforward. It's probably something in the since I tested it now and it returns wrong answer in some cases
@frenata I just tested that gcd(6, 60) returns the correct answer of 6 but gcd(60, 6) returns a wrong answer of 1
Andrew Nichols
@frenata
Mar 02 2017 04:45
That's what I had just honed in on too! :)
Probably you can check and fix your argument order in lcm or gcd
achudoz
@achudoz
Mar 02 2017 04:47
@frenata It should be a simple fix. Thank you so much for looking at it. Often just explaining what is wrong with my thing to someone else helps me realize myself what exeactly is wrong!
CamperBot
@camperbot
Mar 02 2017 04:47
achudoz sends brownie points to @frenata :sparkles: :thumbsup: :sparkles:
:cookie: 457 | @frenata |http://www.freecodecamp.com/frenata
Andrew Nichols
@frenata
Mar 02 2017 04:47
No problem! http://wiki.c2.com/?RubberDucking saves the day again!
Chris Jantzen
@XXiphias
Mar 02 2017 04:48
@achudoz you need a rubber duck! :D
Actually this is better: https://rubberduckdebugging.com/
Andrew Nichols
@frenata
Mar 02 2017 04:49
Other people are even better though.
Chris Jantzen
@XXiphias
Mar 02 2017 04:49
of coruse :)
achudoz
@achudoz
Mar 02 2017 04:49
@frenata ha! I didn't realize it is such common thing that it even has it's own joke name :D Thanks for the links @XXiphias
CamperBot
@camperbot
Mar 02 2017 04:49
achudoz sends brownie points to @frenata and @xxiphias :sparkles: :thumbsup: :sparkles:
:cookie: 373 | @xxiphias |http://www.freecodecamp.com/xxiphias
:warning: achudoz already gave frenata points
Chris Jantzen
@XXiphias
Mar 02 2017 04:50
haha didnt even notice a link was posted before I said that :P
Andrew Nichols
@frenata
Mar 02 2017 04:51
This is also why pair programming is a thing I guess. I've not had many chances to do that though. :(
Cristian
@cristianalmanzar
Mar 02 2017 04:55
Understand String Immutability
Simon
@smnshulgan
Mar 02 2017 04:57
hey guys
why isnt this working

function reverseString(str)
{
var array = str.split(' ');
array.reverse();
array.join();
return array;
}

reverseString("hello");

it is just returning "hello"
heroiczero
@heroiczero
Mar 02 2017 04:58
@smnshulgan array.join() needs something join it with in the ()
eyesore-
@eyesore-
Mar 02 2017 04:58
You can also chain it
Simon
@smnshulgan
Mar 02 2017 04:59
@heroiczero what do you mean join it with something? glue? lol
do you mean ' '
eyesore-
@eyesore-
Mar 02 2017 04:59
function reverseString(str) {
  return str.split('').reverse().join('')
}
heroiczero
@heroiczero
Mar 02 2017 04:59
@smnshulgan how did you split it str.split(' ')
@smnshulgan yes
Simon
@smnshulgan
Mar 02 2017 05:00
var array = str.split(' ');
array.reverse();
array.join(' ');
return array;
whats wrong?
Andrew Nichols
@frenata
Mar 02 2017 05:00
Yall need to read the docs of split reverse and join!
Simon
@smnshulgan
Mar 02 2017 05:01
I did and I still dont understand why.
Joseph
@revisualize
Mar 02 2017 05:01
Hello.
Andrew Nichols
@frenata
Mar 02 2017 05:02
In particular: which of those methods modify what they are called on? What does each return?
eyesore-
@eyesore-
Mar 02 2017 05:02
@smnshulgan
function reverseString(str) {
  return str.split('').reverse().join('')
}
heroiczero
@heroiczero
Mar 02 2017 05:02
@smnshulgan you have to store it or it won't save
eyesore-
@eyesore-
Mar 02 2017 05:02
Chain 'em
Simon
@smnshulgan
Mar 02 2017 05:02
@heroiczero store it?
why do i have to chain them
Andrew Nichols
@frenata
Mar 02 2017 05:02
It's really better not to just give out solutions, but to help people understand how to build a solution themselves.
@smnshulgan Can you answer my questions?
:wave: @revisualize
heroiczero
@heroiczero
Mar 02 2017 05:03
@smnshulgan you see how u assigned it for var array = str.split(' '); into a variable
Simon
@smnshulgan
Mar 02 2017 05:03
@frenata i dont understand your question
@heroiczero yes
eyesore-
@eyesore-
Mar 02 2017 05:03
He had the answer.
Simon
@smnshulgan
Mar 02 2017 05:03
i just put the string into an array there
Andrew Nichols
@frenata
Mar 02 2017 05:03
Lets start with split. Does it change the thing it is called on? What does it return?
Simon
@smnshulgan
Mar 02 2017 05:04
It just divides each item according to what you put inside the parentheses
heroiczero
@heroiczero
Mar 02 2017 05:04
@smnshulgan if you do not assign the new array to a variable. you are not changing the array
Simon
@smnshulgan
Mar 02 2017 05:04
@heroiczero but i am assigning it to array
mitron6
@mitron6
Mar 02 2017 05:04
@frenata It does not change the thing it is called on. It returns an array.
Simon
@smnshulgan
Mar 02 2017 05:05
var array = str.split(' ');
eyesore-
@eyesore-
Mar 02 2017 05:05
@heroiczero That is not necessarily correct information because you can do it all in one line
Simon
@smnshulgan
Mar 02 2017 05:05
@eyesore- but it can be done in multiple lines, and i wanna know why it doesnt work
Andrew Nichols
@frenata
Mar 02 2017 05:05
Still didn't answer my question!
var str = "test";
str.split(''); Has str been changed @smnshulgan ?
mitron6
@mitron6
Mar 02 2017 05:05
@frenata str is not changed.
machao112
@machao112
Mar 02 2017 05:06

why isnt this working

function titleCase(str) {
var x = str.split(' ');
var y = ' ';
for(var i = 0; i < x.length; i++) {
var z = x[i].charAt(0).toUpperCase();
y = y + z + x[i].substring(1).toLowerCase() + " ";
}
return y;
}

titleCase("sHoRt AnD sToUt");

Simon
@smnshulgan
Mar 02 2017 05:06
is str changed into [t,e,s,t]
Joseph
@revisualize
Mar 02 2017 05:06
@frenata .split() doesn't mutate the string into an array. The string is still a string. Because Strings are Immutable.
heroiczero
@heroiczero
Mar 02 2017 05:06
@eyesore- you can technically but from his code its different and there is no "correct" answer, and it is good practice to not just give teh answer
machao112
@machao112
Mar 02 2017 05:06
pls help
Andrew Nichols
@frenata
Mar 02 2017 05:06
@smnshulgan str is not changed. The docs specify this. a new array is returned, that you have to assign to a variable.
Joseph
@revisualize
Mar 02 2017 05:06
I don't gift away answers. Studies have shown that giving people answers to problems instills an illusionary sense of learning. Because, it only puts information into short-term memory. Of which people think they are learning. Only through a little struggle and repetition that the human brain puts things into long-term memory. I don't know what your end goal. I don't know if you want to do this as a personal project, hobby, or if you want to move into industry. Because of this, I strongly feel that working with people to allow them to solve problems on their own is a far better outcome than giving away answers. But, others clearly don't agree with my methods for helping people learn.
Simon
@smnshulgan
Mar 02 2017 05:07
@frenata so are you saying that the split didnt do anything
Andrew Nichols
@frenata
Mar 02 2017 05:07
I'm saying split didn't do anything to the string. It provided you a new value. (that you have to assign/store)
Simon
@smnshulgan
Mar 02 2017 05:08
@frenata what do you mean value?
eyesore-
@eyesore-
Mar 02 2017 05:08
@smnshulgan He is not saying that. He is asking what happens when it is called. Which is that it returns an array of strings.
Simon
@smnshulgan
Mar 02 2017 05:08
like an array value or string value
Joseph
@revisualize
Mar 02 2017 05:08
@smnshulgan @frenata having .split() on a line by itself doesn't "do" anything. You have you use assignment operation to assign the value returned from .split() to a reference.
Simon
@smnshulgan
Mar 02 2017 05:08
i did
var array = str.split(' ');
Joseph
@revisualize
Mar 02 2017 05:08
That works.
Andrew Nichols
@frenata
Mar 02 2017 05:08
I know you did.
Simon
@smnshulgan
Mar 02 2017 05:08
yeah but it doesnt work
Andrew Nichols
@frenata
Mar 02 2017 05:08
Now reverse
Simon
@smnshulgan
Mar 02 2017 05:08
i ddi

function reverseString(str)
{
var array = str.split(' ');
array.reverse();
array.join(' ');
return array;
}

reverseString("hello");

heroiczero
@heroiczero
Mar 02 2017 05:08
@smnshulgan you just didnt do it for reverse or join
Simon
@smnshulgan
Mar 02 2017 05:09
thats what i had at the start
and you guys havent helped much
Andrew Nichols
@frenata
Mar 02 2017 05:09
Does reverse change the value that it is called on? What does it return?
Joseph
@revisualize
Mar 02 2017 05:09
@smnshulgan the .join()
@smnshulgan The .join() doesn't do anything on a line by itself like that.
Simon
@smnshulgan
Mar 02 2017 05:09
oh so you always have to assign stuff?
Andrew Nichols
@frenata
Mar 02 2017 05:09
No, not always.
Joseph
@revisualize
Mar 02 2017 05:09
@smnshulgan No.
Simon
@smnshulgan
Mar 02 2017 05:09
wh
why
Andrew Nichols
@frenata
Mar 02 2017 05:09
Answer my questions about reverse ;)
Joseph
@revisualize
Mar 02 2017 05:09
@smnshulgan array.reverse(); mutates the array
Simon
@smnshulgan
Mar 02 2017 05:10

function reverseString(str)
{
var array = str.split(' ');
array = array.reverse();
array = array.join(' ');
return array;
}

reverseString("hello");

so like this?
Joseph
@revisualize
Mar 02 2017 05:10
@smnshulgan Look. It goes back to understanding what the mutable types are.
@smnshulgan Sure.
Simon
@smnshulgan
Mar 02 2017 05:10
it still dont work
what does mutable mean
changeable?
Joseph
@revisualize
Mar 02 2017 05:10
@smnshulgan Because you're splitting on a " " space
@smnshulgan There are no spaces in your string.
eyesore-
@eyesore-
Mar 02 2017 05:11
So when you call join it doesnt do anything with array. IT just creates a string from array, but array still exists.
Andrew Nichols
@frenata
Mar 02 2017 05:11
Mutable means changeable, yes.
Simon
@smnshulgan
Mar 02 2017 05:11
@eyesore- doesnt the split make spaces in my array
Joseph
@revisualize
Mar 02 2017 05:11
@smnshulgan Look.
eyesore-
@eyesore-
Mar 02 2017 05:11
No
Joseph
@revisualize
Mar 02 2017 05:11
@smnshulgan Let me ask you a question.
Simon
@smnshulgan
Mar 02 2017 05:12
ok
Joseph
@revisualize
Mar 02 2017 05:12
Slow down one second.
Simon
@smnshulgan
Mar 02 2017 05:12
ok
Joseph
@revisualize
Mar 02 2017 05:12
@smnshulgan Let's say I have a string.
machao112
@machao112
Mar 02 2017 05:12
function titleCase(str) {
var x = str.split(' ');
var y = ' ';
for(var i = 0; i < x.length; i++) {
var z = x[i].charAt(0).toUpperCase();
y = y + z + x[i].substring(1).toLowerCase() + " ";
}
return y;
}
titleCase("sHoRt AnD sToUt");
why is it so wrong, someone help me.
Andrew Nichols
@frenata
Mar 02 2017 05:12
@revisualize Technically "test".split('') does do something, it just doesn't matter because we aren't keeping the result.
eyesore-
@eyesore-
Mar 02 2017 05:12
'hello'.split('') turned into ['h', 'e' so on.
Joseph
@revisualize
Mar 02 2017 05:12

@smnshulgan

var arr = "HappyFeetLovesToDance".split(" ");

What is the value of arr?

@eyesore- I want to ask a couple of questions. One sec.
Simon
@smnshulgan
Mar 02 2017 05:13
is it [H,a,....
Joseph
@revisualize
Mar 02 2017 05:13
@smnshulgan Incorrect.
eyesore-
@eyesore-
Mar 02 2017 05:13
Look at what he is passing into split
Joseph
@revisualize
Mar 02 2017 05:13
@smnshulgan .split(" ") Is looking for a SPACE
Simon
@smnshulgan
Mar 02 2017 05:13
is it [H , a, ....
Joseph
@revisualize
Mar 02 2017 05:13
There are no spaces in the string.
Simon
@smnshulgan
Mar 02 2017 05:13
oh so it doesnt change
it splits with what it gets in the parnetheses?
Andrew Nichols
@frenata
Mar 02 2017 05:14
:+1:
Joseph
@revisualize
Mar 02 2017 05:14
@smnshulgan It makes an array ["HappyFeetLovesToDance"]
@smnshulgan NOW!
Simon
@smnshulgan
Mar 02 2017 05:14
ok
Joseph
@revisualize
Mar 02 2017 05:14

@smnshulgan

var arr = "Happy Feet Loves To Dance".split(" ");

What is the value of arr?

Simon
@smnshulgan
Mar 02 2017 05:14
now it has an array with 5 items in it
[Happy, Feet ....
Joseph
@revisualize
Mar 02 2017 05:15
@smnshulgan ["Happy", "Feet", "Loves", "To", "Dance"]
Simon
@smnshulgan
Mar 02 2017 05:15
yeah that
Joseph
@revisualize
Mar 02 2017 05:15

@smnshulgan

var arr = "HappyFeetLovesToDance".split("");

What is the value of arr?

...
A really long array
Simon
@smnshulgan
Mar 02 2017 05:15
is it an array of strings?
Joseph
@revisualize
Mar 02 2017 05:15
Yes
eyesore-
@eyesore-
Mar 02 2017 05:15
keep in mind that "Happy Feet Loves To Dance" still exists. Split didn't mutate that.
Simon
@smnshulgan
Mar 02 2017 05:15
does it [h,a,p....
Joseph
@revisualize
Mar 02 2017 05:16
@smnshulgan Quotes define strings.
Simon
@smnshulgan
Mar 02 2017 05:16
yeah i was just double checking
Joseph
@revisualize
Mar 02 2017 05:16
@smnshulgan But, yes, it becomes ... ["H", "a", "p", "p", ........... I'm lazy I'm not going to write all of that out.
Simon
@smnshulgan
Mar 02 2017 05:17
yeah i get that
Joseph
@revisualize
Mar 02 2017 05:17
@smnshulgan So.. You have to evaluate what you're doing your split ON.
Simon
@smnshulgan
Mar 02 2017 05:17
oh so when you put just "" it divides it between each character
Joseph
@revisualize
Mar 02 2017 05:18
@smnshulgan Also, knowing that .split() returns an array.. You should be assigning that array value that is returned by the method call to SOMETHING.
Simon
@smnshulgan
Mar 02 2017 05:18
var array = str.split("");
array = array.reverse();
array = array.join();
return array;
like this?
Joseph
@revisualize
Mar 02 2017 05:18
@smnshulgan Correct. "" doesn't have a character betwen it.
@smnshulgan No. Your join needs to have an argument.
eyesore-
@eyesore-
Mar 02 2017 05:18
Look at your join method now
Simon
@smnshulgan
Mar 02 2017 05:18
does join work the same way
eyesore-
@eyesore-
Mar 02 2017 05:18
Yes
Joseph
@revisualize
Mar 02 2017 05:18
@smnshulgan Kind of.
Simon
@smnshulgan
Mar 02 2017 05:18
it takes away a thing instead though?
Joseph
@revisualize
Mar 02 2017 05:18
@smnshulgan But in reverse
Simon
@smnshulgan
Mar 02 2017 05:18
so i put "" into join
Joseph
@revisualize
Mar 02 2017 05:18
@smnshulgan Let's do this.
@smnshulgan Not always.
@smnshulgan Let me show you this.
Simon
@smnshulgan
Mar 02 2017 05:19
it worked
sure
@revisualize @eyesore- thanks guys
CamperBot
@camperbot
Mar 02 2017 05:19
smnshulgan sends brownie points to @revisualize and @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 57 | @eyesore- |http://www.freecodecamp.com/eyesore-
:star2: 3388 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 02 2017 05:20
var arr = ["h","e","l","l","o"];
str = arr.join("-");
What is the value of str?
Simon
@smnshulgan
Mar 02 2017 05:20
it doesnt change
Joseph
@revisualize
Mar 02 2017 05:20
"h-e-l-l-o"
eyesore-
@eyesore-
Mar 02 2017 05:20
Whatever you tell it is what it is going to input inbetween
Joseph
@revisualize
Mar 02 2017 05:21
var arr = ["h","e","l","l","o"];
str = arr.join(" 123 ");
What is the value of str?
"h 123 e 123 l 123 l 123 o";
Simon
@smnshulgan
Mar 02 2017 05:21
is that really how it works?
Joseph
@revisualize
Mar 02 2017 05:21
Yes.
eyesore-
@eyesore-
Mar 02 2017 05:21
Spoiler alert
Simon
@smnshulgan
Mar 02 2017 05:21
so it fills the spaces with whatever is in the ()
eyesore-
@eyesore-
Mar 02 2017 05:22
Yes
Joseph
@revisualize
Mar 02 2017 05:22
@smnshulgan I could argue semantics here. But, sure?
@smnshulgan Is it starting to make more sense?
eyesore-
@eyesore-
Mar 02 2017 05:23
@revisualize trying to get into the nitty gritty, but I can see how 'fills the space' can be misunderstood /:
Simon
@smnshulgan
Mar 02 2017 05:23
ok i understand now, the split() seperates depending on what is in the parentheses and the join() connects the array elements together with what is inside the parentheses
Joseph
@revisualize
Mar 02 2017 05:23
@smnshulgan YES.
I'm not arguing semantics on that one.
eyesore-
@eyesore-
Mar 02 2017 05:24
:+1:
Simon
@smnshulgan
Mar 02 2017 05:24
so if i put nothing into the join()
what happens
Joseph
@revisualize
Mar 02 2017 05:24
@smnshulgan Jack
Simon
@smnshulgan
Mar 02 2017 05:24
so its useless
eyesore-
@eyesore-
Mar 02 2017 05:24
Nothing. It needs to have something
Joseph
@revisualize
Mar 02 2017 05:24
@smnshulgan Because .join() requires an argument.
eyesore-
@eyesore-
Mar 02 2017 05:24
an argument if I may.
Haha
Simon
@smnshulgan
Mar 02 2017 05:24
ah thanks guys
really appreciate it
Joseph
@revisualize
Mar 02 2017 05:24
@smnshulgan BUT now.. Some methods are chain able.
It's called method chaining.
Simon
@smnshulgan
Mar 02 2017 05:25
how do you chain them
Joseph
@revisualize
Mar 02 2017 05:25
@smnshulgan SO You have to know what the method returns
eyesore-
@eyesore-
Mar 02 2017 05:25
@smnshulgan actually that is wrong. If you call it with no argument it adds ','
sorry
sjewell57
@sjewell57
Mar 02 2017 05:25

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

return item;// Change this line
}

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

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

Joseph
@revisualize
Mar 02 2017 05:26

@sjewell57
Gist by revisualize / FreeCodeCamp - Stand in Line.js

// How do you add a number (item) to the end of an array (arr)? What does this method return?
// How do you remove the first element from an array (arr)? What does this method return?

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

function nextInLine(arr, item) { }

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

Here's an example of this:

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

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

You just need to add a number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr).
But, there is another part of this challenge. You need to know What the methods that do those two things return. (If you don't know what a method returns. Look it up on the MDN.)
@sjewell57

Simon
@smnshulgan
Mar 02 2017 05:27
@revisualize ok so I get what they return what is the syntax for chaining
Andrew Nichols
@frenata
Mar 02 2017 05:27
these().functions().are().chained()
eyesore-
@eyesore-
Mar 02 2017 05:27
@smnshulgan If you know what it returns then that is what is going to go into the next method
Joseph
@revisualize
Mar 02 2017 05:27
@smnshulgan
function reverseString(str) {
  return str.split('').reverse().join('')
}
heroiczero
@heroiczero
Mar 02 2017 05:28
@sjewell57 review on how to Manipulate array in Free code camp
Joseph
@revisualize
Mar 02 2017 05:28
@eyesore- -^
I was lazy. LOL
eyesore-
@eyesore-
Mar 02 2017 05:28
Totally understandable. I was going to do the same.
Simon
@smnshulgan
Mar 02 2017 05:28
can you only chain when it returns
Joseph
@revisualize
Mar 02 2017 05:28
@smnshulgan ALL methods return SOMETHING.
@smnshulgan You can use what the method returns.
Or not.
Andrew Nichols
@frenata
Mar 02 2017 05:28

Sometimes this is nice too:

return foo()
  .bar()
  .baz();

This is also chaining!

Simon
@smnshulgan
Mar 02 2017 05:28
so could you chain and put it into a var
Joseph
@revisualize
Mar 02 2017 05:29
@smnshulgan Depending.
Simon
@smnshulgan
Mar 02 2017 05:29
like what if
Joseph
@revisualize
Mar 02 2017 05:29
@smnshulgan Let me give an example.
Michael Durfey
@Mdurfey1
Mar 02 2017 05:29
Would you guys use a for loop and the .indexOf() method to determine if two strings have the same letters?
Joseph
@revisualize
Mar 02 2017 05:29
@smnshulgan I know you may be typing but, Let's dive into an example.
eyesore-
@eyesore-
Mar 02 2017 05:29
@Mdurfey1 You can
Simon
@smnshulgan
Mar 02 2017 05:29
var array = str.split("").reverse().join("");
eyesore-
@eyesore-
Mar 02 2017 05:29
You doing the mutations one?
Michael Durfey
@Mdurfey1
Mar 02 2017 05:29
@eyesore- Yeah I am
eyesore-
@eyesore-
Mar 02 2017 05:30
Yeah, you can do that.
Andrew Nichols
@frenata
Mar 02 2017 05:30
@Mdurfey1 includes is probably more straightforward
Joseph
@revisualize
Mar 02 2017 05:30
@smnshulgan Let's say.. You have an array...
Let's say you have a value that you want to add to the front of an array and you want to reverse the array.
Simon
@smnshulgan
Mar 02 2017 05:30
ok
Andrew Nichols
@frenata
Mar 02 2017 05:30
But indexOf is perfectly fine, of course.
Joseph
@revisualize
Mar 02 2017 05:30
@smnshulgan Let's say the array was ... [2,3,4,5,6] and we wanted to add 1 to the front.
@smnshulgan Easy because I'm lazy.
Simon
@smnshulgan
Mar 02 2017 05:30
would you use .push
Michael Durfey
@Mdurfey1
Mar 02 2017 05:30
@frenata Nice! I'll give that one a try as well
Simon
@smnshulgan
Mar 02 2017 05:30
.push(1)
Joseph
@revisualize
Mar 02 2017 05:31
@smnshulgan Now we know.. .unshift() adds to the FRONT of the array.
eyesore-
@eyesore-
Mar 02 2017 05:31
@smnshulgan This is really not going to effect you in any way anytime soon, but if there is no need to store something to a variable don't do it. Plus thos one liners look goooood. :smile: haha
Joseph
@revisualize
Mar 02 2017 05:31
@smnshulgan SO...
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
Simon
@smnshulgan
Mar 02 2017 05:31
@eyesore- just make it short and sweet?
Joseph
@revisualize
Mar 02 2017 05:31
@smnshulgan Let's say we tried to method chaining here.
Andrew Nichols
@frenata
Mar 02 2017 05:31
I prefer one-statement-ers over one-liners.
Joseph
@revisualize
Mar 02 2017 05:32
@smnshulgan [2,3,4,5,6].unshift(1); What's returned?
Simon
@smnshulgan
Mar 02 2017 05:32
@revisualize [1,2,3,4,5,6]?
eyesore-
@eyesore-
Mar 02 2017 05:32
I think it really depends how complex the function is.
Joseph
@revisualize
Mar 02 2017 05:32
@smnshulgan Nope.
eyesore-
@eyesore-
Mar 02 2017 05:32
Returns the length
Joseph
@revisualize
Mar 02 2017 05:32
@smnshulgan and returns the new length of the array.
Andrew Nichols
@frenata
Mar 02 2017 05:32
Sure, if your oneline fits in 80 chars, go crazy.
Simon
@smnshulgan
Mar 02 2017 05:32
what do you mean returns the new length
Joseph
@revisualize
Mar 02 2017 05:33
@smnshulgan See.. That's where I said.. You can do method chaining IF you know what the method returns.
eyesore-
@eyesore-
Mar 02 2017 05:33
The new length of the array.
Simon
@smnshulgan
Mar 02 2017 05:33
so what is the new length
Joseph
@revisualize
Mar 02 2017 05:33
@smnshulgan It adds the value to the front of the array and returns the new .length
@smnshulgan 6
Simon
@smnshulgan
Mar 02 2017 05:33
so what would i look like i mean
Andrew Nichols
@frenata
Mar 02 2017 05:33
Not all array methods return the new/modified array, so yes, you have to be careful what you chain.
Simon
@smnshulgan
Mar 02 2017 05:33
it*
Joseph
@revisualize
Mar 02 2017 05:34
@smnshulgan 6
Simon
@smnshulgan
Mar 02 2017 05:34
it would just be 6
Joseph
@revisualize
Mar 02 2017 05:34
@smnshulgan What would what be?
Simon
@smnshulgan
Mar 02 2017 05:34
[6]?
Joseph
@revisualize
Mar 02 2017 05:34
NO
@smnshulgan What would the array be?
[1,2,3,4,5,6]
Simon
@smnshulgan
Mar 02 2017 05:34
[1,2,3,4,5,6]
Joseph
@revisualize
Mar 02 2017 05:34
@smnshulgan That would be the array.
Simon
@smnshulgan
Mar 02 2017 05:34
so it gets an extra spot
in the front
Joseph
@revisualize
Mar 02 2017 05:35
@revisualize BUT, if I wanted to do this.
[2,3,4,5,6].unshift(1).reverse();
This would be all messed up.
eyesore-
@eyesore-
Mar 02 2017 05:35
Would this work:
[2,3,4,5,6].unshift(1).push(2)
Simon
@smnshulgan
Mar 02 2017 05:35
would that ^ return [6,5,4,3,2,1]
Joseph
@revisualize
Mar 02 2017 05:35
Because the .unshift() returns a number .. not the array.
@smnshulgan Nope.
eyesore-
@eyesore-
Mar 02 2017 05:35
Damn, I was doing an example as well haha
Joseph
@revisualize
Mar 02 2017 05:36
@smnshulgan Because.. You have to look at what the method returns.
Simon
@smnshulgan
Mar 02 2017 05:36
how do you guys make that black box of code appear
Joseph
@revisualize
Mar 02 2017 05:36

If you are posting code that is large, Please use Gist - https://gist.github.com/ then please paste the link here.
...
How to do code block format: ..... PLEASE try with a small block of code before you try to make a bigger one.
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code
```js [SHIFT+ENTER]
// your code here
``` [CTRL+ENTER or CMD+ENTER to send]
Please do not confuse `s with 's.
Also note that the ```s need to each be on their own lines
The ` key can usually be found on most keyboards up next to the 1 key.
If you hit SHIFT+` it will give you the ~.
Example:
```
code
```
...
Output:

var code = undefined;

...
You can also do inline code formatting:
A string of text with a `variable` or `other bit of code`.
Output:
A string of text with a variable or other bit of code.

eyesore-
@eyesore-
Mar 02 2017 05:37
So on that example Joseph gave: [2,3,4,5,6].unshift(1).reverse();
Joseph
@revisualize
Mar 02 2017 05:37
@smnshulgan Again.. Method chaining is confusing. Because you have to know what is being returned by the previous method.
eyesore-
@eyesore-
Mar 02 2017 05:37
Why wouldn't reverse work?
Joseph
@revisualize
Mar 02 2017 05:37
I KNOW!
Simon
@smnshulgan
Mar 02 2017 05:38
yeah i want to know why it wouldnt work also
eyesore-
@eyesore-
Mar 02 2017 05:38
Haha
So we know that [2,3,4,5,6].unshift(1) returns what?
Joseph
@revisualize
Mar 02 2017 05:38
Because... .unshift() returns a NUMBER not the array.
Simon
@smnshulgan
Mar 02 2017 05:38
so what number is that
Joseph
@revisualize
Mar 02 2017 05:38
.length is a number
@smnshulgan depends on how long the array is.
Andrew Shieh
@andrewlikes
Mar 02 2017 05:39
Just finished Basic JavaScript challenges. Now im on object oriented and functional programming :D
eyesore-
@eyesore-
Mar 02 2017 05:39
Exactly. .reverse() is a method on array and not number
Simon
@smnshulgan
Mar 02 2017 05:39
@andrewlikes congrats man!
wait what does .unshift() do
Joseph
@revisualize
Mar 02 2017 05:39
@smnshulgan ["b","c"].unshift("a"); What is the new .length of the array after the element is added to the front of the array?
Andrew Shieh
@andrewlikes
Mar 02 2017 05:39
Moves a number to the front
Joseph
@revisualize
Mar 02 2017 05:40
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
Andrew Shieh
@andrewlikes
Mar 02 2017 05:40
Or string
Simon
@smnshulgan
Mar 02 2017 05:40
4
oops 3
Joseph
@revisualize
Mar 02 2017 05:40
@smnshulgan 3
@smnshulgan Can you .reverse() a number 3?
Simon
@smnshulgan
Mar 02 2017 05:40
no lol
Joseph
@revisualize
Mar 02 2017 05:40
@smnshulgan Now do you see?
["b","c"].unshift("a").reverse();
won't work.
Simon
@smnshulgan
Mar 02 2017 05:40
so why use unshift() when you can just use .length
eyesore-
@eyesore-
Mar 02 2017 05:41
.reverse() only exists for arrays. Have you gone into constructors by any chance?
Joseph
@revisualize
Mar 02 2017 05:41
@smnshulgan Because... you want to use the FIRST part of what .unshift() does.
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
Simon
@smnshulgan
Mar 02 2017 05:41
ok what about this then
var array = [1,2,3];
Joseph
@revisualize
Mar 02 2017 05:42
@smnshulgan That's an array with 3 numbers as elements
Simon
@smnshulgan
Mar 02 2017 05:42
array = array.unshift(0);
Joseph
@revisualize
Mar 02 2017 05:42
@smnshulgan array becomes 4
Simon
@smnshulgan
Mar 02 2017 05:42
array = array.reverse();
Joseph
@revisualize
Mar 02 2017 05:42
fail.
eyesore-
@eyesore-
Mar 02 2017 05:42
From what we have said, what is reverse a method of?
Simon
@smnshulgan
Mar 02 2017 05:43
arrays
Andrew Nichols
@frenata
Mar 02 2017 05:43
You've introduced a bug by rebinding the variable array from an array value to a number value.
Joseph
@revisualize
Mar 02 2017 05:43
@smnshulgan That wouldn't work. That would result in an error.
eyesore-
@eyesore-
Mar 02 2017 05:43
And array is now 4
Does 4 have that method in its proto?
Simon
@smnshulgan
Mar 02 2017 05:44
so why would you need to use .unshift
Joseph
@revisualize
Mar 02 2017 05:44
@smnshulgan adds one or more elements to the beginning of an array
Simon
@smnshulgan
Mar 02 2017 05:44
so does .unshift convert an array to a number
sjewell57
@sjewell57
Mar 02 2017 05:44
Beginning to hate this website. When stuck, having a hint or eventual solution helps me work my way back through the problem an