These are chat archives for FreeCodeCamp/HelpJavaScript

8th
Jun 2017
André
@andregomesp
Jun 08 2017 00:05
Hello. I am kinda of lost in Using Objects for Looksups challenge. It asks me to convert the switch statement into a lookup table and use it to lookup val and assign the associated string to the result variable.
chloenhy
@chloenhy
Jun 08 2017 00:06
i am stuck with this...
Pervinan
@Pervinan
Jun 08 2017 00:06
@andregomesp Have you converted the table?
chloenhy
@chloenhy
Jun 08 2017 00:06

function abTest(a, b) {
// Only change code below this line
if ((a<0)||(b<0)); {
return undefined;
} else {

// Only change code above this line

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

what is wrong with the else line?
yash5657
@yash5657
Jun 08 2017 00:07
@revisualize so I seperated them into different elements in an array
André
@andregomesp
Jun 08 2017 00:07

I tried, but i am not really sure how this conversion happens. This is what i did.

```

yash5657
@yash5657
Jun 08 2017 00:08
and I'm trying to save the length into a variable
Pervinan
@Pervinan
Jun 08 2017 00:08
@chloenhy look at your else.
Long Nguyen
@longnt80
Jun 08 2017 00:08
hey guys, I nearly finish all the advanced front end project, should I start learning React or Angular now?
Pervinan
@Pervinan
Jun 08 2017 00:08
@chloenhy very simple fix
yash5657
@yash5657
Jun 08 2017 00:08
and getting this error @revisualize
Joseph
@revisualize
Jun 08 2017 00:09
Got code?
yash5657
@yash5657
Jun 08 2017 00:09
commonFramework-120fa0af86.js:1 TypeError: Cannot assign to read only property 'length' of string 'The'
Christopher McCormack
@cmccormack
Jun 08 2017 00:09
@longnt80 I jumped into React and it's been pretty interesting
Joseph
@revisualize
Jun 08 2017 00:09
Try resetting the challenge and see what happens thats odd.
yash5657
@yash5657
Jun 08 2017 00:09
yeah here it is
function findLongestWord(str) {
  var ab = str.split(" ");
  console.log(ab);
  for(var i = 0;i<ab.length;i++){
    var ac;
    ab[i].length= ac;
    console.log(ac);
  }
  return str.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Long Nguyen
@longnt80
Jun 08 2017 00:09
@cmccormack so should I?
Christopher McCormack
@cmccormack
Jun 08 2017 00:10
@longnt80 if you want!
Joseph
@revisualize
Jun 08 2017 00:10
Wait.
yash5657
@yash5657
Jun 08 2017 00:10
this is just starting , I actually did not go completely.
sure
Joseph
@revisualize
Jun 08 2017 00:10
@yash5657 your assignemwnt is broke.
yash5657
@yash5657
Jun 08 2017 00:11
@revisualize I did not get you
can you explain plz
Joseph
@revisualize
Jun 08 2017 00:11
How do you assign 7 to the variable ac?
yash5657
@yash5657
Jun 08 2017 00:12
var ac= 7;
Joseph
@revisualize
Jun 08 2017 00:12
7 = ac; ... ?
Christopher McCormack
@cmccormack
Jun 08 2017 00:12
@longnt80 I think it's probably worth it to know, even if you don't end up using it. It's much more structured then just throwing together Javascript, that's for sure
Joseph
@revisualize
Jun 08 2017 00:12
But, youre doing it backwards in your loop.
Youre doing
7 = ac;
yash5657
@yash5657
Jun 08 2017 00:12
ohh I did not know that would make difference oops;
André
@andregomesp
Jun 08 2017 00:13
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line

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

  };

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

// Change this value to test
phoneticLookup("charlie");
Long Nguyen
@longnt80
Jun 08 2017 00:13
@cmccormack do you have any resource for beginner like me? Which resource did you start with?
JaedMon
@JaedMon
Jun 08 2017 00:13
Hi I am having trouble with my Multiple Switch Statements, can anyone help?
Joseph
@revisualize
Jun 08 2017 00:13
@andregomesp good so far.
yash5657
@yash5657
Jun 08 2017 00:13
@revisualize got it now... good to know that.
Joseph
@revisualize
Jun 08 2017 00:13
Well youre missing an =
Christopher McCormack
@cmccormack
Jun 08 2017 00:14
@longnt80 I went about it the wrong way - watched a bunch of youtube videos thinking it would be pretty easy to start cobbling something together. don't do that. Read the Facebook documentation slowly and carefully and follow along.
Joseph
@revisualize
Jun 08 2017 00:14
@andregomesp you forgot the = for the variable assignment when creating your object.
Long Nguyen
@longnt80
Jun 08 2017 00:14

@cmccormack

@longnt80 I think it's probably worth it to know, even if you don't end up using it. It's much more structured then just throwing together Javascript, that's for sure

oh yeah, framework is much easy to work with. I've only been using jQuery for my advanced projects.

André
@andregomesp
Jun 08 2017 00:15
@revisualize Oh i see what you meant, let me see...
Christopher McCormack
@cmccormack
Jun 08 2017 00:15
@longnt80 React has a whole flow to it, it's designed with components that pass down state as properties, and changing that state is what forces re-renders.
Long Nguyen
@longnt80
Jun 08 2017 00:15
@cmccormack I was about to watch youtube videos too. Thanks for the tip! I'll go read the doc.
CamperBot
@camperbot
Jun 08 2017 00:15
longnt80 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 798 | @cmccormack |http://www.freecodecamp.com/cmccormack
André
@andregomesp
Jun 08 2017 00:15
@revisualize well, that fixed the error messages, i think i can figure the rest.
@revisualize thanks.
CamperBot
@camperbot
Jun 08 2017 00:16
andregomesp sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4122 | @revisualize |http://www.freecodecamp.com/revisualize
Christopher McCormack
@cmccormack
Jun 08 2017 00:16
@longnt80 there are times I wish I could just use jQuery when trying to get some state to work with React :laughing:
Vamp
@the-vampiire
Jun 08 2017 00:16
anyone here have experience working with slack’s API? in particular interactive messages
Christopher McCormack
@cmccormack
Jun 08 2017 00:16
@longnt80 FCC Youtube has been doing a lot of React stuff lately as well
Long Nguyen
@longnt80
Jun 08 2017 00:16
@cmccormack yeah, FCC also have challenges for React in the future

@cmccormack

@longnt80 there are times I wish I could just use jQuery when trying to get some state to work with React :laughing:

so you cannot use jQuery with React?

Christopher McCormack
@cmccormack
Jun 08 2017 00:18
@longnt80 you can of course, but within the bounds of React. If you want to perform well, which is the whole point, you wouldn't just use jQuery for the whole thing
@longnt80 I rarely ever have a need to use jQuery when using react though
Zach Hope
@Baipanda11
Jun 08 2017 00:20
has anyone done the fahrenheit to celcius conversion yet?
Christopher McCormack
@cmccormack
Jun 08 2017 00:20
@longnt80 you're working with components that store the html elements, so when you want to make changes you change the state which propagates to those elements, so you don't really need to use jQuery selectors or anything.
@longnt80 here's a simple React project I made as a test for something else a while back, you can take a look and see the structure if you like https://codepen.io/cmccormack/pen/dWQoRM?editors=1010
Long Nguyen
@longnt80
Jun 08 2017 00:23
@cmccormack I see
@cmccormack do you think React is something you need to have good knowledge of Javascript in order to use it?
@cmccormack I learned jQuery even before I started learning javascript and it was ok
Christopher McCormack
@cmccormack
Jun 08 2017 00:26
@longnt80 You should definitely understand how objects work, loops, conditionals, all the base stuff, that's for sure
@longnt80 but what you don't know you can lookup anytime, better to jump into something challenging and learn than to do something you already know and get bored
I gotta run for dinner, :wave:
Long Nguyen
@longnt80
Jun 08 2017 00:28
@cmccormack ok, thank you
CamperBot
@camperbot
Jun 08 2017 00:28
longnt80 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: longnt80 already gave cmccormack points
yash5657
@yash5657
Jun 08 2017 00:30
@revisualize @JLuboff do you think this is right way?? any suggestions
function findLongestWord(str) {
  var ab = str.split(" ");
  ab.sort(function(a,b){
    return b.length - a.length;
  });

  return ab[0].length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
I just thought this would be easy, I couldnt really figure out how to compare between elements and return "Longest".
andrewmparker
@andrewmparker
Jun 08 2017 00:36
var myList = [["Cookie", 4][".Milk", 2]["Steak", 4]["Chicken", 7]["Cake", 1]];
what is wrong???
yash5657
@yash5657
Jun 08 2017 00:37
@andrewmparker what is the error??
andrewmparker
@andrewmparker
Jun 08 2017 00:38
it says: The first elements in each of your sub-arrays must all be strings
The second elements in each of your sub-arrays must all be numbers
You must have at least 5 items in your lis
yash5657
@yash5657
Jun 08 2017 00:40
can you paste the whole code? and what test you are failing?
@andrewmparker
andrewmparker
@andrewmparker
Jun 08 2017 00:41
that is the whole code. The name is "Shopping List" @yash5657
Ravi Kishore Thella
@ravikishorethella
Jun 08 2017 00:41
@yash5657 yes it is
yash5657
@yash5657
Jun 08 2017 00:43
@andrewmparker ahh I see... there is no seperator in your array myList
andrewmparker
@andrewmparker
Jun 08 2017 00:43
what do you mean by separator???
yash5657
@yash5657
Jun 08 2017 00:44
@andrewmparker " , "
var arr = ["abc" , "def"]; syntax example
andrewmparker
@andrewmparker
Jun 08 2017 00:44
ok i will give it a try
thx @yash5657
CamperBot
@camperbot
Jun 08 2017 00:45
andrewmparker sends brownie points to @yash5657 :sparkles: :thumbsup: :sparkles:
:cookie: 242 | @yash5657 |http://www.freecodecamp.com/yash5657
yash5657
@yash5657
Jun 08 2017 00:45
@ravikishorethella I was able to do it 2 diff ways, so just want to know which one is more reliable
@andrewmparker you got it
ShravikaNarayanam
@ShravikaNarayanam
Jun 08 2017 00:46

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

switch(answer)
{
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
switchOfStuff("a");
switchOfStuff("b");
switchOfStuff("c");
switchOfStuff("d");
switchOfStuff(4);

do u think this is correct?Not able pass through case a,b and c

yash5657
@yash5657
Jun 08 2017 00:49
@ShravikaNarayanam why did you assign a "val" to answer and then reassigning
also you are comparing "answer" while you have to compare the parameter you pass which is "val"
MohammedAssar
@MohammedAssar
Jun 08 2017 00:53
I need help in ( Stand in Line ) challenge
yash5657
@yash5657
Jun 08 2017 00:53
@MohammedAssar what's the issue?
MohammedAssar
@MohammedAssar
Jun 08 2017 00:54

here is the code '
function nextInLine(arr, item) {
// Your code here
return item; // Change this line
}

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

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

Moisés Man
@moigithub
Jun 08 2017 00:54
https://www.youtube.com/watch?v=7i1f23AVsn4
https://www.youtube.com/watch?v=ZGoP6PsIO_M
https://www.youtube.com/watch?v=9bF0np-Z4kI
@ShravikaNarayanam
MohammedAssar
@MohammedAssar
Jun 08 2017 00:54

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

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

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

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

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

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

CamperBot
@camperbot
Jun 08 2017 00:55
:bulb: to format code use backticks! ``` more info
MohammedAssar
@MohammedAssar
Jun 08 2017 00:55

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

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

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

MJ
@mjcello
Jun 08 2017 00:55

Good evening! anybody know what i'm missing?

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

testArr.push(item);
removedArr = (arr).shift();

return removedArr; // Change this line
}

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

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

it doesn't meet the requirement: "nextInLine([], 1) should return 1" -- how am i supposed to return something removed from an empty function??

Moisés Man
@moigithub
Jun 08 2017 00:56
@mjcello dont use testArr on ur function
use ur parameter arr
MohammedAssar
@MohammedAssar
Jun 08 2017 00:56

@yash5657 ```

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

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

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

Moisés Man
@moigithub
Jun 08 2017 00:56
@MohammedAssar 3 backticks at top and at bottom on its OWN line
MohammedAssar
@MohammedAssar
Jun 08 2017 00:57

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

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@moigithub finally thanks
CamperBot
@camperbot
Jun 08 2017 00:57
mohammedassar sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3342 | @moigithub |http://www.freecodecamp.com/moigithub
MJ
@mjcello
Jun 08 2017 00:58
oh wow! that worked!
yash5657
@yash5657
Jun 08 2017 00:58
@MohammedAssar alright! what you have to do is push(); item parameter into testArr
MJ
@mjcello
Jun 08 2017 00:58
thank you!
yash5657
@yash5657
Jun 08 2017 00:58
and take the 1st item from the same array and return that item.
use push(); and shift(); methods
@MohammedAssar
ShravikaNarayanam
@ShravikaNarayanam
Jun 08 2017 01:01
@yash5657

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

switch(answer)
{
case 1:
answer = "alpha";
break;

  case 2:

   answer = "beta";
    break;

  case 3:
    answer = "gamma";
    break;

    case 4:
    answer = "delta";
    break;

default :
console.log("invalid");
}

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

my last switch case which got executed
bt for some reason i'm not able to pass the previous oe
tommy
@tommygebru
Jun 08 2017 01:02

not sure that this bit of code needs to be repeated

answer =

@shravikaNarayanam

Joseph Henshaw
@Big-jo
Jun 08 2017 01:03

function reverseString(str) {
  return str;
}


var smh = reverseString("hello");
var myArray =[];
myArray = reverseString.split(' ');
isnt supposed the value of reverseString to be returned to smh variable.
CreateTheHype
@CreateTheHype
Jun 08 2017 01:04
im stuck on this Word Blanks challenge

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

// Your code above this line
return result;
}

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

any tips?
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:04
@Big-jo carry out the operation in the function block not outside
Joseph Henshaw
@Big-jo
Jun 08 2017 01:04
@CreateTheHype your just supposed to make a meaningful sentence with addition of some of your own words
CreateTheHype
@CreateTheHype
Jun 08 2017 01:05
thx guys
Joseph Henshaw
@Big-jo
Jun 08 2017 01:05
@Lumexralph Okay thanks
CamperBot
@camperbot
Jun 08 2017 01:05
big-jo sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1879 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:05
@CreateTheHype form a sentence/phrase with the strings held by the 4 parameters of your function and remember to separate them with spaces and assign it to result
Joseph Henshaw
@Big-jo
Jun 08 2017 01:05
@Lumexralph so it's not possible to carry out the operation outsite the function.
CreateTheHype
@CreateTheHype
Jun 08 2017 01:06
@Lumexralph thx ill try that
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:06
@ShravikaNarayanam switch(expression) expression should be val not answer
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:06
can someone please help
I keep getting this message
golfScore(4, 7) should return "Go Home!"
CreateTheHype
@CreateTheHype
Jun 08 2017 01:07
thanks for the help @tommygebru
CamperBot
@camperbot
Jun 08 2017 01:07
createthehype sends brownie points to @tommygebru :sparkles: :thumbsup: :sparkles:
:cookie: 804 | @tommygebru |http://www.freecodecamp.com/tommygebru
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:07
@Big-jo it's possible but here you want to work on the parameter which exists in the function
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:07
that is the error
else if (strokes >= par + 3){
return "Go Home";
}
this is my code statement
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:07
@haseebuchiha missing ! ==> "Go Home!"
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:07
o
:'D
@Lumexralph thanks :D
CamperBot
@camperbot
Jun 08 2017 01:08
haseebuchiha sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1880 | @lumexralph |http://www.freecodecamp.com/lumexralph
tommy
@tommygebru
Jun 08 2017 01:08
@haseebuchiha when asking for help/tips share the title of challenge + link, then the code you used :wink:
Joseph Henshaw
@Big-jo
Jun 08 2017 01:08
@Lumexralph cant i just make them global variables
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:08
@haseebuchiha :+1:
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:08
@tommygebru Okay will keep that in mind next time. thanks
CamperBot
@camperbot
Jun 08 2017 01:08
haseebuchiha sends brownie points to @tommygebru :sparkles: :thumbsup: :sparkles:
:cookie: 805 | @tommygebru |http://www.freecodecamp.com/tommygebru
Kelechi Chinaka
@ke1echi
Jun 08 2017 01:09
@Lumexralph
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:10
@Big-jo in real-life projects, globals should be limited if possible avoided, since you can do it in the block of your function why doing it out of it? and moreover the function codes will be used again for other inputs
@kelechichinaka Bro :wave:
Kelechi Chinaka
@ke1echi
Jun 08 2017 01:10
hw work goin @Lumexralph
Drew
@Duffelbag
Jun 08 2017 01:12
Any hints for 'Stand In Line' using the nextInLine functions with queue?
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:13
@kelechichinaka going well, yours?
Joseph Henshaw
@Big-jo
Jun 08 2017 01:14
@Lumexralph lol , Oboy! , i get am ! thanks
CamperBot
@camperbot
Jun 08 2017 01:14
big-jo sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:warning: big-jo already gave lumexralph points
Kelechi Chinaka
@ke1echi
Jun 08 2017 01:14
cool @Lumexralph
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:15
@Duffelbag you need to make queue, by adding item a parameter in your function to the end of arr parameter holding the array passed to your function.... you need an array method for that and then you need to remove the first element in the array arr, and return it you need another array method for that
Alexandre M
@GreenCoder01
Jun 08 2017 01:15
hey everyone, I am doing the "Check for Palindromes" problem and I am encountering an issue palindrome("1 eye for of 1 eye.") should return false. The thing is shouldn't return true as once you remove the non-alphanumeric characters you get "eye for of eye", remove the spaces and you get a palindrome...therefore it should return true
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:15
@Big-jo cool :smile:
Alexandre M
@GreenCoder01
Jun 08 2017 01:15
where am I going wrong?
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:15
@GreenCoder01 alphanumeric is alphabet and numbers
Alexandre M
@GreenCoder01
Jun 08 2017 01:16
right...the problem also mentioned the removal of characters which in this case would remove punctuation
i forgot to mention that
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:17
@GreenCoder01 removing all non-alphanumeric, will remove other characters except a number or a letter/alphabet
Alexandre M
@GreenCoder01
Jun 08 2017 01:18
everything else checks out except for that 1 phrase which I think may be a mistake
yes exactly so the question is do you think "1 eye for of 1 eye" should be a palindrome?
Stephen James
@sjames1958gm
Jun 08 2017 01:19
@GreenCoder01 Under the rules of this challenge that is not a palindrome
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:19
@sjames1958gm that's weird :smirk:
at this hour
Alexandre M
@GreenCoder01
Jun 08 2017 01:20
that is the issue I am getting @Lumexralph ...I am glad you agree that it is a palindrome
I'll report it
Ogundele Olumide
@Lumexralph
Jun 08 2017 01:21
@GreenCoder01 it's not. sorry for the mistake
Kelechi Chinaka
@ke1echi
Jun 08 2017 01:22
i still do not know y my python tutor doesnt work
Stephen James
@sjames1958gm
Jun 08 2017 01:25
@GreenCoder01 The rules of the challenge say only remove special characters (not numbers or letters)
1eyeforof1eye is not a palindrome
Alexandre M
@GreenCoder01
Jun 08 2017 01:27
@sjames1958gm oh right thanks...I'll review my code :)
CamperBot
@camperbot
Jun 08 2017 01:27
greencoder01 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7673 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:33
I'm solving this problem Returning Boolean Values from Functions
I can't use if or else
switch (a, b){ case a < b: return true; default: return false; }
this is not solving my true case :/
?
Sandip Shrestha
@saninmersion
Jun 08 2017 01:37
@haseebuchiha maybe not use a switch
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:37
@saninmersion what else can I use?
Sandip Shrestha
@saninmersion
Jun 08 2017 01:37
@haseebuchiha see this example on the left?
Since === returns true or false, we can return the result of the comparison:

function isEqual(a,b) {
  return a === b;
}
Kelechi Chinaka
@ke1echi
Jun 08 2017 01:37
your switch statement is wrong @haseebuchiha
Sandip Shrestha
@saninmersion
Jun 08 2017 01:37
is that not self explanatory?
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:38
interesting :D
Kelechi Chinaka
@ke1echi
Jun 08 2017 01:38
you are switching b @haseebuchiha
Haseeb Arshad
@haseebuchiha
Jun 08 2017 01:40
@saninmersion it worked :D
@saninmersion thanks
CamperBot
@camperbot
Jun 08 2017 01:40
haseebuchiha sends brownie points to @saninmersion :sparkles: :thumbsup: :sparkles:
:cookie: 511 | @saninmersion |http://www.freecodecamp.com/saninmersion
Kelechi Chinaka
@ke1echi
Jun 08 2017 01:40
a = 10 b = 20 a, b 20 @haseebuchiha
switch(true) would get it done @haseebuchiha
a = 10
b = 20
a, b
20
@haseebuchiha
sonnguyen2603
@sonnguyen2603
Jun 08 2017 01:50

var myVar = 87;

// Only change code below this line
myVar = myVar ++;

can anyone tell me where I did it wrong ? the result should be 88
d.j
@danhym1
Jun 08 2017 01:57
hey how Come this command doesn't work for it containing undefined and the value of I am a
a = 5;
b = 10;
c =" i am a ";
hey how Come this command doesn't work for it containing undefined and the value of I am a
Stephen James
@sjames1958gm
Jun 08 2017 02:00
@danhym1 "I am a" possibly - the string must match exactly
@sonnguyen2603 ++ include assignment back to variable
Fady safwat
@fadySWHS
Jun 08 2017 02:00
2017-06-08_04h00_11.png
feeback about my code !?
Stephen James
@sjames1958gm
Jun 08 2017 02:02
@fadySWHS You could simply return the filter without assignment
d.j
@danhym1
Jun 08 2017 02:09
@sjames1958gm I forgot to add the stupid c=NaN of course I did but I forgot the caps for the N's so annoying sometimes but thanks for the input haha
CamperBot
@camperbot
Jun 08 2017 02:09
danhym1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7674 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Omarwali Jones
@Omarwali
Jun 08 2017 02:15
hi can anyone tell me what's wrong with my code for the chunky monkey algorithm in basic algorithm scripting section I give up at this point smh its so frustrating lol
function chunkArrayInGroups(arr, size) {
  let finalArray = [];
  let storage = [];
  for(let i = 0; i < arr.length; i++) {
    if (storage.length >= size) {
      console.log("here's a split");
      finalArray.push(storage)
      console.log(finalArray);
      storage = [];
    }
    storage.push(arr[i]);
    console.log(storage);
  }
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Screen Shot 2017-06-07 at 10.15.38 PM.png
Omarwali Jones
@Omarwali
Jun 08 2017 02:21
NOTE: Adding plus one to the loop condition helps a bit as I'm able to get the final two dimensional array for some of the answers but not all the test pass
alysonalyson
@alysonalyson
Jun 08 2017 02:21
For some reason I can't get past Use Conditional Logic with If Statements (https://www.freecodecamp.com/challenges/use-conditional-logic-with-if-statements). My console is showing what it's supposed to, but for some reason it won't pass me. Help? I'm probably missing something obvious.

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.
if(wasThatTrue) {
return "Yes, it's true";
}
return "No, it's false";
// Only change code above this line.
}

// Change this value to test
trueOrFalse(true);

Omarwali Jones
@Omarwali
Jun 08 2017 02:22
Screen Shot 2017-06-07 at 10.21.55 PM.png
Screen Shot 2017-06-07 at 10.23.11 PM.png

@alysonalyson very simple solution


// Example
function ourTrueOrFalse(isItTrue) {
  if (isItTrue) { 
    return "Yes, it's true";
  }
  return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

  // Only change code below this line.
  if(wasThatTrue){
    return "Yes, that was true";
  }
  else {
    return "No, that was false";
  }

  // Only change code above this line.

}

// Change this value to test
trueOrFalse(true);

should work

Screen Shot 2017-06-07 at 10.25.46 PM.png
Abhishek Tiwari
@fillopfy
Jun 08 2017 02:31
var vow=/[aeiou]/g;
var len=str.indexOf(str.match(vow)[0]);
can anyone describe me the above code
alysonalyson
@alysonalyson
Jun 08 2017 02:33
Haha! I knew it had to be something stupid. Thanks @Omarwali!
CamperBot
@camperbot
Jun 08 2017 02:33
alysonalyson sends brownie points to @omarwali :sparkles: :thumbsup: :sparkles:
:cookie: 254 | @omarwali |http://www.freecodecamp.com/omarwali
Omarwali Jones
@Omarwali
Jun 08 2017 02:33
@fillopfy the regex variable. Checks the second variable (a string) at its zero index or first char in the string and matches it against any of those 5 vowels(aeio or u) in the intial regex expression... that seems to be the gist of it I think but idk shxt about regex lol
Abhishek Tiwari
@fillopfy
Jun 08 2017 02:35
@Omarwali it starts checking at index 0?
Omarwali Jones
@Omarwali
Jun 08 2017 02:36
@fillopfy its only checking the char at the zero index if I'm reading it right so if you had "banana" it would check "b" against aeio and u and fail because "b" is none of those chars
Abhishek Tiwari
@fillopfy
Jun 08 2017 02:37
@Omarwali what if it it is bbc?
Omarwali Jones
@Omarwali
Jun 08 2017 02:38
none of those are aeio or u so it wouldn't matter
Abhishek Tiwari
@fillopfy
Jun 08 2017 02:38
@Omarwali then what will be the value of len this time?
Omarwali Jones
@Omarwali
Jun 08 2017 02:39
@fillopfy no idea lol trying to solve my own problem
Abhishek Tiwari
@fillopfy
Jun 08 2017 02:40
@Omarwali that line is confusing me, anyways thanks!
CamperBot
@camperbot
Jun 08 2017 02:40
fillopfy sends brownie points to @omarwali :sparkles: :thumbsup: :sparkles:
:cookie: 255 | @omarwali |http://www.freecodecamp.com/omarwali
minhnguyenduc97
@minhnguyenduc97
Jun 08 2017 02:41
help
Fady safwat
@fadySWHS
Jun 08 2017 02:42
2017-06-08_04h41_57.png
@sjames1958gm AND now !
Raghav Gupta
@realRaghavGupta
Jun 08 2017 02:50
Somebody please explain the Word Blanks problem in Javascript!
Manish Giri
@Manish-Giri
Jun 08 2017 02:54
@realraghavgupta you need to form a string, and assign it to result, using string concatenation (+). The string has to be formed by concatenating the four parameters in your function - myNoun, myAdjective, etc, along with spaces and (optionally) some words of your own - to form a coherent sentence.
Nikola
@alokin95
Jun 08 2017 02:59
myStr should have encoded text with the proper escape sequences and no spacing
CreateTheHype
@CreateTheHype
Jun 08 2017 03:00
@realraghavgupta result+= "My "+myAdjective+" "+myNoun+" "+myVerb+" very "+myAdverb+".";
Raghav Gupta
@realRaghavGupta
Jun 08 2017 03:02
Thanks!
CreateTheHype
@CreateTheHype
Jun 08 2017 03:02
wow no brownie points :( @realraghavgupta
Long Nguyen
@longnt80
Jun 08 2017 03:03
:cookie: :cookie: :cookie: :cookie:
CreateTheHype
@CreateTheHype
Jun 08 2017 03:04
hahaha
baersc
@baersc
Jun 08 2017 03:05

`function bouncer(arr) {
arr = arr.filter(function(test){
return test;
});

return arr;

}`
Can anyone help me understand why the return statement in the above code returns a boolean value?

the return test specifically
Joseph
@revisualize
Jun 08 2017 03:05
@baersc Sure.
@baersc Do you know about value coercion in JavaScript?
baersc
@baersc
Jun 08 2017 03:06
Yes
Joseph
@revisualize
Jun 08 2017 03:07
@baersc So, the .fiter() method does a sort of value coercion.
@baersc Because the way .fiter() works is based upon a true or false value.
If the value evaluates to false it is removed from the array.
baersc
@baersc
Jun 08 2017 03:09
@revisualize Thats what I thought. but .filter() requires a function, so we make an empty function that accepts an argument and passes it back into .filter() unchanged, and then .filter() performs the actual coersion to test true/false?
Joseph
@revisualize
Jun 08 2017 03:09
@baersc It can
Nikola
@alokin95
Jun 08 2017 03:10
myStr should have encoded text with the proper escape sequences and no spacing ??
Guderian Raborg
@hypercuber
Jun 08 2017 03:10
How do I round 10.111 to 10.1?
I think there was something other than Math.round()
Joseph
@revisualize
Jun 08 2017 03:11
@alokin95 You have to assign 'FirstLine newline backslash SecondLine backslash carriage-return ThirdLine' to the variable myStr.
But, You have to replace the escape words with the proper escape sequences. (And per the instructions: remove all spaces.)
How do you escape a newline?
How do you escape a backslash?
How do you escape a carriage-return?
Nikola
@alokin95
Jun 08 2017 03:12
\n \b \r
baersc
@baersc
Jun 08 2017 03:12
@hypercuber try .toFixed(1)
Nikola
@alokin95
Jun 08 2017 03:12
@revisualize \n \b \r
Joseph
@revisualize
Jun 08 2017 03:12
@alokin95 That's incorrect the backslash isn't correct.
Nikola
@alokin95
Jun 08 2017 03:13
oh
\
Guderian Raborg
@hypercuber
Jun 08 2017 03:13
@baersc Oh, right. Thanks!
CamperBot
@camperbot
Jun 08 2017 03:13
hypercuber sends brownie points to @baersc :sparkles: :thumbsup: :sparkles:
Nikola
@alokin95
Jun 08 2017 03:13
i read it as "backspace"
CamperBot
@camperbot
Jun 08 2017 03:13
:cookie: 253 | @baersc |http://www.freecodecamp.com/baersc
Joseph
@revisualize
Jun 08 2017 03:13
Correct.
@alokin95 So, you just replace the words in the strings with the proper escape sequence.
And remove the spaces.
and assign all of that to the variable myStr
Nikola
@alokin95
Jun 08 2017 03:14
@revisualize thank you very much
CamperBot
@camperbot
Jun 08 2017 03:14
alokin95 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4123 | @revisualize |http://www.freecodecamp.com/revisualize
Austin Wiggins
@austinwiggins
Jun 08 2017 03:17
Can anyone here help me with the JS Challenge "Caesar's Cipher"?
Long Nguyen
@longnt80
Jun 08 2017 03:18
@austinwiggins yes, A -> N and N -> A
Austin Wiggins
@austinwiggins
Jun 08 2017 03:19
@longnt80 I don't understand...
Greg Lawrence
@Chewieez
Jun 08 2017 03:19
I have a question about my code for the Palindrome challenge. My code seems to work for all the options except the word "almostomla".
function palindrome(str) {
  str = str.replace(/[^A-Za-z0-9]/g, '');
  str = str.toLowerCase();
  str.split('');

  for (i = 0; i <= str.length - 1; i++) {
    if (str[i] === str[(str.length - 1) - i]) {
    return (true);
  }
    else {
    return (false);
  } 
  }
}


palindrome("almostomla");
Long Nguyen
@longnt80
Jun 08 2017 03:23
@Chewieez you need to convert str to 2 strings: one in normal direction and one in reversed and compare them
if you compare the first and the last like this, it will cause problem
Greg Lawrence
@Chewieez
Jun 08 2017 03:24
hmm ok, I'll have to rethink that one. :smile:
Raghav Gupta
@realRaghavGupta
Jun 08 2017 03:27
@CreateTheHype how brownie points work? Since I am new, I am not able to find the option
Ken Haduch
@khaduch
Jun 08 2017 03:34
@Chewieez - it is a lot easier to generate the lowercase version, stripped of the special characters, and then generate a reversed version of the same word (which is already stripped of the special characters) and then just do an === comparison, instead of the letter-by-letter approach.
Greg Lawrence
@Chewieez
Jun 08 2017 03:39
Thanks @longnt80 @khaduch. That approach makes sense and didn't occur to me at all. I just finished reading a help page on FCC that listed three ways to do this challenge.
CamperBot
@camperbot
Jun 08 2017 03:39
chewieez sends brownie points to @longnt80 and @khaduch :sparkles: :thumbsup: :sparkles:
:cookie: 335 | @longnt80 |http://www.freecodecamp.com/longnt80
:star2: 2953 | @khaduch |http://www.freecodecamp.com/khaduch
Greg Duncan
@GregatGit
Jun 08 2017 03:47
@Chewieez just return true or return false you don't need the brackets
RyanHuang06
@RyanHuang06
Jun 08 2017 03:48
i am not sure how to do the counting cards challenge
Zach Hope
@Baipanda11
Jun 08 2017 03:49
var myStr ='Firstline\n \SecondLine\ \r ThirdLine';
RyanHuang06
@RyanHuang06
Jun 08 2017 03:49
@realraghavgupta use the word t h a n k s without the spaces. it worked for me.
Greg Lawrence
@Chewieez
Jun 08 2017 03:49
@GregatGit Thanks!
CamperBot
@camperbot
Jun 08 2017 03:49
chewieez sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 859 | @gregatgit |http://www.freecodecamp.com/gregatgit
lmagee001
@lmagee001
Jun 08 2017 03:50
having trouble with the java script far to cels converter
Zach Hope
@Baipanda11
Jun 08 2017 03:50
does anyone know whats going on with the escape sequences?
var myStr ='Firstline\n \SecondLine\ \r ThirdLine';
lmagee001
@lmagee001
Jun 08 2017 03:50
don't really know where to start with it
RyanHuang06
@RyanHuang06
Jun 08 2017 03:51
@Baipanda11 i know. to escape \n, use \n\, and same with \r. do \ instead of \ for the SecondLine.
*\
*\\
it is not escaping properly in chat.
Zach Hope
@Baipanda11
Jun 08 2017 03:52
@RyanHuang06 alright will give it a try
Greg Duncan
@GregatGit
Jun 08 2017 03:52
@Chewieez just remember when you have a loop and inside that loop is a return statement - like you have - once it hits return whatever you exit out of the funciton
RyanHuang06
@RyanHuang06
Jun 08 2017 03:52
@Baipanda11 working?
Zach Hope
@Baipanda11
Jun 08 2017 03:53
h/o
var myStr ='Firstline\n\\SecondLine\\r\ThirdLine'; nope
RyanHuang06
@RyanHuang06
Jun 08 2017 03:54
@Baipanda11
FirstLine\n\\SecondLine\\r\ThirdLine
when \\ i mean \\
when double slash i mean triple slash
Diego Mayer
@Chrono79
Jun 08 2017 03:55
@RyanHuang06 use `to format the code in the chat
Click more info below
CamperBot
@camperbot
Jun 08 2017 03:55
:bulb: to format code use backticks! ``` more info
Diego Mayer
@Chrono79
Jun 08 2017 03:55
\\
@Baipanda11 it's FirstLine and you have more backslashes than needed (if you see only 6 in the challenge that's fine)
Zach Hope
@Baipanda11
Jun 08 2017 03:57
ah thanks for pointing that out
Diego Mayer
@Chrono79
Jun 08 2017 03:57
@Baipanda11 the backslash before the T is wrong
Zach Hope
@Baipanda11
Jun 08 2017 03:58
var myStr ='FirstLine\n \SecondLine\ \rThirdLine';
Diego Mayer
@Chrono79
Jun 08 2017 03:58
@Baipanda11 delete all spaces, that's what no spacing means
Zach Hope
@Baipanda11
Jun 08 2017 03:59
@Chrono79 thanks all
CamperBot
@camperbot
Jun 08 2017 03:59
baipanda11 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4213 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jun 08 2017 03:59
:+1:
Greg Lawrence
@Chewieez
Jun 08 2017 04:01

@GregatGit Thanks for that reminder. Part of me wants to make this approach work. I haven't figured out where/why it fails. But I understand it isn't the best approach and will prob fail somewhere, maybe right at the middle characters.

Would this code work better, by removing the return from inside the For loop and just using var assignments?

function palindrome(str) {
  var ans ;
  str = str.replace(/[^A-Za-z0-9]/g, '');
  str = str.toLowerCase();
  str.split('');

  for (i = 0; i <= str.length - 1; i++) {
    if (str[i] === str[(str.length - 1) - i]) {
    ans = true;
  }
    else {
    ans = false;
  } 
  }
  return ans;
}

palindrome("almostomla");
CamperBot
@camperbot
Jun 08 2017 04:01
chewieez sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:warning: chewieez already gave gregatgit points
Greg Duncan
@GregatGit
Jun 08 2017 04:02
@Chewieez the moment it doesn't match you can return false
Diego Mayer
@Chrono79
Jun 08 2017 04:02
@Chewieez like that you only compare first and last letter (you overwrite ans several times)
Zach Hope
@Baipanda11
Jun 08 2017 04:02
is it a common experience for everyone to not have any idea WTF the instructions are asking for until you see it/figure it out and then it seems simple?
Greg Duncan
@GregatGit
Jun 08 2017 04:03
@Chewieez So what you need to do is loop through making your checks - if at any stage there is a mismatch return false not need to check any more. So if you get outside the loop return true
Markus Ivancsics
@ivancsicsmarkus
Jun 08 2017 04:03
@Baipanda11 Sometimes it is hard to understand freeCodeCamp. You are not alone.
@Baipanda11 We are here to help you anytime you need!
tommy
@tommygebru
Jun 08 2017 04:04
@Baipanda11 common enough ... the other day I wrote maybe 300 lines of code but only needed 2 lines to solve a challenge...
Zach Hope
@Baipanda11
Jun 08 2017 04:04
@ivancsicsmarkus @tommygebru word , just checkin
thanks
Greg Duncan
@GregatGit
Jun 08 2017 04:04
@Chewieez you only need one if statement - no else statement
Greg Lawrence
@Chewieez
Jun 08 2017 04:06

Ok, so I got the challenge to complete with this code.


function palindrome(str) {
  var ans ;
  str = str.replace(/[^A-Za-z0-9]/g, '');
  str = str.toLowerCase();
  str.split('');

  for (i = 0; i <= str.length - 1; i++) {
    if (str[i] != str[(str.length - 1) - i]) {
    return false;
   }

  }
  return true;
}


palindrome("almostomla");

Will this approach still not work in all cases? The idea of comparing individual characters from beginning and end, then moving to the next, and next to last, etc.

I understand, after reading a tutorial, that there is a better approach that is much faster if you're checking a large amount of text.
But I wasn't sure if this approach would work for all palindromes, albeit slowly.
Diego Mayer
@Chrono79
Jun 08 2017 04:08
@Chewieez you need to compare only half of them, if it's a palindrome that'll be enough
Greg Lawrence
@Chewieez
Jun 08 2017 04:09
That makes sense @Chrono79
Ali
@ichbinali
Jun 08 2017 04:20
Hallo guys, need some help here.
I'm trying to figure out "Counting Cards". My code is as follows:
var count = 0;

function cc(card) {
  // Only change code below this line

  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
    break;

    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
    break;

  }
  if(count > 0) {
    return count += " Bet";
  }
  else {
    return count += " Hold";
  }

  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(8);
It's returning what I think it should.
But the problem is, all the red circles aren't changing into green.
Am i missing something?
heroiczero
@heroiczero
Jun 08 2017 04:22
@ichbinali return count += " Bet"; this is not concrating the string try reviewing it in Free code camp
Markus Ivancsics
@ivancsicsmarkus
Jun 08 2017 04:22

@ichbinali

if(count > 0) {
    return count += " Bet";
  }
  else {
    return count += " Hold";
  }

instead:

if(count > 0) {
    return count + " Bet";
  }
  else {
    return count + " Hold";
  }
Ali
@ichbinali
Jun 08 2017 04:24
![alt](http://www.gifbay.com/gif/5_and_already_learning_who_the_idiots_are-26338/)
lol fail.
Joseph
@revisualize
Jun 08 2017 04:24
@ichbinali Doing += is causing a conflict with your code especially in the return statement.
Ali
@ichbinali
Jun 08 2017 04:24
Thanks you, the two of you. :)
Markus Ivancsics
@ivancsicsmarkus
Jun 08 2017 04:25
@ichbinali It is working :D not failing...
Joseph
@revisualize
Jun 08 2017 04:25
@ichbinali You should be careful with += even if you were to do it outside of the return statement. Because you're turning the number into a string by doing += with a string.
Ali
@ichbinali
Jun 08 2017 04:26
Just realised that. += can only be done with a string and another string, not a number and a string.
Again, thanks. (y)
Joseph
@revisualize
Jun 08 2017 04:26
var num = 5;
num += 1; // 6
num += 1; // 7
num += "a"; // "7a"
num += 1; // "7a1"
num += 1; // "7a11"
Ali
@ichbinali
Jun 08 2017 04:28
Welp, we all have moments like this. :D
Joseph
@revisualize
Jun 08 2017 04:28
@ichbinali I'm not saying don't do it.. I'm saying be mindful. :D
Ali
@ichbinali
Jun 08 2017 04:28
Yeah, I know.
Joseph
@revisualize
Jun 08 2017 04:29
@ichbinali A stylistic suggestion. Have the break; in your switch cases indented as well.
    switch (variable) {
        case "a":
        case "b":
                statement;
                break;
        defualt:
                statement;
    }
You don't need to use 4 spaces though. It just makes things easier to read.
Ali
@ichbinali
Jun 08 2017 04:31
I dunno why, I'm just OCD looking at the break on the same column as the statement. My mind thinks it looks better sitting on the same column as the cases. Guess I'll try to get used to that.
Again, cheers for le help!
Avery Biskup
@fraknard
Jun 08 2017 04:35
Safal
@safal07
Jun 08 2017 04:38

In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called Card Counting.

Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

Count Change Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K', 'A'
You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then 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.

Example Output
"-3 Hold"
"5 Bet"

Hint
Do NOT reset count to 0 when value is 7, 8, or 9.

I don't need explicit answer. Please help me with the algorithm. Help!!

Joseph
@revisualize
Jun 08 2017 04:41
@safal07 What have you written?
@safal07 I've re-written the instructions if you'd like to see that.
Ace-Monkey-Ilium
@Ace-Monkey-Ilium
Jun 08 2017 04:44
HI I made a discord chat to talk about Javascipt because I do not go on gitter.im as much as I do on Discord. I am sharing this so people who do use discord may talk to me! https://discord.gg/WY4G7xy
Vamp
@the-vampiire
Jun 08 2017 04:46
anyone able to help me working with .then promises?
Mario Ley Tello
@23marioley
Jun 08 2017 04:46
can somebody help me in my "Profile Lookup" challenge?

function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0; i<contacts.length; i++){
if (firstName == contacts[i].firstName){
document.write(contacts[i].prop);
}
}

// Only change code above this line
}

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

I can't print the "contacts[i].prop", it just prints "undefined"

OldmanVimes
@OldmanVimes
Jun 08 2017 04:51

function nextInLine(arr, item) {
// Your code here
testArr.push(item);
var elementRemoved=testArr.shift();

return elementRemoved; // Change this line
}

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

Pranav Goel
@pranavgoel25
Jun 08 2017 04:51
Need help in the 'Falsy Bouncer' probem.
OldmanVimes
@OldmanVimes
Jun 08 2017 04:51
What did I do wrong
?
Pranav Goel
@pranavgoel25
Jun 08 2017 04:51
five = four.filter(function(num){
return (!isNaN(num));
This function removes the strings also in the array
OldmanVimes
@OldmanVimes
Jun 08 2017 04:52
All conditions except nextInLine([5,6,7,8,9], 1) should return 5 are met
Pranav Goel
@pranavgoel25
Jun 08 2017 04:52
And I only need to remove the NaN values
suraj-kalu
@suraj-kalu
Jun 08 2017 04:57
need help in title case a sentence
Alexandru Higyedi
@Journeytojah
Jun 08 2017 04:58
Hello, can anyone help me at Selecting from many options with Switch Statements?
Ken Haduch
@khaduch
Jun 08 2017 04:58
@oldmanvines - use arr within your function instead of testArr
@oldmanvimes - the function argument should be used
Henry
@GitHub-Henry
Jun 08 2017 05:00
@the-vampiire here's an example of how promises work https://codepen.io/fccHenry/pen/Qgjjym
OldmanVimes
@OldmanVimes
Jun 08 2017 05:00
Oh thanks a lot. Could u explain in short why did it happen?
@khaduch thanks a lot. Most appreciated.
CamperBot
@camperbot
Jun 08 2017 05:00
:star2: 2955 | @khaduch |http://www.freecodecamp.com/khaduch
oldmanvimes sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Alexandru Higyedi
@Journeytojah
Jun 08 2017 05:05
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case 1:
      console.log("alpha");
      break;
    case 2:
      console.log("beta");
      break;
    case 3:
      console.log("gamma");
      break;
    case 4:
      console.log("delta");
      break;
  }


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

// Change this value to test
caseInSwitch(1);
y u no work? :(
fdemaa
@fdemaa
Jun 08 2017 05:06

Guys why this is wrong ?

// Example
var ourArray = [1,2,3];
ourArray[1] = 3; // ourArray now equals [1,3,3].

// Setup
var myArray = [1,2,3];

// Only change code below this line.
myArray [0] = 3;

I have to modify the array data ?

Coy Sanders
@coymeetsworld
Jun 08 2017 05:06
shouldn't be a space between myArray and the brackets
fdemaa
@fdemaa
Jun 08 2017 05:07
@coymeetsworld thanks coy and hi !
CamperBot
@camperbot
Jun 08 2017 05:07
fdemaa sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 2739 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Mario Ley Tello
@23marioley
Jun 08 2017 05:08
how can I make a screenshot of my code and send it?
Alexandru Higyedi
@Journeytojah
Jun 08 2017 05:08
you dont need to screenshot it
use code here
pahosler
@pahosler
Jun 08 2017 05:08
higlight your code press ctrl+c
Alexandru Higyedi
@Journeytojah
Jun 08 2017 05:08
oh
put code in between ` without the spaces `
:/
pahosler
@pahosler
Jun 08 2017 05:09
use three ` aka ``` then paste code with ctrl+v
Alexandru Higyedi
@Journeytojah
Jun 08 2017 05:09
i fail
Coy Sanders
@coymeetsworld
Jun 08 2017 05:09
np and hey @fdemaa
Vamp
@the-vampiire
Jun 08 2017 05:11
@GitHub-Henry thank you henry. I actually have the promise working as expected. my issue is with trying to return something out of it
if i can fix this then my slackbot will be working
Henry
@GitHub-Henry
Jun 08 2017 05:12
@the-vampiire the example returns data, converts to json then displays it
@the-vampiire insert your own functions instead of display
Mario Ley Tello
@23marioley
Jun 08 2017 05:13
//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 (firstName == contacts[i].firstName){
       return contacts[i].prop;
    }
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Can somebody help me in this challenge?
I can't return "contacts[i].prop"
thank you @Journeytojah @pahosler
CamperBot
@camperbot
Jun 08 2017 05:14
23marioley sends brownie points to @journeytojah and @pahosler :sparkles: :thumbsup: :sparkles:
:cookie: 372 | @pahosler |http://www.freecodecamp.com/pahosler
:cookie: 194 | @journeytojah |http://www.freecodecamp.com/journeytojah
Vamp
@the-vampiire
Jun 08 2017 05:17
@GitHub-Henry I think my situation is more complex. I have a function with a promise occuring within it. i want to return data from the function which will then be used in another module
where that function is called
Markus Kiili
@Masd925
Jun 08 2017 05:18
@23marioley .prop looks for property key "prop", and not the key stored in parameter prop. Use bracket notation.
Aditya Soni
@adist98
Jun 08 2017 05:18
i have to reverse a string and this is my code, please help me

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

reverseString("hello");
Vamp
@the-vampiire
Jun 08 2017 05:18
@GitHub-Henry do you have any experience with that? care to view my code?
Markus Kiili
@Masd925
Jun 08 2017 05:19
@adist98 .join("");
Henry
@GitHub-Henry
Jun 08 2017 05:19
@the-vampiire if i was staying i'd say sure, but i'm just about to head out
Aditya Soni
@adist98
Jun 08 2017 05:19
it worked , please explain @Masd925
never mind i got it @Masd925
Mario Ley Tello
@23marioley
Jun 08 2017 05:20
@Masd925 Thank you man!!
CamperBot
@camperbot
Jun 08 2017 05:20
23marioley sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4223 | @masd925 |http://www.freecodecamp.com/masd925
Aditya Soni
@adist98
Jun 08 2017 05:20
thanks for the help @Masd925
CamperBot
@camperbot
Jun 08 2017 05:20
adist98 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4224 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jun 08 2017 05:20
@adist98 Try to chain those method calls to one line and remove the redundant variables you use.
Vamp
@the-vampiire
Jun 08 2017 05:20
@GitHub-Henry alright have a good night
Henry
@GitHub-Henry
Jun 08 2017 05:21
@the-vampiire good luck
Aditya Soni
@adist98
Jun 08 2017 05:21
okay, i will try @Masd925
Vamp
@the-vampiire
Jun 08 2017 05:21
@GitHub-Henry thanks I’ve been stuck on it for some time now. cant seem to put it into the correct wording to search for an answer
CamperBot
@camperbot
Jun 08 2017 05:21
the-vampiire sends brownie points to @github-henry :sparkles: :thumbsup: :sparkles:
:cookie: 350 | @github-henry |http://www.freecodecamp.com/github-henry
Vamp
@the-vampiire
Jun 08 2017 05:22

anyone else think they can help? here is my issue:

I have a function which has a promise occuring within it. i want to return data from the function to another module where it is being called. (so promise [data] --> function [data] --> return to main module and send a POST response with that data)

Aditya Soni
@adist98
Jun 08 2017 05:23
@Masd925 , i cant think of a way - help
Markus Kiili
@Masd925
Jun 08 2017 05:24
@adist98 return str.split("").reverse().join("");
Aditya Soni
@adist98
Jun 08 2017 05:24
@Masd925 that is awesome man
works like a charm
Fernando Garibaldi
@Ferngari95
Jun 08 2017 05:31
Could someone help me with passing on the non alphabet characters in Ceasars Cipher?
function rot13(str) { // LBH QVQ VG!
var Index = [];
var Cipher = [];
var alph = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
alph = alph.join(" ");
alph = alph.toUpperCase();
alph = alph.split(" ");
//Getting Index
for(var i=0;i<str.length;i++){
Index[i] = alph.indexOf(str[i]);
if(Index[i] < 0){
Index[i] =" ";
}
}
//Shifting string
for(var n = 0;n < Index.length;n++){
if( Index[n] < 13){
Index[n] = Index[n]+13;
}
else{
Index[n] = Index[n]-13;
}
}
//Decoding Cipher
for(var j = 0; j < Index.length;j++){
Cipher[j] = alph[Index[j]];
}
return Cipher;
}
Mo.
@mokyox
Jun 08 2017 05:33
@Ferngari95 Just a hint, try using MarkDown for posting your code; it makes it alot cleaner to see.
function rot13(str) { // LBH QVQ VG!
  var Index = [];
  var Cipher = [];
  var alph = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
  alph = alph.join(" ");
  alph = alph.toUpperCase();
  alph = alph.split(" ");
//Getting Index  
  for(var i=0;i<str.length;i++){
      Index[i] = alph.indexOf(str[i]);
    if(Index[i] < 0){
      Index[i] =" ";
    }
  }
//Shifting string  
for(var n = 0;n < Index.length;n++){ 
      if( Index[n] < 13){
        Index[n] = Index[n]+13;
      }
    else{
      Index[n] = Index[n]-13;
    } 
}
//Decoding Cipher  
for(var j = 0; j < Index.length;j++){
  Cipher[j] = alph[Index[j]];
}
  return Cipher;
}
Markus Kiili
@Masd925
Jun 08 2017 05:33
@Ferngari95 There are methods String.fromCharCode and str.charCodeAt. With those you can work with charcodes without listing all the letters.
Fernando Garibaldi
@Ferngari95
Jun 08 2017 05:33
ahh
Ming Zhu
@chocobrownie
Jun 08 2017 05:35
blob
Hi there, I'm trying Atom for the first time. I pasted a javasript code in atom and it doesn't seem right. Any idea why?
Anyone had experience with it?
erkais
@erkais
Jun 08 2017 05:40
"""
```

function palindrome(str) {
// Good luck!
var saved = str.replace(/[^a-zA-Z]+/gi,'').toLowerCase();
var savedRev = str.replace(/[^a-zA-Z]+/gi,'').toLowerCase().split('').reverse().join('');

console.log(saved);

if(saved === savedRev)
return true;
else
return false;
}

palindrome("eye");
```

Mo.
@mokyox
Jun 08 2017 05:43
@erkais You want your code formatted like this
function palindrome(str) {
// Good luck!
var saved = str.replace(/[^a-zA-Z]+/gi,'').toLowerCase();
var savedRev = str.replace(/[^a-zA-Z]+/gi,'').toLowerCase().split('').reverse().join('');
console.log(saved);
if(saved === savedRev)
return true;
else
return false;
}
palindrome("eye");
rugano
@rugano
Jun 08 2017 05:44
Hello campers,where am i failing and how should i correct the spinal tap case code?

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins

  //change all '_' and spaces to a '-'
  var finStr = str.replace(/[_]/g, '-');


  function upperToHyphenLower(match,offset,string){

    //see the arguments of the callback function.
    for(var d = 0;d < arguments.length;d++){
      console.log(arguments[d]);
    }

    //convert the words to lowercase and add a '-' to a word that starts with a capital letter.
    if(offset > 0){
      if(string[offset-1] === '-'){
        return match.toLowerCase();
      }
      else{
        return '-'+match.toLowerCase();
      }

    }


    //use replace() method to change capital letters for dash if necessary.


 return finStr.replace(/[A-Z]/g, upperToHyphenLower);

  }

spinalCase('This Is Spinal Tap');
Dilbarcan
@Dilbarcan
Jun 08 2017 05:51
how can i slove the problem with "String Immutability"? myStr="Jello World";
Manish Giri
@Manish-Giri
Jun 08 2017 06:00
@Dilbarcan you need to assign a new string to the variable
Dilbarcan
@Dilbarcan
Jun 08 2017 06:05
@Manish-Giri thanks, is down....but i did't unterstand the Sense
CamperBot
@camperbot
Jun 08 2017 06:05
dilbarcan sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5884 | @manish-giri |http://www.freecodecamp.com/manish-giri
ShirazPirzada
@ShirazPirzada
Jun 08 2017 06:06

// Setup
var a;
var b = 2;

// Only change code below this line
var a = 7;
var b = 7;
Can we someone show me the code of this need help "Assign the contents of a to variable b how do i do that ?
Long Nguyen
@longnt80
Jun 08 2017 06:08
assign a to b
var a = 7 meaning assign 7 to a
Ella
@ellacai
Jun 08 2017 06:09
@ShirazPirzada your last line should be var b = a;
the way you have it set up now, if you reassign a as another value, b will not change.
ShirazPirzada
@ShirazPirzada
Jun 08 2017 06:10
@ellacai thx
HappyRedditor59
@HappyRedditor59
Jun 08 2017 06:18
Anyone here in Using Objects for Lookups? Why does return lookup[val]; return the right statement while return lookup.val; does not return anything?
Markus Kiili
@Masd925
Jun 08 2017 06:19
@HappyRedditor59 .val looks for property key "val", and [val] looks for property key stored in parameter val.
@ellacai If you do var b=a; and then reassign to a, the value of b doesn't change. Just to be clear.
HappyRedditor59
@HappyRedditor59
Jun 08 2017 06:21
@Masd925 thank you!
CamperBot
@camperbot
Jun 08 2017 06:21
happyredditor59 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4225 | @masd925 |http://www.freecodecamp.com/masd925
Jason Yang
@zjasonyang
Jun 08 2017 06:23
i have issue with "Arguments Optional". code runs without problem on repl.it but can't pass the test.
Markus Kiili
@Masd925
Jun 08 2017 06:24
@zjasonyang Post the code please.
sonnguyen2603
@sonnguyen2603
Jun 08 2017 06:25

//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
if (firstName == contacts[firstName] && contacts.hasOwnProperty(prop)){
return contacts[prop];
}
else if(firstName != contacts[firstName]){
return "No such contact";
}
else if(!contacts.hasOwnProperty(prop)){
return "No such property";
}
// Only change code above this line
}

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

can anyone show me where did I get this wrong ?
Markus Kiili
@Masd925
Jun 08 2017 06:26
@sonnguyen2603 You need to loop the contacts array first.
rugano
@rugano
Jun 08 2017 06:26
Hey campers,am still stuck on spinal tap case
sonnguyen2603
@sonnguyen2603
Jun 08 2017 06:26
@Masd925 oh yeah right, thanks
CamperBot
@camperbot
Jun 08 2017 06:26
sonnguyen2603 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4226 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jun 08 2017 06:26
@zjasonyang Global variable like that can mess up fcc tests.
@zjasonyang JS functions return undefined by default, so you can avoid returning undefined there.
Jason Yang
@zjasonyang
Jun 08 2017 06:28
the test require : addTogether(2)(3) should return 5.
and my code actually return 5 in repl.it
heidisdad2
@heidisdad2
Jun 08 2017 06:29
guys im stumped
Markus Kiili
@Masd925
Jun 08 2017 06:29
@zjasonyang Did you put the variable declaration inside the function?
heidisdad2
@heidisdad2
Jun 08 2017 06:30
///
\\
'''
CamperBot
@camperbot
Jun 08 2017 06:31
:bulb: to format code use backticks! ``` more info
heidisdad2
@heidisdad2
Jun 08 2017 06:32
// Setup
function phoneticLookup(val) {
  var result = "";

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



  var lookup = "alpha";
  lookup;

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

// Change this value to test
phoneticLookup("charlie");
thanks camper
@camperbot thanks camper
CamperBot
@camperbot
Jun 08 2017 06:32
heidisdad2 sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 3301 | @camperbot |http://www.freecodecamp.com/camperbot
heidisdad2
@heidisdad2
Jun 08 2017 06:33
i was supposed to do a lookup table
i got confused
monk
@monkingame
Jun 08 2017 06:35
hi,Is there any lessons about javascript closure?thanks!
heidisdad2
@heidisdad2
Jun 08 2017 06:36
Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable.
that is my assignment can anyone give me a hint
rugano
@rugano
Jun 08 2017 06:37

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins

  //change all '_' and spaces to a '-'
  var finStr = str.replace(/[_]/g,'-');


  function upperToHyphenLower(match,offset,string){

    //see the arguments of the callback function.
    for(var d = 0;d < arguments.length;d++){
      console.log(arguments[d]);
    }

    //convert the words to lowercase and add a '-' to a word that starts with a capital letter.
    if(offset > 0){
      if(string[offset-1] === '-'){
        return match.toLowerCase();


    }
      else{
        return '-'+match.toLowerCase();
      }

    }

  }

    //use replace() method to change capital letters for dash if necessary.


 return finStr.replace(/[A-Z]/g,upperToHyphenLower);


}

spinalCase('This Is Spinal Tap');
still not getting it,how do i correct it?
@Masd925 hi,may i have your help on spinal tap case challenge?
sonnguyen2603
@sonnguyen2603
Jun 08 2017 06:40

@sonnguyen2603

//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 (firstName == contacts[i][firstName] && contacts[i].hasOwnProperty(prop)){
return contacts[prop];
}
}
for(var j =0; j<contacts.length;j++){
if(firstName != contacts[j][firstName]){
return "No such contact";
}
}
return "No such property";

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
can anyone help me to solve this ?

Aditya Soni
@adist98
Jun 08 2017 06:41
the palindrome algorithm challenge says that we have to remove the punctuation but it passes punctuation in the test.Here is my code

function palindrome(str) {
  // Good luck!
  var newstr = str.replace(/([\d+])([-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/])([\s])/i, "");
  var secondVar = newstr.toLowerCase();
  var array = secondVar.split('');
  var newArray=[];
  newArray = array.reverse();
  var a = newArray.join("");
  if (a == secondVar){
      return true;
  }else {
      return false;
  }

}



palindrome("eye");
PLEASE HELP!!!!
rugano
@rugano
Jun 08 2017 06:43

function palindrome(str) {
  // Good luck!
   /*To convert string to lower case and replace anything which is not Alphanumeric and digit*/
 var lCaseStr = str.toLowerCase().replace(/([^a-z\d]*)/g, '');


  //To reverse the above string;
  var revStr = lCaseStr.split('').reverse().join('');

  //To check whether 'str' is palindrome or not
  return revStr == lCaseStr;




}



palindrome("1 eye for of 1 eye");
@adist98 have a look at that
Calin Seredenco
@Noit0ra
Jun 08 2017 06:45

can u guys help my what si wrong with my code

Instructions
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found".

my code:

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

function checkObj(checkProp) {
// Your Code Here

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

}

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

Aditya Soni
@adist98
Jun 08 2017 06:45
@rugano thanks man
CamperBot
@camperbot
Jun 08 2017 06:45
adist98 sends brownie points to @rugano :sparkles: :thumbsup: :sparkles:
:cookie: 283 | @rugano |http://www.freecodecamp.com/rugano
rugano
@rugano
Jun 08 2017 06:46
@adist98 welcome,
Markus Kiili
@Masd925
Jun 08 2017 06:47
@Noit0ra What is the object you are supposed to test?
You have if(checkObj.hasOwnProperty(checkProp))
rugano
@rugano
Jun 08 2017 06:48
@Noit0ra to post your code here type three backticks like this ```then press shift+enter type your code press ctrl+enter
Calin Seredenco
@Noit0ra
Jun 08 2017 06:48
ok thx
Vedant Kashyap
@vedant15188
Jun 08 2017 06:49

The strings aren't getting replaced... what am I doing Wrong? I'm on Validate US Telephone numbers

https://www.freecodecamp.com/challenges/validate-us-telephone-numbers
Here is my code for the same:


function telephoneCheck(str) {
  // Good luck!
  str=str.replace(/ (-1) /,"11");
  str=str.replace(/ (\(\d{3}\)) /g,"");
  str=str.replace(/ ( )|(-) /g,"");
  return str;
//   return str.length;
  if(str.length!=10 && str.length!=11) {
//     return "hey";
    return false;
  }
  if(str.length==10) {
    for(var i=0; i<str.length; i++) {
      if(isNaN(parseInt(str[i]))) {
        return false;
      }
    }
  }
  if(str.length==11) {
    if(str[0]!=1)
      return false;
  }
  return true;
}


telephoneCheck("1 555)555-5555");
heidisdad2
@heidisdad2
Jun 08 2017 06:49
'''
CamperBot
@camperbot
Jun 08 2017 06:49
:bulb: to format code use backticks! ``` more info
heidisdad2
@heidisdad2
Jun 08 2017 06:50
function phoneticLookup(val) {
  var result = "";

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

  var value = "alpha";
  lookup.value;
pooja
@poojaghetia
Jun 08 2017 06:50
plz help to solveMake Unique Objects by Passing Parameters to our Constructor
rugano
@rugano
Jun 08 2017 06:50
Any idea on solving spinal tap case challenge?
heidisdad2
@heidisdad2
Jun 08 2017 06:50
whatam i doing wrong
just a small hint please
Vedant Kashyap
@vedant15188
Jun 08 2017 06:52
umm your function isn't returning anything...
@heidisdad2 ^
heidisdad2
@heidisdad2
Jun 08 2017 06:52
oh
i had return val; below that
Vedant Kashyap
@vedant15188
Jun 08 2017 06:52
what exactly are you trying to achieve here? @heidisdad2
Matúš Námešný
@LordMathis
Jun 08 2017 06:53
@heidisdad2 You should be using bracket notation
heidisdad2
@heidisdad2
Jun 08 2017 06:53
@vedant15188
rugano
@rugano
Jun 08 2017 06:53
@vedant15188 can you help me out on spinal tap case challenge?
heidisdad2
@heidisdad2
Jun 08 2017 06:53
@vedant15188 i meant that i had return result; below that code
Vedant Kashyap
@vedant15188
Jun 08 2017 06:53
@heidisdad2 result isin't being allocated any value
@rugano send me your code and the link to the challenge
heidisdad2
@heidisdad2
Jun 08 2017 06:55
function phoneticLookup(val) {
  var result = "";

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

  var value = "alpha";
  lookup[value];

  // Only change code above this line
  return result;
}
Matúš Námešný
@LordMathis
Jun 08 2017 06:56
@heidisdad2 you are not assigning anything to result
heidisdad2
@heidisdad2
Jun 08 2017 06:56
ooops there was one more line i am missing
phoneticLookup("charlie");
Vedant Kashyap
@vedant15188
Jun 08 2017 06:56
@heidisdad2 you aren't allotting any value to result
HappyRedditor59
@HappyRedditor59
Jun 08 2017 06:56
can anyone explain to me what is the difference of variable.something with variable["something"]?
Vedant Kashyap
@vedant15188
Jun 08 2017 06:56
your function is always gonna return ""
rugano
@rugano
Jun 08 2017 06:57
heidisdad2
@heidisdad2
Jun 08 2017 06:57
@LordMathis @vedant15188 why am I not assigning it anything
i thought that is what the lookup table was supposed to do
rugano
@rugano
Jun 08 2017 06:57

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins

  //change all '_' and spaces to a '-'
  var finStr = str.replace(/[_]/g,'-');


  function upperToHyphenLower(match,offset,string){

    //see the arguments of the callback function.
    for(var d = 0;d < arguments.length;d++){
      console.log(arguments[d]);
    }

    //convert the words to lowercase and add a '-' to a word that starts with a capital letter.
    if(offset > 0){
      if(string[offset-1] === '-'){
        return match.toLowerCase();


    }
      else{
        return '-'+match.toLowerCase();
      }

    }

  }

    //use replace() method to change capital letters for dash if necessary.


 return finStr.replace(/[A-Z]/g,upperToHyphenLower);


}

spinalCase('This Is Spinal Tap');
@vedant15188 that one
Matúš Námešný
@LordMathis
Jun 08 2017 06:58
@heidisdad2 your result variable contains "" and you never assign to it anything else
@HappyRedditor59 it's equivalent
heidisdad2
@heidisdad2
Jun 08 2017 06:58
thanks
let me see if i can figure it out then
HappyRedditor59
@HappyRedditor59
Jun 08 2017 07:02
thanks @LordMathis
CamperBot
@camperbot
Jun 08 2017 07:02
happyredditor59 sends brownie points to @lordmathis :sparkles: :thumbsup: :sparkles:
:cookie: 344 | @lordmathis |http://www.freecodecamp.com/lordmathis
Vedant Kashyap
@vedant15188
Jun 08 2017 07:03

@rugano you can use somthing like

string.replace(regex for spaces and underscore, "-");

another can be

string.replace(uppercase if its not followed by a space, yourMatch => yourMatch.toLowerCase());

and finally

string.replace(lowercase if its followed by a capital letter, theMath=>theMath.toLowerCase()+"-");
@Aakriti94 great... not bad at all
Aakriti
@Aakriti94
Jun 08 2017 07:05
@vedant15188 ty
CamperBot
@camperbot
Jun 08 2017 07:05
aakriti94 sends brownie points to @vedant15188 :sparkles: :thumbsup: :sparkles:
:cookie: 302 | @vedant15188 |http://www.freecodecamp.com/vedant15188
Vedant Kashyap
@vedant15188
Jun 08 2017 07:05

The strings aren't getting replaced... what am I doing Wrong? I'm on Validate US Telephone numbers

https://www.freecodecamp.com/challenges/validate-us-telephone-numbers
Here is my code for the same:


function telephoneCheck(str) {
  // Good luck!
  str=str.replace(/ (-1) /,"11");
  str=str.replace(/ (\(\d{3}\)) /g,"");
  str=str.replace(/ ( )|(-) /g,"");
  return str;
//   return str.length;
  if(str.length!=10 && str.length!=11) {
//     return "hey";
    return false;
  }
  if(str.length==10) {
    for(var i=0; i<str.length; i++) {
      if(isNaN(parseInt(str[i]))) {
        return false;
      }
    }
  }
  if(str.length==11) {
    if(str[0]!=1)
      return false;
  }
  return true;
}


telephoneCheck("1 555)555-5555");
rugano
@rugano
Jun 08 2017 07:05
@vedant15188 i use it at final return?
Vedant Kashyap
@vedant15188
Jun 08 2017 07:06
yeah... if you wanna club all those 3 together... or just use them separately but they all must be in a specific order for replaces to be done at the right time...
@rugano ^
heidisdad2
@heidisdad2
Jun 08 2017 07:06
@vedant15188 @LordMathis ```
// Setup
function phoneticLookup(val) {
  var result = val;

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

  var value = "alpha";
  lookup[value] ;

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


// Change this value to test
phoneticLookup("charlie");
Raghu Raj Rai
@Raidestro
Jun 08 2017 07:06
Can someone please tell me why this code is not working :

function factorialize(num) {
var fact=1;
for(var i=1;i<=num;i++){
fact = fact * num;
}
return fact;
}

factorialize(5);

heidisdad2
@heidisdad2
Jun 08 2017 07:07
its assigned to val ..im not understanding this lookup table
Manish Giri
@Manish-Giri
Jun 08 2017 07:07
@heidisdad2 delete this
  var value = "alpha";
  lookup[value] ;
the property you need to lookup is val
and assign it to result.
Vedant Kashyap
@vedant15188
Jun 08 2017 07:08
@Raidestro try using the keyword let instead of var
heidisdad2
@heidisdad2
Jun 08 2017 07:08
yeah the lookup table is supposed to replace the switch statement
Raghu Raj Rai
@Raidestro
Jun 08 2017 07:09
@vedant15188 Why ?
heidisdad2
@heidisdad2
Jun 08 2017 07:10
i tried that and it still returns charlie...if i say charlie it is supposed to return chicago
Manish Giri
@Manish-Giri
Jun 08 2017 07:11
post code
Matúš Námešný
@LordMathis
Jun 08 2017 07:11
@heidisdad2 your result shoud be whats in the table for val. You should use bracket notation to acces it from the lookup table. For example if I have obj={"1": "one", "2": "two"} you can do obj["1"] to return one
jasonrest
@jasonrest
Jun 08 2017 07:12
hello room. need help with a stand in line challenge if possible.
Manish Giri
@Manish-Giri
Jun 08 2017 07:12
@jasonrest sure, show your code
Matúš Námešný
@LordMathis
Jun 08 2017 07:12
@Aakriti94 looks very nice
jasonrest
@jasonrest
Jun 08 2017 07:13

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

var removed = arr.shift();
arr.push(item);

return removed; // Change this line
}

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

rugano
@rugano
Jun 08 2017 07:13
@vedant15188 thanks
CamperBot
@camperbot
Jun 08 2017 07:13
rugano sends brownie points to @vedant15188 :sparkles: :thumbsup: :sparkles:
:cookie: 303 | @vedant15188 |http://www.freecodecamp.com/vedant15188
Vedant Kashyap
@vedant15188
Jun 08 2017 07:13
@Raidestro lol you are multiplying the factorial by num ... and not by i
jasonrest
@jasonrest
Jun 08 2017 07:13
I am getting one error saying that nextInLine([], 1) should return 1
Vedant Kashyap
@vedant15188
Jun 08 2017 07:13
sorry didn't notice it before
Manish Giri
@Manish-Giri
Jun 08 2017 07:13
@jasonrest inverse your operations
Vedant Kashyap
@vedant15188
Jun 08 2017 07:13
no problem @rugano
Manish Giri
@Manish-Giri
Jun 08 2017 07:13
push first
then shift
jasonrest
@jasonrest
Jun 08 2017 07:14
@Manish-Giri ohhhhhhhhh
ok ill try it.
Raghu Raj Rai
@Raidestro
Jun 08 2017 07:14
@vedant15188 T_T Oh god why
@vedant15188 Thanx T_T
CamperBot
@camperbot
Jun 08 2017 07:14
raidestro sends brownie points to @vedant15188 :sparkles: :thumbsup: :sparkles:
:cookie: 304 | @vedant15188 |http://www.freecodecamp.com/vedant15188
heidisdad2
@heidisdad2
Jun 08 2017 07:14
@LordMathis thanks, i am going to give that a try
Vedant Kashyap
@vedant15188
Jun 08 2017 07:14
@Raidestro its fine... I did this mistake too... just remember not to repeat it again :P
heidisdad2
@heidisdad2
Jun 08 2017 07:15
@LordMathis that my have cleared things up for me
Raghu Raj Rai
@Raidestro
Jun 08 2017 07:15
@vedant15188 :P Never will
jasonrest
@jasonrest
Jun 08 2017 07:15
@Manish-Giri works.....thanks so much. I stuck with it as long as I could but didnt think about the order
CamperBot
@camperbot
Jun 08 2017 07:15
jasonrest sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5885 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jun 08 2017 07:15
:+1:
Vedant Kashyap
@vedant15188
Jun 08 2017 07:16

The strings aren't getting replaced... what am I doing Wrong? I'm on Validate US Telephone numbers

https://www.freecodecamp.com/challenges/validate-us-telephone-numbers
Here is my code for the same:


function telephoneCheck(str) {
  // Good luck!
  str=str.replace(/ (-1) /,"11");
  str=str.replace(/ (\(\d{3}\)) /g,"");
  str=str.replace(/ ( )|(-) /g,"");
  return str;
//   return str.length;
  if(str.length!=10 && str.length!=11) {
//     return "hey";
    return false;
  }
  if(str.length==10) {
    for(var i=0; i<str.length; i++) {
      if(isNaN(parseInt(str[i]))) {
        return false;
      }
    }
  }
  if(str.length==11) {
    if(str[0]!=1)
      return false;
  }
  return true;
}


telephoneCheck("1 555)555-5555");
@Manish-Giri could you help me? ^
Vedant Kashyap
@vedant15188
Jun 08 2017 07:23
ANYBODY????? :/
HappyRedditor59
@HappyRedditor59
Jun 08 2017 07:24
can someone pls help me? my code only displays a total of 6 instead of 20. my code is as follows:
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
for (var i = 0; i < myArr.length; i++){
  var total = 0;
  total += myArr[i];
}
Ogundele Olumide
@Lumexralph
Jun 08 2017 07:26
@HappyRedditor59 you should initialize total before the loop
@Manish-Giri Bro!
HappyRedditor59
@HappyRedditor59
Jun 08 2017 07:26
oh my god im stupid haha thanks @Lumexralph
CamperBot
@camperbot
Jun 08 2017 07:26
happyredditor59 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1881 | @lumexralph |http://www.freecodecamp.com/lumexralph
heidisdad2
@heidisdad2
Jun 08 2017 07:26
@LordMathis man i am still not getting through that lookup table
Ogundele Olumide
@Lumexralph
Jun 08 2017 07:27
@heidisdad2 show your code
Matúš Námešný
@LordMathis
Jun 08 2017 07:28
@heidisdad2 return = lookup[val]
that should do it
Dex777
@Dex777
Jun 08 2017 07:29
This is fun.
wonder
@wonder2991
Jun 08 2017 07:30
yup
heidisdad2
@heidisdad2
Jun 08 2017 07:32
@LordMathis yeah that worked thank you
CamperBot
@camperbot
Jun 08 2017 07:32
heidisdad2 sends brownie points to @lordmathis :sparkles: :thumbsup: :sparkles:
:cookie: 345 | @lordmathis |http://www.freecodecamp.com/lordmathis
heidisdad2
@heidisdad2
Jun 08 2017 07:33
@lord mathis...the program threw me off because it told me to only change code above that line
baersc
@baersc
Jun 08 2017 07:33
Hey guys, why is this code giving me a "Bad assignment." warning?
 arguments[0] = arguments[0].filter(tester);
heidisdad2
@heidisdad2
Jun 08 2017 07:36
@LordMathis now i get it. I tried lookup[val] = result
return result; and that didn't work

but when i say result = lookup[val];
return result;

that works

@LordMathis why is that? shouldn't = not matter which side of the equation its on?
Ogundele Olumide
@Lumexralph
Jun 08 2017 07:39
@baersc what environment is your code?
Matúš Námešný
@LordMathis
Jun 08 2017 07:39
@heidisdad2 = assigns the value on the right to the value on the left, whent you do lookup[val] = result it assigns the value in result to lookup[val]
heidisdad2
@heidisdad2
Jun 08 2017 07:41
@LordMathis thanks i really struggled there. apreciate the help
CamperBot
@camperbot
Jun 08 2017 07:41
heidisdad2 sends brownie points to @lordmathis :sparkles: :thumbsup: :sparkles:
:warning: heidisdad2 already gave lordmathis points
HappyRedditor59
@HappyRedditor59
Jun 08 2017 07:43
I'm on Profile Lookup and pressed reset button, causing my code including the pre-written ones to be removed. Has anyone encountered an issue like this before?
Mark R. Baker
@mrbaker1917
Jun 08 2017 07:47
Hello all, I have a question about the filter function. How do I make it to compare elements in two different subarrays?
Mark R. Baker
@mrbaker1917
Jun 08 2017 07:52
I guess, what I am thinking is that I need two nested for loops to compare the individual elements in the subarrays, and this should be inside the filter.
baersc
@baersc
Jun 08 2017 07:53
@Lumexralph What do you mean what environment?
@mrbaker1917 Which challenge are you working on?
Mark R. Baker
@mrbaker1917
Jun 08 2017 07:54
Sorted Union
My code so far:
function uniteUnique(arr) {
  var args = Array.prototype.slice.call(arguments);
  var newArray = [];
   newArray = args.filter(function(val) {
       for (var i = 0; i < args.length; i++) {
         if (args[i] === args[i])
         return val;
       }
     });
  return newArray;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
I know it does not make sense. I am just having trouble figuring how to filter out redundant elements inside subarrays.
I know that filter iterates through the array, but does it go through the subarrays?
sorry, too many questions.
baersc
@baersc
Jun 08 2017 07:57
@mrbaker1917 Ahh, I'm pretty far behind you. not sure i'd be able to help
Mark R. Baker
@mrbaker1917
Jun 08 2017 07:59
That's ok. Thanks @baersc Good luck coding!
CamperBot
@camperbot
Jun 08 2017 07:59
mrbaker1917 sends brownie points to @baersc :sparkles: :thumbsup: :sparkles:
:cookie: 255 | @baersc |http://www.freecodecamp.com/baersc
baersc
@baersc
Jun 08 2017 07:59
@mrbaker1917 Maybe build a for loop that iterates through the primary array and then nest your .filter() call inside of that. You'll want to move your callback function outside of the new foor loop though.
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:00
I tried that but I think it is not a good idea to put a function inside a for loop.
baersc
@baersc
Jun 08 2017 08:00
Your function doesn' thave to be inside of the for loop though, you just call it from inside the loop, right?
Ogundele Olumide
@Lumexralph
Jun 08 2017 08:01

@Lumexralph What do you mean what environment?

@baersc where your code is

Mark R. Baker
@mrbaker1917
Jun 08 2017 08:01
I am going to try using indexOf
Pieter Stokkink
@forkerino
Jun 08 2017 08:02
@mrbaker1917 easiest is to concatenate the arrays first and then do the filter.
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:02
I thought of that, Peter, but then how will I maintain the order?
Ogundele Olumide
@Lumexralph
Jun 08 2017 08:03
@forkerino Bro!
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:03
I guess it depends on how I used the filter.
baersc
@baersc
Jun 08 2017 08:07
@mrbaker1917 From what I've read so far, it seems like its okay to use a callback function inside of a for loop so long as the callback function is decalred outside of the loop.
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:07
Thanks, baersc. I did not know that.
Derek Reilly
@Delboyeire
Jun 08 2017 08:07
Hey guys could someone help with this please
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
} else {
return "No such contact";
}
}
baersc
@baersc
Jun 08 2017 08:10
@Lumexralph Heres my code in whole,
function destroyer(arr) {
    function tester(test) {
        return test !== remove;
    }

    for (var i = 1; i < arguments.length; i++) { 
        var remove = arguments[i];
        arguments[0] = arguments[0].filter(tester);
    }
    return arguments[0];
}
Pieter Stokkink
@forkerino
Jun 08 2017 08:12
@Lumexralph :wave:
@mrbaker1917 if you concatenate you keep the order. Just make sure you only keep the first instance of any value you encounter (which is easy with an .indexOf comparison in your filter, the second argument to filter is namely the index of the current element).
@baersc @mrbaker1917 in this case it is not necessary, but it is better to have a loop inside a filter than the other way around.
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:14
@forkerino thanks! The only problem I am having now is how to filter out repeat values. I tried val !=== val, but this gives me an empty array.
CamperBot
@camperbot
Jun 08 2017 08:14
mrbaker1917 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2497 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 08 2017 08:14
@mrbaker1917 that would only keep NaN
:)
Ming Zhu
@chocobrownie
Jun 08 2017 08:15
Hi guys, just starting to play with Atom for the first time. Anyone know why this happened?
blob
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:15
my code:

function uniteUnique(arr) {
  var args = Array.prototype.slice.call(arguments);
  var newArray = [];

 for (var i = 0; i < args.length; i++) {
   newArray = newArray.concat(args[i]);
 }
 newArray = newArray.filter(function(val) {
   return val !== val;
  });
  return newArray;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
marcelovbb
@marcelovbb
Jun 08 2017 08:15
for(var i = 0;i < contacts.length; i++){
if(contacts[i].firstName == firstName){
if(contacts[i].hasOwnProperty(prop)){
console.log(contacts[i].prop);
return contacts[i].prop;**
}else{
return "No such property";
}
}
}
return "No such contact";
Pieter Stokkink
@forkerino
Jun 08 2017 08:15
@mrbaker1917 you would have to check if the index of the value is the index of the current element (.indexOf finds the first occurence).
baersc
@baersc
Jun 08 2017 08:15
@forkerino Even if you declare the function outside of the loop?
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:15
o cool
marcelovbb
@marcelovbb
Jun 08 2017 08:15
Can somone help. I just missiing the return I put ** on
challenge 216
Pieter Stokkink
@forkerino
Jun 08 2017 08:16
@baersc the thing is, often when you use higher order functions, you won't need any loops. So if you force yourself to start that way, in most cases you can solve it without for/while loops.
Is it technically problematic to put filter inside a loop? In some cases yes, it definitely makes it harder to reason about the code
@chocobrownie no exp with Atom, but it looks like you need to install node
Ming Zhu
@chocobrownie
Jun 08 2017 08:18
@forkerino what is node? node.js?
Pieter Stokkink
@forkerino
Jun 08 2017 08:18
yes, @chocobrownie atom uses it to run your code.
no need to learn it just yet
just install
Ming Zhu
@chocobrownie
Jun 08 2017 08:19
Got it
Pieter Stokkink
@forkerino
Jun 08 2017 08:20
@baersc same holds by the way for declaring variables inside the loop, like your var remove =. Put the declaration outside the loop and only reassign inside it.
@baersc If you put the arguments in an array, you won't even need a loop, you can use .indexOf much like @mrbaker1917
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:22
@forkerino So how do I get the indexOf to check for the index of the current element?
Prince
@princekumar036
Jun 08 2017 08:22
image.png
baersc
@baersc
Jun 08 2017 08:22
@forkerino I guess I don't understand why it makes a difference if var remove is inside or outside of the loop? Is it something to do with it creating a shadow variable on each iteration?
Prince
@princekumar036
Jun 08 2017 08:23
whats wrong with this?
Pieter Stokkink
@forkerino
Jun 08 2017 08:24
@mrbaker1917 the second parameter of .filter is the index of the current element. So you can compare the .indexOf the first param to the second param, if this is true, it is the first occurence.
Joshua Frias
@Juke-Magic
Jun 08 2017 08:24
guys
how can i make my code find the highest element in an array?
lazzlo
@lazzlo
Jun 08 2017 08:25
function telephoneCheck(str) {
  var elevenDigits = /([^0-9]*[0-9]){11}/;
  if(str.match(elevenDigits)) {
    return true;
  }
  return false;
}
telephoneCheck("10 (757) 622-7382");
Why is this string returning true? Shouldn't the regex match only with strings that have eleven digits?
It does so with the other strings that have eleven digits
Xarri Jorge
@xarrijorge
Jun 08 2017 08:27
@Lazzlo put g flag and see
Blauelf
@Blauelf
Jun 08 2017 08:27
@Lazzlo ^ outside of character sets matches the line start, $ matches the line end. If you don't use those, it might match any substring.
@kodinglife Nope, g flag does not help. It's global flag, used for multiple matches in the same string. We need to match the whole string once here.
Pieter Stokkink
@forkerino
Jun 08 2017 08:28
@baersc behaviour can be unpredictable across javascript engines. In most browsers using the modern V8 engine it won't be a problem, though.
lazzlo
@lazzlo
Jun 08 2017 08:29
@Blauelf Awesome! That solved the problem, thanks man :)
CamperBot
@camperbot
Jun 08 2017 08:29
lazzlo sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4351 | @blauelf |http://www.freecodecamp.com/blauelf
Vedant Kashyap
@vedant15188
Jun 08 2017 08:29
in the record collection challenge why are we making a copy of the collection object by reparsing the collections json converted to a string... why dont be just use
var copy_collection=collection
https://www.freecodecamp.com/challenges/record-collection
Pieter Stokkink
@forkerino
Jun 08 2017 08:30
@vedant15188 because then if you change one, you change the other.
baersc
@baersc
Jun 08 2017 08:30
@forkerino Hmm, that's good to know, thanks! But is that the reason it's better to declare the variable outside of the loop? because on each iteration it will enter a new variable into memory?
CamperBot
@camperbot
Jun 08 2017 08:30
baersc sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2498 | @forkerino |http://www.freecodecamp.com/forkerino
Vedant Kashyap
@vedant15188
Jun 08 2017 08:30
@forkerino it won't make a copy of it?? like why would it change both of them??? this doesn't happen with other normal variable...
Blauelf
@Blauelf
Jun 08 2017 08:31

@21-Orange You could have a variable to keep the maximum, having an initial value of -Infinity, and a loop, in which you compare each element to the maximum-so-far, and update it if required. Or, use Math.max. To apply it to an array, you have to use like

var myMax = Math.max.apply(null, array);

or with ES6 spread operator (won't work on Internet Explorer)

var myMax = Math.max(...array);
Pieter Stokkink
@forkerino
Jun 08 2017 08:31
@vedant15188 objects and arrays are reference types. If you assign the same object to two variables, they will point to the same thing in memory
Vedant Kashyap
@vedant15188
Jun 08 2017 08:32
damn i had totally forgotten that... thanks @forkerino and btw another thanks for helping me with the Validating US Telephone Numbers challenge!! Your logic helped and I solved it this morning! :D
CamperBot
@camperbot
Jun 08 2017 08:32
vedant15188 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2499 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 08 2017 08:32
@vedant15188 :+1: Great!
@baersc I'm not 100% sure about how it works behind the curtains. I think some JS engines will ignore subsequent var declarations with the same name. In strict mode it will definitely throw an error.
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:36
@forkerino Pieter, I am sorry, but I am really not sure how to use indexOf. I also did not know that filter could take two params. The examples in MDN show only one. Anyway, here is what I tried to do:
function uniteUnique(arr) {
  var args = Array.prototype.slice.call(arguments);
  var newArray = [];

 for (var i = 0; i < args.length; i++) {
   newArray = newArray.concat(args[i]);
 }
 newArray = newArray.filter(function(val1, val2) {
   return newArray.indexOf(val2) !== newArray.indexOf(val1);
   });
  return newArray;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Pieter Stokkink
@forkerino
Jun 08 2017 08:38
@mrbaker1917 your second param will be the index, no need to call indexOf for that.
I would do something like return newArray.indexOf(val1) === val2
On mdn you can read all about the parameters at the top in the syntax.
and more under the description
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:40
OK, that works, but I am not sure why.
JS
@Pouncealot
Jun 08 2017 08:41
filter iterates over the array
and calls the function with the args value, index, arr
its not val1, val2
its val, index
Pieter Stokkink
@forkerino
Jun 08 2017 08:42
@mrbaker1917 You are looking at each element in the array, you have 2 pieces of info, the value of the element and the index of the element. You then look for the first index of the element in the array (that is what indexOf does) and check if it is equal to the index of the current element. If it is, great, keep the value (return true), if not remove it, because we already had that value before (return false)
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:42
I think what I do not understand is how comparing index values filters out the redundant real values. I think indexes were just the value's position in the array.
Pieter Stokkink
@forkerino
Jun 08 2017 08:42
and yeah, naming your parameters properly is useful
Long Nguyen
@longnt80
Jun 08 2017 08:43
@mrbaker1917 indexOf only return the first result it can find
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:44
When you write "current element", do you mean exactly the very next element in the array?
Long Nguyen
@longnt80
Jun 08 2017 08:45
@mrbaker1917 so for example an array like this [1,3,4,1]
indexOf(1) is always 0
you'll never have indexOf(1) is 3
HappyRedditor59
@HappyRedditor59
Jun 08 2017 08:45

if i have an array like the following:

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"]
    }
];

how can i loop through each one of those?

Ogundele Olumide
@Lumexralph
Jun 08 2017 08:46
@HappyRedditor59 use any form of looping you know
baersc
@baersc
Jun 08 2017 08:46
@forkerino Trying stict mode, I'm not getting any error from var remove, also, any idea why the linter on the FCC site is showing a "Bad assignment." warning on my line that says arguments[0] = arguments[0].filter(tester);?
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:47
Thanks, @longnt80 ! But isnt the indexOf() the last 1 "3"?
CamperBot
@camperbot
Jun 08 2017 08:47
mrbaker1917 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 339 | @longnt80 |http://www.freecodecamp.com/longnt80
Long Nguyen
@longnt80
Jun 08 2017 08:47
@mrbaker1917 I just edited my comment
:point_up: June 8, 2017 3:45 PM
@mrbaker1917 indexOf(1) on that array is always return 0
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:48
Thanks, but why will you "never have indexOf(1) is 3"?
Pieter Stokkink
@forkerino
Jun 08 2017 08:48
@mrbaker1917 the current element that you are looking at, not the next, not the previous.
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:49
I am sorry, but this is breaking my brain. If indexOf is comparing the index of the current element to itself, how does it filter anything?
Long Nguyen
@longnt80
Jun 08 2017 08:49

@mrbaker1917

Thanks, but why will you "never have indexOf(1) is 3"?

because indefOf only return the first index it can find, so in an array there are multiple number 1s, it only return the index of the first one

CamperBot
@camperbot
Jun 08 2017 08:49
:cookie: 273 | @mrbaker1917 |http://www.freecodecamp.com/mrbaker1917
longnt80 sends brownie points to @mrbaker1917 :sparkles: :thumbsup: :sparkles:
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:50
You mean, the first index of any particular integer?
or can it be any type of value?
Long Nguyen
@longnt80
Jun 08 2017 08:50
any value
with the same value, it only return the index of the first one
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:51
So, it is kind of stubborn, like, if it gets in its head that any value has a certain index, it ignores other occurrences of the same value?
Long Nguyen
@longnt80
Jun 08 2017 08:51
kinda like that
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:52
Thanks. You guys are very patient with me.
HJ5253
@HJ5253
Jun 08 2017 08:52

hi guys function titleCase(str) {
var str1 ="";
var arr = str.split(" ");
var str2;
for (var i=0;i<arr.length;i++){
arr[i] = arr[i].split("");
arr[i][0]=arr[i][0].toUpperCase();
for (var j=1; j<arr[i].length;j++){
arr[i][j]=arr[i][j].toLowerCase();
}
if (i<arr.length-1){
str2 = " ";
}else{
str2="";
}
str1 += arr[i].join("")+str2;
}

return "\""+str1+"\"";
}

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

ozimanik
@ozimanik
Jun 08 2017 08:53
Anyone here with C# knowledge?
HJ5253
@HJ5253
Jun 08 2017 08:53
this is my code and the output is correct still the challenge is not completed
algorithm challenge title case a sentence
Long Nguyen
@longnt80
Jun 08 2017 08:55
@mrbaker1917 can you understand the filter function yet?
Pieter Stokkink
@forkerino
Jun 08 2017 08:55
@baersc I did some more digging. You are right, it isn't wrong per se, it can however lead to loss of readability, especially in larger code bases and especially if you use the variable outside of the loop (like in your tester function).
It is generally thought to be a bad idea to change the function parameters inside a function (which is what you do with that assignment), that's why you get the error.
Mark R. Baker
@mrbaker1917
Jun 08 2017 08:57
Yes, Long, I think I understand it.
But it is all relative, right?
sonnguyen2603
@sonnguyen2603
Jun 08 2017 08:57

function palindrome(str) {
// Good luck!
alphabet = "abcdefghijklmnopqrstuvwxyz123456789";
newArray = [];
for (var i =0; i<str.length;i++){
for(var j =0; j <alphabet.length;j++){
if(str[i].toLowerCase() == alphabet[j]){
newArray.push(str[i].toLowerCase());
}
}
}
newArray1=[];
if(newArray.length %2 === 0){
for(var i = 0; i< (newArray.length/2);i++){
check = newArray.pop();
newArray1.push(check);
}
}
else{
for(var i = 0; i< (newArray.length/2);i++){
check = newArray.pop();
newArray1.push(check);
}
}

for(var i =0; i<newArray1.length;i++){
if(newArray[i] !== newArray1[i]){
return false;
}
}
return true;
}

palindrome("almostomla");

Can anyone help me to point out where did I do wrong please?/
Long Nguyen
@longnt80
Jun 08 2017 08:59
@HJ5253 return "\""+str1+"\""; should be return str1;
@HJ5253 you don't have to add " for it to be a string
HJ5253
@HJ5253
Jun 08 2017 09:00
@longnt80 yes you are right, got it
@longnt80 thanks
CamperBot
@camperbot
Jun 08 2017 09:00
hj5253 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 340 | @longnt80 |http://www.freecodecamp.com/longnt80
Manish Chandra
@chandrajob365
Jun 08 2017 09:01
Hi Need help in converting '{"sender":"test1Docomo","text":"Hi"},{"sender":"test1Docomo","text":"Hello”}’ to objects
baersc
@baersc
Jun 08 2017 09:01
@forkerino That makes sense, but it was necessary to assign remove within the loop in order to pass the new value to the tester function on each loop. I'm not sure declaring the variable outside the loop and then reassigning it inside would improve readability.
Your suggestion about the assignment warning makes sense too, and I had originally thought the same thing, but the MDN page for the arguments object specifically talks about reassigning an argument so I didn't think it would be an issue.
YozhikM
@YozhikM
Jun 08 2017 09:02
Hello guys
$(".speaker img").bind("click", function() {
            var src = ($(this).attr("src") === "icons/speaker-b.png") ?
                "icons/nspeaker-b.png" :
                "icons/speaker-b.png";
            $(this).attr("src", src);
            var bg = ($(this).css('background-color') === 'rgba(21,22,23,0.149)') ?
                '#fff' :
                'rgba(21,22,23,0.149)';
            $(this).css('background-color', bg);
        });
Where is my mistake?
Pieter Stokkink
@forkerino
Jun 08 2017 09:02
@baersc yeah, only thing is that it becomes a problem if the user of your function doesn't know that you will change the array he/she passes in. This can have unintended consequences (mental breakdown on the part of the user :) ).
Aakriti
@Aakriti94
Jun 08 2017 09:03
how can i achieve toggle easing effect like the one in website on menu click http://www.razvangarofeanu.com/#the-g
Pieter Stokkink
@forkerino
Jun 08 2017 09:04
@baersc either way, if you use .filter first, you won't have to use a loop. Just make sure to make an array out of the arguments after the first one and use that inside your filter callback. It is much easier to read.
Ogundele Olumide
@Lumexralph
Jun 08 2017 09:05
@chandrajob365 you have an object there
baersc
@baersc
Jun 08 2017 09:05
@forkerino Yeah I can see how that would be a poor experience lol ! I haven't done anything yet like that so it wasn't even a consideration. I assumed that if the function is called, the return is going to be stored as a new variable and not passed back out overwriting the input.
Ogundele Olumide
@Lumexralph
Jun 08 2017 09:06
@forkerino done the interview yet?
forgot to ask
Pieter Stokkink
@forkerino
Jun 08 2017 09:06
@Lumexralph no, it was delayed until this afternoon.
Ogundele Olumide
@Lumexralph
Jun 08 2017 09:06
okay, all the best Bro!
Pieter Stokkink
@forkerino
Jun 08 2017 09:07
thanks buddy @Lumexralph
CamperBot
@camperbot
Jun 08 2017 09:07
forkerino sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1882 | @lumexralph |http://www.freecodecamp.com/lumexralph
YozhikM
@YozhikM
Jun 08 2017 09:07
$(".speaker img").bind("click", function() {
            var src = ($(this).attr("src") === "icons/speaker-b.png") ?
                "icons/nspeaker-b.png" :
                "icons/speaker-b.png";
            $(this).attr("src", src);
            var bg = ($(this).css('background-color') === 'rgba(21,22,23,0.149)') ?
                '#fff' :
                'rgba(21,22,23,0.149)';
            $(this).css('background-color', bg);
        });
Where is my mistake?
Ogundele Olumide
@Lumexralph
Jun 08 2017 09:07
@forkerino how's the Princess and Queen?
Long Nguyen
@longnt80
Jun 08 2017 09:07
@chandrajob365
var email = {
  "email1": {"sender":"test1Docomo","text":"Hi"},
  "email2": {"sender":"test1Docomo","text":"Hello”}
};
Ogundele Olumide
@Lumexralph
Jun 08 2017 09:08
I hope you won't be stolen away from here :smile:
baersc
@baersc
Jun 08 2017 09:08
@forkerino I'll give the problem another go tomorrow and try to do it that way. My thought of reassigning the paramater was that if I could, I should, because copying the arguments[0] to a new variable would use more memory and that might not be necessary.
Pieter Stokkink
@forkerino
Jun 08 2017 09:09
@baersc the first argument is already in its own parameter, I believe. So you can just use that and filter it. Don't worry too much about memory use unless you have tons of arrays with millions of elements.
The worrying will cost you way more time than you will ever save.
erkais
@erkais
Jun 08 2017 09:10
@forkerino that's the good advice :P
Pieter Stokkink
@forkerino
Jun 08 2017 09:10
@Lumexralph They are well. The princess is princessing all day, the Queen has her hands full. :smile:
Ogundele Olumide
@Lumexralph
Jun 08 2017 09:11
@forkerino :smile: cool
@forkerino guess that's the beauty of watching them grow
Pieter Stokkink
@forkerino
Jun 08 2017 09:12
yup
baersc
@baersc
Jun 08 2017 09:12
@forkerino I was initially trying to filter the argument into a new variable, but on each iteration of the for loop, the filter passes the entire original array back into the new variable, essentially undoing the work that had been done on the previous iteration :D That's when I realized I had to overwrite the argument to do it this way.
Blauelf
@Blauelf
Jun 08 2017 09:12
@YozhikM Any error messages on the browser's console (Ctrl+Shift+I on many browsers)? Also, bind is deprecated in newer jQuery, I think on should be used instead.
YozhikM
@YozhikM
Jun 08 2017 09:13
@Blauelf Sorry, I did it
$(".speaker img").bind("click", function() {
            var src = ($(this).attr("src") === "icons/speaker-b.png") ?
                "icons/nspeaker-b.png" :
                "icons/speaker-b.png";
            $(this).attr("src", src);
        });
$(".speaker img").bind("click", function() {
            var bg = ($(this).attr("src") === "icons/speaker-b.png") ?
                'rgba(21,22,23,0.149)' :
                '#fff';
            $('.speaker').css('background-color', bg);
        });
Pieter Stokkink
@forkerino
Jun 08 2017 09:13
@baersc yeah, that's a valid insight. This is another thing that is prevented when you filter and use a loop inside if necessary
baersc
@baersc
Jun 08 2017 09:14
@forkerino Thanks again for all the help, its been a big help. I've got a lot more learning to do! Have a good day!
CamperBot
@camperbot
Jun 08 2017 09:14
baersc sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: baersc already gave forkerino points
Pieter Stokkink
@forkerino
Jun 08 2017 09:16
@sonnguyen2603 Your alphabet is missing the number 0.
I find it hard to find the bug in your code because your approach is very unconventional. Usually people sanitize the string with a regex and compare this to itself but reversed (use what you learned in reverse a string exercise). One tip to help you find the bug: use pythontutor.com to visualize the execution of your code.
@baersc you too! :wave:
sonnguyen2603
@sonnguyen2603
Jun 08 2017 09:17
@forkerino thank you so much
CamperBot
@camperbot
Jun 08 2017 09:17
:star2: 2500 | @forkerino |http://www.freecodecamp.com/forkerino
sonnguyen2603 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
Pieter Stokkink
@forkerino
Jun 08 2017 09:17
2500!! Woot woot!
@sonnguyen2603 You're welcome!
Blauelf
@Blauelf
Jun 08 2017 09:19

@YozhikM Two handlers then on the same element? If so, I'd use an if-else instead, like

        $(".speaker img").on("click", function() {
            var src, bg;
            if ($(this).attr("src") === "icons/speaker-b.png") {
                src = "icons/nspeaker-b.png";
                bg = 'rgba(21,22,23,0.149)';
            } else {
                src = "icons/speaker-b.png";
                bg = '#fff';
            }
            $(this).attr("src", src);
            $('.speaker').css('background-color', bg);
        });

(maybe with colours swapped?)

Ogundele Olumide
@Lumexralph
Jun 08 2017 09:19
@forkerino :clap: :fire:
Blauelf
@Blauelf
Jun 08 2017 09:22
@forkerino :+1: Congratulations :)
Pieter Stokkink
@forkerino
Jun 08 2017 09:24
feels like it took forever since 2k. Probably because I was offline a lot in the past two weeks.
Markus Kiili
@Masd925
Jun 08 2017 09:24
@forkerino :sparkles:
Pieter Stokkink
@forkerino
Jun 08 2017 09:24
@Blauelf @Lumexralph thank you
CamperBot
@camperbot
Jun 08 2017 09:24
forkerino sends brownie points to @blauelf and @lumexralph :sparkles: :thumbsup: :sparkles:
:warning: forkerino already gave lumexralph points
:star2: 4352 | @blauelf |http://www.freecodecamp.com/blauelf
Pieter Stokkink
@forkerino
Jun 08 2017 09:24
@Masd925 thanks
CamperBot
@camperbot
Jun 08 2017 09:24
forkerino sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4227 | @masd925 |http://www.freecodecamp.com/masd925
Aditya Soni
@adist98
Jun 08 2017 09:26
can anybody help me on this find the longest word algo

function findLongestWord(str) {
  var array =[];
  array = str.split(" ");
  for(var i=0; i< array.length; i++){
    if (array[i].length > array[i+1].length){
      return array[i].length ;
    }else if (array[i].length<array[i+1].length){
      return array[i+1].length;
    }else if (array[i].length == array[i+1].length){
      return array[i].length;
}

  }
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Ankur
@noobcoder007
Jun 08 2017 09:26
1.png
Pieter Stokkink
@forkerino
Jun 08 2017 09:27
@adist98 you are just comparing the first and second word and return immediately without checking any of the other words
Ankur
@noobcoder007
Jun 08 2017 09:27
can you please let me where I am going wrong ?
Aditya Soni
@adist98
Jun 08 2017 09:27
i know, please tell me how to compare all the strings @forkerino please
Pieter Stokkink
@forkerino
Jun 08 2017 09:27
@adist98 one approach is to create a variable to store the length of the longest word outside your loop and update within.
Blauelf
@Blauelf
Jun 08 2017 09:27
@adist98 Keep track of the longest word, or its length, and compare to that.
Aditya Soni
@adist98
Jun 08 2017 09:28
an example please @Blauelf @forkerino
Pieter Stokkink
@forkerino
Jun 08 2017 09:29
@adist98
var longest = 0
for (....) {
  check if the current word is longer, if so update longest
} 
return longest
Aditya Soni
@adist98
Jun 08 2017 09:29
cool @forkerino , i will try this
Pethaf
@Pethaf
Jun 08 2017 09:32
@Blauelf We talked about Javascript: The Good Parts yesterday. I started reading You Don't Know JS: Scopes and Closures.
Aditya Soni
@adist98
Jun 08 2017 09:34
here it is
var longest = 0;
for (var i = 0 ; i < array.length ; i++){
    if (longest < array[i]) {
        longest = array[i].length;
    }

}
return longest;
Ming Zhu
@chocobrownie
Jun 08 2017 09:34
Hi I'm doing the algorithm challenge "Sum All Numbers in a Range", the code works in my text editor, but the system won't let it pass. Any idea where is wrong? The system says "SyntaxError: Unexpected token ;"
function sumAll(arr) {
  var sum=0;
  if (arr[0]<arr[1]){
    for (i=arr[0];i<=arr[1];i++){
      sum=sum+i;
    }
  }
  else{
    for (i=arr[0];i>=arr[1];i--){
      sum=sum+i;
    }
  }
  console.log(sum);
  return sum;
}
sumAll([4,1]);
Aditya Soni
@adist98
Jun 08 2017 09:34
@forkerino my code
var longest = 0;
for (var i = 0 ; i < array.length ; i++){
    if (longest < array[i]) {
        longest = array[i].length;
    }

}
return longest;
Ogundele Olumide
@Lumexralph
Jun 08 2017 09:35
@adist98 if (longest < array[i] check the length there
Pieter Stokkink
@forkerino
Jun 08 2017 09:36
@adist98 yeah, what @Lumexralph says
Aditya Soni
@adist98
Jun 08 2017 09:36
@Lumexralph what do you mean
??
okaay
worked
Pieter Stokkink
@forkerino
Jun 08 2017 09:36
array[i] is a word, you have to find its length in the if check
:+1:
Aditya Soni
@adist98
Jun 08 2017 09:36
you guys are awesome @forkerino thanks @Lumexralph thanks
CamperBot
@camperbot
Jun 08 2017 09:36
adist98 sends brownie points to @forkerino and @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1883 | @lumexralph |http://www.freecodecamp.com/lumexralph
:star2: 2501 | @forkerino |http://www.freecodecamp.com/forkerino
Aditya Soni
@adist98
Jun 08 2017 09:37
@Blauelf thanks
CamperBot
@camperbot
Jun 08 2017 09:37
adist98 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4353 | @blauelf |http://www.freecodecamp.com/blauelf
Ming Zhu
@chocobrownie
Jun 08 2017 09:39
Repost: Hi I'm doing the algorithm challenge "Sum All Numbers in a Range", the code works in my text editor, but the system won't let it pass. Any idea where is wrong? The system says "SyntaxError: Unexpected token ;"
function sumAll(arr) {
  var sum=0;
  if (arr[0]<arr[1]){
    for (i=arr[0];i<=arr[1];i++){
      sum=sum+i;
    }
  }
  else{
    for (i=arr[0];i>=arr[1];i--){
      sum=sum+i;
    }
  }
  console.log(sum);
  return sum;
}
sumAll([4,1]);
Blauelf
@Blauelf
Jun 08 2017 09:39
@chocobrownie Your code works for me. Have you tried reloading the page?
Rainhard Yeppy
@rainyblessed
Jun 08 2017 09:39
hi guys.can someone give me a hint on js profile lookup challenge.i'm stuck.
my code
for (var i=0; i < contacts.length; i++) {
    if(firstName == contacts[i].firstName) {
    console.log(contacts[i].prop);
    }else{
      console.log("No such contact");
    }
Ming Zhu
@chocobrownie
Jun 08 2017 09:40
@Blauelf I have, let me tried to close and reopen. It works for me too
Blauelf
@Blauelf
Jun 08 2017 09:40
@chocobrownie BTW, you forgot to declare i using var, accidentally making it a global variable.
Stephen James
@sjames1958gm
Jun 08 2017 09:40
@rainyblessed You should return not use console.log - also .prop is not correct as prop is a variable
@rainyblessed You will have trouble returning no such contact there - because you will not check all contacts
Ming Zhu
@chocobrownie
Jun 08 2017 09:41
@Blauelf got it, I didn't notice that
Rainhard Yeppy
@rainyblessed
Jun 08 2017 09:42
@sjames1958gm Can you give me a draft of how to do it..if you won't mind..thanks
CamperBot
@camperbot
Jun 08 2017 09:42
rainyblessed sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7675 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ming Zhu
@chocobrownie
Jun 08 2017 09:42
Reopening the whole thing worked, weird bug but thanks @Blauelf
CamperBot
@camperbot
Jun 08 2017 09:42
chocobrownie sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4354 | @blauelf |http://www.freecodecamp.com/blauelf
Stephen James
@sjames1958gm
Jun 08 2017 09:43
@rainyblessed
The return would be return contacts[i][prop];
You should also be using hasOwnProperty to check if the property exists.
You are on the correct path just need some tweaks
Blauelf
@Blauelf
Jun 08 2017 09:45
@chocobrownie Sometimes, when the interpreter executes faulty code (for example some incomplete implementation), it's left in an inconsistent state. A page reload should fix that, unless of course reloading the code triggers the state again (for that, or when you've built an infinite loop, there's ?run=disabled parameter)
EpicTriffid
@EpicTriffid
Jun 08 2017 09:45
Hi there guys, So im doing the golf code, and maybe im making this more complicated than it needs to be, but I want to say that if the strokes value is less than 2 below the par value, return "Eagle". Is there a way to do that?
Pethaf
@Pethaf
Jun 08 2017 09:47
Yes.
Pieter Stokkink
@forkerino
Jun 08 2017 09:47
@EpicTriffid what did you try?
Ming Zhu
@chocobrownie
Jun 08 2017 09:47
How could a code error affect the page tho? It's supposed to be a code editor and bugs shouldn't affect page functionality @Blauelf
Rainhard Yeppy
@rainyblessed
Jun 08 2017 09:48
@sjames1958gm woow thanks for the hint..let me work that up..
CamperBot
@camperbot
Jun 08 2017 09:48
rainyblessed sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: rainyblessed already gave sjames1958gm points
EpicTriffid
@EpicTriffid
Jun 08 2017 09:49
@forkerino Right now, not alot. I've got hole in one and par, but im struggling to see how the operators can compare another figure minus a value
Bhavya Kamboj
@bhavyakamboj
Jun 08 2017 09:50
I'm doing counting cards challenge. since cards 7,8,9 will have 0 change, do we need to add that to switch statement? I skipped these 3 cases and my code works just fine
Stephen James
@sjames1958gm
Jun 08 2017 09:50
@EpicTriffid the code is pretty ugly for this one because you have to check each one with if / else if separately
@bhavyakamboj No need to add to switch
Pieter Stokkink
@forkerino
Jun 08 2017 09:51
@EpicTriffid strokes <= par - 2
EpicTriffid
@EpicTriffid
Jun 08 2017 09:51
@sjames1958gm Ugh, I was hoping i wouldnt have to do that
@forkerino That's what i was looking for!
Bhavya Kamboj
@bhavyakamboj
Jun 08 2017 09:52
@forkerino Thanks man. Such a fast response! This is my first FCC gitter chat nd i'm impressed
CamperBot
@camperbot
Jun 08 2017 09:52
bhavyakamboj sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2502 | @forkerino |http://www.freecodecamp.com/forkerino
Bhavya Kamboj
@bhavyakamboj
Jun 08 2017 09:52
sry @sjames1958gm
NSS534
@NSS534
Jun 08 2017 09:53

// Initialize these three variables
var a = 5;
var b = 10;
var c ="i am a";

// Do not change code below this line

a = a + 1;
b = b + 5;
c = c + " String!";

Stephen James
@sjames1958gm
Jun 08 2017 09:53
@bhavyakamboj All good :)
@NSS534 Case matters "I" not "i"
Pieter Stokkink
@forkerino
Jun 08 2017 09:56
@sjames1958gm ty have some cookies
CamperBot
@camperbot
Jun 08 2017 09:56
forkerino sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7676 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jun 08 2017 09:56
@forkerino Nom Nom
Pieter Stokkink
@forkerino
Jun 08 2017 09:56
:P
NSS534
@NSS534
Jun 08 2017 10:16

myVar = myVar should be changed var myVar = 87;

//Only change code below this line
myVar = ++ myVar;

Lukasz
@LukaszWolfgang
Jun 08 2017 10:18

Hi, I am stuck on Using Objects for Lookups challange, could anyone share any tips, thank you.
var lookup = {

"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank",
};
lookup[alpha];
lookup[beta];

var phoneticLookup = "alpha";
lookup[phoneticLookup];

NSS534
@NSS534
Jun 08 2017 10:20
var myVar = 87;
//Only change code below this line
myVar = ++ myVar;
myVar = myVar should be changed....................getting this
Blauelf
@Blauelf
Jun 08 2017 10:22
@NSS534 ++ increments even without an assignment myVar =
NSS534
@NSS534
Jun 08 2017 10:22
@Blauelf TQ
CamperBot
@camperbot
Jun 08 2017 10:22
nss534 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4355 | @blauelf |http://www.freecodecamp.com/blauelf
Ankur
@noobcoder007
Jun 08 2017 10:22

@LukaszWolfgang check this
'var lookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank",
};
lookup[alpha];
lookup[beta];

var phoneticLookup = "alpha";
lookup[phoneticLookup];

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

result = lookup[val];
// Only change code above this line
return result;
}'

Paul Christian L. Catoera
@poncatoera
Jun 08 2017 10:24
oohh thats what im missing, result=lookup[]
@noobcoder007 thanks
CamperBot
@camperbot
Jun 08 2017 10:25
poncatoera sends brownie points to @noobcoder007 :sparkles: :thumbsup: :sparkles:
:cookie: 230 | @noobcoder007 |http://www.freecodecamp.com/noobcoder007
Lukasz
@LukaszWolfgang
Jun 08 2017 10:27
@noobcoder007 thanks, I am not sure weather is my english not sufficient or I am just being stupid about those challanges
CamperBot
@camperbot
Jun 08 2017 10:27
lukaszwolfgang sends brownie points to @noobcoder007 :sparkles: :thumbsup: :sparkles:
:cookie: 231 | @noobcoder007 |http://www.freecodecamp.com/noobcoder007
Carlos Melero
@fcc-cmelblan
Jun 08 2017 10:30
Hi. About the "title case a sentence" exercise. Could anyone found any solution ? Mine is here, it almost works but not at all. It's here below :

function titleCase(str) {
var clean=str.toLowerCase();
var test=[];
var re = /(\b\w)/gi;
test=clean.split(' ');

return test.join(' ').replace(re,function(m){return m.toUpperCase();});
}

titleCase("I'M a liTTle tEa pOT");

ms-dosx86
@ms-dosx86
Jun 08 2017 10:32

After updateRecords(2548, "artist", ""), artist should not be set

function updateRecords(id, prop, value) {

  if (prop == "tracks" && !collection[id].hasOwnProperty(prop)) {
    collection[id][prop] = [];
    collection[id][prop].push(value);
  }
  else if (value === "") {
    return collection;
  }
  else if (prop == "tracks") {
    collection[id][prop].push(value);
  }
  else
    collection[id][prop] = value;

  return collection;
}

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

what am i doing wrong? everything works, artists not be set

HappyRedditor59
@HappyRedditor59
Jun 08 2017 10:36
can anyone help me? I'm stuck on Profile Lookup.
Blauelf
@Blauelf
Jun 08 2017 10:38
@ms-dosx86 If value === "", you should delete the property. Also, that should be your first test in this line of if-elseifs.
ramarcinek
@ramarcinek
Jun 08 2017 10:41

Can anyone give me his feedback? Is the code OK? I mean. it works, but from the point of vew of quality, is it OK?

function chunkArrayInGroups(arr, size) {
var newArr = [];
var stopCondition = Math.ceil(arr.length/size);
console.log(stopCondition);

for (var i=0; i < stopCondition; i++){

  if (i==0){
      newArr.push(arr.slice(i, size));

  } else {
      newArr.push(arr.slice(i*size,(i+1)*size));

  }

}

return newArr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2);

Yashaswi Maharshi
@mahayash
Jun 08 2017 10:41
For profile lookup

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

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

 if(contacts[i].firstName==firstName && contacts[i].hasOwnProperty(prop) ){
   return contacts[i][prop];
 }

}

for(i=0;i<count;i++){

if(contacts[i].firstName!=firstName){
  return "No such contact";
}else if(!contacts[i].hasOwnProperty(prop)){
  return "No such property";
}

}

// Only change code above this line
}

ms-dosx86
@ms-dosx86
Jun 08 2017 10:42
@Blauelf Sorry, I did not read the instructions completely, but thanks)
CamperBot
@camperbot
Jun 08 2017 10:42
ms-dosx86 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4356 | @blauelf |http://www.freecodecamp.com/blauelf
Thomas
@sjurs1
Jun 08 2017 10:42
In the challenge "Sorted Union" (#280), do I have to change the function input arguments?
Blauelf
@Blauelf
Jun 08 2017 10:42
Sounds like a case for the use of arguments object
It's like an array containing all arguments passed to the current function, it just doesn't have Array.prototype in its prototype chain, so you cannot that easily use Array methods on it. Otherwise, it's like an array (has length and numeric indices), this kind of object is hence called "array-like".
Blauelf
@Blauelf
Jun 08 2017 10:48
@mahayash You don't need two loops. But returning "No such property" within the loop is probably not a good idea, as you can tell that only after you've checked all contacts. And please do declare your variable i using var, otherwise it's a global variable.
4sipita
@4sipita
Jun 08 2017 10:49
pls what does this error mean and how do i solve it "XMLHttpRequest cannot load https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1. The 'Access-Control-Allow-Origin' header has a value 'http://localhost:8000' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access."
Thomas
@sjurs1
Jun 08 2017 10:49
@Blauelf Thanks man!
CamperBot
@camperbot
Jun 08 2017 10:49
sjurs1 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4357 | @blauelf |http://www.freecodecamp.com/blauelf
4sipita
@4sipita
Jun 08 2017 10:50
thanks CamperBot
Deepak Kumar Vellingiri
@dkvellin
Jun 08 2017 10:50
@camperbot
Profile lookup - https://www.freecodecamp.com/challenges/profile-lookup
Is this the right way of doing it?
function lookUpProfile(firstName, prop){
// Only change code below this line
 for(var i=0; i<contacts.length; i++) {
   if(firstName === contacts[i].firstName) {
     if(contacts[i].hasOwnProperty(prop) === true) {
       return contacts[i][prop];
     } else if (contacts[i].hasOwnProperty(prop) !== true) {
       return "No such property";
     }
   } else if(i === (contacts.length-1)) {
       return "No such contact";
   }
 }
// Only change code above this line
}
Blauelf
@Blauelf
Jun 08 2017 10:51
@4sipita Are you testing on your local hard drive?
And to thank CamperBot, you'd have to use the @camperbot handle.
CamperBot
@camperbot
Jun 08 2017 10:51
blauelf sends brownie points to @4sipita :sparkles: :thumbsup: :sparkles:
:cookie: 256 | @4sipita |http://www.freecodecamp.com/4sipita
Blauelf
@Blauelf
Jun 08 2017 10:52
Hmm... listening even when it shouldn't.
4sipita
@4sipita
Jun 08 2017 10:52
@Blauelf i don't get you, what do you mean local "hard-drive"?
Ogundele Olumide
@Lumexralph
Jun 08 2017 10:53
@dkvellin did it solve it? worry about the right way after
Blauelf
@Blauelf
Jun 08 2017 10:53
@4sipita Website stored on your computer. The Access-Control-Allow-Origin header must match the server you're running your site on (or be *).
Deepak Kumar Vellingiri
@dkvellin
Jun 08 2017 10:53
@Lumexralph Yup it did
4sipita
@4sipita
Jun 08 2017 10:53
@Blauelf i was trying to test the camperBot by thanking it
YozhikM
@YozhikM
Jun 08 2017 10:55
What should be the script for scrolling the progress bar part of the screen? http://new.rofas.kz/slide1.html
4sipita
@4sipita
Jun 08 2017 10:56
how do i set the access-control-allow-origin @Blauelf
Pieter Stokkink
@forkerino
Jun 08 2017 10:57
@dkvellin if you move the last return outside of your loop, you don't need to put an else if around it. The first else if is also unnecessary, this one can just be an else.
Ogundele Olumide
@Lumexralph
Jun 08 2017 10:59
@dkvellin i don't know if this way is more efficient but 'i'll reduce the number of the if/else statements
HappyRedditor59
@HappyRedditor59
Jun 08 2017 10:59
did anyone use array.prototype.filter() for Profile Lookup?
Pieter Stokkink
@forkerino
Jun 08 2017 11:00
@HappyRedditor59 For one of my solutions, yes, but I found another array method more suitable.
HappyRedditor59
@HappyRedditor59
Jun 08 2017 11:01
what did you use for your other solution @forkerino ?
Pieter Stokkink
@forkerino
Jun 08 2017 11:03
@HappyRedditor59 .find
Thomas
@sjurs1
Jun 08 2017 11:05
I'm getting an alert for a potential infinite loop at line five, but why?

function uniteUnique(arr) {
  var newArr = [];
  for (var i = 0; arguments.length; i++) {
    for (var j = 0; arguments[i].length; j++){
      if (!(arguments[i][j] in newArr)) {
        newArr.push(arguments[i][j]);
      }
    }
  }
  return newArr;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
schrempi
@schrempi
Jun 08 2017 11:06
@sjurs1 I think its because you keep pushing arguments into newArr in a loop that goes through all elements of the same array
@sjurs1 My bad, it has to be something else :)
Pieter Stokkink
@forkerino
Jun 08 2017 11:07
@sjurs1 you need to compare i and j to the length of the arrays
in the heads of your loops
schrempi
@schrempi
Jun 08 2017 11:07
yeah thats it
Thomas
@sjurs1
Jun 08 2017 11:07
@forkerino Oh, lol
Of course
Boop, it worked! Thanks @forkerino
CamperBot
@camperbot
Jun 08 2017 11:08
sjurs1 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2503 | @forkerino |http://www.freecodecamp.com/forkerino
bradsterr
@bradsterr
Jun 08 2017 11:10
hey guys i need help with escaping sequences is strings
in*
Ogundele Olumide
@Lumexralph
Jun 08 2017 11:12
@bradsterr what have you tried?
Blauelf
@Blauelf
Jun 08 2017 11:12
@4sipita I have no idea how that would work for the wordpress API. Usually, jQuery or whatever you use to make the request would pass the name of your current site to the service, and the service would respond with that name. Not sure why your browser expects null, I'd assume you are building the page locally and it currently is not hosted on a server.
bradsterr
@bradsterr
Jun 08 2017 11:13
@Lumexralph"Firstline\n \SecondLine\ \r ThirdLine"
Stephen James
@sjames1958gm
Jun 08 2017 11:13
@sjurs1 You in test will not work on arrays it tests the indexes not the values
5 in [1, 2, 3, 6, 7, 8]
true
7 in [1, 2, 3, 6, 7, 8]
false
Blauelf
@Blauelf
Jun 08 2017 11:13
@bradsterr Remove spaces from the string
bradsterr
@bradsterr
Jun 08 2017 11:13
cant seem to understand this escaping line concept
Stephen James
@sjames1958gm
Jun 08 2017 11:13
@bradsterr Make sure the case of each word is correct
RAVIKISHANNAG
@RAVIKISHANNAG
Jun 08 2017 11:14
Screen Shot 2017-06-08 at 4.42.42 PM.png
devpaaji
@devpaaji
Jun 08 2017 11:14
@Blauelf why do we need to create an API for a mobile or web app
what is the purpose
Blauelf
@Blauelf
Jun 08 2017 11:14
@RAVIKISHANNAG Please consider posting code instead of images. https://forum.freecodecamp.com/t/markdown-code-formatting/18391
RAVIKISHANNAG
@RAVIKISHANNAG
Jun 08 2017 11:14
I am getting correct output even though it showing error ..may I know whats wrong
devpaaji
@devpaaji
Jun 08 2017 11:14
I was speaking to a mobile dev other day
about costing
he said
Stephen James
@sjames1958gm
Jun 08 2017 11:15
@RAVIKISHANNAG extra space at start?
devpaaji
@devpaaji
Jun 08 2017 11:15
without API cost is less
with API higher
Pieter Stokkink
@forkerino
Jun 08 2017 11:15
@RAVIKISHANNAG yeah, you have a space at the beginning.
Ogundele Olumide
@Lumexralph
Jun 08 2017 11:15
@bradsterr Firstline ==> FirstLine
@bradsterr also eliminate any space between your string
Stephen James
@sjames1958gm
Jun 08 2017 11:15
@RAVIKISHANNAG It is easier if you put element back into your array and then just join
Thomas
@sjurs1
Jun 08 2017 11:16
@sjames1958gm Huh? It works.. I check the values.
RAVIKISHANNAG
@RAVIKISHANNAG
Jun 08 2017 11:16
I have used join but it was showing .join is undefined
bradsterr
@bradsterr
Jun 08 2017 11:16
var myStr = "Firstline\n\SecondLine\\rThirdLine";
Pieter Stokkink
@forkerino
Jun 08 2017 11:16
@RAVIKISHANNAG did you use it on an array?
Stephen James
@sjames1958gm
Jun 08 2017 11:16
@sjurs1 in appears to check indexes not values
Blauelf
@Blauelf
Jun 08 2017 11:16
@devpaaji "API" usually means a server-side interface that either other backend services or your frontend will access.
bradsterr
@bradsterr
Jun 08 2017 11:16
I dont understand this man
Ogundele Olumide
@Lumexralph
Jun 08 2017 11:17
@bradsterr Firstline ==> FirstLine
Stephen James
@sjames1958gm
Jun 08 2017 11:17
@RAVIKISHANNAG substring[i] = element then after loop join substring
bradsterr
@bradsterr