These are chat archives for FreeCodeCamp/HelpJavaScript

10th
Apr 2017
Mohamed Derhalli
@derhallim
Apr 10 2017 00:04
@TinCan-Assassin i didn't do this challeng eyet
:worried:
Stephen James
@sjames1958gm
Apr 10 2017 00:05
@TinCan-Assassin YOu need to call your weather function from inside the callback from get location
TinCan-Assassin
@TinCan-Assassin
Apr 10 2017 00:05
I guess I'll come back later then. Wife wants me downstairs.
Seth Church
@iEnder
Apr 10 2017 00:05
Anyone know how to assign an ID/Name to and resolved promise from a fetch request and keep them all together with promise.all ?
Stephen James
@sjames1958gm
Apr 10 2017 00:05
@TinCan-Assassin You URL needs http:// at the front as well
Seth Church
@iEnder
Apr 10 2017 00:06
let categories = ['alltime', 'monthly', 'weekly'];

            const getRecords = (type, id) => fetch(`https://api.bbroleplay.co.uk/v1/games/surf/records/${type}/map/${id}`, { 
                    method: 'post', 
                    headers: {
                        'Content-Type': 'application/json'
                    },
                }).then((res) => { 
                    res.name = type;
                    return res;
                });

            Promise
                .all(categories.map(type => getRecords(type, this.mapId)))
                .then(res => {
                    Promise.all(res.map(resp => {
                        let json = resp.json();
                        json.name = resp.name;
                        return json;
                    })).then(data => console.log(data))
                });
this is what I have so far but the .name gets assigned tot he promise not the value D:
Charles Williams
@cfunkles
Apr 10 2017 00:07
Hello again, my cipher is finally getting the result I need. Unfortunately I am getting an undefined before my result? I also just realized I am changing the character code for the spaces, that isn't my priority to fix right now. I just need to get rid of the undefined?
Stephen James
@sjames1958gm
Apr 10 2017 00:07
@pkmn9060 getRecords is not returning a promise (at least it doesn't look like it)
Charles Williams
@cfunkles
Apr 10 2017 00:07
function rot13(str) { // LBH QVQ VG!
  var decodedStr;

  var charArr = [];
  for (var i = 0; i < str.length; i++) {
      charArr.push((str.charCodeAt([i])-65+13)%26+65);
  }
      for (var j = 0; j < charArr.length; j++) {
      decodedStr += String.fromCharCode(charArr[j]);
  }
 return decodedStr;
  }

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Stephen James
@sjames1958gm
Apr 10 2017 00:08
@cfunkles When your string starts with undefined - usually means you didn't initialize the string variable
Seth Church
@iEnder
Apr 10 2017 00:08
@sjames1958gm its returning the fetch response with name of the category appended to the response for access
Charles Williams
@cfunkles
Apr 10 2017 00:08
@sjames1958gm oh man that was too simple
Stephen James
@sjames1958gm
Apr 10 2017 00:08
@cfunkles Sometimes it just is :)
Mohamed Derhalli
@derhallim
Apr 10 2017 00:09
@TinCan-Assassin u wrote $getJSON, u need $.getJSON
keithdidier
@keithdidier
Apr 10 2017 00:09

Please, could anyone tell me what's wrong with my code?

Return the remaining elements of an array after chopping off n elements from the head.

The head means the beginning of the array, or the zeroth index.

var myWords = ["big", "kind", "quick", "fast"];
var sliced = myWords.slice(0,1);
function slasher(arr, howMany) {
  // it doesn't always pay to be first
  return arr;
}

slasher([1, 2, 3], 2);
Charles Williams
@cfunkles
Apr 10 2017 00:10
how would I send a message with my code in the fancy format with out sending two messages?
one message the black box of code and one message being my comment?
Moisés Man
@moigithub
Apr 10 2017 00:10
write ur code INSIDE the function @keithdidier
...before return
u also need to use the function parameters (arr, howMany)
Mohamed Derhalli
@derhallim
Apr 10 2017 00:11
@TinCan-Assassin u also have different function call than ur function name : geoloc vs geoLoc
Charles Williams
@cfunkles
Apr 10 2017 00:13
here is a comment typed outside of the black box that will hopefully be one message with the black box of code var testingCode = 'how do I do this?';
Stephen James
@sjames1958gm
Apr 10 2017 00:13
@pkmn9060 Ah, I see - but why are you doing a second Promise.all on res - it is an array of responses
keithdidier
@keithdidier
Apr 10 2017 00:13
@moigithub Where would I place the parameters?
Charles Williams
@cfunkles
Apr 10 2017 00:15
here is a comment typed outside of the black box that will hopefully be one message with the black box of code
 var testingCode = 'how do I do this?';
okay figured it out, needed to use compose mode
Seth Church
@iEnder
Apr 10 2017 00:18
@sjames1958gm just realized Promise.all does infact preserve order of original array... lmao
keithdidier
@keithdidier
Apr 10 2017 00:18
@cfunkles Well done!
Seth Church
@iEnder
Apr 10 2017 00:18
thanks for the help anyways @sjames1958gm
CamperBot
@camperbot
Apr 10 2017 00:18
pkmn9060 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6612 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 10 2017 00:18
@pkmn9060 Sure - I learned something new about fetch and promises - thx
CamperBot
@camperbot
Apr 10 2017 00:18
sjames1958gm sends brownie points to @pkmn9060 :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @pkmn9060 |http://www.freecodecamp.com/pkmn9060
Seth Church
@iEnder
Apr 10 2017 00:19
Oh and no it wasnt a array of responses on the 2nd promise.all it was returing a array of promises from the mapped fetch function
my fault for bad param names :L
Dylan Ler
@dylanler
Apr 10 2017 00:24

var array = [4,5,6,7,8];
var singleVal = array.reduce(function(prevVal, currVal){
  return prevVal + currVal;
});
what am i doing wrong here? IT is to sum all values in array
nvm i got it
keithdidier
@keithdidier
Apr 10 2017 00:27
@garciadecastro What is your code looking like so far?
Shrey Sethi
@Shrey-S
Apr 10 2017 00:41
how do you output a variable to the screen?
Jor
@joreyesl
Apr 10 2017 00:43
@dylanler that looks fine, try refreshing the page
webennes
@webennes
Apr 10 2017 00:51
Hey, some help what's wrong here :

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

// Only change code above this line
return fahrenheit = ( 9/5 ) * (celsius-32);
}

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

Fabusuyi David Oluwasegun
@dav4thevid
Apr 10 2017 00:55
pls read the instruction carefully @webennes
ur code should be in between //only change code below dis line en only change code above dis line
webennes
@webennes
Apr 10 2017 00:56
ok, thanks you
Donnie
@Donnie-D
Apr 10 2017 00:58
function funct(nothigToDoWithThisEntry) {
  var arr = [];
  for(i = 1; i < 6; i++) {
    arr = arr.push[i];
  }
  return arr;
}

funct(5);
Why does it return ... arr is undefined
if i take out the for loop it runs fine
Keon Samuel
@keonsam
Apr 10 2017 01:01
you push wrong
Donnie
@Donnie-D
Apr 10 2017 01:01
okay?
Keon Samuel
@keonsam
Apr 10 2017 01:01
just put arr.push[i];
Donnie
@Donnie-D
Apr 10 2017 01:01
tried that
throws error
Keon Samuel
@keonsam
Apr 10 2017 01:02
not arr = arr.push[i];
keithdidier
@keithdidier
Apr 10 2017 01:02
@webennes Should you be subtracting 32 or adding 32? Read instructions once more.
Donnie
@Donnie-D
Apr 10 2017 01:02
@keonsam oh actually i spelt that wrong lol. sorry for that and cheers
Keon Samuel
@keonsam
Apr 10 2017 01:03
did it worked?
Donnie
@Donnie-D
Apr 10 2017 01:03
yup but dont know whats the difference though
Keon Samuel
@keonsam
Apr 10 2017 01:03
for(var i=1
Carlos García de Castro
@garciadecastro
Apr 10 2017 01:04

@webennes @dav4thevid Thank! I finally did it this way function convertToF(celsius) {
var fahrenheit;

fahrenheit= celsius * 9/5 + 32;

}

CamperBot
@camperbot
Apr 10 2017 01:04
garciadecastro sends brownie points to @webennes and @dav4thevid :sparkles: :thumbsup: :sparkles:
:cookie: 141 | @webennes |http://www.freecodecamp.com/webennes
:cookie: 219 | @dav4thevid |http://www.freecodecamp.com/dav4thevid
Donnie
@Donnie-D
Apr 10 2017 01:05
@keonsam but it doesn't add anyvalues from the loop to the array now
Keon Samuel
@keonsam
Apr 10 2017 01:05
because your for loop is wrong
for (var i= 1
you forget var
Donnie
@Donnie-D
Apr 10 2017 01:07
added var. still no difference buddy
keithdidier
@keithdidier
Apr 10 2017 01:07
@webennes Have you completed the challenge?
Keon Samuel
@keonsam
Apr 10 2017 01:07
what challenge you on your code looks wrong?
webennes
@webennes
Apr 10 2017 01:08
not ... i not was completed .-.
CamperBot
@camperbot
Apr 10 2017 01:08
:bulb: to format code use backticks! ``` more info
Donnie
@Donnie-D
Apr 10 2017 01:08
no its not on any challenge. i just happened to be trying something and came across this silly situation which logically seemed fine to me but not running well
but, thanks for your help bro
i will complete it..
Keon Samuel
@keonsam
Apr 10 2017 01:11
@Donnie-D
try arr.push([i]);
lol my bad.
You might need console.log(arr); to see the array.
arr.push(i);
that should work
Donnie
@Donnie-D
Apr 10 2017 01:15
@keonsam oh it was a syntax error. i was not putting parenthesis around i grrr. but still whats the difference between arr.push(i) and arr= arr.push(i) ?
Donnie
@Donnie-D
Apr 10 2017 01:18
will do cheers bud
Anica
@matosa
Apr 10 2017 01:18
Can someone help me with switch statements?
Keon Samuel
@keonsam
Apr 10 2017 01:19
sure
Anica
@matosa
Apr 10 2017 01:20
function sequentialSizes(val) {
  var answer = "";
  // Only change code below this line
  switch (val)
  {
    case 1:
    case 2:
    case 3:
      answer = "low";
      break;
    case 4:
    case 5:
    case 6:
      answer = "mid";
      break;
    case 7:
    case 8:
    case 9:
      answer = "high";
  }


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

// Change this value to test
sequentialSizes(1);
keithdidier
@keithdidier
Apr 10 2017 01:22
@webennes Remember to use the var Fahrenheit, the argument (celsius) and the math operation all below the function but above the return and you'll solve the problem.
Mohamed Derhalli
@derhallim
Apr 10 2017 01:24
@matosa what's the problem?
Anica
@matosa
Apr 10 2017 01:24
I just figured it out. It wasn't passing the tests because the strings needed to be capitalized
Mohamed Derhalli
@derhallim
Apr 10 2017 01:28
:'( gd
webennes
@webennes
Apr 10 2017 01:28
i have completed my friend this is the solution.. : ( fahrenheit = celsius * 9/5 + 32;) from @garciadecastro thanks =)
CamperBot
@camperbot
Apr 10 2017 01:28
webennes sends brownie points to @garciadecastro :sparkles: :thumbsup: :sparkles:
:cookie: 152 | @garciadecastro |http://www.freecodecamp.com/garciadecastro
Noel Miller
@Xmas13
Apr 10 2017 01:30
//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].hasOwnProperty(firstName) && contacts[i].hasOwnProperty(prop)) {
      return contacts[i].prop;
    }
    else if (contacts[i].firstName === undefined) {
      return "No such contact";
    }
    else {
      return "No such property";
    }
  }
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
sorry, meant this to be a code block
I'm trying to figure out why my test isn't passing for the profile lookup
Vicky Lai
@vickylai
Apr 10 2017 01:42
Apparently it's 129°C in Seattle... :laughing:
Keon Samuel
@keonsam
Apr 10 2017 01:44
wow
how do you survive that hell?
Vicky Lai
@vickylai
Apr 10 2017 01:49
@keonsam With bad javascript math...
Moisés Man
@moigithub
Apr 10 2017 01:55
129ºC or 129ºF ?
cuz water boil at 100ºC
Dylan Ler
@dylanler
Apr 10 2017 01:58

function findLongestWord(str) {
  var arr = str.split(" ");
  var wordLengthArr;
  for(var i = 0; i < arr.length; i++){
    wordLengthArr.push(arr[i].length);
  }
  return Math.max(wordLengthArr);
}

findLongestWord("The quick brown fox jumped over the lazy dog");
I can't seem to get this algorithm right
What am i doing wrong here?
Keon Samuel
@keonsam
Apr 10 2017 01:59
var wordLengthArr =[];
Moisés Man
@moigithub
Apr 10 2017 02:00
also Math.max requires number (or list of numbers separated by comma)
NOT arrays
Math.max(1) //ok
Math.max(1,2,3,4); //ok
Math.max([1,2,3]) // wrong no arrays
@dylanler
Keon Samuel
@keonsam
Apr 10 2017 02:00
try joining the array
Moisés Man
@moigithub
Apr 10 2017 02:01
neither strings...
BUT.. u can use apply or spread operator... (IF u wanna work with arrays)
Joseph
@revisualize
Apr 10 2017 02:02
Is apply ES6?
Moisés Man
@moigithub
Apr 10 2017 02:03
5 i thiknk
Dylan Ler
@dylanler
Apr 10 2017 02:03
I got it to work with this

function findLongestWord(str) {
  var arr = str.split(" ");
  var wordLengthArr=[];

  for(var i = 0; i < arr.length; i++){
    wordLengthArr.push(arr[i].length);
}
  var max = wordLengthArr.reduce(function(a,b){
    return Math.max(a,b);
});
  return max;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
Thanks everyone!
Joseph
@revisualize
Apr 10 2017 02:03
@dylanler I did it a different way.
Almezing
@Almezing
Apr 10 2017 02:04
its always neat to see different ways to solve the problem
like i kept a running count of the longest word
Joseph
@revisualize
Apr 10 2017 02:04
return Math.max(...str.replace(/[^A-Z0-9 -]/gi, "").split(" ").map(w => w.length));
Dylan Ler
@dylanler
Apr 10 2017 02:04
nice work
Joseph
@revisualize
Apr 10 2017 02:05
function findLongestWord(str) {
  str.replace(/[\W_]/g, "");       // Sanitize the string to remove comas.
  var array = str.split(" ");          // Split the string into an array
  var elementSize = 0;                 // Variable for storing the size of longest item in array.
  for (var i = 0; i < array.length; i++) {
    if (elementSize < array[i].length) {      // If the element size is less than item length
      elementSize = array[i].length;          // set the elementSize to the item length in the array.
    }
  }
  // return str.length;
  return elementSize;
}
Almezing
@Almezing
Apr 10 2017 02:05
@revisualize that's so short
Joseph
@revisualize
Apr 10 2017 02:06
function findLongestWord(str) {
   return str.split(" ").reduce(function (pre, curr) { 
                             if (curr.length > pre) { 
                                 return curr.length; 
                             } 
                             else { 
                                 return pre;
                             } }, 0);
}
Keon Samuel
@keonsam
Apr 10 2017 02:06
yes that's how you solve it
Moisés Man
@moigithub
Apr 10 2017 02:06
str.split(" ").sort((a,b)=>b.length-a.length)[0].length;
Al
@fingrlicknchickn
Apr 10 2017 02:09
hey guys im stuck on the counting cards exercise in Basic Javascript can anyone help?
Danny Welstad
@GoonTwo
Apr 10 2017 02:10
Intermediate algorithm scripting "Diff Two Arrays" not sure why this isn't working. it makes sense in my head but maybe I'm way off.
function diffArray(arr1, arr2) {

  var newArr = arr1.filter(function(val){
   return arr2.indexOf(val) < 0;
 });

  return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Al
@fingrlicknchickn
Apr 10 2017 02:12

var count = 0;

function cc(card) {
// Only change code below this line
switch (card) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
count ++;
if (count > 0) {
return count + " Bet";
}
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count --;
if (count < 0) {
return count + " Hold";
}
break;
}
return "0 Hold";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(10);

what how do i make it llok good like u guys
CamperBot
@camperbot
Apr 10 2017 02:13
:bulb: to format code use backticks! ``` more info
Al
@fingrlicknchickn
Apr 10 2017 02:14

""
var count = 0;

function cc(card) {
// Only change code below this line
switch (card) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
count ++;
if (count > 0) {
return count + " Bet";
}
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count --;
if (count < 0) {
return count + " Hold";
}
break;
}
return "0 Hold";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(10); ""

Danny Welstad
@GoonTwo
Apr 10 2017 02:14
@fingrlicknchickn three backticks
Al
@fingrlicknchickn
Apr 10 2017 02:15

"""
var count = 0;

function cc(card) {
// Only change code below this line
switch (card) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
count ++;
if (count > 0) {
return count + " Bet";
}
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count --;
if (count < 0) {
return count + " Hold";
}
break;
}
return "0 Hold";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(10); """

'''
var count = 0;

function cc(card) {
// Only change code below this line
switch (card) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
count ++;
if (count > 0) {
return count + " Bet";
}
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count --;
if (count < 0) {
return count + " Hold";
}
break;
}
return "0 Hold";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(10); '''

CamperBot
@camperbot
Apr 10 2017 02:15
:bulb: to format code use backticks! ``` more info
Danny Welstad
@GoonTwo
Apr 10 2017 02:16
@fingrlicknchickn for me, its top left of the keyboard. not quation marks.
Al
@fingrlicknchickn
Apr 10 2017 02:16
var count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count ++;
      if (count > 0) {
        return count + " Bet";
      }
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count --;
      if (count < 0) {
        return count + " Hold";
      }
      break;
  }
  return "0 Hold";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(10);
there i go
lol
i dont even know if i can use if in this way
@GoonTwo u gotta know this one right
Danny Welstad
@GoonTwo
Apr 10 2017 02:18
@fingrlicknchickn im not sure what you're trying to do
Al
@fingrlicknchickn
Apr 10 2017 02:19
the card counting exercise havent u done it?
its in the Basic Javascript course
im trying to incremment count everytime the function is called with a number < 6
am i way of?
when calling 2 , 3, 10 i should end up with a value of 1 on count and i want the string "Bet" to be attached in a return
Danny Welstad
@GoonTwo
Apr 10 2017 02:22
@fingrlicknchickn the if statements go at the end. don't think you can use them in the middle of a switch statement like that.
@fingrlicknchickn the count increments look right. just move the if else statemtns to the end after the switch
Joseph
@revisualize
Apr 10 2017 02:23
@fingrlicknchickn You're returning too early.
@fingrlicknchickn Counting Cards is a challenge where your function will receive a card parameter. You're supposed to increment or decrement the global count variable according to the card's value
If the value of the card parameter is 2, 3, 4, 5 or 6 you need to increment the global variable count.
If the value of the card parameter is 10, 'J', 'Q', 'K' or 'A' you need to decrement the global variable count.
...
Then the function will return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.
The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
@fingrlicknchickn Basically, move your if block below your switch.
Danny Welstad
@GoonTwo
Apr 10 2017 02:24
Intermediate algorithm scripting "Diff Two Arrays" not sure why this isn't working. it makes sense in my head but maybe I'm way off.
function diffArray(arr1, arr2) {

  var newArr = arr1.filter(function(val){
   return arr2.indexOf(val) < 0;
 });

  return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
c0d0er
@c0d0er
Apr 10 2017 02:26
does anybody know why if i mouseover the small circles which is covered by big circles (e.g. biggest circle which cover spots in Japan and China), then the covered small circles' tooltips cannot be shown? http://codepen.io/c0d0er/pen/RpzOZO?editors=0010
Al
@fingrlicknchickn
Apr 10 2017 02:26
@revisualize @GoonTwo huh look at that, i wasnt that far of , thx guys i got it!
CamperBot
@camperbot
Apr 10 2017 02:26
:warning: @goontwo's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
fingrlicknchickn sends brownie points to @revisualize and @goontwo :sparkles: :thumbsup: :sparkles:
:star2: 3704 | @revisualize |http://www.freecodecamp.com/revisualize
Francis Ngo
@francisngo
Apr 10 2017 02:42
how do I find out the shortest word in an array? I am having trouble with my result.

function findMinLengthOfThreeWords(word1, word2, word3) {
// your code here
var arr = [];
arr.push(word1, word2, word3);
console.log(arr);
var shortestWord = arr.reduce(function(shortest, currentWord) {
if(currentWord.length < shortest.length) {
return currentWord;
} else {
return shortest;
}
}, '');
return shortestWord.length;
}

var output = findMinLengthOfThreeWords('a', 'be', 'see');
console.log(output); // --> 1

function findMinLengthOfThreeWords(word1, word2, word3) {
  // your code here
  var arr = [];
  arr.push(word1, word2, word3);
  console.log(arr);
  var shortestWord = arr.reduce(function(shortest, currentWord) {
    if(currentWord.length < shortest.length) {
      return currentWord;
    } else {
      return shortest;
    }
  }, '');
  return shortestWord.length;
}


var output = findMinLengthOfThreeWords('a', 'be', 'see');
console.log(output); // --> 1
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 02:42
@suraj-davariya use http for your codepen
Suraj
@suraj-davariya
Apr 10 2017 02:43
@HeebieGeeBee how's that ? Isn't it an http request i made?
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 02:43
@suraj-davariya yes but you need to use http for the codepen too
Suraj
@suraj-davariya
Apr 10 2017 02:46
@HeebieGeeBee what changes did you make buddy ?
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 02:46
@suraj-davariya use http for the codepen url
Dylan Ler
@dylanler
Apr 10 2017 02:46
hmm, what am i doing wrong here
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  str = str.replace(" ", "");
  var targetLength = target.length;
  var endOfStr = str.substr(-1*targetLength);
  if(endOfStr == targetLength)
    return true;
  else
    return false;

}

confirmEnding("Bastian", "n");
Mohamed Derhalli
@derhallim
Apr 10 2017 02:46
@suraj-davariya why not using getJSON instead of $.ajax 90 ? @HeebieGeeBee am i right?
Phillip Troutman
@troutman21
Apr 10 2017 02:46
HI everyone. I'm having trouble with the "setTimeout" method. Can anyone tell me why this is printing "Hello" but its not actually pausing before invoking the functions.
function printer(){
  console.log("Hello");
}

function delay(func, wait ) {
    setTimeout(func(), wait ) ;
}
delay(printer,2000);
delay(printer,6000);
delay(printer,9000);
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 02:47
@derhallim can use either cant you
getJSON is just a jquery shortcut isnt it
Suraj
@suraj-davariya
Apr 10 2017 02:47
@derhallim getJSON method calls $.ajax eventually . $.ajax give better performance.
Nerando Johnson
@Nerajno
Apr 10 2017 02:47
greetings
Gulsvi
@gulsvi
Apr 10 2017 02:48
getJSON = ajax. It's the same code
Mohamed Derhalli
@derhallim
Apr 10 2017 02:48
but don't u need to set the headers for accept in the ajax?
ur missing that in ur code
Nerando Johnson
@Nerajno
Apr 10 2017 02:48
i am doing the weather app an i an having an issue with assigning some stuff
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 02:48
@dylanler your arguments for the substr are wrong
Suraj
@suraj-davariya
Apr 10 2017 02:48
got it :) @HeebieGeeBee thanks
CamperBot
@camperbot
Apr 10 2017 02:48
suraj-davariya sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1235 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
dn92
@dn92
Apr 10 2017 02:48

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

function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp) === true) {
if (myObj.hasOwnProperty(checkProp) == "gift") {
return "pony";
} else if (myObj.hasOwnProperty(checkProp) == "pet") {
return "kitten";
} else if (myObj.hasOwnProperty(checkProp) == "bed") {
return "sleigh";
}
} else {
return "Not Found";
}
}
'

hi everyone, could someone let me know if the above code correctly does the following:
1) checks to see if a property exists
2) returns the property's value if it exists

woops. i'll make it look nicer
Gulsvi
@gulsvi
Apr 10 2017 02:48
$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
});
^^ That's getJSON
Mohamed Derhalli
@derhallim
Apr 10 2017 02:48
@SkyCoder01 wassup man, long time no see
Nerando Johnson
@Nerajno
Apr 10 2017 02:48
can i get some help ?
Gulsvi
@gulsvi
Apr 10 2017 02:49
@derhallim :wave: Hey!
Francis Ngo
@francisngo
Apr 10 2017 02:49
what am i doing wrong?
```
function findMinLengthOfThreeWords(word1, word2, word3) {
  // your code here
  var arr = [];
  arr.push(word1, word2, word3);
  console.log(arr);
  var shortestWord = arr.reduce(function(shortest, currentWord) {
    if(currentWord.length < shortest.length) {
      return currentWord;
    } else {
      return shortest;
    }
  }, '');
  return shortestWord.length;
}


var output = findMinLengthOfThreeWords('a', 'be', 'see');
console.log(output); // --> 1
Nerando Johnson
@Nerajno
Apr 10 2017 02:49
`

$(document).ready(function() {
var long;
var lat;
//get location code from freeCodecamp = http://bit.ly/2nxT7pG
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
long = position.coords.longitude;
lat = position.coords.latitude;
$("#data").html("latitude: " + lat+ "<br>longitude: " + long);
});
}

//JSON call for Open weather API
var api ="http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+long+"&appid=32317440735df175bc0a92379a41137c";
$.getJSON(api,function(data){
alert(data.coords.lat);
console.log(api);
//api.openweathermap.org/data/2.5/weather?lat=35&lon=139

});
});

it keep telling me bad request or lat an lon are not assigned
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 02:50
@francisngo what return do you get?
Francis Ngo
@francisngo
Apr 10 2017 02:51
0
Dylan Ler
@dylanler
Apr 10 2017 02:51
@HeebieGeeBee huh? hmm
@HeebieGeeBee let me try it again
Francis Ngo
@francisngo
Apr 10 2017 02:51
something is wrong with my if statement but i cant figure out where i am doing it wrong
mls408
@mls408
Apr 10 2017 02:52
I am trying to convert celsius into fahrenheit,

convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86

1

2
function convertToF(celsius) {
3
var fahrenheit;
4
// Only change code below this line
5
fahrenheit= 30(9/5)+32;
6
fahrenheit= -30
(9/5)+32;
7
fahrenheit= -10(9/5)+32;
8
fahrenheit= 20
(9/5)+32;
9
fahrenheit= 0*(9/5)+32;
10
// Only change code above this line
11
return fahrenheit;
12
}
13

14
// Change the inputs below to test your code
15
convertToF(30);
16
convertToF(-30);
17
convertToF(-10);
18
convertToF(20);
19

Suraj
@suraj-davariya
Apr 10 2017 02:52
@derhallim i was running codepen in secured connection! i should have make an http call .
reference : https://api.jquery.com/jQuery.getJSON/
Dylan Ler
@dylanler
Apr 10 2017 02:53
still not working

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  str = str.replace(/\s+/g, '');
  var targetLength = target.length;
  var endOfStr = str.substring(str.length - targetLength);
  if(endOfStr == targetLength)
    return true;
  else
    return false;

}

confirmEnding("Bastian", "n");
mls408
@mls408
Apr 10 2017 02:53
I don't know how to get all the answers to come out at once... I got all of them individually
Dylan Ler
@dylanler
Apr 10 2017 02:53
How do I get the console to print out console.log
it makes it really hard to debug without that.
dn92
@dn92
Apr 10 2017 02:54
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  myObj.hasOwnProperty(checkProp);
  if (myObj.hasOwnProperty(checkProp) === true) {
    if (myObj.hasOwnProperty(checkProp) == "gift") {
      return "pony";
    } else if (myObj.hasOwnProperty(checkProp) == "pet") {
      return "kitten";
    } else if (myObj.hasOwnProperty(checkProp) == "bed") {
      return "sleigh";
    }
  } else {
    return "Not Found";
  }
}
will that return the value of the property?
Moisés Man
@moigithub
Apr 10 2017 02:55

@dylanler what value will CONTAIN endOfSTr variable??
also.. what VALUE have targetLength variable?

  var targetLength = target.length;
  var endOfStr = str.substring(str.length - targetLength);

cuz u comparing here both of those
if(endOfStr == targetLength)

Du5tDevil
@Du5tDevil
Apr 10 2017 02:55
@mls408 Make sure you are using the * for any multiplication values. You also want to house the whole formula in parenthesis.
dn92
@dn92
Apr 10 2017 02:56
more specifically, after checking for whether or not the property exists, will it return the value of the property that was checked?
mls408
@mls408
Apr 10 2017 02:56
Thanks! @Du5tDevil
CamperBot
@camperbot
Apr 10 2017 02:56
mls408 sends brownie points to @du5tdevil :sparkles: :thumbsup: :sparkles:
:cookie: 156 | @du5tdevil |http://www.freecodecamp.com/du5tdevil
Du5tDevil
@Du5tDevil
Apr 10 2017 02:57
No problem! @mls408
Dylan Ler
@dylanler
Apr 10 2017 02:58
@moigithub OHHH, I got it
mls408
@mls408
Apr 10 2017 02:58

Okay I out them all in parenthesis, but I still only get one answer.. function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
fahrenheit= (30(9/5)+32);
fahrenheit= (-30
(9/5)+32);
fahrenheit= (-10(9/5)+32);
fahrenheit= (20
(9/5)+32);
fahrenheit= (0*(9/5)+32);
// Only change code above this line
return fahrenheit;
}

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

This is my code
Dylan Ler
@dylanler
Apr 10 2017 02:58
@moigithub Thanks man!
CamperBot
@camperbot
Apr 10 2017 02:58
:star2: 3040 | @moigithub |http://www.freecodecamp.com/moigithub
dylanler sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
Mohamed Derhalli
@derhallim
Apr 10 2017 02:59
@suraj-davariya ah ok thanks :)
CamperBot
@camperbot
Apr 10 2017 02:59
derhallim sends brownie points to @suraj-davariya :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @suraj-davariya |http://www.freecodecamp.com/suraj-davariya
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 02:59
@francisngo dont initiate with a " " at the end of the reduce method
Joseph
@revisualize
Apr 10 2017 02:59

@mls408
There is the function declaration of function convertToF(celsius) { .. You have a function name of convertToF and a parameter of celsius
Parameters are used just like variables. So, inside of the function you can use celsius JUST like any other variable.
If I have this code:

function addThree (num) {
    var result;
    result = num + 3;
    return result;
}

So, when we make the function call of:

addThree(10);

You're calling the function addThree You're also passing a value 10 as an argument.
In the function declaration of function addThree (num) { You see that there is a parameter defined of num
When we do addThree(10) then the value of the parameter num is passed the argument value of ... 10
Then if you follow the code through.. result = num + 3; ... and we know the value of num is 10.
Therefore, if we follow through the function we end up with ... result = 10 + 3; then result = 13; then we return the result.

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

Sam Houlahan
@Sam-Houlahan
Apr 10 2017 02:59

Hey guys im doing the javascript calculator project can anyone help me push my values into an array hear is my code . let arr =[];
$(".calcbtn").click(function() {

     let value = $(this).val();
     value = value.split(' ');

     $("#screen").text(value);
     console.log(value);
     console.log(arr);





 })

})

Nerando Johnson
@Nerajno
Apr 10 2017 02:59
is anyone gonna help me ?
help
Du5tDevil
@Du5tDevil
Apr 10 2017 03:02
@mls408 Here is an example of how I did it. Have to make sure you use the when multiplying (JS will not read it as multiplication if written without a ).
fahrenheit = (celsius * (9/5)) + 32;
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:02
@Nerajno you need to use https for geolocation but then youre using http for you api url, you cant have mixed origins
@Sam-Houlahan what problem are you having exactly? i cant see where youre trying to push elements into the array
Joseph
@revisualize
Apr 10 2017 03:04
@mls408 I know that was a wall of text. But, does it make sense?
Sam Houlahan
@Sam-Houlahan
Apr 10 2017 03:04
@HeebieGeeBee Im trying to figure out how to push that value to an empty arr ive tried various ways already how would you do this?
mls408
@mls408
Apr 10 2017 03:05
That helped! Thank you both! @revisualize @Du5tDevil
CamperBot
@camperbot
Apr 10 2017 03:05
mls408 sends brownie points to @revisualize and @du5tdevil :sparkles: :thumbsup: :sparkles:
:warning: mls408 already gave du5tdevil points
:star2: 3705 | @revisualize |http://www.freecodecamp.com/revisualize
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:05
@Sam-Houlahan arr.push(value)?
@Sam-Houlahan is console logging value giving you the correct value?
Joseph
@revisualize
Apr 10 2017 03:07
My 11" x 14" dry erase board arrived today.
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:07
@revisualize baby whiteboard?
Joseph
@revisualize
Apr 10 2017 03:10
@HeebieGeeBee I'm going to take it to work.
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:10
nice
Joseph
@revisualize
Apr 10 2017 03:11
I'm going to start bullet journaling my day.
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:11
i got a one but stuck on the wall
cool they do come in far more useful than you realise
Nerando Johnson
@Nerajno
Apr 10 2017 03:21
@HeebieGeeBee thanks
CamperBot
@camperbot
Apr 10 2017 03:21
nerajno sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1236 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Nerando Johnson
@Nerajno
Apr 10 2017 03:22
nows its giving me another error lol
Usman Akram
@usmanakram1996
Apr 10 2017 03:25
@Nerajno whats the issue ?
Ryan Haire
@RyaanH
Apr 10 2017 03:41
Should I understand what the Generate Random Whole Numbers within a Range lesson is doing? or will i understand later
the formula is confusing
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:42
@tsolar74 dont put the second object in another array like that
you should just end up with two objects in the myMusic array
Ryan Haire
@RyaanH
Apr 10 2017 03:43
@tsolar74 use the same syntax the example provides
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:43
@RyaanH you should be understanding with the challenge
Ryan Haire
@RyaanH
Apr 10 2017 03:43
@HeebieGeeBee the formula they use is confusing
Joseph
@revisualize
Apr 10 2017 03:44
@tsolar74 You need to have one array with two elements that are objects.
@tsolar74 [ { . . . } , { . . . } ]
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:44
@RyaanH what are you confused about?
Ryan Haire
@RyaanH
Apr 10 2017 03:44
Math.floor(Math.random() * (max - min + 1)) + min
how is this returning a random number between min and max?
the range of max and min is confusing
Tina
@tsolar74
Apr 10 2017 03:45
This was my solution:
// Add record here
[{
"artist": "Pink Floyd",
"title": "The Wall",
"release_year": 1979,
"formats": [
"CS",
"LP",
"8T",
"CD",
"MP3"
],
}
];
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:46
because Math.random generates a number between 0 and 1 but never actually 1
Ryan Haire
@RyaanH
Apr 10 2017 03:46
@tsolar74 [] this is an array, {} this is an object
@HeebieGeeBee why subtract min from max add 1
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:48
because math.floor rounds down you add the 1 to compensate for the fact that math random never generates a total 1
Chris Cullen
@123xylem
Apr 10 2017 03:48

[{"_id":"58eafc073889620a38e7aa4d",
"name":".id",
"category":"Yoga",
"price":1,
"image":"https://cdn.pixabay.com/phot/2014/01/10/13/30/yoga-241609__480.jpg","
__v":0}]
Above is my group.product... Yoga is the group and I populated its .product att with product named .id

<% group.product.forEach(function(group){ %>

<img class="img-responsive"src="<%=group.product.image%>">
For each product in group... Display the prodcts image property...
But i get error::::: > 30| <img class="img-responsive"src="<%=group.product.image%>">
Cannot read property 'image' of undefined
How is .image undefined if my console is showing group.product clearly? How do i access it?
Feel free to ask for more info!! PLease help!

HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:48
so without add the one you'll never have a chance of generating a number that is the maximum
Tina
@tsolar74
Apr 10 2017 03:49
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
{
"artist": "Pink Floyd",
"title": "The Wall",
"release_year": 1979,
"formats": [
"CS",
"LP",
"8T",
"CD",
"MP3"
],
}
];
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:49
@tsolar74 do you understand what the object is in the array?
ok yes like that @tsolar74
but what seperates elements in arrays?
Ryan Haire
@RyaanH
Apr 10 2017 03:51
@HeebieGeeBee outside of the brackets why does it add min
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:51
well its a comma, you need to separate the two objects with a comma
@RyaanH so it will be at least the minimum
Ryan Haire
@RyaanH
Apr 10 2017 03:52
ahh ok
Joseph
@revisualize
Apr 10 2017 03:52
@tsolar74 [ { . . . } , { . . . } ]
@tsolar74 commas , seperate array elements
HeebieGeeBee
@HeebieGeeBee
Apr 10 2017 03:52
@tsolar74 also you shouldnt really put a comma after the last property in an object
RachelDoren
@RachelDoren
Apr 10 2017 03:55

hey guys i have a question...
how is this missing a semicolon? I am confused :(
``` function caseInSwitch(val) {
var answer = "";
// Only change code below this line

case 1:
val = "alpha";
break;

case 2:
val = "beta";
break;

case 3:
val = "gamma";
break;

case 4:
val = "delta";

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

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

```

Sanford Banks
@sbanks77
Apr 10 2017 03:56

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "The was not but __ down the street";
// Your code below this line
myNoun = dog;
myAdjective = big;
myVerb = ran;
myAdverb = quickly;
// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("myNoun", "myAdjective", "myVerb", "myAdverb");

can anyone help me withe mad lib challenege
???
Treylerp
@Treylerp
Apr 10 2017 03:57

function testGreaterOrEqual(val) {
if (val) { // Change this line
return "20 or Over";
}

if (val) { // Change this line
return "10 or Over";
}
return "9 or Under";
}

// Change this value to test
testGreaterOrEqual(10);
So its telling me to put a >= but im not sure where im meant to put it

RachelDoren
@RachelDoren
Apr 10 2017 03:59
@Treylerp Maybe it's...
if (val >= 20)
return "20 or Over";
{ } with brackets
Treylerp
@Treylerp
Apr 10 2017 04:00
@RachelDoren Thanks
CamperBot
@camperbot
Apr 10 2017 04:00
treylerp sends brownie points to @racheldoren :sparkles: :thumbsup: :sparkles:
:cookie: 192 | @racheldoren |http://www.freecodecamp.com/racheldoren
RachelDoren
@RachelDoren
Apr 10 2017 04:01
:D
Tina
@tsolar74
Apr 10 2017 04:02
@HeebieGeeBee commas
Ryan Haire
@RyaanH
Apr 10 2017 04:03
@RachelDoren your code didn't have a switch loop in it
@sbanks77 use the arguments of the function in the sentence you created
RachelDoren
@RachelDoren
Apr 10 2017 04:07
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
} switch (foo) {

  case 1:
  val = "alpha";
  break;

  case 2:
  val = "beta";
  break;

  case 3:
  val = "gamma";
  break;

  case 4:
  val = "delta";


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

// Change this value to test
caseInSwitch(4);
so I added a switch (I also tried switch (num) and switch (val) but it's still wrong? :(
@RyaanH
Ryan Haire
@RyaanH
Apr 10 2017 04:10
you closed your function
RachelDoren
@RachelDoren
Apr 10 2017 04:11
okay that fixed one of the problems. haha I'm stumped o___o
Ryan Haire
@RyaanH
Apr 10 2017 04:11
@RachelDoren your switch has to take the argument val to evaluate the cases
RachelDoren
@RachelDoren
Apr 10 2017 04:11
is val = "answer"; correct?
Ryan Haire
@RyaanH
Apr 10 2017 04:12
return val
i can explain how it all works if you want
RachelDoren
@RachelDoren
Apr 10 2017 04:12
I GOTS IT THANK YOU
heroiczero
@heroiczero
Apr 10 2017 04:13
@RachelDoren should be
switch (val){}
RachelDoren
@RachelDoren
Apr 10 2017 04:13
but why on top does it say
var answer = "";
what does that part mean?
Ryan Haire
@RyaanH
Apr 10 2017 04:13
did you add that?
RachelDoren
@RachelDoren
Apr 10 2017 04:13
no that came with the page
heroiczero
@heroiczero
Apr 10 2017 04:13
@RachelDoren and need to do answer=""; not val=
Ryan Haire
@RyaanH
Apr 10 2017 04:14
^
but both works
you took the value of val and changed it to the string
RachelDoren
@RachelDoren
Apr 10 2017 04:14
also thanks @RyaanH
@heroiczero answer=""; was wrong as well
CamperBot
@camperbot
Apr 10 2017 04:14
racheldoren sends brownie points to @ryaanh and @heroiczero :sparkles: :thumbsup: :sparkles:
:warning: @ryaanh's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:star2: 1113 | @heroiczero |http://www.freecodecamp.com/heroiczero
Augusto
@hackedWifi
Apr 10 2017 04:14
@RachelDoren why are you return answer; answer is empty
RachelDoren
@RachelDoren
Apr 10 2017 04:16
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
 switch (val) {

  case 1:
  return "alpha";
  break;

  case 2:
  return "beta";
  break;

  case 3:
  return "gamma";
  break;

  case 4:
  return "delta";

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

// Change this value to test
caseInSwitch(4);
heroiczero
@heroiczero
Apr 10 2017 04:16
@RachelDoren
 switch (val) {

  case 1:
  answer= "alpha";
  break;

  case 2:
  answer= "beta";
  break;

  case 3:
  answer= "gamma";
  break;

  case 4:
  answer= "delta";
}
Ryan Haire
@RyaanH
Apr 10 2017 04:16
@RachelDoren np, they mean in your switch statement after the cases you used val = ""; , the challenge gave you the variable answer so you can assign it like answer = "alpha";
RachelDoren
@RachelDoren
Apr 10 2017 04:16
it worked this way ^ but it also says "unreachable 'break' after 'return'" even though freecodecamp approved me to continue on to the next challenge
oh i get it. variable doesnt have to be repeated
:D thanks again
Ryan Haire
@RyaanH
Apr 10 2017 04:17
yea
no problem
then you return answer; outside the switch loop but still in the function so it returns the new value of answer from the loop cases
RachelDoren
@RachelDoren
Apr 10 2017 04:20
okay thanks @heroiczero that worked too! :D
CamperBot
@camperbot
Apr 10 2017 04:20
racheldoren sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:warning: racheldoren already gave heroiczero points
Cody Smith
@TheCodingSmith
Apr 10 2017 04:24
Joseph
@revisualize
Apr 10 2017 04:25

@TheCodingSmith Gist by revisualize / FreeCodeCamp - Profile Lookup.js

We have an array of objects representing different people in our contacts lists.
Example:var contacts = [ { ... } , { ... } , { ... } , { ... } ];

@TheCodingSmith What is the current state of your function?
juiiii
@juiiii
Apr 10 2017 04:28

Return true if the given string is a palindrome. Otherwise, return false.

A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.

Note
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.

We'll pass strings with varying formats, such as "racecar", "RaceCar", and "race CAR" among others.

We'll also pass strings with special symbols, such as "2A33a2", "2A3 3a2", and "2_A33#A2".

function palindrome(str) {
  // Good luck!
  str.toLowerCase();
  re = / \_\$\&\+\,\:\;\=\?\@\#\|\'\.\-\^\*\(\)\%\!\\/g;
  str.replace(re, "");
  //str.replace(/[^\w\s]/gi, "");
  string = str.split("");
  /*for(i=0;i<string.length;i++){
    if(string[i]===" " || string[i]==="," || string[i]==="_" || string[i]==="/" || string[i]==="\\" || string[i]==="|"){
      str.replace(string[i], "");
    }
  }*/
  console.log(string);
  if(string.join("")===string.reverse().join("")){
  return true;
  }else return false;
}
palindrome("A man, a plan, a canal. Panama");

How do i eliminate special characters here... The method I've tried doesn't seem to work

Cody Smith
@TheCodingSmith
Apr 10 2017 04:28
I think it should include a for loop and som if statements. But I'm not really sure how to arrange this loop.
//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
 firstName = contacts.firstName;

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

 if (firstName && prop) {
     return prop;
   }
 }


// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Ryan Haire
@RyaanH
Apr 10 2017 04:28
@TheCodingSmith that challenge took me a couple days, you just gotta think about it in different ways, making the function word by word helped me, you could write it out on paper and doodle it out
Joseph
@revisualize
Apr 10 2017 04:29
@TheCodingSmith You're not accessing data correctly.
@TheCodingSmith First off.. firstName = contacts.firstName; Don't do this. You do not want to overwrite the firstName parameter.
@TheCodingSmith also, contacts.firstName is not how you access an array element.
Ryan Haire
@RyaanH
Apr 10 2017 04:30
@TheCodingSmith return to previous lessons of objects, arrays, and looping. Reset the code and do the lessons again so you can build up memory
Cody Smith
@TheCodingSmith
Apr 10 2017 04:31
@revisualize Thank you. I was pretty sure I was doing that wrong.
CamperBot
@camperbot
Apr 10 2017 04:31
thecodingsmith sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3706 | @revisualize |http://www.freecodecamp.com/revisualize
Claudio Restifo
@Marmiz
Apr 10 2017 04:33

@TheCodingSmith If I may, I suggest you to do a quick console.log(contacts) to see how's the data structure. You'll see that contacts looks like:

[Object, Object, Object ..]

Sometimes visualizing the data helps making clearer how to acces it

Cody Smith
@TheCodingSmith
Apr 10 2017 04:33
@RyaanH I kind of did that. I blew threw them pretty quickly, they were all pretty simple compared to this one.
Francis Ngo
@francisngo
Apr 10 2017 04:33
@HeebieGeeBee i dont quite get why to not initiate it with anything
and when i find the longest string in word, i do have to initiate '';
Ryan Haire
@RyaanH
Apr 10 2017 04:36
@TheCodingSmith ok. An object is inside of {} and when it's in an array you can access objects with index like contacts[0], how would you iterate through all of the objects to find the right one with value of firstName
same idea with prop too
Mychal Simka
@msimka
Apr 10 2017 04:39
@TheCodingSmith The "=" operator, unlike mathematics and physics, does not affect the objects on either side of itself. What it does is make the left side equal to the right side, but does nothing to the right side.
i.e. x = y is not the same as y = x
Vicky Lai
@vickylai
Apr 10 2017 04:44
I don't seem to be able to get sunriseTime with this. Am I missing a resource link or something? (Converting UNIX time to readable time) http://codepen.io/vickylaixy/pen/jBXgeR
Jessica Hernandez
@GirlCode87
Apr 10 2017 05:15

function repeatStringNumTimes(str, num) {
// repeat after me
var a = [];

return str;
}

repeatStringNumTimes("abc", 3);

i dont get it
challenge repeat a string
devpaaji
@devpaaji
Apr 10 2017 05:15
@GirlCode87
check the PM and links I shared
Mychal Simka
@msimka
Apr 10 2017 05:16
@GirlCode87 what don't you get
devpaaji
@devpaaji
Apr 10 2017 05:16
@GirlCode87 if the str = "hello" it should appear as "hellohellohello"
Vicky Lai
@vickylai
Apr 10 2017 05:17
@jtan I saw that before but couldn't get it to work. Maybe I'll stop trying to do it as a one liner for now...
Johnny
@jtan3
Apr 10 2017 05:17
@vickylaixy var d = new Date(sunrise time) and return var d
Jessica Hernandez
@GirlCode87
Apr 10 2017 05:19
String.prototype.repeat() does this have to do with repeating it? im trying to reference to the guide it gives me
devpaaji
@devpaaji
Apr 10 2017 05:20
@GirlCode87 correct that will do
Markus Kiili
@Masd925
Apr 10 2017 05:24
@GirlCode87 You learn the most if you solve it using a loop of some kind.
@msimka Actually assignment doesn't imply equality, so it would be better to talk about assignment rather that setting equal to.
Johnny
@jtan3
Apr 10 2017 05:27
@vickylaixy did you get it to work?
Vicky Lai
@vickylai
Apr 10 2017 05:28
@jtan3 Working on it..
Mychal Simka
@msimka
Apr 10 2017 05:30
@Masd925 I was trying to use the most basic terminology. In all but rare cases setEqualTo can be replaced with assignTo
Of course when dealing with Booleans you'll have issues, but I think that can be learned at a later time.
Markus Kiili
@Masd925
Apr 10 2017 05:32
@msimka I just mean that such (math) term is not used in programming and there is a reason for it.
Mychal Simka
@msimka
Apr 10 2017 05:34
@Masd925 I see your point. = should not be seen as "equal to"
Markus Kiili
@Masd925
Apr 10 2017 05:34
@msimka Yes. Assignment just copies the value. Nothing really to do with equality.
Mychal Simka
@msimka
Apr 10 2017 05:36
@Masd925 Well that's my point. Setting value to is making a equal to b. So there IS a connection but it performs an action, rather than just stating a fact, and therefore is best disconnected from its application to pure mathematics at least
JDW
@jd-wheaton
Apr 10 2017 05:37
Evening peoples
Vicky Lai
@vickylai
Apr 10 2017 05:38
@jtan3 Think I got it working (it
's producing a time anyway)
Now to figure out timezones..
Markus Kiili
@Masd925
Apr 10 2017 05:39
@msimka In programming, a copy of a value is not necessarily equal to the original. Most languages have such values.
That is why assignment is not setting equal to.
Calvin Wat
@watcalvin
Apr 10 2017 05:40
I was having trouble understanding the escape sequences and newline/carriage return
Thanks for anyone who can help
Johnny
@jtan3
Apr 10 2017 05:41
@vickylaixy https://darksky.net/dev/docs/faq i'm guessing you read this?
Daniel
@OldRainBlaze
Apr 10 2017 05:41
can anyone see where i went wrong

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

function checkObj(checkProp) {
// Your Code Here

if (myObj.hasOwnProperty("checkProp")=== true);
{return myObj[checkProp];}
return "Not Found";}

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

Vicky Lai
@vickylai
Apr 10 2017 05:42
@jtan3 :thumbsup: Thanks
CamperBot
@camperbot
Apr 10 2017 05:42
vickylaixy sends brownie points to @jtan3 :sparkles: :thumbsup: :sparkles:
:cookie: 365 | @jtan3 |http://www.freecodecamp.com/jtan3
Markus Kiili
@Masd925
Apr 10 2017 05:42
@OldRainBlaze Think about whether you should use checkProp or "checkProp".
Also this semicolon ruins your if logic true);
It terminates the if block.
devpaaji
@devpaaji
Apr 10 2017 05:44
JS does not have block scoping
Daniel
@OldRainBlaze
Apr 10 2017 05:44
thanks heaps @Masd925
CamperBot
@camperbot
Apr 10 2017 05:44
oldrainblaze sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3818 | @masd925 |http://www.freecodecamp.com/masd925
devpaaji
@devpaaji
Apr 10 2017 05:44
so a var declared inside an if block can be accessed outside it
@OldRainBlaze
Mychal Simka
@msimka
Apr 10 2017 05:45
@Masd925 Actually setEqualTo is a reference of value, which is also true for assigments. The only time it doesn't apply is in rare cases where object values won't equal each other even if they appear to, and in some Booleans
Daniel
@OldRainBlaze
Apr 10 2017 05:45
thanks too @devpaaji
CamperBot
@camperbot
Apr 10 2017 05:45
oldrainblaze sends brownie points to @devpaaji :sparkles: :thumbsup: :sparkles:
:cookie: 228 | @devpaaji |http://www.freecodecamp.com/devpaaji
Mychal Simka
@msimka
Apr 10 2017 05:45
@Masd925 Otherwise you would be deleting y when you declare x = y. y still exists, therefore it is a reference
Markus Kiili
@Masd925
Apr 10 2017 05:46
@msimka What do you mean by setEqualTo ?
Mychal Simka
@msimka
Apr 10 2017 05:46
@Masd925 I mean a user defined function that sets a variable equal to another variable
devpaaji
@devpaaji
Apr 10 2017 05:47
var obj = {
"name":  "jay",
"add": "35 ABC Street"
}
@msimka
var refObj = obj;
Markus Kiili
@Masd925
Apr 10 2017 05:47
@msimka Are you talking about assignment or something else?
devpaaji
@devpaaji
Apr 10 2017 05:48
any change made to obj will be reflected to refObj
:(
Mychal Simka
@msimka
Apr 10 2017 05:48
@devpaaji OK I see your point. Numerical values don't change but variables can
devpaaji
@devpaaji
Apr 10 2017 05:49
But when you do this
Mychal Simka
@msimka
Apr 10 2017 05:49
OK I concede. It is entirely different
devpaaji
@devpaaji
Apr 10 2017 05:49
var name = "boy";
Mychal Simka
@msimka
Apr 10 2017 05:49
@devpaaji YES I see your point haha
devpaaji
@devpaaji
Apr 10 2017 05:49
var name2 = "toy";
Markus Kiili
@Masd925
Apr 10 2017 05:49
@msimka Objects and Booleans are not the problem in JS. Assigning them always implies equality.
devpaaji
@devpaaji
Apr 10 2017 05:50
name = "new Boy";
but when you console.log() value of name2 it will not be updated
Markus Kiili
@Masd925
Apr 10 2017 05:50
@msimka But here is a better example:

var a = NaN;
var b=a;
b===a; // false
Mychal Simka
@msimka
Apr 10 2017 05:50
@Masd925 In objects, if you test for equality between values even if they look the same, they return false
devpaaji
@devpaaji
Apr 10 2017 05:51
obj1 and obj2 even have same values
Josh
@jknapp25
Apr 10 2017 05:51
Hey gang, I can't seem to get the lookupProfile function to work. Can someone help me out? This is what I have for my function...
Mychal Simka
@msimka
Apr 10 2017 05:51
@Masd925 And that was my point with Booleans specifically truthy vs falsy values
Josh
@jknapp25
Apr 10 2017 05:51

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

// Only change code above this line
}

devpaaji
@devpaaji
Apr 10 2017 05:51
will point to diff memory
so return false
when you do obj1===obj2
Mychal Simka
@msimka
Apr 10 2017 05:52
@devpaaji That was my mistake. Assignments are not hard-coded, but just pointers to memory locations
Markus Kiili
@Masd925
Apr 10 2017 05:52
@msimka Equality with objects compares object identity (memory location). Assigning just copies the reference and it is always equal to the original. It has nothing to do with content (what a literal looks like).
Mychal Simka
@msimka
Apr 10 2017 05:53
Man I swear half of the questions in this forum are about the profileLookup challenge
Josh
@jknapp25
Apr 10 2017 05:53
Haha, it's killin me man
Mychal Simka
@msimka
Apr 10 2017 05:54
@Masd925 Right, in that way assigments and object equality comparisons are similar
devpaaji
@devpaaji
Apr 10 2017 05:54
var obj = {
"name":  "jay",
"add": "35 ABC Street"
}


var obj1 = {
"name":  "jay",
"add": "35 ABC Street"
}
@msimka they are different even though have same values
Markus Kiili
@Masd925
Apr 10 2017 05:54
@msimka Yes, for some values assignment implies equality, but not for all values.
Mychal Simka
@msimka
Apr 10 2017 05:54
@devpaaji obj.name !== obj1.name
I know
devpaaji
@devpaaji
Apr 10 2017 05:55
but when you do var obj2 = obj1
it copies a reference
and retains
this is also a imp JS interview question
Mychal Simka
@msimka
Apr 10 2017 05:56
@Masd925 Actually no assignment implies sustained equality
because the assignor variable can change unless it's a const
Markus Kiili
@Masd925
Apr 10 2017 05:57
@msimka Variables are not assigned. You are messing things up. Values are assigned to variables.
Mychal Simka
@msimka
Apr 10 2017 05:58
@Masd925 That's semantics. Of course the variable itself, which occupies a specific memory location, can't be assigned
Markus Kiili
@Masd925
Apr 10 2017 05:59
@msimka I was talking about whether the value that is assigned is equal to the original. Nothing to do with what happens to some variable later.
Mychal Simka
@msimka
Apr 10 2017 06:00
@Masd925 explain
Markus Kiili
@Masd925
Apr 10 2017 06:01
@msimka If we have a value on a variable and we make a copy of it by assigning, it is usually equal to the original:
var a = 5;
var b=a;
b===a; // true
But not always:
var a = NaN;
var b=a;
b===a; // false
Mychal Simka
@msimka
Apr 10 2017 06:03
@Masd925 There you are mistaken, because NaN will never return true when using an equality comparison
Conor Murphy
@cmurphy580
Apr 10 2017 06:03
How do i check for duplicates in an array ?
Mychal Simka
@msimka
Apr 10 2017 06:03
NaN === NaN is also false
devpaaji
@devpaaji
Apr 10 2017 06:04
@cmurphy580
arr[i] === arr[i+1]
Markus Kiili
@Masd925
Apr 10 2017 06:04
@msimka Where I am mistaken? The fact that NaN is not equal to anything proves that assignment doesn't imply equality.
Conor Murphy
@cmurphy580
Apr 10 2017 06:04
@devpaaji i think that compares values that are next to one another>
devpaaji
@devpaaji
Apr 10 2017 06:05
@cmurphy580 correct so that can also give you an idea if the values are same
that means they are duplicates
another way of doing is
using indexOf and lastIndexOf
var arr = [1, 2, 3, 3, 3, 4, 5, 7, 9];
Mychal Simka
@msimka
Apr 10 2017 06:06
@Masd925 because NaN is something like undefined. It doesn't say much about what it is, but rather what it is not
When you say a = NaN you are not really defining its value
Markus Kiili
@Masd925
Apr 10 2017 06:07
@msimka NaN and undefined are values in JS (of types Number and Undefined). Don't just wave your hands.
Conor Murphy
@cmurphy580
Apr 10 2017 06:08
@devpaaji alright i'll work with the indexof method thanks
CamperBot
@camperbot
Apr 10 2017 06:08
cmurphy580 sends brownie points to @devpaaji :sparkles: :thumbsup: :sparkles:
:cookie: 229 | @devpaaji |http://www.freecodecamp.com/devpaaji
Mychal Simka
@msimka
Apr 10 2017 06:09
@Masd925 They are not actually values just like arguments is not actually an array
Although they occupy the same functionality in most way
ways
Markus Kiili
@Masd925
Apr 10 2017 06:11
@msimka Open the ECMAScript standard at chapter 8. Types or look at MDN article about JS types and values before arguing here about what values JS has, when you clearly don't know what you are talking about.
webennes
@webennes
Apr 10 2017 06:11

hey, friends what's wrong here ?
Instructions: Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.

function nextInLine(arr, item) {
// Your code here
arr.push(item); // add the number to the and of the array
item = arr.shift(); // remove the first element of the array

return item; // Change this line
}

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

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

devpaaji
@devpaaji
Apr 10 2017 06:13
var str = "Hello planet earth, you are a great planet.";
var n = str.lastIndexOf("planet"); // 36

var str = "Hello planet earth, you are a great planet.";
var n = str.indexOf("planet"); //  6
@cmurphy580
Markus Kiili
@Masd925
Apr 10 2017 06:13
@msimka From chapter 10.6 you can read what arguments object is. Then you don't have to say that it is something like something else.
webennes
@webennes
Apr 10 2017 06:13
ok, was bug...
devpaaji
@devpaaji
Apr 10 2017 06:13
when indexOf and lastIndex of are not same
that means there are duplicates
if they are same
that means only single occurrence is there
You can try this using map() or filter() as well
try 2-3 diff ways of doing a problem
Conor Murphy
@cmurphy580
Apr 10 2017 06:14
@devpaaji sweet thanks again for the help
CamperBot
@camperbot
Apr 10 2017 06:14
:warning: cmurphy580 already gave devpaaji points
cmurphy580 sends brownie points to @devpaaji :sparkles: :thumbsup: :sparkles:
Mychal Simka
@msimka
Apr 10 2017 06:15
@Masd925 So this is a test of who is more knowledgeable now. Well I don't really care to compete, but clearly you don't understand the way computers work IN GENERAL
Markus Kiili
@Masd925
Apr 10 2017 06:16
@msimka No, I was just commenting about your lack of knowledge on JS values. You could read this article https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
Coy Sanders
@coymeetsworld
Apr 10 2017 06:16
don't worry @Masd925, I don't know how computers work in general either :)
Mychal Simka
@msimka
Apr 10 2017 06:16
Oh boy, here we go lol
kirbyedy
@kirbyedy
Apr 10 2017 06:17
jesus... is this still an ongoing story ? Am I stuck in the groundhog day or what ?!
Mychal Simka
@msimka
Apr 10 2017 06:17
The guy who doesn't even know how loops work on a fundamental level
Coy Sanders
@coymeetsworld
Apr 10 2017 06:17
yes, I do not know what a loop is
Mychal Simka
@msimka
Apr 10 2017 06:17
Yes I'm sure your logic boards love your loops haha
Markus Kiili
@Masd925
Apr 10 2017 06:17
@coymeetsworld Good morning.
Coy Sanders
@coymeetsworld
Apr 10 2017 06:18
good morning, well night for me @Masd925
Mychal Simka
@msimka
Apr 10 2017 06:18
Try putting a for loop through a series of nand gates
Coy Sanders
@coymeetsworld
Apr 10 2017 06:20
Have to go find my nexys board but I'll be sure to put that in my todo list
Markus Kiili
@Masd925
Apr 10 2017 06:22
@coymeetsworld I will read up on COMPUTERS IN GENERAL. Seems like an important topic here.
Coy Sanders
@coymeetsworld
Apr 10 2017 06:24
very, important for all web devs to know how things work at the machine level. Just wish there were levels of abstraction we could rely on
Mychal Simka
@msimka
Apr 10 2017 06:24
@coymeetsworld yeah keep working that low level IT job what is it 10 years+ now? I'll do my thing, writing/directing/producing my 13th animated film with national distribution, hopefully I can make that $60K nut to keep up with you
Coy Sanders
@coymeetsworld
Apr 10 2017 06:25
lol now whose using the ad hominem arguments?
Mychal Simka
@msimka
Apr 10 2017 06:26
I'm here to learn. I've been coding for less than a month. Why would someone who's been coding for 10 years be here. Either you're Forest Gump or Gandhi or someone with a serious big fish small pond complex
Coy Sanders
@coymeetsworld
Apr 10 2017 06:26
you've coded less than a month but you feel comfortable telling people who worked in the industry they don't know anything?
rekcik
@rekcik
Apr 10 2017 06:27
When internet warriors clash
Mychal Simka
@msimka
Apr 10 2017 06:27
@coymeetsworld When someone is wrong they
When someone is wrong, they're wrong no matter how long they've been doing something
kirbyedy
@kirbyedy
Apr 10 2017 06:28
@msimka ok, you are right, you win, can you now leave please
please
people come here for help
Coy Sanders
@coymeetsworld
Apr 10 2017 06:29
yes, but how do you know when someone is wrong? You're basing that off of weeks of experience? Don't you think that is just a bit arrogant?
rekcik
@rekcik
Apr 10 2017 06:29
😴
Coy Sanders
@coymeetsworld
Apr 10 2017 06:29
Can I go direct animated films for a month and rebut everything people say in Hollywood?
Al
@fingrlicknchickn
Apr 10 2017 06:30
lol drama in the gitter help chat, real nice
rekcik
@rekcik
Apr 10 2017 06:30
LOL
Mychal Simka
@msimka
Apr 10 2017 06:30
@coymeetsworld No. I said that for loops are functions which call themselves at a fundamental level, and it's true. You argued that since I've been coding for less than a month that I am wrong.
Coy Sanders
@coymeetsworld
Apr 10 2017 06:33
I merely pointed that fact out to suggest you may not know what you're talking about
Mychal Simka
@msimka
Apr 10 2017 06:33
If I said that hand-drawn squash and stretch is impossible in CGI, I would be wrong even though 99% of animators at Pixar would say it's true.
The only way a loop works is by directing the circuit back on itself, and therefore it is a self-calling function.
Coy Sanders
@coymeetsworld
Apr 10 2017 06:36
no
rekcik
@rekcik
Apr 10 2017 06:36
????
Coy Sanders
@coymeetsworld
Apr 10 2017 06:36
just, no
Yuval Blass
@YuvalBlass
Apr 10 2017 06:36
What is the problem with my code (Find the Longest Word in a String)?
function findLongestWord(str) {
  var first = str.split(' ');
  var zero = 0;
  var len;
  for ( var i = 0; i < first.length; i++) {
    len = first(i).length;
    if (len > zero) {
      len == zero;
    }
  } 
  return lengthI;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Markus Kiili
@Masd925
Apr 10 2017 06:37
@YuvalBlass first[i] is the looped word, not first(i)
Coy Sanders
@coymeetsworld
Apr 10 2017 06:37
@YuvalBlass also your if statement needs work, you just keep comparing the length to 0
and there is no lengthI variable
Yuval Blass
@YuvalBlass
Apr 10 2017 06:38

So why this:

function findLongestWord(str) {
  var first = str.split(' ');
  var zero = 0;
  var len;
  for ( var i = 0; i < first.length; i++) {
    len = first[i].length;
    if (len > zero) {
      len == zero;
    }
  } 
  return len;
}

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

Return 3?

Coy Sanders
@coymeetsworld
Apr 10 2017 06:39
because "dog" is 3 characters long
wait is that 0?
Yuval Blass
@YuvalBlass
Apr 10 2017 06:40
because "dog" is 3 characters long
But I'm searching for the longest word...
devpaaji
@devpaaji
Apr 10 2017 06:40
console.log(typeof NaN === "number"); // logs "true"
Markus Kiili
@Masd925
Apr 10 2017 06:40
@YuvalBlass Inside the if block you should assign, not compare.
Joseph
@revisualize
Apr 10 2017 06:41
@YuvalBlass == is comparison.. Not assignment.
devpaaji
@devpaaji
Apr 10 2017 06:41
console.log(NaN === NaN); // logs "false"
Coy Sanders
@coymeetsworld
Apr 10 2017 06:41
len == zero; yeah thats wrong too
just completely missed that
devpaaji
@devpaaji
Apr 10 2017 06:41
@Masd925
Joseph
@revisualize
Apr 10 2017 06:41
@coymeetsworld Beat you!
@coymeetsworld :P
Coy Sanders
@coymeetsworld
Apr 10 2017 06:41
ugh
Markus Kiili
@Masd925
Apr 10 2017 06:41
@devpaaji Yeah, it is an error number.
Joseph
@revisualize
Apr 10 2017 06:41
I'm actually quite slow sometimes.
devpaaji
@devpaaji
Apr 10 2017 06:41
the number type has three symbolic values: +Infinity, -Infinity, and NaN (not-a-number).
when you do type of NaN === "number" is true
rekcik
@rekcik
Apr 10 2017 06:42
Where's the "loops are functions guy" I wanna know what he thinks
devpaaji
@devpaaji
Apr 10 2017 06:42
is it because of the above statement
Coy Sanders
@coymeetsworld
Apr 10 2017 06:42
plz no
Joseph
@revisualize
Apr 10 2017 06:42
Loops are functions?
rekcik
@rekcik
Apr 10 2017 06:42
You missed it
Joseph
@revisualize
Apr 10 2017 06:42
WAT!?
rekcik
@rekcik
Apr 10 2017 06:42
LOL
Yuval Blass
@YuvalBlass
Apr 10 2017 06:42

@YuvalBlass == is comparison.. Not assignment.
```
function findLongestWord(str) {
var first = str.split(' ');
var zero = first[0];
var len;
for ( var i = 0; i < first.length; i++) {
len = first[i].length;
if (len > zero) {
len = zero;
}
}
return len;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
```
Why it still returns 3?

Coy Sanders
@coymeetsworld
Apr 10 2017 06:42
no no one missed anything
Augusto
@hackedWifi
Apr 10 2017 06:43
Can anyone explains something to me. I feel really dumb right now. Why does this code return 0
function factorialize(num) {
total = 1;
for(var i = 0 ; i <= num; i++){
total = total * i;
}
return total;
}
DMXGeo
@DMXGeo
Apr 10 2017 06:43
@YuvalBlass because len=first.[i].length should not be inside your for loop
Markus Kiili
@Masd925
Apr 10 2017 06:43
@devpaaji Those three are special values of type Number.
Joseph
@revisualize
Apr 10 2017 06:43
@YuvalBlass Have you tried visualizing your code execution?
Augusto
@hackedWifi
Apr 10 2017 06:43
If I change i to 2 it return the correct result
Coy Sanders
@coymeetsworld
Apr 10 2017 06:43
@hackedWifi probably on factorialize(0) is where you see that
HN
@haydennorthcott
Apr 10 2017 06:43
Computer says no:

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

  switch (val){
    case 1:
    case 2:
    case 3:
      answer = "low";
       break;
    case 4:
    case 5:
    case 6:
      answer = "Mid";
       break;
    case 7:
    case 8:
    case 9:
      answer = "High";
       break;  
  }

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

// Change this value to test
sequentialSizes(4);
Joseph
@revisualize
Apr 10 2017 06:44
@YuvalBlass var zero = first[0]; you should make that var zero = first[0].length;
Coy Sanders
@coymeetsworld
Apr 10 2017 06:44
@hackedWifi 0! is equal to 1
so you need to account for that one
Markus Kiili
@Masd925
Apr 10 2017 06:44
@revisualize You can also assign something to variables that are not values.
HN
@haydennorthcott
Apr 10 2017 06:44
I copied & pasted case 1,2, and 3 for the rest of the problem. When testing numbers 1,2 & 3 it works.
Joseph
@revisualize
Apr 10 2017 06:44
@YuvalBlass (len > zero) this is backwards?
Augusto
@hackedWifi
Apr 10 2017 06:45
@coymeetsworld not really it is with factorialize(5);
Coy Sanders
@coymeetsworld
Apr 10 2017 06:45
@YuvalBlass 2 things, you don't want to set zero to a String
Joseph
@revisualize
Apr 10 2017 06:45
@Masd925 Huh?
Coy Sanders
@coymeetsworld
Apr 10 2017 06:45
and when len > zero you don't want to set len
Markus Kiili
@Masd925
Apr 10 2017 06:45
@revisualize We learned a lot a while ago.
Mychal Simka
@msimka
Apr 10 2017 06:45
@hackedWifi zero times anything is zero
Coy Sanders
@coymeetsworld
Apr 10 2017 06:45
@hackedWifi oh i see the first loop starts at 0
your total will set to 0 so every number you multiply after with be just zero
Mychal Simka
@msimka
Apr 10 2017 06:46
@coymeetsworld like I said
rekcik
@rekcik
Apr 10 2017 06:46
;)
Joseph
@revisualize
Apr 10 2017 06:46
@Masd925 A function is a value. An object is a value and array is a value.
Coy Sanders
@coymeetsworld
Apr 10 2017 06:46
so you don't want to start i at 0, and also you need to account for 0! @hackedWifi
Joseph
@revisualize
Apr 10 2017 06:46
@Masd925 At least how I understand it.
Mostafa Hesham
@mhesham32
Apr 10 2017 06:47
what is wrong with that

function titleCase(str) {
  var C="";
  for(var i=0; i<str.lenght; i++){

  }

   C=str[i][0].toUpperCase.join('');
  return C;
}

titleCase("I'm a little tea pot");
Joseph
@revisualize
Apr 10 2017 06:47
@Masd925 I don't see values as just strings or numbers.
rekcik
@rekcik
Apr 10 2017 06:47
Spelling
Markus Kiili
@Masd925
Apr 10 2017 06:47
@revisualize Yeah, I was just quoting to the nice debate earlier ;)
Augusto
@hackedWifi
Apr 10 2017 06:48
@msimka Dang I feel really dumb. Thank you
CamperBot
@camperbot
Apr 10 2017 06:48
hackedwifi sends brownie points to @msimka :sparkles: :thumbsup: :sparkles:
:cookie: 313 | @msimka |http://www.freecodecamp.com/msimka
Mychal Simka
@msimka
Apr 10 2017 06:48
@mhesham32 you have your statements outside your loop
Joseph
@revisualize
Apr 10 2017 06:48
@Masd925 Hmmm...
devpaaji
@devpaaji
Apr 10 2017 06:48
console.log(NaN === NaN); // logs "false" why it logs false
@Masd925
does NaN mean any other data type which can be string, objects ?
Markus Kiili
@Masd925
Apr 10 2017 06:49
@revisualize Yes, variables hold values, either primitive values or references to objects.
Mychal Simka
@msimka
Apr 10 2017 06:49
@devpaaji because NaN doesn't assign a value in the usual way
Joseph
@revisualize
Apr 10 2017 06:49
@Masd925 Yeah.
devpaaji
@devpaaji
Apr 10 2017 06:49
var n = NaN;
Joseph
@revisualize
Apr 10 2017 06:49
@devpaaji NaN means not a number
devpaaji
@devpaaji
Apr 10 2017 06:50
so n can hold string, date or obj
Joseph
@revisualize
Apr 10 2017 06:50
NaN === NaN is false because the compiler doesn't know how NaN was derived.
Mychal Simka
@msimka
Apr 10 2017 06:50
@revisualize exactly, not because it is in a different memory location
Joseph
@revisualize
Apr 10 2017 06:51
The IEEE 754 spec for floating-point numbers (which is used by all languages for floating-point) says that NaNs are never equal.
Mostafa Hesham
@mhesham32
Apr 10 2017 06:51
well now what is its wrong

function titleCase(str) {
  var arr=str.split('');

  var C="";
  for(var i=0; i<arr.lenght; i++){
     C=str[i][0].toUpperCase.join('');

  }



  return C;
}

titleCase("I'm a little tea pot");
Markus Kiili
@Masd925
Apr 10 2017 06:52
@devpaaji The JS value NaN of type Number represents 9007199254740990 different not-a-number values of IEEE standard. That is why NaN is set not to be equal to any value, and NaN===NaN is false.
Mychal Simka
@msimka
Apr 10 2017 06:52
@revisualize because they are empty items in an array, not some mystical NaN object like some people here would like to believe
Joseph
@revisualize
Apr 10 2017 06:53
If you want to understand more about NaN you can read up on https://en.wikipedia.org/wiki/NaN and https://en.wikipedia.org/wiki/IEEE_floating_point
Markus Kiili
@Masd925
Apr 10 2017 06:53
or ECMAScript standard chapter 8.5 Number type
Mychal Simka
@msimka
Apr 10 2017 06:53
Sorry items is not the correct word: empty locations
Yuval Blass
@YuvalBlass
Apr 10 2017 06:54
@DMXGeo @revisualize @Masd925 @coymeetsworld Thanks you! I finally finished this challenge!
CamperBot
@camperbot
Apr 10 2017 06:54
yuvalblass sends brownie points to @dmxgeo and @revisualize and @masd925 and @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 3707 | @revisualize |http://www.freecodecamp.com/revisualize
:cookie: 240 | @dmxgeo |http://www.freecodecamp.com/dmxgeo
:star2: 2423 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
:star2: 3819 | @masd925 |http://www.freecodecamp.com/masd925
Coy Sanders
@coymeetsworld
Apr 10 2017 06:54
nice work @YuvalBlass
Joseph
@revisualize
Apr 10 2017 06:54
Woot I got a brownie just before the clock ticked over to midnight!
@devpaaji If you do var n = ... n can hold whatever the hell you want.
Except my hand.
n can't hold my hand.
I won't let it.
Our relationship hasn't gotten to that level yet.
First, n has to tell me how it really feels about our "relationship".
Yuval Blass
@YuvalBlass
Apr 10 2017 06:57
@coymeetsworld what the difference between var and let?
Joseph
@revisualize
Apr 10 2017 06:57
@YuvalBlass Scope
@YuvalBlass let is block scoped
@YuvalBlass funfunfunction has a good video about it.
@YuvalBlass Also
Feelthewind
@Feelthewind
Apr 10 2017 07:00

var re = /apples/gi;
var str = 'Apples are round, and apples are juicy.';
var newstr = str.replace(re, 'oranges');
console.log(newstr);

I don't know how to use a variable here in place of the string 'apples' like var fruit = 'apple' and var re = /fruit/gi;

Joseph
@revisualize
Apr 10 2017 07:02
@YuvalBlass var allows hoisting.
...
Okay. I need to get to bed.
:v:
Yuval Blass
@YuvalBlass
Apr 10 2017 07:04
@revisualize Thank you again. Now I understand it....
CamperBot
@camperbot
Apr 10 2017 07:04
:warning: yuvalblass already gave revisualize points
yuvalblass sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
Joseph
@revisualize
Apr 10 2017 07:04
:zzz: ... :sailboat: ... :zzz: ... :sailboat: :sunrise: ... :zzz: ... :sailboat: :tropical_fish: :sunrise: ... :zzz: ... :sailboat: :tropical_fish: :dolphin: :whale2: :sunrise: ... :zzz:
It's a new day!
Screw you @camperbot
GIVE ME MY POINT!
Siddartha.A
@asiddu
Apr 10 2017 07:05

function palindrome(str) {
// Good luck!
var str1 = str.split('#[a-zA-Z0-9]+#').reverse().join('');
if(str === str1){
return true;
}else{
return false;
}
}

palindrome("nope");
I want to check palindrome or not but this code works partially not allowing space and all please help me anyone

Joseph
@revisualize
Apr 10 2017 07:05
@asiddu You need to replace on both sides.
Siddartha.A
@asiddu
Apr 10 2017 07:05
What i am getting will you explain bit deeply @revisualize
Joseph
@revisualize
Apr 10 2017 07:06
@asiddu You also need to transform the case because Palindromes are case insensitive.
Siddartha.A
@asiddu
Apr 10 2017 07:06
Ok
Joseph
@revisualize
Apr 10 2017 07:06
@asiddu You're not changing str you need to remove all non-alphanumeric characters from str
Yuval Blass
@YuvalBlass
Apr 10 2017 07:07
@asiddu
var str1 = str;
str1 = str1.replace(/[^a-zA-Z0-9]/gi, '').toLowerCase();
Then you can:
str2 = str1.split('').reverse('').join('');
if (str1 === str2) {
return true;
} else {
return false;
}
DMXGeo
@DMXGeo
Apr 10 2017 07:08
function largestOfFour(arr) {

  var total = [3];
  total[0] = arr[0][0];
  total[1] = arr[1][0];
  total[2] = arr[2][0];
  total[3] = arr[3][0];

  for (var i = 0; i < 4; i++){
    if(arr[0][i] > total[0])
      total[0] = arr[0][i];

    if(arr[1][i] > total[1])
      total[1] = arr[1][i];

    if(arr[2][i] > total[2])
      total[2] = arr[2][i];

    if(arr[3][i] > total[3])
      total[3] = arr[3][i];
  }

  return total;

}

largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]);
I completed this challenge, but I needed a second opinion. Is this solution fine or is there technically a better/preferred way to do this? I feel as if my code is "janky," so to speak.
Mychal Simka
@msimka
Apr 10 2017 07:11
@DMXGeo You can accomplish the same thing with a nested for loop, using a second incremented variable (j)
DMXGeo
@DMXGeo
Apr 10 2017 07:12
Ohh okay, that would be cleaner. I will try it next time. Thank you @msimka
CamperBot
@camperbot
Apr 10 2017 07:12
dmxgeo sends brownie points to @msimka :sparkles: :thumbsup: :sparkles:
:cookie: 314 | @msimka |http://www.freecodecamp.com/msimka
Markus Kiili
@Masd925
Apr 10 2017 07:12
@DMXGeo You could also use array iterators and/or Math.max method.
Mychal Simka
@msimka
Apr 10 2017 07:17
@DMXGeo but as @Masd925 said, you would be better served using array iterators (forEach, map, every etc.) as they apply to asynchronous programming which is eventually what you'll want to be using 90% of the time
MoguBen
@mogu9628
Apr 10 2017 07:19
hi guys, anyone know how to do this "Stand in Line" module
Markus Kiili
@Masd925
Apr 10 2017 07:20
@mogu9628 Find out the two array methods you need and use them on arr and item.
Mychal Simka
@msimka
Apr 10 2017 07:20
@mogu9628 whats the prob
MoguBen
@mogu9628
Apr 10 2017 07:21
i dont understand what it want
Mychal Simka
@msimka
Apr 10 2017 07:22
@mogu9628 post your code and the challenge rules
challenge objective
MoguBen
@mogu9628
Apr 10 2017 07:22

In Computer Science a queue is an abstract Data Structure where items are kept in order. New items can be added at the back of the queue and old items are taken off from the front of the queue.

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

Markus Kiili
@Masd925
Apr 10 2017 07:22
@mogu9628 On earlier challenges you learned some array methods. You need to use two of them here. Read the description and review the earlier challenges.
MoguBen
@mogu9628
Apr 10 2017 07:23
using the push pop?
shift and unshift?
Markus Kiili
@Masd925
Apr 10 2017 07:23
@mogu9628 Two of those.
Mychal Simka
@msimka
Apr 10 2017 07:24
@mogu9628 push puts stuff at the end. Shift takes it off the front.
MoguBen
@mogu9628
Apr 10 2017 07:24
thanks
Mychal Simka
@msimka
Apr 10 2017 07:24
Anything that takes stuff off an array returns what it took off
Not the modified array
MoguBen
@mogu9628
Apr 10 2017 07:25
ok, let me try first
Gilbert
@gilbertp97
Apr 10 2017 07:27
hello i have a question
soo the parameters of a function... are they considered variaables also or something similar?
like this..
function wordBlanks(myNoun, myAdjective, m
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
Markus Kiili
@Masd925
Apr 10 2017 07:29
@gilbertp97 When the function call is executed, those parameters become variables on the execution context, and there they hold the passed arguments. So you can use them like variables in the function code.
In the code they are just part of the function declaration.
devpaaji
@devpaaji
Apr 10 2017 07:29
@gilbertp97
Mychal Simka
@msimka
Apr 10 2017 07:30
@gilbertp97 All 3 in different contexts. They are arguments and parameters in that they are what you pass to the function, and they are variables in that you call them inside the function
Marco Galizzi
@Tezenn
Apr 10 2017 07:30
hello everyone, on my wikipedia viewer if i do multiple research and i click the results it opens not only the current result but also all the old ones.
success: function(data){

        $("#output1").html("<h3>" +data[1][0] +"</h3></br><h4>"+data[2][0]+"</h4>");
        $("#output1").on("click", function(){
          window.open(data[3][0])
        });
        if (data[1][1] !== undefined){
        $("#output2").html("<h3>" +data[1][1] +"</h3></br><h4>"+data[2][1]+"</h4>");
        $("#output2").on("click", function(){
          window.open(data[3][1])
        });
devpaaji
@devpaaji
Apr 10 2017 07:30
note that any function call three most important attrs
paramters as local vars
context of this
Gilbert
@gilbertp97
Apr 10 2017 07:30
ok i just want to understand it fully
devpaaji
@devpaaji
Apr 10 2017 07:30
arguements
Gilbert
@gilbertp97
Apr 10 2017 07:30
soo if im calling a function like this```
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line

result = myAdjective+ " " + myNoun+ " " + myVerb+ " " + myAdverb;
  // Your code above this line
  return result;
}
devpaaji
@devpaaji
Apr 10 2017 07:31
this comes packed with every function you call
Gilbert
@gilbertp97
Apr 10 2017 07:31
they are considered variables correct?
devpaaji
@devpaaji
Apr 10 2017 07:31
provided params are also passed
@gilbertp97 yes
Gilbert
@gilbertp97
Apr 10 2017 07:31
wordBlanks("dog", "big", "ran", "quickly");
devpaaji
@devpaaji
Apr 10 2017 07:31
four
Gilbert
@gilbertp97
Apr 10 2017 07:31
i used those as strings for those variables
i want to understand it fully so i learn better ;D
devpaaji
@devpaaji
Apr 10 2017 07:32
@gilbertp97 you are assing the values to those vars when calling
wordBlanks("dog", "big", "ran", "quickly");
Gilbert
@gilbertp97
Apr 10 2017 07:32
ok @devpaaji
thank u
Markus Kiili
@Masd925
Apr 10 2017 07:33
@gilbertp97 On the code parameters are just part of the function declaration. When such function is called, the engine makes an execution context where the function code is run and there it makes variables from those parameters.
In the execution context, parameters live in the same variable environment as any local variables.
Gilbert
@gilbertp97
Apr 10 2017 07:34
soo the brackets next to a function... is that what you call a local scope?
and outside of it is global scope?? im trying to get better
Mychal Simka
@msimka
Apr 10 2017 07:35
@gilbertp97 No, local scope is everything after the declaration of the function and before the end crackets
brackets
Dylan Ler
@dylanler
Apr 10 2017 07:35
Facing some problems here

function mutation(arr) {
  var temp = arr;
  temp[0]=temp[0].split("").sort().join("").toLowerCase();
  temp[1]=temp[1].split("").sort().join("").toLowerCase();

  if((temp[0].indexOf(temp[1]) !== -1) || (temp[1].indexOf(temp[0]) !== -1))
    return true;
  else 
    return false;
}

mutation(["hello", "hey"]);
Gilbert
@gilbertp97
Apr 10 2017 07:35
so everything within the brackets is considered the global scope?
Dylan Ler
@dylanler
Apr 10 2017 07:35
I need to check if a word contains the other word
Mychal Simka
@msimka
Apr 10 2017 07:36
<global> function foo(local) {scope} <global>
MoguBen
@mogu9628
Apr 10 2017 07:36
guys i have no idea how to code it
anyone can help here
@msimka
Mychal Simka
@msimka
Apr 10 2017 07:37
@mogu9628 Try to break it up into mini-tasks
@mogu9628 First just get the item out of the array, and then console.log to your array to make sure it worked
MoguBen
@mogu9628
Apr 10 2017 07:37
i did this
Gilbert
@gilbertp97
Apr 10 2017 07:37
values of a function must outside of scope always?? why is that?
MoguBen
@mogu9628
Apr 10 2017 07:37
var removed = nextInLine.shift
Markus Kiili
@Masd925
Apr 10 2017 07:38
@gilbertp97 When a function is executed, the parameters and variables exist in a local scope. The function has a reference to outer scope that is determined lexically (how the function sits in respect to other functions). Such references eventually lead to the global scope of the script. So JS has function scope.
Mychal Simka
@msimka
Apr 10 2017 07:39
@gilbertp97 because a function is a complete circuit. There is no way for anything outside the function to see into it unless it passes something out through a return
Sam Houlahan
@Sam-Houlahan
Apr 10 2017 07:39
hey guys can i please get a code review on my javascript calculaotr https://sam-houlahan.github.io/js-calculator/. The styling doesnt work on codepen so put it on github
Mychal Simka
@msimka
Apr 10 2017 07:40
@Sam-Houlahan You have an error with the clear function
Sam Houlahan
@Sam-Houlahan
Apr 10 2017 07:41
in what way?
Mychal Simka
@msimka
Apr 10 2017 07:41
You should set sum to zero if next input != +,-,*,/
Mostafa Hesham
@mhesham32
Apr 10 2017 07:42
can any one explain this code to me pls
String.prototype.replaceAt = function(index, character) {
    return this.substr(0, index) + character + this.substr(index+character.length);
};


function titleCase(str) {
    var newTitle = str.split(' ');
    var updatedTitle = [];
    for (var st in newTitle) {
        updatedTitle[st] = newTitle[st].toLowerCase().replaceAt(0, newTitle[st].charAt(0).toUpperCase());
    }
    return updatedTitle.join(' ');
}

titleCase("sHoRt AnD sToUt");
Sam Houlahan
@Sam-Houlahan
Apr 10 2017 07:43
Okay will look into it. But other then that you think it is okay?
Mychal Simka
@msimka
Apr 10 2017 07:43
@Sam-Houlahan yes
MoguBen
@mogu9628
Apr 10 2017 07:44
@msimka maybe i dont understand the objective, can u give some hint here?
Markus Kiili
@Masd925
Apr 10 2017 07:44
@mhesham32 First part makes a new string method that replaces a character of a string and returns the new string. It is then used to solve the titleCase challenge.
Sam Houlahan
@Sam-Houlahan
Apr 10 2017 07:44
Any idea why it wont run properly on codepen?
http://codepen.io/keewhy/pen/wJVqqv see here looks like shit on codepen.
Mychal Simka
@msimka
Apr 10 2017 07:45
@Sam-Houlahan codepen has issues of its own. It's not always your code
Sam Houlahan
@Sam-Houlahan
Apr 10 2017 07:45
ah .i see.
Markus Kiili
@Masd925
Apr 10 2017 07:45
@mhesham32 for...in loop is not really meant for iterating array or string indices, so a simple for loop would be better.
Mychal Simka
@msimka
Apr 10 2017 07:45
@mogu9628 OK you have an array [2,3,4,5,6] for example. Just try shifting the first item and then console.log'ing the array to make sure 2 is gone
That's step 1. Never try to solve multiple steps at once. One simple step at a time.
Mostafa Hesham
@mhesham32
Apr 10 2017 07:47
@Masd925 i couldn't do this with what i learned i copied that code and i try to understand it
MoguBen
@mogu9628
Apr 10 2017 07:47
ok
HN
@haydennorthcott
Apr 10 2017 07:48
Anyone able to better explain the challenge 'Returning Boolean Values from Functions'??
Mychal Simka
@msimka
Apr 10 2017 07:48
@haydennorthcott what's the confusion
Markus Kiili
@Masd925
Apr 10 2017 07:48
@mhesham32 There are much simpler ways to do it. Just split the string into array of words and loop the words and use string operations to make a new titlecased word and assign it back to the array and join it back to a string at the end.
But nothing wrong with generalizing the character replace into another function.
HN
@haydennorthcott
Apr 10 2017 07:50
@msimka is this just a tidier method of doing if statements?
Mychal Simka
@msimka
Apr 10 2017 07:51
@mhesham32 You can also do it with regex lookbehind /s and capitalize the first character of every capture group but what @Masd925 said is simpler
Sorr \s
@haydennorthcott Yes returning a Boolean value doesn't require an = operator
HN
@haydennorthcott
Apr 10 2017 07:52
@msimka cheers.
Mychal Simka
@msimka
Apr 10 2017 07:52
x = 1; i (x) will return true
if (x)
Sorry, typing too fast, Booleans don't require the equality operator ===
Mostafa Hesham
@mhesham32
Apr 10 2017 07:54
thanks @Masd925 @msimka
CamperBot
@camperbot
Apr 10 2017 07:54
mhesham32 sends brownie points to @masd925 and @msimka :sparkles: :thumbsup: :sparkles:
:cookie: 315 | @msimka |http://www.freecodecamp.com/msimka
:star2: 3820 | @masd925 |http://www.freecodecamp.com/masd925
vivekpadia70
@vivekpadia70
Apr 10 2017 07:58
hey guys, is it compulsory to use clementine js for backend projects??
juiiii
@juiiii
Apr 10 2017 08:02
How do i eliminate special characters here... The method I've tried doesn't seem to work
https://www.freecodecamp.com/challenges/check-for-palindromes
function palindrome(str) {
  // Good luck!
  str.toLowerCase();
  re = / \_\$\&\+\,\:\;\=\?\@\#\|\'\.\-\^\*\(\)\%\!\\/g;
  str.replace(re, "");
  //str.replace(/[^\w\s]/gi, "");
  string = str.split("");
  /*for(i=0;i<string.length;i++){
    if(string[i]===" " || string[i]==="," || string[i]==="_" || string[i]==="/" || string[i]==="\\" || string[i]==="|"){
      str.replace(string[i], "");
    }
  }*/
  console.log(string);
  if(string.join("")===string.reverse().join("")){
  return true;
  }else return false;
}
palindrome("A man, a plan, a canal. Panama");
MoguBen
@mogu9628
Apr 10 2017 08:05
@msimka oh god i did it.
@msimka thanks so much.
CamperBot
@camperbot
Apr 10 2017 08:05
mogu9628 sends brownie points to @msimka :sparkles: :thumbsup: :sparkles:
:cookie: 316 | @msimka |http://www.freecodecamp.com/msimka
Mychal Simka
@msimka
Apr 10 2017 08:05
@mogu9628 nice job
@juiiii strings are immutable
@juiiii use myStr = str etc.
Dan Couper
@DanCouper
Apr 10 2017 08:07
@juiiii str.toLowerCase(); and str.replace(re, ""); both create new strings. str is still the original string.
ah, snap
micojay020
@micojay020
Apr 10 2017 08:09
can someone help me
with escape sequences in strings
i got everything except one right
myStr should have encoded text with the proper escape sequences and no spacing
Jor
@joreyesl
Apr 10 2017 08:11
@juiiii there are simler regex you can use. Try looking at meta character \W, will cover all special except _. You will have to add that one yourself.
juiiii
@juiiii
Apr 10 2017 08:11
@DanCouper @msimka i am already using a new variable string using which I am doing the rest of the code
Mychal Simka
@msimka
Apr 10 2017 08:12
@juiiii no you
Spyrantis Theodoros
@thodorisanta
Apr 10 2017 08:12

im working on the tic tac toe project and this is my work so far. How should i continue? And how should i make the tic tac toe "borders" ?

http://codepen.io/oshikurou/pen/dvEOOX?editors=1111

Mychal Simka
@msimka
Apr 10 2017 08:13
@juiiii you're not. When you say str.toLowercase() for example that output goes to the abyss with James Cameron
down the rabbit hole with Alice
micojay020
@micojay020
Apr 10 2017 08:13
someon help ?
maybe ?
juiiii
@juiiii
Apr 10 2017 08:13

@msimka okay how about this
```function palindrome(str) {
// Good luck!
str.toLowerCase();
re = / _\$\&+\,\:\;\=\?\@#|\'.-\^*()\%!\/g;
//str.replace(re, "");
//str.replace(/[^\w\s]/gi, "");
string = str;
string.replace(re, "");
string = string.split("");
/for(i=0;i<string.length;i++){
if(string[i]===" " || string[i]==="," || string[i]==="_" || string[i]==="/" || string[i]==="\" || string[i]==="|"){
str.replace(string[i], "");
}
}
/
console.log(string);
if(string.join("")===string.reverse().join("")){
return true;
}else return false;
}

palindrome("A man, a plan, a canal. Panama");
```

Mychal Simka
@msimka
Apr 10 2017 08:13
You need to capture it with a variable and assignment in front like myStr = str.toLowercase()
Dan Couper
@DanCouper
Apr 10 2017 08:14
@juiiii
function palindrome(str = 'Hello World') {
  // str is 'Hello World'
  str.toLowerCase();
  // str is still 'Hello World'
  re = / \_\$\&\+\,\:\;\=\?\@\#\|\'\.\-\^\*\(\)\%\!\\/g;
  str.replace(re, "");
  // str is still 'Hello World'
  string = str.split("");
  // str is still 'Hello World'
  // string is '['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']'
}
Mychal Simka
@msimka
Apr 10 2017 08:14
@juiiii same problem
@juiiii when you read the MDN manual pages, or wherever you're reading up on these, pay attention to what the functions RETURN
micojay020
@micojay020
Apr 10 2017 08:15
i need help
Mychal Simka
@msimka
Apr 10 2017 08:15
@micojay020 waddu
waddup
micojay020
@micojay020
Apr 10 2017 08:15
so im stuck
with escape sequences in strings
i did all except one
i cant figure it out
Mychal Simka
@msimka
Apr 10 2017 08:16
which one
micojay020
@micojay020
Apr 10 2017 08:16
myStr should have encoded text with the proper escape sequences and no spacing.
Mychal Simka
@msimka
Apr 10 2017 08:17
not enough info to advise. explain
micojay020
@micojay020
Apr 10 2017 08:17
here is my code
var myStr = ' \"firstline\"\n \secondline\ \r thirdline';
so whats wrong with my code?
Mychal Simka
@msimka
Apr 10 2017 08:17
@micojay020 many things
micojay020
@micojay020
Apr 10 2017 08:18
how is it suppose to be
Mychal Simka
@msimka
Apr 10 2017 08:18
why are you escaping the "s?
you don't need to if you're wrapping the string in ' (single quotes)
And no reason whatsoever to escape the s in secondlline
micojay020
@micojay020
Apr 10 2017 08:19
so whats the solution?
i got everything with check
except the porper escape sequences and no spacing
Claudio Restifo
@Marmiz
Apr 10 2017 08:21
@micojay020 first start by making the text the correct one: FirstLine and not firstline
Mychal Simka
@msimka
Apr 10 2017 08:21
Claudio Restifo
@Marmiz
Apr 10 2017 08:21
same for the others
@micojay020 then in order to see a \ you need to escape it.
micojay020
@micojay020
Apr 10 2017 08:23
what do you mean by that?
idk what do to now
var myStr = " \"firstLine\" \n \secondLine\ \r \"third\" "; // Change this line
thats my code
Mychal Simka
@msimka
Apr 10 2017 08:27
@micojay020 Why are you escaping those characters? Just curious.
micojay020
@micojay020
Apr 10 2017 08:27
thats what it says in the activity
Mychal Simka
@msimka
Apr 10 2017 08:27
The "" wraps anything you put inside it, you know. So the escape performs a different function from what you are trying to accomplish
devpaaji
@devpaaji
Apr 10 2017 08:27
@msimka how are you learning JS
micojay020
@micojay020
Apr 10 2017 08:28
i have accomplish everything except one thing
the porper escape sequences and no spacing
Mychal Simka
@msimka
Apr 10 2017 08:28
@devpaaji I went through the freecodecamp challenges, and working on async stuff now, why?
devpaaji
@devpaaji
Apr 10 2017 08:29
just a general
query
Mychal Simka
@msimka
Apr 10 2017 08:30
@devpaaji Not planning to spend 10 years on it like whats his name earlier Coy or whatever, what a joke, this shit is so easy and people pretend it's like advanced number theory or something
Claudio Restifo
@Marmiz
Apr 10 2017 08:31

@micojay020 your code produce this output:

 "firstLine" 
 secondLine 
 "third"

Which is quite different from the expected one:

FirstLine
\SecondLine\
ThirdLine

Even the name itself are wrong

i have accomplish everything except one thing
the porper escape sequences and no spacing

Which is basically whay tou have to do

Blauelf
@Blauelf
Apr 10 2017 08:32
@micojay020 Re-start that one, from the "FirstLinenew-line backslashSecondLinebackslash carriage-returnThirdLine" as you find it on the left. Replace the words like "new-line" with the corresponding sequence. In the end, you should have a string containing four escape sequences (and no spaces).
omer
@avliomeravliomer
Apr 10 2017 08:33
Hi, i need help.

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

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

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

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

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

What i'm going to do ?
Mychal Simka
@msimka
Apr 10 2017 08:35
I can't believe that guy Coy, a "JS veteran" of 10 years hanging around a beginners chat room like this competing to see who gets the answer first to basic algorithms. Moron. Bad influence on newbies. We have plenty of people like that in animation, and I have no tolerance for them.
Blauelf
@Blauelf
Apr 10 2017 08:36
@avliomeravliomer Add a single line between the two comments, and don't change the rest. It's celsius, not celcius, and that parameter contains the temperature in degrees Celsius. You are meant to compute the temperature in degrees Fahrenheit and assign that value to variable fahrenheit.
micojay020
@micojay020
Apr 10 2017 08:37
still not working
omer
@avliomeravliomer
Apr 10 2017 08:37
@Blauelf My english not as good as you. I'm in a trouble to understand this messege.
Blauelf
@Blauelf
Apr 10 2017 08:38

@avliomeravliomer Have a single line, assigning to fahrenheit:

fahrenheit = ...; // formula replaces ...

On the right side, use the formula you find in the text, and use parameter celsius for the temperature in degrees Celsius.

Claudio Restifo
@Marmiz
Apr 10 2017 08:39

@msimka

I can't believe that guy Coy, a "JS veteran" of 10 years hanging around a beginners chat room like this competing to see who gets the answer first to basic algorithms. Moron. Bad influence on newbies. We have plenty of people like that in animation, and I have no tolerance for them.

what?

Mychal Simka
@msimka
Apr 10 2017 08:41
@Marmiz I had an argument here earlier with a "regular" who tried to say insult me for arguing a point, and defending it by the fact that he's known JS for 10 years. I've been learning for less than a month. But truth is truth, and I will argue a point until it's proven wrong. That is how you learn. Not listening to people like that.
kirbyedy
@kirbyedy
Apr 10 2017 08:41
@Marmiz please, dont feed
Mychal Simka
@msimka
Apr 10 2017 08:42
@kirbyedy You don't even understand the concept we were arguing about
omer
@avliomeravliomer
Apr 10 2017 08:43
@Blauelf :( I cant do this.
Povilas Krasavinas
@povkas
Apr 10 2017 08:43
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    }];
function lookUpProfile(firstName, prop){
if (contacts.hasOwnProperty(firstName)){
  if (contacts.hasOwnProperty(prop)){
    return contacts[prop];
  } else return "No such property";
} else return "No such contact";
}
lookUpProfile("Akira", "likes");
Hey there! Could you help me, have no idea how to get proper response, I have an idea that something is wrong with the first if statement, could you help me?
omer
@avliomeravliomer
Apr 10 2017 08:43
In instructions. ıt says
convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86
what should , write to find solutions.
Stephen James
@sjames1958gm
Apr 10 2017 08:44
@Dreamaz contacts is an array so you need to use a loop and test contacts[x] as this is the contact object
Blauelf
@Blauelf
Apr 10 2017 08:44
@avliomeravliomer A single line between the comments, like fahrenheit = some formula involving celsius;
Claudio Restifo
@Marmiz
Apr 10 2017 08:44

@msimka I'm sorry to hear you had an argument before.
Regardless insulting or attacking other is not nice.
Please refrain from doing that.

We're all here on the same boat :)

Povilas Krasavinas
@povkas
Apr 10 2017 08:44
@sjames1958gm Could you give an example?
kirbyedy
@kirbyedy
Apr 10 2017 08:45
@msimka and you obviously dont understand how public chats are functioning
omer
@avliomeravliomer
Apr 10 2017 08:45
@Blauelf i cant organize to write to formula.
Actually i dont understand how to write to formula :(
Stephen James
@sjames1958gm
Apr 10 2017 08:45
@Dreamaz Use a for loop over the contacts
for (var x = 0; x < contacts.length; x++) {
test contacts[x].firstName here
}
kirbyedy
@kirbyedy
Apr 10 2017 08:45
@msimka not to mention how rude is to call someone moron.
Blauelf
@Blauelf
Apr 10 2017 08:46
@avliomeravliomer Basic maths. Temperature in degrees Fahrenheit is calculated from Temperature in degrees Celsius times 9/5, plus 32.
Povilas Krasavinas
@povkas
Apr 10 2017 08:46
@sjames1958gm Thanks, will try!
CamperBot
@camperbot
Apr 10 2017 08:46
dreamaz sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6613 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 10 2017 08:46
@Dreamaz :+1:
webennes
@webennes
Apr 10 2017 08:47

please someone can tell me what's wrong here:

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

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

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

Mychal Simka
@msimka
Apr 10 2017 08:47
@Marmiz It's a principle. I offered up an argument for why something worked a certain way and he said I don't know what I'm talking about.
Claudio Restifo
@Marmiz
Apr 10 2017 08:48
@msimka If you know what you're talking about, ignore and move on :+1:
Blauelf
@Blauelf
Apr 10 2017 08:48
@webennes Why declare extra variables? And shouldn't you have case 1:, case 2:, and case 3:?
Mychal Simka
@msimka
Apr 10 2017 08:48
And then supported his argument for me not knowing what I'm talking about, by the fact that he's been programming JS for 10 years. Which is pathetic
Stephen James
@sjames1958gm
Apr 10 2017 08:48
@webennes The cases I recall are supposed to be strings "a" etc.
Blauelf
@Blauelf
Apr 10 2017 08:48
@webennes Or is that the one with case "a": and so on? ("a" is string with an a inside, while a is variable of that name)
Mychal Simka
@msimka
Apr 10 2017 08:48
@Marmiz True dat
Coy Sanders
@coymeetsworld
Apr 10 2017 08:49
That's not how the conversation went, at all
webennes
@webennes
Apr 10 2017 08:49
why was it known as undefined ..
Coy Sanders
@coymeetsworld
Apr 10 2017 08:49
never said I had 10 years exp in JavaScript either
Mychal Simka
@msimka
Apr 10 2017 08:49
Oh really?
Blauelf
@Blauelf
Apr 10 2017 08:50
@webennes You probably tried case a: when meant to do case "a": or case 'a': instead.
webennes
@webennes
Apr 10 2017 08:50
yes, i had make it ... thanks friend
Coy Sanders
@coymeetsworld
Apr 10 2017 08:50
nope
Stephen James
@sjames1958gm
Apr 10 2017 08:51
@avliomeravliomer Were you able to solve?
the formula for conversion is F = C * 9/5 + 32
In the function replace F with fahrenheit and C with celsius
webennes
@webennes
Apr 10 2017 08:51
i will go solve it, thanks for your explanation =)
omer
@avliomeravliomer
Apr 10 2017 08:52
I'm trying.
Mychal Simka
@msimka
Apr 10 2017 08:53
@coymeetsworld So how did it go?
omer
@avliomeravliomer
Apr 10 2017 08:53
Fahrenheit = Celsius * 9/5 + 32
its not working :(

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

Fahrenheit = Celsius * 9/5 + 32
// Only change code above this line
return fahrenheit;
}

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

convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86
Stephen James
@sjames1958gm
Apr 10 2017 08:53
@avliomeravliomer Close but js is case sensitive Celsius is not the same as celsius
webennes
@webennes
Apr 10 2017 08:54

@Blauelf thanks bro...
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch(val) {
case "a":
answer = "apple";
break;
case "b":
answer = "bird";
break;
case "c":
answer = "cat";
break;
default: answer = "stuff";
}

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

// Change this value to test