These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
Jun 2017
Jason Luboff
@JLuboff
Jun 22 2017 00:01
@cmccormack Man, I don't have an hour a night! But I got time during work and the weekend! lol
And on that note, I'm out
@sandsbe review the challenge using variables in strings
mrgrizzlie33
@mrgrizzlie33
Jun 22 2017 00:01

Hey guys, I've run into a weird problem. Here's my code:

var gear=0;

this.setGear=function(change) {
gear += change;
};
this.getGear=function() {
return gear;
};
};

var myCar = new Car();

var myBike = new Bike();

And here are the conditions to be met:

Yes)The method getGear of myBike should be accessible outside the object.
Yes)The method setGear of myBike should be accessible outside the object.
Yes)myBike.gear should remain undefined.
Yes)myBike.getGear() should return 4 after calling myBike.setGear(4).
No)myBike.getGear() should return 3 after calling myBike.setGear(3).
No)myBike.getGear() should return 1 after calling myBike.setGear(1).

You can see why I'm confused...
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:04
Hey can you mark down your code
@mrgrizzlie33 can you mark down the complete code. I can help you
mrgrizzlie33
@mrgrizzlie33
Jun 22 2017 00:07

@jalakamsairam Ok...

var Bike = function() {

// Only change code below this line.

var gear=0;

this.setGear= function(change) {
gear += change;
};
this.getGear=function() {
return gear;
};
};

var myCar = new Car();

var myBike = new Bike();

like this?

I got it actually thanks tho @jalakamsairam
CamperBot
@camperbot
Jun 22 2017 00:08
mrgrizzlie33 sends brownie points to @jalakamsairam :sparkles: :thumbsup: :sparkles:
:cookie: 79 | @jalakamsairam |http://www.freecodecamp.com/jalakamsairam
Diego Mayer
@Chrono79
Jun 22 2017 00:14
@mrgrizzlie33 click more info below
You can edit your own posts, right of the timestamp, ... -> Edit
CamperBot
@camperbot
Jun 22 2017 00:14
:bulb: to format code use backticks! ``` more info
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:14
@mrgrizzlie33 no problem.
Eunice Park
@eunicode
Jun 22 2017 00:21
I'm trying to solve Factorialize a Number https://www.freecodecamp.com/challenges/factorialize-a-number
Can anyone please tell me what's wrong with my code?
function factorialize(num) {

  var createAnArray = [];
  for (var i = 1; i <= num; i++) {
    return createAnArray.push(i);
  }

  var myProduct = 1;
  for (var j = 0; j < createAnArray.length; j++) {
    return myProduct *= createAnArray[j];
  }

}

factorialize(5);
Coy Sanders
@coymeetsworld
Jun 22 2017 00:22
@eunipa doesn't work for 0
you also aren't returning anything
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:22
@eunipa I think you are trying to access a variable whose scope is private to function.
Coy Sanders
@coymeetsworld
Jun 22 2017 00:23
no @jalakamsairam, theres only one function
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:23
And what @CoyoteTrackz
Coy Sanders
@coymeetsworld
Jun 22 2017 00:23
its not a scope issue
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:24
Ya.. What @coymeetsworld said is right
Eunice Park
@eunicode
Jun 22 2017 00:24
@coymeetsworld According to FCC's console/tests, my code doesn't work for any number :(
And I'm trying to return myProduct
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:24
It returns 01234*5
Coy Sanders
@coymeetsworld
Jun 22 2017 00:25
@eunipa oh
@jalakamsairam no
@eunipa you're returning inside the for loop
you don't want to do that
return exits out of the function immediately
so for loop only runs one time
Eunice Park
@eunicode
Jun 22 2017 00:25
@jalakamsairam okay, how did you get that?
Coy Sanders
@coymeetsworld
Jun 22 2017 00:25
thats not right
Eunice Park
@eunicode
Jun 22 2017 00:25
@coymeetsworld thank you, I will try this.
CamperBot
@camperbot
Jun 22 2017 00:25
eunipa sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 2848 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:25
0 x1 x 2 x 3 x 4x 5
Coy Sanders
@coymeetsworld
Jun 22 2017 00:26
it doesn't return that @jalakamsairam
dont confuse them please :)
Eunice Park
@eunicode
Jun 22 2017 00:26
@jalakamsairam According to FCC's console, factorialize(5) gives me 1
@coymeetsworld it still doesn't work
function factorialize(num) {

  var createAnArray = [];
  for (var i = 1; i <= num; i++) {
    return createAnArray.push(i);
  }

  var myProduct = 1;
  for (var j = 0; j < createAnArray.length; j++) {
    myProduct *= createAnArray[j];
  }

  return myProduct;
}

factorialize(5);
Coy Sanders
@coymeetsworld
Jun 22 2017 00:28
you have another return statement
remember, return ends the function @eunipa
doesn't do anything after the return statement
Eunice Park
@eunicode
Jun 22 2017 00:28
@coymeetsworld thank you!!! it works now!!!!
CamperBot
@camperbot
Jun 22 2017 00:28
eunipa sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: eunipa already gave coymeetsworld points
Coy Sanders
@coymeetsworld
Jun 22 2017 00:29
yw @eunipa
Eunice Park
@eunicode
Jun 22 2017 00:29
I will read more about how the return keyword works :)
Coy Sanders
@coymeetsworld
Jun 22 2017 00:29
also, you don't necessarily need to create an array
Moisés Man
@moigithub
Jun 22 2017 00:29
@eunipa u ccould remove the first loop... and the array
multiply directly by ur index variable i or j <--instead of pushing its values
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:29
I am sorry about that eunipa
Coy Sanders
@coymeetsworld
Jun 22 2017 00:29
since you're just pushing the number
Eunice Park
@eunicode
Jun 22 2017 00:29
@coymeetsworld Do you mean an empty array?
Coy Sanders
@coymeetsworld
Jun 22 2017 00:29
dont need an array at all
Sairam jalakam Devarajulu
@jalakamsairam
Jun 22 2017 00:30
@coymeetsworld made a mistake.. Sorry
Coy Sanders
@coymeetsworld
Jun 22 2017 00:30

now that you did it you could do something like

let i = 1;
while (i < num) {
  product *= i;
  i++;
}

something like that

Diego Mayer
@Chrono79
Jun 22 2017 00:31
won't that miss a number?
Coy Sanders
@coymeetsworld
Jun 22 2017 00:31
or
for (int i = 1; i <= num; i++) {
  product *= i;
}
yea it will @Chrono79 just giving quick example
Diego Mayer
@Chrono79
Jun 22 2017 00:31
:+1:
Coy Sanders
@coymeetsworld
Jun 22 2017 00:31
not testing it exactly
2nd one will work
Moisés Man
@moigithub
Jun 22 2017 00:31
int ?
Eunice Park
@eunicode
Jun 22 2017 00:33
@moigithub @coymeetsworld Thank you. I will mull over your suggestions. I need lots of time to think things through orz
CamperBot
@camperbot
Jun 22 2017 00:33
eunipa sends brownie points to @moigithub and @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: eunipa already gave coymeetsworld points
:star2: 3396 | @moigithub |http://www.freecodecamp.com/moigithub
Coy Sanders
@coymeetsworld
Jun 22 2017 00:33
@moigithub lol
been doing some java recently
Meelo Armando
@Meelo1
Jun 22 2017 00:47

just curious on how would you:
Assign the value 7 to variable a.

Assign the contents of a to variable b.

Stephen James
@sjames1958gm
Jun 22 2017 00:48
@Meelo1 The two variable goes on the left of the =
Meelo Armando
@Meelo1
Jun 22 2017 00:48
wouldn't it be, " var a = 7;
var b = var a; ?
Stephen James
@sjames1958gm
Jun 22 2017 00:48
@Meelo1 Don't repeat the var (especially never var on the left of =)
@Meelo1 Otherwise you are correct
Meelo Armando
@Meelo1
Jun 22 2017 00:49
okay okay I got it now. thank you @sjames1958gm !
CamperBot
@camperbot
Jun 22 2017 00:49
meelo1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7846 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jun 22 2017 00:50
my bad that should be never var on the right of =
Meelo Armando
@Meelo1
Jun 22 2017 00:50
haha figured with the error message
Ai (oldscrow)
@oldscrow
Jun 22 2017 01:09
@Coy is the Java youve been involved working on..lets get a taste of the Juice
sbh111
@sbh111
Jun 22 2017 01:16
hey how do i add multiple function to this
arr=testArr.push(item).shift();
Abdoullah Alee U
@abdoullfurya
Jun 22 2017 01:16
Hello world
sbh111
@sbh111
Jun 22 2017 01:16
how can i add both .push() and .shift()
halp
JeroPRC
@JeroPRC
Jun 22 2017 01:24

I'm doing the "Testing Objects for Properties" exercise, and I don't know how to return the property's value if it's true. I would greatly appreciate any kind of help. This is the code:
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
;
if (myObj.hasOwnProperty(checkProp)) {
return ;
} else {
return 'Not Found';
}
}

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

Bethany Roberts
@Betanya
Jun 22 2017 01:30
I'm stuck on trying figure out how to see if the property exists for the given contact.
//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){
  // Your Code Here
for(var i=0;i<contacts.length;i++){ for (var j=0; j<contacts[firstName].length;j++){
  var answerProp="";
  var answerName="";
  answerProp=contacts[prop];
  answerName=contacts[firstName];
  var firstNameOutput=contacts.hasOwnProperty(firstName);
  var propOutput=contacts[i].hasOwnProperty(prop);
  if (propOutput===false){answer= "No such property";} else if (firstNameOutput===false){answer= "No such property";}
  return answerProp;
  return answerName;
}

}

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
@JeroPRC I would try defining an arbitrary variable and making it equal to 'Not Found' ect then returning that variable at the end
Bethany Roberts
@Betanya
Jun 22 2017 01:36
@JeroPRC also take advantage of the fact that hasOwnProperty has only T /F as the output
So I would define myObj.hasOwnProperty(checkProp) as a separate variable as well that will give the output of either T/F
sbh111
@sbh111
Jun 22 2017 01:39

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

return arr[0]; // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
// i dont know how to remove the first element from the array, cant i just write arr.push(item).shift();

Bethany Roberts
@Betanya
Jun 22 2017 01:39
@JeroPRC I kinda did something in my code above that might help out. But It isn't working for my challenge :/
JeroPRC
@JeroPRC
Jun 22 2017 01:47
@Betanya I'll try that :)
Moisés Man
@moigithub
Jun 22 2017 01:47
@sbh111 not any method can be CHAINED, to do that u need to know whats the input and output of each methods
shift method is the right one to remove first element.. but how u applying is not
@Betanya u only need 1 loop to iterate the contacts array
this contacts array contains OBJECTS as elements
to access array elements...
ie: myArr = ["hello", "world" ];
u use the array name.. and some index with brackets..
ie: myArr[0] will give u "hello" <-- first element
Bethany Roberts
@Betanya
Jun 22 2017 01:50
@moigithub hmm, I see..
Moisés Man
@moigithub
Jun 22 2017 01:52

@Betanya soo on contacts case.. since this array contains OBJECTS
if u do
contacts[1] this will give u the second object

{
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    }

once u have the object with contacts[1] u can access its properties using dot or bracket notation...

Claudio R M
@cl4udiorm
Jun 22 2017 01:52
Hello everyone, i need some help with the chalenge 143
Moisés Man
@moigithub
Jun 22 2017 01:53
@cl4udiorm challenges dont have numbers... that numbers represent how many brownie points u got
use the challenge/exercise name
ie: words blanks
or post a link
Adithya
@Adithya1243
Jun 22 2017 01:53
mine is StandInLine
Bethany Roberts
@Betanya
Jun 22 2017 01:53
@moigithub Oh.. that is making more sense, I'm going to try it again.
Moisés Man
@moigithub
Jun 22 2017 01:53
also.. showing what code u did helps...
Claudio R M
@cl4udiorm
Jun 22 2017 01:54

i put this...

var myStr;

myStr = "FirstLine \n \SecondLine\ \r ThirdLine"

and I received the message..

TypeError: "FirstLine \n \SecondLine\ \r ThirdLine"

is not a function. (In '"FirstLine \n \SecondLine\ \r ThirdLine"

(function(){
if (myStr !== undefined){
return 'myStr = '+ JSON.stringify(myStr);}
else{return null;}})', '"FirstLine \n \SecondLine\ \r ThirdLine"

' is "FirstLine
\SecondLine\
ThirdLine")

@moigithub ok about it. =D
Moisés Man
@moigithub
Jun 22 2017 01:55

i put this...
myStr = "FirstLine \n \\SecondLine\\ \r ThirdLine"

thats correct.. except u need to remove all spaces @cl4udiorm

Murrium
@Murrium123
Jun 22 2017 01:56
I am seriously struggling with the Fahrenheit conversion
please help!
Claudio R M
@cl4udiorm
Jun 22 2017 01:57
@moigithub
var myStr;
myStr = "FirstLine\n\SecondLine\\rThirdLine"

@moigithub
TypeError: "FirstLine\n\SecondLine\\rThirdLine"

is not a function. (In '"FirstLine\n\SecondLine\\rThirdLine"

(function(){
if (myStr !== undefined){
return 'myStr = '+ JSON.stringify(myStr);}
else{return null;}})', '"FirstLine\n\SecondLine\\rThirdLine"

' is "FirstLine
\SecondLine\
ThirdLine")

Moisés Man
@moigithub
Jun 22 2017 01:58
@Adithya1243 u need to add item to the end of the array arr (those 2 are ur function parameters)
then remove and return the first element removed.
if u dont recall how.. review array methods: push pop shift unshift
@cl4udiorm reset ur code.. make sure u only modify 1 line
Claudio R M
@cl4udiorm
Jun 22 2017 02:00
@moigithub it works ! o/*\o
@moigithub thanks !
CamperBot
@camperbot
Jun 22 2017 02:00
cl4udiorm sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3397 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Jun 22 2017 02:01
@Murrium123 basicly u need to transform the formula on the instructions to code
and assign this formula to fahrenheit variable...
fahrenheit = some formula here with celsius parameter involved
ie: someResult = x + 2 * 3 / 4
JeroPRC
@JeroPRC
Jun 22 2017 02:04
@Betanya Thanks, it worked!
CamperBot
@camperbot
Jun 22 2017 02:04
jeroprc sends brownie points to @betanya :sparkles: :thumbsup: :sparkles:
:cookie: 219 | @betanya |http://www.freecodecamp.com/betanya
Jacob Barnett
@jabarnett97
Jun 22 2017 02:05
could someone help me with the record collection?? For some reason I can't pass one of the challenge checks even though it's working -.-

// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  if(prop == 'tracks' && value !== ''){
    if(collection[id][prop])
      collection[id][prop].push(value);
    else{
      collection[id][prop] = value;
    }
  } else if(value !== ''){
    collection[id][prop] = value;
  } else {
    delete collection[id][prop];
  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");
Moisés Man
@moigithub
Jun 22 2017 02:07

tracks is the only array on collection
but NOT every album have a tracks array property @jabarnett97
like 5439
soo when prop is tracks.. and value isnt empty
before u be able to add something to tracks.. first u need to create this property as an array

    else{
      collection[id][prop] = value;
    }

that wont create an array

Jacob Barnett
@jabarnett97
Jun 22 2017 02:09
I tried to push it on and it said that it's not a function
Moisés Man
@moigithub
Jun 22 2017 02:09
push only works on arrays.. if tracks dont exist (is undefined) using array methods like push on undefined will fail
aaaa = []; //<--- create an array
aaaa.push(value);
or in same line
aaa = [value]
Jacob Barnett
@jabarnett97
Jun 22 2017 02:10
Just what I was thinking! I'll try it out
Aalok Gupta
@aalokgupta
Jun 22 2017 02:14
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
}

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

return "No such contact";
// Only change code above this line
}

plz help
Jacob Barnett
@jabarnett97
Jun 22 2017 02:14
@moigithub thanks for the tip, still working it out but Im sure this info is helpful
CamperBot
@camperbot
Jun 22 2017 02:14
jabarnett97 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3398 | @moigithub |http://www.freecodecamp.com/moigithub
Aalok Gupta
@aalokgupta
Jun 22 2017 02:15
why the function does not return the prop value
Moisés Man
@moigithub
Jun 22 2017 02:15
@aalokgupta NO dot notation with variables like prop
if u do myObj.prop it will try to find a property literally named prop inside myObj
Aalok Gupta
@aalokgupta
Jun 22 2017 02:16
okey
than how to return the prop value?
Moisés Man
@moigithub
Jun 22 2017 02:17
what other object notation u know besides dot notation? (there are only 2 ) :)
gtg bbl
Aalok Gupta
@aalokgupta
Jun 22 2017 02:18
okey , let me check
thanks
@moigithub thanks
CamperBot
@camperbot
Jun 22 2017 02:19
aalokgupta sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3399 | @moigithub |http://www.freecodecamp.com/moigithub
jasonrest
@jasonrest
Jun 22 2017 02:19
palindrome check. my true tests are passing. but I have a few that are not. it looks like the spaces are not being removed. i can't tell. anybody know where i went wrong here.

function palindrome(str) {
// Good luck!

var strLower = str.toLowerCase();
strLower = strLower.replace(/[^0-9a-zA-Z ]/g, '');
var strReverse = strLower.split('').reverse().join('');

if (strLower === strReverse){
return true;
}
else {
return false;
}
}

palindrome("eye");

Bethany Roberts
@Betanya
Jun 22 2017 02:24

@moigithub


//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){
  // Your Code Here
var answerProp="";
for(var i=0;i<contacts.length;i++){if (contacts[i].firstName==firstName){if (contacts[i].prop==prop){answerProp=contacts[i].prop}else if{answerProp="No such property"}else if {answerProp="No such contact"}}

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

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

This is what I got so far that makes sense to me

Ginger
@GingerChew
Jun 22 2017 02:31
I think I need some help on my scope
function largestOfFour(arr) {
  // You can do this!
  var largest = [];
  for (var i=0;i<arr.length;i++) {
    for (var j=0;j<arr[i].length;j++){
      var large = 0;
      if (arr[i][j]>large) {
        large = arr[i][j];
      }
    }
    largest.push(large);
  }
  return largest;
}
This is only returning the last value of each array, not the largest value
Ruijie Geng
@Hubert51
Jun 22 2017 02:33
You can put var large =0; on the top of the function body
Ginger
@GingerChew
Jun 22 2017 02:34
@Hubert51 aaaaaaand that fixed it, thanks for the tip!
CamperBot
@camperbot
Jun 22 2017 02:34
gingerchew sends brownie points to @hubert51 :sparkles: :thumbsup: :sparkles:
:cookie: 172 | @hubert51 |http://www.freecodecamp.com/hubert51
Ruijie Geng
@Hubert51
Jun 22 2017 02:35
@GingerChew No problem~
Hamza Amer
@Heyrio
Jun 22 2017 02:37

```var arr = [];

function titleCase(str) {

arr = str.split(" ");

return arr.map(function() {

arr[0].charAt().toUpperCase();

});

}

titleCase("I'm a little tea pot");
```

whoops wasn't markdown
console says null any idea
gernertj12
@gernertj12
Jun 22 2017 02:38
Anyone stuck on the word blanks one? Not exactly sure what they are looking for
jasonrest
@jasonrest
Jun 22 2017 02:38

```function palindrome(str) {
var strLower = str.toLowerCase().replace(/[\W_]/g, '');
var strReverse = strLower.split('').reverse().join('');

if (strLower === strReverse){
return true;
}
else {
return false;
}
}

palindrome("eye");

Diego Mayer
@Chrono79
Jun 22 2017 02:38
@Heyrio the function inside map should return too
jasonrest
@jasonrest
Jun 22 2017 02:38

```function palindrome(str) {
var strLower = str.toLowerCase().replace(/[\W_]/g, '');
var strReverse = strLower.split('').reverse().join('');

if (strLower === strReverse){
return true;
}
else {
return false;
}
}

palindrome("eye");
```

Diego Mayer
@Chrono79
Jun 22 2017 02:39
@jasonrest leave the ``` in their own line
Hamza Amer
@Heyrio
Jun 22 2017 02:39
@Chrono79 hm I'm getting a return of "I" it doesnt seem to be maping throught the array though.
Diego Mayer
@Chrono79
Jun 22 2017 02:40
@Heyrio review how map works
the function needs a parameter
Hamza Amer
@Heyrio
Jun 22 2017 02:41
@Chrono79 ok i'll read over it online
@GingerChew large should be reset for each subarray
Ginger
@GingerChew
Jun 22 2017 02:48
@Chrono79 yeah, I fixed it after i ran the tests
Diego Mayer
@Chrono79
Jun 22 2017 02:48
:+1:
Bethany Roberts
@Betanya
Jun 22 2017 02:50
//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){
  // Your Code Here
var answerProp="";
for(var i=0;i<contacts.length;i++){if (contacts[i].firstName==firstName){if (contacts[i].hasOwnProperty(prop)===true){answerProp=prop;} else if (contacts[i].hasOwnProperty(prop)===false){answerProp="No such property"}  } else if  }

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

// Change these values to test your function
lookUpProfile("Akira", "likes");
How do I make it print out (at the end) "No such contact"? I'm stumped!
Hamza Amer
@Heyrio
Jun 22 2017 02:51
var arr = [];

function titleCase(str) {

  arr = str.split(" ");


  var newArr = arr.map(function(final) {

   return final = arr[0].charAt().toUpperCase();

  });


}

titleCase("I'm a little tea pot");
I gave map a parameter but I see no return on the console
Duffy125
@Duffy125
Jun 22 2017 02:54

var string = "Split me into an array";
var array = [];

// Only change code below this line.

array = string.split('Split me into an array');
I cant seem to get this to split

Hamza Amer
@Heyrio
Jun 22 2017 02:54
@Betanya use an else
@Betanya with console.log();
@Duffy125 assign your string to your array then connect it with the dot operator to split
delete the string you have in the method just leave it with a space
Duffy125
@Duffy125
Jun 22 2017 02:59
array = string.split( );
this works but its not a pass
Hamza Amer
@Heyrio
Jun 22 2017 02:59
@Duffy125 put quotes in the ()
("")
Duffy125
@Duffy125
Jun 22 2017 02:59
array = string.split('');
Diego Mayer
@Chrono79
Jun 22 2017 03:00
@Heyrio the function doesn't return there, don't use a global var
Duffy125
@Duffy125
Jun 22 2017 03:00
when i do this it splits all the up
Hamza Amer
@Heyrio
Jun 22 2017 03:00
@Duffy125 with a space in between (" ")
@Chrono79 thanks checking
CamperBot
@camperbot
Jun 22 2017 03:01
heyrio sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4365 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jun 22 2017 03:01
@Heyrio you're not using the function param properly, final is each word of your array, why would you overwrite it with a constant value?
Duffy125
@Duffy125
Jun 22 2017 03:01
@Heyrio ok that worked
Hamza Amer
@Heyrio
Jun 22 2017 03:01
@Duffy125 nice im glad
Duffy125
@Duffy125
Jun 22 2017 03:02
@Chrono79 is there a cleaner way of doing that?
Diego Mayer
@Chrono79
Jun 22 2017 03:02
@Duffy125 doing what?
Duffy125
@Duffy125
Jun 22 2017 03:03
Split Strings with split
Nevermind
phuzisham
@phuzisham
Jun 22 2017 03:07

Hoping for some help on a side project of Pong Clone. I want the ball to bounce off the paddle but right now it’s going through the paddle and bouncing off the wall. Here’s the code I have for it right now…

if (ballX > canvas.width - BALL_RADIUS) {
if (ballY > computerPaddleY && ballY < computerPaddleY + PADDLE_HEIGHT
&& ballX > canvas.width - BALL_RADIUS - PADDLE_THICKNESS) {
ballSpeedX *= -1;
else {
playerScore++;
ballReset();
}
}

So the second if statement deals with the ball hitting the paddle but even though I added ‘&& ballX > canvas.width - BALL_RADIUS - PADDLE_THICKNESS’ it’s still going through the paddle.

Hamza Amer
@Heyrio
Jun 22 2017 03:08

function titleCase(str) {


 return str.toLowerCase().split(' ').map(function(final) {

    return (final.charAt(0).toUpperCase() + final.slice(1));

  }).join(' ');


}

titleCase("I'm a little tea pot");
got it that was annoying...
Diego Mayer
@Chrono79
Jun 22 2017 03:08
:+1:
Hamza Amer
@Heyrio
Jun 22 2017 03:08
@Chrono79 Thank you
CamperBot
@camperbot
Jun 22 2017 03:08
heyrio sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: heyrio already gave chrono79 points
Bethany Roberts
@Betanya
Jun 22 2017 03:09
//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){
  // Your Code Here
var answerProp="";
for(var i=0;i<contacts.length;i++){if (contacts[i].firstName==firstName){if (contacts[i].hasOwnProperty(prop)){answerProp=contacts[i].prop;} else {answerProp="No such property";} else {answerProp="No such contact";}
console.log(answerProp);
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
@Heyrio this is what i did differently
Diego Mayer
@Chrono79
Jun 22 2017 03:09
you can try with loops first and only use higher order methods when you feel comfortable with them @Heyrio
@Betanya indent your code, it's easier to read
Hamza Amer
@Heyrio
Jun 22 2017 03:11
@Betanya if you need multiples you can connect the with else if
@Heyrio the very last else should be your console.log();
@Chrono79 I feel like I start getting messy with loops
Diego Mayer
@Chrono79
Jun 22 2017 03:13

@Betanya

function lookUpProfile(firstName, prop){
  // Your Code Here
  var answerProp="";
  for(var i=0;i<contacts.length;i++){
    if (contacts[i].firstName==firstName){
      if (contacts[i].hasOwnProperty(prop)){
        answerProp=contacts[i].prop;
      } else {
        answerProp="No such property";
      } else {
        answerProp="No such contact";
      }
      console.log(answerProp);
// Only change code above this line
}

You're missing some } there

Hamza Amer
@Heyrio
Jun 22 2017 03:13
@Chrono79 I'd like to see more challenges with them
your pic brings back chrono trigger nostalgia
sharathki442gmailcom
@sharathki442gmailcom
Jun 22 2017 03:16
Hi does anyone stuck at stand in line challenge in Javascript basics.
Ogundele Olumide
@Lumexralph
Jun 22 2017 03:18
@sharathki442gmailcom are you?
Max
@maxiwer
Jun 22 2017 03:18
Hello, everyone. I'd like to check if my code is correct in "Using Objects for Lookups" task?
// 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"
};
var alpha = "alpha";
lookup[alpha];
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("alpha");
Diego Mayer
@Chrono79
Jun 22 2017 03:19
@maxiwer you need to use your function param: val and change result value (that's what your function returns)
Ogundele Olumide
@Lumexralph
Jun 22 2017 03:21
@maxiwer lookup[val], assign the value to result
Max
@maxiwer
Jun 22 2017 03:21
Oh sorry this is rewritten version
// 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"
};
var alpa = val;
// lookup[alpa];
result += lookup[alpa];
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("");
VinayVijayJoshi
@VinayVijayJoshi
Jun 22 2017 03:22
Hi, I am at 'Sorted Union'. Looking into solutions to flatten the array to a single one, saw solutions on google but not able to understand, can someone help
Ogundele Olumide
@Lumexralph
Jun 22 2017 03:22
@maxiwer all almost there, assign it don't use += use =
Diego Mayer
@Chrono79
Jun 22 2017 03:23
@maxiwer @Lumexralph it'll work anyway, unless there is some test that should return undefined
But delete all the unneeded code
VinayVijayJoshi
@VinayVijayJoshi
Jun 22 2017 03:24
below is the solution from web
var flatten = function(toFlatten) {
  var isArray = Object.prototype.toString.call(toFlatten) === '[object Array]';

  if (isArray && toFlatten.length > 0) {
    var head = toFlatten[0];
    var tail = toFlatten.slice(1);

    return flatten(head).concat(flatten(tail));
  } else {
    return [].concat(toFlatten);
  }
};
sharathki442gmailcom
@sharathki442gmailcom
Jun 22 2017 03:24
@Lumexralph Hi I am at Stand in Line
Max
@maxiwer
Jun 22 2017 03:24
@Lumexralph @Chrono79 thanks
CamperBot
@camperbot
Jun 22 2017 03:24
maxiwer sends brownie points to @lumexralph and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1978 | @lumexralph |http://www.freecodecamp.com/lumexralph
:star2: 4366 | @chrono79 |http://www.freecodecamp.com/chrono79
Ogundele Olumide
@Lumexralph
Jun 22 2017 03:24
@maxiwer you don't need this line var alpa = val; why not use val directly?
@Chrono79 yeah but.........
@sharathki442gmailcom tried anything?
jasonrest
@jasonrest
Jun 22 2017 03:26
Having trouble with my find the longest word challenge. only passing one test. anybody got a hint on where i went wrong?

function findLongestWord(str) {

  var strArray = str.split('');
  var maxLength = 0;

    for (i = 0; i < strArray.length; i++){
      if (strArray[i].length > maxLength){
        maxLength = strArray[i].length;
      }
    }  
  return maxLength;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Ogundele Olumide
@Lumexralph
Jun 22 2017 03:27
@jasonrest you're to split by space and not character var strArray = str.split('')
@jasonrest var strArray = str.split(' ');
jasonrest
@jasonrest
Jun 22 2017 03:28
@Lumexralph hmmmmm let me try it. brb
Ralph Nahra
@Rallph
Jun 22 2017 03:28
Hey can someone help me understand the smallest common multiple problem? The linked explanation seems to be different that the challenge's explanation
jasonrest
@jasonrest
Jun 22 2017 03:29
@Lumexralph Thanks so much missed that.
CamperBot
@camperbot
Jun 22 2017 03:29
jasonrest sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1979 | @lumexralph |http://www.freecodecamp.com/lumexralph
sharathki442gmailcom
@sharathki442gmailcom
Jun 22 2017 03:30
@Lumexralph

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

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

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

Ogundele Olumide
@Lumexralph
Jun 22 2017 03:30
@sharathki442gmailcom push item into arr
@sharathki442gmailcom shift only once return arr.shift(); will return the first element removed from arr
sharathki442gmailcom
@sharathki442gmailcom
Jun 22 2017 03:33

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

These are the instructions

They didn't mentioned push item to arr
Diego Mayer
@Chrono79
Jun 22 2017 03:35
@sharathki442gmailcom you're suppossed to deduce that reading the instructions after you've done the array manipulation challenges
Add the number (item) to the end of the array (arr) <- see?
Bethany Roberts
@Betanya
Jun 22 2017 03:35
@Chrono79 @Heyrio @moigithub thank you! I finally got it somehow!
CamperBot
@camperbot
Jun 22 2017 03:35
betanya sends brownie points to @chrono79 and @heyrio and @moigithub :sparkles: :thumbsup: :sparkles:
:cookie: 245 | @heyrio |http://www.freecodecamp.com/heyrio
:star2: 4367 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 3400 | @moigithub |http://www.freecodecamp.com/moigithub
Diego Mayer
@Chrono79
Jun 22 2017 03:44
:wave: bye
Ogundele Olumide
@Lumexralph
Jun 22 2017 03:54
@Chrono79 :wave:
Kelechi Chinaka
@ke1echi
Jun 22 2017 03:57
:wave: @Lumexralph morning
Ogundele Olumide
@Lumexralph
Jun 22 2017 03:58
@kelechichinaka Morning Bro!
Kelechi Chinaka
@ke1echi
Jun 22 2017 04:01
how's the morning looking like @Lumexralph
Abdullah Karaman
@storm2013ak
Jun 22 2017 04:02
'code'
Ryan Williams
@Ryanwfile
Jun 22 2017 04:03
I'm trying to make a 10 by 10 grid and I can't seem to get the desired element to appear more than once, any help is greatly appreciated
var cols = 10;
var rows = 10;
var cell = document.createElement('td');
var text = document.createTextNode('T');
cell.appendChild(text);
var grid = document.getElementById('cellBlock');
var clone = cell.cloneNode(true);

for (var i = 0; i< cols; i++){
    for (var j=0; j< rows; j++){
      grid.appendChild(clone);
    }
}
Kelechi Chinaka
@ke1echi
Jun 22 2017 04:04
use backticks ``` @storm2013ak
Abdullah Karaman
@storm2013ak
Jun 22 2017 04:05

Hey guys could you help with this. Can't pass "Hole-in-one" case.

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

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

@kelechichinaka so like code is here ?
Ogundele Olumide
@Lumexralph
Jun 22 2017 04:07
@kelechichinaka optimistic
heroiczero
@heroiczero
Jun 22 2017 04:07
@storm2013ak need the ! at the end of Hole-in-one!
Abdullah Karaman
@storm2013ak
Jun 22 2017 04:08
@heroiczero omg! thanks!
CamperBot
@camperbot
Jun 22 2017 04:08
storm2013ak sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1408 | @heroiczero |http://www.freecodecamp.com/heroiczero
Joseph
@revisualize
Jun 22 2017 04:18
@moigithub Congrats on 3400.
fdemaa
@fdemaa
Jun 22 2017 04:24
Any hint on why im getting the biggest number of my array, insted the biggest number of each subarray ?
function largestOfFour(arr) {
 var finalArray = [] ;
 var comparator = 0;

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

      }  
   }
 }
 return(comparator);
}


largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Manish Giri
@Manish-Giri
Jun 22 2017 04:25
@fdemaa this if
if(arr[i][j] > comparator ){
        comparator = arr[i][j];

      }
all it does is find the biggest number among all the arrays
fdemaa
@fdemaa
Jun 22 2017 04:26
thanks @Manish-Giri
CamperBot
@camperbot
Jun 22 2017 04:26
fdemaa sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6079 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jun 22 2017 04:27
:+1:
Joseph
@revisualize
Jun 22 2017 04:28
@fdemaa You need to reset compare before the inner loop iterates
Ogundele Olumide
@Lumexralph
Jun 22 2017 04:28
@Manish-Giri gggggm :smiling_imp:
Manish Giri
@Manish-Giri
Jun 22 2017 04:28
@Lumexralph good morning :smiling_imp:
:sunny:
fdemaa
@fdemaa
Jun 22 2017 04:28
@revisualize thank you
Joseph
@revisualize
Jun 22 2017 04:28
@fdemaa Because if you have a really large number like 1001 in the first outer array element. You're never going to find an inner array element larger than that.
CamperBot
@camperbot
Jun 22 2017 04:28
fdemaa sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4221 | @revisualize |http://www.freecodecamp.com/revisualize
Adam Bohannon
@abohannon
Jun 22 2017 04:32
Hey all. I'm running around in circles on the spinal tap challenge. I've worked through 4-5 different solutions but none of them satisfy all the tests. A nudge in the right direction would be helpful.
function spinalCase(str) {

  var strSplit = str.split(" ");
  var newArr = [];

  for (var i = 0; i < strSplit.length; i++){
    newArr.push(strSplit[i].charAt(0).toUpperCase() + strSplit[i].substr(1));
  }

  return newArr.join(" ").replace(/\s/g,'-').toLowerCase();

}

spinalCase("This Is Spinal Tap");
This is one of my more verbose solutions. More of a last ditch effort to see if it worked. Before I had a string of methods that almost got me there, but not quite.
chain of methods might be more appropriate
Ken Haduch
@khaduch
Jun 22 2017 04:40
@abohannon -in my solution, I tried getting any of the special characters that were already there (like the '-' and the '_') replaced with spaces. Then a couple regexp replaces to deal with existing uppercase letters - like the place where there is "AllThe" - I change that to All The and by doing that, standardizing any place where the dashes should be placed to be a space, the final replacement was easy. Sometimes in that conversion I would end up with multiple spaces, so I had one step to replace any multiple spaces with a single space (another regexp replacement). I don't know if that will help - but that's how i did it. It ended up being 4 lines of actual code, not counting the return line.
heroiczero
@heroiczero
Jun 22 2017 04:41

@abohannon for ("thisIsSpinalTap") it will not split it is separated with a lowercase followed by uppercase. try using Regexp

var re = /(\w+)\s(\w+)/;
var str = 'John Smith';
var newstr = str.replace(re, '$2, $1');
console.log(newstr);

from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp is a good place to start

jasonrest
@jasonrest
Jun 22 2017 04:41

I got two of my tests to pass. but failing 3 others.

function titleCase(str) {

  var titleCaseArray = str.split(' ');
  for (i = 0; i < titleCaseArray.length; i++){
   titleCaseArray[i] = titleCaseArray[i].charAt(0).toUpperCase() + titleCaseArray[i].slice(1);
  }

  return titleCaseArray.join(' ');
}

titleCase("I'm a little tea pot");

any ideas?

Adam Bohannon
@abohannon
Jun 22 2017 04:42
@khaduch @heroiczero that's helpful thank you! I had a feeling i was close, but after trying so many different ways I was getting discouraged. I think I might have an idea for another try. Cheers.
CamperBot
@camperbot
Jun 22 2017 04:42
abohannon sends brownie points to @khaduch and @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 3025 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 1411 | @heroiczero |http://www.freecodecamp.com/heroiczero
Manish Giri
@Manish-Giri
Jun 22 2017 04:43
@jasonrest there might be some test cases where letters other than the first are in uppercase..
you need to handle that.
jasonrest
@jasonrest
Jun 22 2017 04:44
@Manish-Giri ohhhhh ok. need to lowerCase everything??
got it
Ken Haduch
@khaduch
Jun 22 2017 04:47
@abohannon - you're welcome - good luck with that one!
TheCoalTrain
@TheCoalTrain
Jun 22 2017 04:49
var count = 0;

function cc(card) {
  // Only change code below this line
  if (card == 2, 3, 4, 5, 6) {
    return "5 Bet";
  }
  else if (card == 7, 8, 9, 0, 0) {
    return "0 Hold"; 
  }
  else if (card == 10, "J", "Q", "K", "A") {
    return "-5 Hold";
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(7); cc(8); cc(9); cc(); cc();
can i get some help with this? I feel like I've tried almost everything ;-;
Abhijeet Singh
@abhijeetps
Jun 22 2017 04:58
Hello developers, I have developed this website http://iiitt.ac.in.
I need a help in this.
How to remove the horizontal scrollbar?
Anybody?
jasonrest
@jasonrest
Jun 22 2017 04:59
@Manish-Giri I got the function to work and pass all tests but this doesnt seem very efficient. I just want to make sure this is the best approach.
function titleCase(str) {

  var titleCaseArray = str.split(' ');
  for (i = 0; i < titleCaseArray.length; i++){
   titleCaseArray[i] =titleCaseArray[i].toLowerCase();
   titleCaseArray[i] = titleCaseArray[i].charAt(0).toUpperCase() + titleCaseArray[i].slice(1);
  }

  return titleCaseArray.join(' ');
}

titleCase("I'm a little tea pot");
Abhijeet Singh
@abhijeetps
Jun 22 2017 04:59
Hello developers, I have developed this website http://www.iiitt.ac.in.
I need a help in this.
How to remove the horizontal scrollbar?
Anybody?
Ogundele Olumide
@Lumexralph
Jun 22 2017 05:00
@TheCoalTrain card === 2 || card === 3......
@TheCoalTrain in your conditional statement checking card just increment or decrement card where applicable, then you later check with another condional statement if count is positive > 0 or not to return count + string (Bet or Hold)
Manish Giri
@Manish-Giri
Jun 22 2017 05:03
@jasonrest try this
function titleCase(str) {
  return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.toLowerCase().slice(1)).join(' ');
}
Markus Ivancsics
@ivancsicsmarkus
Jun 22 2017 05:03
@aps120797
body {
    width: 100vw;
    overflow: hidden;
}
Austin Newman
@trashjava
Jun 22 2017 05:04
heidisdad2
@heidisdad2
Jun 22 2017 05:05
@TheCoalTrain you didn't do anything to change the count
Abhijeet Singh
@abhijeetps
Jun 22 2017 05:06
@ivancsicsmarkus Not working, already tried that.
Hey @Manish-Giri , can you help me out?
Manish Giri
@Manish-Giri
Jun 22 2017 05:06

@Lumexralph for the title case challenge, I just went and looked, my first attempt was this -

function titleCase(str) {
  var strWords = str.toLowerCase().split(" ");
  var newWords = [];
  for(var i = 0; i < strWords.length; i++) {
    newWords.push(capitalize(strWords[i]));
  }
  var newWord = newWords.join(" ");
  return newWord;
}

function capitalize(word) {

    var firstLetter = word[0];
    firstLetter = firstLetter.toUpperCase();
    return firstLetter + word.slice(1);
  }

from that, to this -

function titleCase(str) {
  return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.toLowerCase().slice(1)).join(' ');
}

wow..I've come a long way, lol

Markus Ivancsics
@ivancsicsmarkus
Jun 22 2017 05:07
@aps120797
html {
    width: 100vw;
    overflow: hidden;
}
Manish Giri
@Manish-Giri
Jun 22 2017 05:08
@aps120797 I guess Markus helped you out..try that code..
Austin Newman
@trashjava
Jun 22 2017 05:08
//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 (i = 0; i <= contacts.length; i++) {
   if (contacts[i][firstName]) {
     for (j = 0; j <= contacts[i].length; j++) {
       if (contacts[i][j] == prop) {
         return true;
       }
     }
   } else {
     return "No such contact";
   }
 }
// Only change code above this line
}

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

https://www.freecodecamp.com/challenges/profile-lookup

I've been stuck on this for days now, and I cannot for the life of me figure out how to check if the functions given parameters exist in the array. Could anyone possibly point me in the right direction, or give me some idea of what I should be doing?

KinderPreet Singh
@kindercappy
Jun 22 2017 05:10
which challenge is this? @trashjava
Abhijeet Singh
@abhijeetps
Jun 22 2017 05:11
@Manish-Giri @ivancsicsmarkus
Thank you for your help,
but this worked
    overflow-x: hidden !important;
CamperBot
@camperbot
Jun 22 2017 05:11
aps120797 sends brownie points to @manish-giri and @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:cookie: 633 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
:star2: 6080 | @manish-giri |http://www.freecodecamp.com/manish-giri
KinderPreet Singh
@kindercappy
Jun 22 2017 05:12
contacts[i][firstName] ==firstName
you need to display if there is not property in that contact
@trashjava
display " your message"
contacts[i][firstName is just checking for the presence of firstname value not the value in the firstName parameter i think
Yanxi Chen
@xastris
Jun 22 2017 05:16
var result;
for (var i = 0; i<contacts.length; i++){
  if (contacts[i][firstName]==firstName){
    if (contacts[i].hasOwnProperty(prop)){
    result = contacts[i].prop;
    } 
    else {
      result ="No such property";
    } 
  }
    else {
      result ="No such contact";
    }
}

return result;
I've been stuck on the same problem and this is what I have so far; somehow I can only get it to display "No such contact" and nothing else...
Austin Newman
@trashjava
Jun 22 2017 05:17
That's what I was confused on, I was unsure how to check for the value passed to the function rather than just the string "firstName"
That's about as far as I've gotten @xastris
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:17
@xastris contacts[i][prop]
@xastris you can't use 'dot' notation if you are passing variable.
Ogundele Olumide
@Lumexralph
Jun 22 2017 05:21
@Manish-Giri :joy: .... when I'm done with my frontend stuffs I'll go back, suspecting mine will be worse
Manish Giri
@Manish-Giri
Jun 22 2017 05:22
lol
no one's can be worse than mine
Ogundele Olumide
@Lumexralph
Jun 22 2017 05:23
@Manish-Giri i'll show you we'll see
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:23
@xastris also, if you want to get object value by using contacts[i][firstName], you need to remember add double qoute, like contacts[i]["firstName], or it's better to use contacts[i].firstName
Nikhil Palekar
@Nikhil200297
Jun 22 2017 05:24
can someone help me with a profile lookup in Javascript
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:24
@Nikhil200297 What do you have so far?
Ogundele Olumide
@Lumexralph
Jun 22 2017 05:24
@Nikhil200297 we can try, what've you got?
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:26
@xastris Last thing, you need to return your result like " return contacts[i][prop] instead of save it to 'result'. Otherwise, the result variable may get ovewrite.
Nikhil Palekar
@Nikhil200297
Jun 22 2017 05:26
i wanna check if my array index variable doesn't exceed the array within an array full of objects
Ogundele Olumide
@Lumexralph
Jun 22 2017 05:26
@Nikhil200297 index < array.length
Nikhil Palekar
@Nikhil200297
Jun 22 2017 05:27
so is this correct for the length " contacts.prop.length "
Ogundele Olumide
@Lumexralph
Jun 22 2017 05:27
@Nikhil200297 contacts.length
@Nikhil200297 the array is contacts
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:28
Hi Community, any better solution or re-factory my code for problem 'Title Case a Sentence'?

function titleCase(str) {

  // Set up variable for this function
  var result = [];
  var capWord;

  // Split str to an array
  str = str.split(" ");

  // Loop through the array, and lower all the string.
  // Save the first letter to varaible capWord.
  // Replace first letter with capWord
  for (var i = 0; i < str.length; i++){
    str[i] = str[i].toLowerCase();
    capWord = str[i].charAt(0).toUpperCase();
    str[i] = str[i].replace(str[i].charAt(0), capWord);  
  }

  // Join array values together, and save it to 'result'
  // return 'result'
  result = str.join(" ");
  return (result);

}
  titleCase("I'm a little tea pot");
heidisdad2
@heidisdad2
Jun 22 2017 05:28
@TheCoalTrain get it yet? need any help?
Nikhil Palekar
@Nikhil200297
Jun 22 2017 05:28
no no i have an array of objects and inside each object there is one property having an array and i wanna access this array
Will White
@willnwhite
Jun 22 2017 05:28
@xastris "No such property." because
Nikhil Palekar
@Nikhil200297
Jun 22 2017 05:28
how should i send the picture here
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:29
@Nikhil200297 paste your code, and add 3 ` at the top and bottom of your code
` is the key next to 1 on your keyboard
Markus Ivancsics
@ivancsicsmarkus
Jun 22 2017 05:29
@Nikhil200297 just drag’n’drop!
Nikhil Palekar
@Nikhil200297
Jun 22 2017 05:29

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
var firstNameValue = firstName;
var propValue = prop;
for(var i = 0; i < contacts.length; i++){
if(contacts[i].firstName == firstNameValue){

  if(contacts[i].hasOwnProperty(prop)){

    if(contacts[i].prop.length > 1){

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

        return contacts[i].propValue[j];

      }

    }
    else{
      return contacts[i].propValue; 
    }

  }
  else{
    return "No such property";
  }

}
else{
  return "No such contact";
}

}
// Only change code above this line
}

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

KinderPreet Singh
@kindercappy
Jun 22 2017 05:29
@ShenyuSun
var tempStr = str.toLowerCase().split(" ");
  var uppercased = tempStr.map(function(val){
    var splitWord = val.split("");
    var firstLetter = splitWord[0];
    splitWord[0] = firstLetter.toUpperCase();
    return splitWord.join("");
  });
  var final = uppercased.join(" ");
  return final;
Will White
@willnwhite
Jun 22 2017 05:30
if is always false because [firstName] does .Akira
Andrea Mammoliti
@AndreusSH
Jun 22 2017 05:30
Hi everyone, I am experiencing some issue with this challenge https://www.freecodecamp.com/challenges/truncate-a-string
function truncateString(str, num) {
if (str.length > num)
return str.slice(0, num) +"...";
else if (str.length < num)
{return str;}
}
my code is correct only if I assign a number to num
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:31
@kindercappy Thank you! That's interesting that you are using map function. I forgot about map function.
CamperBot
@camperbot
Jun 22 2017 05:31
shenyusun sends brownie points to @kindercappy :sparkles: :thumbsup: :sparkles:
:cookie: 261 | @kindercappy |http://www.freecodecamp.com/kindercappy
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:32
@kindercappy and you also linked to function together. toLowerCase and split. Good to know!
KinderPreet Singh
@kindercappy
Jun 22 2017 05:33
@ShenyuSun awesome
Markus Ivancsics
@ivancsicsmarkus
Jun 22 2017 05:34

@AndreusSH first of all:

if (str.length > num) 
    return str.slice(0, num-3) +"…";

because it should be 11 long with the three dots

Andrea Mammoliti
@AndreusSH
Jun 22 2017 05:36
that makes a lot of sense thanks for the explanation bro @ivancsicsmarkus
CamperBot
@camperbot
Jun 22 2017 05:36
andreussh sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:cookie: 635 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
heidisdad2
@heidisdad2
Jun 22 2017 05:39
@ShenyuSun ```
function titleCase(str) {
 var arraySplit = str.toLowerCase().split(" ");
 for(i=0; i < arraySplit.length; i++){ 

   arraySplit[i] = arraySplit[i].split('');
   arraySplit[i][0] = arraySplit[i][0].toUpperCase();
   arraySplit[i]= arraySplit[i].join('');

 }
  return arraySplit[i];

}  


titleCase("I'm a little tea pot");
that's how i got there
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:40
@heidisdad2 thank you, so split twice, it became multi array, and can use [][] to get value. good to know!
CamperBot
@camperbot
Jun 22 2017 05:40
shenyusun sends brownie points to @heidisdad2 :sparkles: :thumbsup: :sparkles:
:cookie: 249 | @heidisdad2 |http://www.freecodecamp.com/heidisdad2
heidisdad2
@heidisdad2
Jun 22 2017 05:46
@ShenyuSun one of the splits was by word the second split was by letter.
Yanxi Chen
@xastris
Jun 22 2017 05:48
@ShenyuSun I finally got it to work based on your suggestions! thanks a bunch!!
CamperBot
@camperbot
Jun 22 2017 05:48
xastris sends brownie points to @shenyusun :sparkles: :thumbsup: :sparkles:
:cookie: 250 | @shenyusun |http://www.freecodecamp.com/shenyusun
heidisdad2
@heidisdad2
Jun 22 2017 05:50
@ShenyuSun i actually screwed up on that, everything is right except the return statement should be---return arraySplit.join(" "); to join back by word.
BlackTiger
@BlackTigerRoar
Jun 22 2017 05:50
@heidisdad2 It's all good. I got the concept. Just trying to see if there are more solutions.
@xastris awesome! roar :tiger:
heidisdad2
@heidisdad2
Jun 22 2017 05:53
anyone can help me on this?

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


  if (second[i] >= 0){
    return true;
  }else{
    return false;
  }
 }
}
mutation(["hello", "he"]);
i am getting it correct in every test except for when mutation(["hello,"hey]) because the y in hey is returning y instead of a value.
Moses Justin
@mosesjust2016
Jun 22 2017 06:00

function golfScore(par, strokes) {
// Only change code below this line

if (par <= 4 && strokes == 1){

  return "Hole-in-one";

} else if (par <=5 && strokes == 2) {

  return "Eagle";

} else if (par <=5 && strokes == 3) {

 return "Birdie";

} else if (par <=4 && strokes == 5) {

  return "Bogey";

} else if (par <=5 && strokes <= 5) {

  return "Par";

} else if (par <=4 && strokes <= 6) {

  return "Double Bogey";

} else if (par <= 5 && strokes <= 9) {

  return "Go Home!";

} else {

  return "Out of range";

}

// Only change code above this line
}

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

Riyaz
@riyazcool
Jun 22 2017 06:02

var count = 0;

function cc(card) {
// Only change code below this line
if(card==2||card==3||card==4||card==5||card==6)
{

 return count++;

}
else if(card==7||card==8||card==9)
{

  return count;

}

else if(card==10||card=='J'||card=='Q'||card=='K'||card=='A')
{
return count--;

}

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

}

else if(count<=0)
{
return (count+" Hold");

}

else
return "Invalid Entry";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
can any1 say what should i do

Luis Hernandez
@luischernandez
Jun 22 2017 06:03
@heidisdad2
@heidisdad2 try splitting first like you did with second. when you for-loop use full length
also, the return logic just escape you only if you get -1
heidisdad2
@heidisdad2
Jun 22 2017 06:07
@luischernandez hmm, ok let me check
BlackTiger
@BlackTigerRoar
Jun 22 2017 06:07
@mosesjust2016 If strokes is 1, you don't care about how many par.
Luis Hernandez
@luischernandez
Jun 22 2017 06:07
you keep getting true because with one hit that evaluates true your function returns true and completely bypasses the rest
KinderPreet Singh
@kindercappy
Jun 22 2017 06:07
Please check my personal portfolio: https://codepen.io/kindercappy/pen/zzZWaB
All the suggestions appreciated!
BlackTiger
@BlackTigerRoar
Jun 22 2017 06:07
@mosesjust2016 It'll always be Hole-in-one when stroke is equals to 1
Carlos Córdova Sáenz
@Oberyn18
Jun 22 2017 06:08
Hello there
Can someone help me with this please?

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

function checkObj(checkProp) {
// Your Code Here
if(myObj.hasOwnProperty(checkProp)){
return "Not Found";
}else{
return myObj[checkProp];
}
}

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

Luis Hernandez
@luischernandez
Jun 22 2017 06:09
@heidisdad2 I know we should not take hand me downs, but I think you are close enough. I just refactored your code a little bit. try this
BlackTiger
@BlackTigerRoar
Jun 22 2017 06:10
@kindercappy Looking sharp! Like the animated words.
Carlos Córdova Sáenz
@Oberyn18
Jun 22 2017 06:10
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if(myObj.hasOwnProperty(checkProp)){
    return "Not Found";
  }else{
    return myObj[checkProp];
  }
}

// Test your code by modifying these values
checkObj("gift");
Luis Hernandez
@luischernandez
Jun 22 2017 06:10
@heidisdad2 function mutation(arr) {
var first = arr[0].toLowerCase(); console.log(first)
var firstSplit = first.split(''); console.log(firstSplit)
var second = arr[1].toLowerCase().split(''); console.log(second)
for(var i=0; i<second.length; i++){
var idx = first.indexOf(second[i]);
console.log(idx)
if (idx === -1){
return false;
}
}
return true
}
mutation(["hello", "hey"]);
Carlos Córdova Sáenz
@Oberyn18
Jun 22 2017 06:10
don't know what is bad in the function "hasOwnProperty"
KinderPreet Singh
@kindercappy
Jun 22 2017 06:10
@ShenyuSun thank you
CamperBot
@camperbot
Jun 22 2017 06:10
kindercappy sends brownie points to @shenyusun :sparkles: :thumbsup: :sparkles:
:cookie: 251 | @shenyusun |http://www.freecodecamp.com/shenyusun
BlackTiger
@BlackTigerRoar
Jun 22 2017 06:10
@Oberyn18 If your object has the prop, then it should return the prop
Carlos Córdova Sáenz
@Oberyn18
Jun 22 2017 06:11
oh
yes yes
BlackTiger
@BlackTigerRoar
Jun 22 2017 06:11
@Oberyn18 Right now, in your code, if prop existed, it returns Not Found, which is opposite.
Carlos Córdova Sáenz
@Oberyn18
Jun 22 2017 06:11
thanks!
stupid error :worried:
heidisdad2
@heidisdad2
Jun 22 2017 06:11
luis, thanks man, that totally makes sense
BlackTiger
@BlackTigerRoar
Jun 22 2017 06:12
@Oberyn18 We've all been there ;)
Luis Hernandez
@luischernandez
Jun 22 2017 06:12
@heidisdad2 you are welcome :)
heidisdad2
@heidisdad2
Jun 22 2017 06:13
i had my logic backwards a little
Luis Hernandez
@luischernandez
Jun 22 2017 06:15
yeah, we tend to think 'true' first and then 'false', it happens to me all the time
heidisdad2
@heidisdad2
Jun 22 2017 06:21
that firstSplit var doesn't really do anything though
Adam Kim
@resv
Jun 22 2017 06:34
been a while since i've been here, whats the format to paste code here again? "~~"?
Abdullah Karaman
@storm2013ak
Jun 22 2017 06:34
@resv ```
Adam Kim
@resv
Jun 22 2017 06:38
@storm2013ak thanks!
CamperBot
@camperbot
Jun 22 2017 06:38
resv sends brownie points to @storm2013ak :sparkles: :thumbsup: :sparkles:
:cookie: 199 | @storm2013ak |http://www.freecodecamp.com/storm2013ak
KinderPreet Singh
@kindercappy
Jun 22 2017 06:44
function mutation(arr) {
  var word = arr[0].toLowerCase();//console.log(word);
  var checkword = arr[1];//console.log(checkword);
  var checkwordArray = checkword.toLowerCase().split("");//console.log(checkwordArray);
  var number;
  for(var i = 0; i < checkwordArray.length; i++){
     number = word.indexOf(checkwordArray[i]);//console.log(checkwordArray[i]);
  }
  if(number === -1){
    return false;
  }else{
    return true;
  }
}

mutation(["voodoo", "no"]);
https://www.freecodecamp.com/challenges/mutations
Why is this not working?
Pieter Stokkink
@forkerino
Jun 22 2017 06:52
@kindercappy you're overwriting number each time, so you'll ultimately only have the result of the check of the last letter.
One way to solve this is to return false as soon as you find a mismatch (i.e. put a conditional inside your loop.)
KinderPreet Singh
@kindercappy
Jun 22 2017 06:53
@forkerino thank you
CamperBot
@camperbot
Jun 22 2017 06:53
kindercappy sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2704 | @forkerino |http://www.freecodecamp.com/forkerino
Silviu Pietreanu
@Spikyd
Jun 22 2017 06:59
hi all
can somebody help me ? :D
i don't understand a thing of js :P
Jiizen
@Jiizen
Jun 22 2017 07:03
Hello everyone, it depends. I need some help, too. XD
Manish Giri
@Manish-Giri
Jun 22 2017 07:04
@Jiizen help with?
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:04

myVariable = 5;
// Setup
var a = 7;
var b = 2;
myVar = 5;
myNum = myVar;
var a = var b;

// Only change code below this line

what is wrong here ? :D :D :D :D
Jiizen
@Jiizen
Jun 22 2017 07:05
I don't understand what I have of bad in my code for the exercice "escape sequences in strings". And I receive the result not interpreted. Thank you.
alleac
@alleac
Jun 22 2017 07:05
@Spikyd var a = b;
Jiizen
@Jiizen
Jun 22 2017 07:06
@Spikyd : var a and b are already declared. a = b should be OK.
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:06
nope
can you write the correct code ?
i still don't understand
i wrote var a = b;
var a = var b;
nothing work
KinderPreet Singh
@kindercappy
Jun 22 2017 07:08
when you have declared with var a
dont declare it again
Jiizen
@Jiizen
Jun 22 2017 07:08
No. Actually, you already declared your variables a and b. ^^
KinderPreet Singh
@kindercappy
Jun 22 2017 07:08
just assign a = b;
alleac
@alleac
Jun 22 2017 07:08
@Spikyd a =b;
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:08

myVariable = 5;
// Setup
var a = 7;
var b = 2;
myVar = 5;
myNum = myVar;
a = b;

// Only change code below this line

like this ?
Jiizen
@Jiizen
Jun 22 2017 07:08
Yes. It should be good.
Adithya
@Adithya1243
Jun 22 2017 07:08
i need help in JavaScript ..Stand in Line
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:09
no.. is all wrong
all requirments are with an red X
Manish Giri
@Manish-Giri
Jun 22 2017 07:09
@Spikyd what are the instructions?
Jiizen
@Jiizen
Jun 22 2017 07:10
But where is declared your myNum variable ? o.o
KinderPreet Singh
@kindercappy
Jun 22 2017 07:10
which challenge is this? @Spikyd
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:10

Instructions
Assign the value 7 to variable a.

Assign the contents of a to variable b.

alleac
@alleac
Jun 22 2017 07:10
var b = a;
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:10
Storing Values with the Assignment Operator
Manish Giri
@Manish-Giri
Jun 22 2017 07:10
@Spikyd then where is myNum and myVar coming from?
you only need to deal with a and b
Assign the value 7 to variable a.
Assign the contents of a to variable b.
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:11
is telling me "Assigns 5 to myVar and then resolves myVar to 5 again and assigns it to myNum."
Manish Giri
@Manish-Giri
Jun 22 2017 07:11
@kindercappy pls don't post answers
Jiizen
@Jiizen
Jun 22 2017 07:11
Warning. Because you have the example and the exercice. Don't shake the both. :3
Manish Giri
@Manish-Giri
Jun 22 2017 07:11
let him attempt it himself
KinderPreet Singh
@kindercappy
Jun 22 2017 07:12
@Manish-Giri my bad
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:12
sorry... for spamming.. i try to understand logically
worked b = a;
but i don't know what i did still can't run test
Do not change code above the line have an red X
KinderPreet Singh
@kindercappy
Jun 22 2017 07:13
solved yet? @Spikyd
Mostafa Hesham
@mhesham32
Jun 22 2017 07:13
Hey i need help pls if i got data from ajax and i want to change this data in the template by event listeners like temp-degree the user can convert the units how could i make this happens once not every time the user uses the event? https://codepen.io/mhesham32/pen/awwBoq?editors=1111
Jiizen
@Jiizen
Jun 22 2017 07:13
Firstly, you declare the "existence" of your variable, the place in the memory. After, you can use them. b = a. b takes the value of a.
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:14
// Setup
myVariable = 5;
var a = 7;
var b = 2;
myVar = 5;
myNum = myVar;
b = a;
// Only change code below this line
this is the final code.. and i can't pass "Do not change code above the line"
Jiizen
@Jiizen
Jun 22 2017 07:16
Yes, you have to write BELOW the line.
KinderPreet Singh
@kindercappy
Jun 22 2017 07:16
firstly remove the myvar and mynum declarations. not needed
@Spikyd
second cut and paste the rest of the code below the line
Madhava Di Florio
@mierz00
Jun 22 2017 07:17
@mhesham32 I am unsure what you are trying to achieve? Where is your ajax call?
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:18
still don't work
i give up
Mostafa Hesham
@mhesham32
Jun 22 2017 07:19
@mierz00 this pen is not what im talking about i just gave u example to understand me
Silviu Pietreanu
@Spikyd
Jun 22 2017 07:19
@kindercappy @Jiizen @Manish-Giri ty!
CamperBot
@camperbot
Jun 22 2017 07:19
spikyd sends brownie points to @kindercappy and @jiizen and @manish-giri :sparkles: :thumbsup: :sparkles:
:cookie: 143 | @jiizen |http://www.freecodecamp.com/jiizen
:cookie: 263 | @kindercappy |http://www.freecodecamp.com/kindercappy
:star2: 6083 | @manish-giri |http://www.freecodecamp.com/manish-giri
pahosler
@pahosler
Jun 22 2017 07:20
@mhesham32 just wrap your text- output- in a <span> give the span an id, id="temp", then use javascript to change the text, document.getElementById("temp").innerHTML(temperature) then you can click away and just change the text and not fill up the page
temperature is just an example variable, use whatever you have in your code...
Madhava Di Florio
@mierz00
Jun 22 2017 07:23
@mhesham32 Link your pen and what you have tried so far.
Mostafa Hesham
@mhesham32
Jun 22 2017 07:25
@pahosler but if the user keeps clicking the value keeps changing what to do to make this happens once ?
pahosler
@pahosler
Jun 22 2017 07:26
removeInterupt
why wouldn't you want the user to keep changing the value though?
locking them into a choice isn't user friendly
Pieter Stokkink
@forkerino
Jun 22 2017 07:30
@mhesham32 You mean you want to store the result of the calculation somewhere?
Mostafa Hesham
@mhesham32
Jun 22 2017 07:33
@forkerino and the event happens once not every click i get a new deg
Pieter Stokkink
@forkerino
Jun 22 2017 07:34
@mhesham32 well the event is the click, not the calculation. If you get strange different results every time you click the button, there's probably a bug in your calculation. Show some code, otherwise it's hard to point you in the right direciton.
Pieter Stokkink
@forkerino
Jun 22 2017 07:41
So you want to replace the element that is already there instead of .append to it?
Mostafa Hesham
@mhesham32
Jun 22 2017 07:41
something like this
Pieter Stokkink
@forkerino
Jun 22 2017 07:42
use something like $('#d').text(...) instead of .append()
@mhesham32
Mostafa Hesham
@mhesham32
Jun 22 2017 07:45
@forkerino thanks
CamperBot
@camperbot
Jun 22 2017 07:45
mhesham32 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2705 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 22 2017 07:47
:+1:
Esteban
@estebansanmartin
Jun 22 2017 07:48
fahrenheit=9/5*celsius+32;
Joe Franco
@BoostedB14
Jun 22 2017 07:49
Can someone help me with a problem I'm having? I just started the jQuery section. The code works on FreeCodeCamp website, but when i tru to run it on my own website the jQuery code doesn't seem to function. Does anyone here know why that is?
Pieter Stokkink
@forkerino
Jun 22 2017 07:50
@estebansanmartin multiplication comes before division
NaveenRathor
@NaveenRathor
Jun 22 2017 07:50
how to add it ?
<div ng-app="" ng-init="quantity=1;cost=5">
<p>Total in dollar: <span ng-bind="quantity"></span><span ng-bind="cost"></span></p>
</div>
Pieter Stokkink
@forkerino
Jun 22 2017 07:51
@BoostedB14 did you include the jQuery library in a script tag?
Joe Franco
@BoostedB14
Jun 22 2017 07:52
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("button").addClass("animated bounce");

});
</script>
This is what i have
Is there a better way to copy code into the chat? Do people just take screenshots?
Pieter Stokkink
@forkerino
Jun 22 2017 07:52
''' more info on code formatting below
CamperBot
@camperbot
Jun 22 2017 07:52
:bulb: to format code use backticks! ``` more info
Pieter Stokkink
@forkerino
Jun 22 2017 07:53
@BoostedB14 that looks ok.
Can you see the classes added to the buttons on the page?
NaveenRathor
@NaveenRathor
Jun 22 2017 07:54
hello guys I have a problem plz suggest to solve it?
<div ng-app="" ng-init="quantity=1;cost=5">
<p>Total in dollar: <span ng-bind="quantity"></span><span ng-bind="cost"></span></p>
</div>
Valdovas1
@Valdovas1
Jun 22 2017 07:56

function mutation(arr) {
  for (var i = 0; i < arr.length; i++){
    arr[0].indexOf(1[i]);
  }if(arr[0] > -1){

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

mutation(["hello", "hey"]);
Why I get true but not false ?
Pieter Stokkink
@forkerino
Jun 22 2017 07:57
@Valdovas1 that is some weird looking code. The .indexOf has bad syntax in it and the result will be thrown away because you don't assign it to anything. So you end up comparing a letter to -1.
Valdovas1
@Valdovas1
Jun 22 2017 07:58
@forkerino So were is the mistake ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:02
@Valdovas1 the line with .indexOf, the first if condition and the else if condition. Plus one of the returns needs to be outside the loop. To check if a letter is NOT inside a word, you do something like word.indexOf(letter) === -1; you have to use array elements instead of word and letter...
also make sure to lowercase both strings.
Valdovas1
@Valdovas1
Jun 22 2017 08:12
@forkerino For example arr[0].indexOf(arr[1[i]]); ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:13
@Valdovas1 those brackets are wrong: arr[1][i] would be the i'th letter of the second word.
Valdovas1
@Valdovas1
Jun 22 2017 08:14
@forkerino So arr[0].indexOf(arr[1][0]); ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:15
@Valdovas1 that would check the index of the first letter of the second word in the first word. It would give the index of it or -1, but you need to compare that to something as well of course.
Valdovas1
@Valdovas1
Jun 22 2017 08:17
@forkerino arr[0].indexOf(arr[1][i]) === -1 ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:18
@Valdovas1 yes
that can be something to put in an if
Valdovas1
@Valdovas1
Jun 22 2017 08:18
function mutation(arr) {
for (var i = 0; i < arr.length; i++){
  arr[0].indexOf(arr[1][i]) === -1;
}

}

mutation(["hello", "hey"]);
pahosler
@pahosler
Jun 22 2017 08:18
today I discovered a funny js trick just screwing around [10,22,30,14][Math.floor(Math.random()*4)]
Valdovas1
@Valdovas1
Jun 22 2017 08:19
So wha I put after for loop ? :o:
WAIT !!!

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

}
}

mutation(["hello", "hey"]);
THIS WORKS KIND OF
@forkerino THANK YOU. I was stuck on this one since last week's thursday !
CamperBot
@camperbot
Jun 22 2017 08:21
valdovas1 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2706 | @forkerino |http://www.freecodecamp.com/forkerino
Valdovas1
@Valdovas1
Jun 22 2017 08:21
I will figure it out now on my own
Also it seems that this code works without toLowerCase() on some expressions ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:26
@Valdovas1 yeah it will work if both words are lowercased. One hint: return stops a function and by extension a loop.
@pahosler that 10 inside Math.random() is superfluous and not needed. ;) Math.random() doesn't take an argument.
pahosler
@pahosler
Jun 22 2017 08:27
AH, ok, cool, should have looked it up LOL
it was still a neat trick, I used it in tic tac toe to pick a random start corner if X picked center :D
Valdovas1
@Valdovas1
Jun 22 2017 08:30
@forkerino I wrote those if else if statements outside of loop now, did not I ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:34
@Valdovas1 ah yes, correct. But now your loop doesn't do anything! It looks up the indexes and throws them away.
Valdovas1
@Valdovas1
Jun 22 2017 08:34
@forkerino what ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:37
that line inside your for loop is looking up the index of the first and second letter and then does nothing with the result. Afterwards you just look at the first letter and return. You need to do a bit more inside your loop (look through all letters in arr[1]
@Valdovas1
Valdovas1
@Valdovas1
Jun 22 2017 08:39
@forkerino But i loop second word with i so it goes thrue all the word and compares ?
Pieter Stokkink
@forkerino
Jun 22 2017 08:45
@Valdovas1 that is not how your code works. If you want to understand it better I suggest you put it over at pythontutor.com and visualize the code execution.
Valdovas1
@Valdovas1
Jun 22 2017 08:50
@forkerino Did not knew about this one before. Thank you.
CamperBot
@camperbot
Jun 22 2017 08:50
valdovas1 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: valdovas1 already gave forkerino points
Zhangze
@NominationP
Jun 22 2017 08:55
Change the 0.0 so that product will equal 5.0.
var product = 2.0 * 0.0;
Adam Gadsby
@dcfcgadders
Jun 22 2017 08:59
hey everyone, hope your all good :)
i am having a problem on one of the Javascript challenges... The Golf Course one...

function golfScore(par, strokes) {

  // Only change code below this line
  if (strokes === 1 ){

    return "Hole In One";

  } else if (strokes <= par -2){

    return "Eagle";

  } else if (strokes <= par -1){

    return "Birdie";

  } else if (strokes === par){

    return "Par";

  } else if ( strokes === par + 1){

    return "Bogey";

  } else if ( strokes === par + 2) {

    return "Double Bogey";   

  } else if( strokes >= par + 3) {

    return "Go Home";

  }
}

// Change these values to test
golfScore(5, 5);
Pieter Stokkink
@forkerino
Jun 22 2017 09:01
@NominationP 2.0 times what is 5.0 ? replace 0.0 by that number
bilaal-s
@bilaal-s
Jun 22 2017 09:02
morning guys ^_^
Pieter Stokkink
@forkerino
Jun 22 2017 09:02
@dcfcgadders spelling needs to be exact!
Adam Gadsby
@dcfcgadders
Jun 22 2017 09:02
actually... fixed it.... the issue was the string values didn't exactly match the version they wanted, like i have exclamation marks etc...
Pieter Stokkink
@forkerino
Jun 22 2017 09:02
:+1:
bilaal-s
@bilaal-s
Jun 22 2017 09:03
for the sum all primes intermediate challenge, im wondering, how can the test case for 10 pass but not 977? cant see whats going on here...
function sumPrimes(num) {
  let arr = [];
  let nonPrimeArr = [];
  let sum = 0;
  for (let i = 2; i < num; i++) {
    arr.push(i);    
  }

  for (let j = 0; j < arr.length; j++) {
    for (let k = 2; k < arr[j]; k++) {
      if (arr[j] % k === 0) {
        nonPrimeArr.push(arr[j]);
        console.log(arr[j] + " has been removed");
        break;
      }
    }
  }

  for (let l = 0; l < nonPrimeArr.length; l++) {
    let index = arr.indexOf(nonPrimeArr[l]);
    arr.splice(index, 1);
  }

  console.log(arr);

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

  return sum;
}

sumPrimes(977);
Blauelf
@Blauelf
Jun 22 2017 09:04
@bilaal-s i <= num
bilaal-s
@bilaal-s
Jun 22 2017 09:05
@Blauelf oh my oh my,
@Blauelf i cant believe i forgot that, thanks!
Blauelf
@Blauelf
Jun 22 2017 09:06
@bilaal-s The reported value for 977 should be different from the expected value by exactly 977
bilaal-s
@bilaal-s
Jun 22 2017 09:06
@Blauelf it even said clearly in the instructions the number provideed may notbe a prime
Blauelf
@Blauelf
Jun 22 2017 09:07
cbot status
CamperBot
@camperbot
Jun 22 2017 09:07
All bot systems are go!
botVersion: 0.0.12
env: prod
botname: camperbot
Madhava Di Florio
@mierz00
Jun 22 2017 09:07
Any one around who is confident with pull requests to FFC repo?
bilaal-s
@bilaal-s
Jun 22 2017 09:07
@Blauelf thanks ^_^
CamperBot
@camperbot
Jun 22 2017 09:07
bilaal-s sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4445 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jun 22 2017 09:08
@bilaal-s Why did it not trigger the first time? I have a feeling that @camperbot seems to miss some posts. Yesterday it did, too.
Adithya
@Adithya1243
Jun 22 2017 09:08
i need help in switch case statements..in Javascript
i am unable to get the output
bilaal-s
@bilaal-s
Jun 22 2017 09:09
@Blauelf I wish I knew x(
Blauelf
@Blauelf
Jun 22 2017 09:09
@Adithya1243 Right channel, then :D
Adithya
@Adithya1243
Jun 22 2017 09:09
@Blauelf can i get the right answer?
Selecting from many options with Switch Statements
This is the task
Blauelf
@Blauelf
Jun 22 2017 09:10
@Adithya1243 So you are switching on the right variable? (use the function parameter)
You use the right case statements (case 1: and so on, as specified)
And you assign the right strings to the variable later returned?
Adithya
@Adithya1243
Jun 22 2017 09:10

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

Blauelf
@Blauelf
Jun 22 2017 09:11
Don't log, but assign to answer!
Adithya
@Adithya1243
Jun 22 2017 09:11
like.. answer="gamma"
???
Blauelf
@Blauelf
Jun 22 2017 09:11
(and please use gitter style markdown when posting code)
@Adithya1243 :+1:
Adithya
@Adithya1243
Jun 22 2017 09:12
thats it..! thank you @Blauelf
CamperBot
@camperbot
Jun 22 2017 09:12
adithya1243 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4446 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jun 22 2017 09:13
@Adithya1243 Your code never changed answer, so having the function return nothing (or more precisely the empty string) is not a big surprise.
Adithya
@Adithya1243
Jun 22 2017 09:14
well, i clicked on a link to learn more about Switch statements.
there, the statements were console.log();
zoeyle
@zoeyle
Jun 22 2017 09:16
Hi guys, I'm stuck on the Arguments Optional challenge. I can't figuring out what to put in the condition to separate the case of the closures and normal function with arguments.

var sum;

if( ){
  return function sumTwoArg(arg) {
  if(typeof arg === 'number' && typeof arguments[0] === 'number'){
  sum = arg + arguments[0];
  }
};

} else {
sum = arguments[0] + arguments[1];
}

return sum;

}

Blauelf
@Blauelf
Jun 22 2017 09:17
Please use gitter style markdown when posting code.
bilaal-s
@bilaal-s
Jun 22 2017 09:17
btw is camperbot trying to automatically detect code?
Blauelf
@Blauelf
Jun 22 2017 09:18
@zoeyle arguments[0] inside the function expression refers to the same thing as arg, also the function expression has no return statement.
@bilaal-s What do you mean? How would @camperbot come into play for that? Do you think it secretly creates a code archive?
@zoeyle The logic is mostly
if called with exactly one argument which also is a number
    return a function that returns the sum if called with another number
else if called with two arguments and both are numbers
    return sum
zoeyle
@zoeyle
Jun 22 2017 09:23
@Blauelf got it. Thanks. Let me try it out
CamperBot
@camperbot
Jun 22 2017 09:23
zoeyle sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4447 | @blauelf |http://www.freecodecamp.com/blauelf
bilaal-s
@bilaal-s
Jun 22 2017 09:23
@Blauelf loooooool, no, i thought it would just read code and try to format it properly
Blauelf
@Blauelf
Jun 22 2017 09:24
@bilaal-s That's a gitter feature, it uses some markdown dialect. @camperbot won't edit your posts, it's here for entertainment/information purposes only.
bilaal-s
@bilaal-s
Jun 22 2017 09:25
@Blauelf cool :thumbsup:
Blauelf
@Blauelf
Jun 22 2017 09:27
@zoeyle You need to find a way to have that first argument passed to the returned function. That could mean a named parameter, it could mean an extra variable, or re-using the addTogether function by using Function.prototype.bind, like return addTogether.bind(this, arguments[0]);.
Rinor Bivolaku
@RinorNotorious
Jun 22 2017 09:30

Hello guys, can anyone point me to the right direction on what I need to do with this in order for it to complete all the requirements?
Thanks in advance!
-
function mutation(arr) {

var newArr = [];

for(var i = 0; i < arr.length; i++){
newArr = arr.join('|').toLowerCase().split('|');

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

    if(newArr[i+1].indexOf(char)){
        return true;
    }
    else{
        return false;
    }
}

}

}
mutation(["hello", "hey"]);

Saif Ur Rahman
@saifsmailbox98
Jun 22 2017 09:32

@RinorNotorious take the secondWord arr[1] and check if all the letters in it are present in the firstWord arr[0] .

indexOf()
Returns the index of the first occurrence of the specified value; -1 if not found.

var str = "hello";

str.indexOf("h") // 0
str.indexOf("e") // 1
str.indexOf("l") //  2
str.indexOf("m") // -1
Ross
@rossfaarley
Jun 22 2017 09:36
Hey folks, I’m not sure what I’m doing wrong but I can’t get one of the test arguments to pass. Any advice? https://www.freecodecamp.com/challenges/mutations

function mutation(arr) {

var elementOne = arr[0].toLowerCase(); // 
var elementTwo = arr[1].toLowerCase(); // 

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

  if (elementOne.indexOf(elementTwo[i]) < 0) {

    return false;

  } 

  return true;

  }

}
mutation(["hello", "hey"]);
Saif Ur Rahman
@saifsmailbox98
Jun 22 2017 09:37
@rossfaarley put return true; outside the loop
Ross
@rossfaarley
Jun 22 2017 09:37
@saifsmailbox98 Ah! So simple. Thanks :)
CamperBot
@camperbot
Jun 22 2017 09:37
rossfaarley sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 547 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Menlam Choden
@menlam
Jun 22 2017 09:43

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

}

titleCase("I'm a little tea pot");

anyone
whats wrong with "n=z[i].charAt(0)" line\/
Brice Afonso
@Qazare
Jun 22 2017 09:44
Hey everyone ! I have trouble understanding something with lookaheads for regexes, based on this challenge : http://beta.freecodecamp.com/en/challenges/regular-expressions/positive-and-negative-lookahead
this code works let pwRegex = /(?=\w{6,})(?=\D*\d{2,})/; but I don't really understand everything in it.
in this case, the \w finds all characters with a minimum of 6 characters and more, right ?
Rinor Bivolaku
@RinorNotorious
Jun 22 2017 09:47
@menlam first, do this var y = strtoLowerCase().split(" "); , then after the for loop remove the n variable and do this: y[i] = y[i].charAt(0).toUpperCase() + y[i].substring(1);
Brice Afonso
@Qazare
Jun 22 2017 09:47
Actually it only matches one character of [a-zA-Z0-9_] then, when it finds one, it follows to the next lookahead statement right ?
which matches one non-digit caracter, then at least 2 digits or more. Am I right ?
Saif Ur Rahman
@saifsmailbox98
Jun 22 2017 09:52

@Qazare/(?=\w{6,})(?=\D*\d{2,})/

/ ... regex .../

( optional ?= alphanumeric \w atleast 6 {6,} ) ( optional ? = not-digit \D zero or more * digit \d alteast {2,} )

Blauelf
@Blauelf
Jun 22 2017 09:52

@Qazare It matches if there's a position followed by at least 6 word characters, and any number of non-digits followed by at least two digits.

Doesn't have to be that specific, even /(?=.{6})(?=.*\d{2})/ would work.

Rinor Bivolaku
@RinorNotorious
Jun 22 2017 09:52

@menlam
So it would look like this:
-
function titleCase(str) {
var y=str.toLowerCase().split(" ");

for(var i=0; i < y.length; i++){
    y[i]= y[i].charAt(0).toUpperCase() + y[i].substring(1);
}
return y.join(" ");

}
titleCase("I'm a little tea pot");

Brice Afonso
@Qazare
Jun 22 2017 09:57
thanks @saifsmailbox98 and @Blauelf, still have a bit of trouble wrapping my head around this but I'll experiment a bit on regexr.com, I think I lack the visual confirmation of it !
CamperBot
@camperbot
Jun 22 2017 09:57
qazare sends brownie points to @saifsmailbox98 and @blauelf :sparkles: :thumbsup: :sparkles:
:cookie: 548 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
:star2: 4448 | @blauelf |http://www.freecodecamp.com/blauelf
Paul de Wouters
@pdewouters
Jun 22 2017 10:00
any good resource on recursive functions?
Keon Samuel
@keonsam
Jun 22 2017 10:02
:+1: fullstack dev
:smile:
Paul de Wouters
@pdewouters
Jun 22 2017 10:07
thanks @bilaal-s
CamperBot
@camperbot
Jun 22 2017 10:07
pdewouters sends brownie points to @bilaal-s :sparkles: :thumbsup: :sparkles:
:cookie: 261 | @bilaal-s |http://www.freecodecamp.com/bilaal-s
MarcusBA96
@MarcusBA96
Jun 22 2017 10:20
Hello Guys! I am on the "Local Scope and Functions" challengs, and i simply can't understand, why i can't pass it. Here is my code:

function myLocalScope() {
'use strict';
myVar = 5;

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

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

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

Pieter Stokkink
@forkerino
Jun 22 2017 10:23
@MarcusBA96 // Now remove the console log line to pass the test
that last one
MarcusBA96
@MarcusBA96
Jun 22 2017 10:24
I tried, but then it just says, that the variable is not defined in strict-condition
Saif Ur Rahman
@saifsmailbox98
Jun 22 2017 10:25
@MarcusBA96 add var
MarcusBA96
@MarcusBA96
Jun 22 2017 10:25
@saifsmailbox98 But that would make it a global variabl, and it needs to be local?
Saif Ur Rahman
@saifsmailbox98
Jun 22 2017 10:25
@MarcusBA96 add var inside the function like var myVar = 5;
@MarcusBA96 adding var doesn't make it a global variable. Scope depends on where you define a variable { .... }
MarcusBA96
@MarcusBA96
Jun 22 2017 10:28
@saifsmailbox98 Thank you very much, it worked
CamperBot
@camperbot
Jun 22 2017 10:28
marcusba96 sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 549 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Saif Ur Rahman
@saifsmailbox98
Jun 22 2017 10:30
@MarcusBA96 :+1:
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jun 22 2017 10:34
hello I have a question about react router, can anyone help me? :)
Keon Samuel
@keonsam
Jun 22 2017 10:37
sure
Brice Afonso
@Qazare
Jun 22 2017 10:44
On this challenge http://beta.freecodecamp.com/en/challenges/regular-expressions/reuse-patterns-using-capture-groups what exactly means "Your regex should reuse the capture group twice." ? It's the only thing that does not pass with the following code let reRegex = /(\d+)\s(\d+)\s\2/;
Blauelf
@Blauelf
Jun 22 2017 10:52
Maybe they meant /^(\d+)\s\1\s\1$/?
Brice Afonso
@Qazare
Jun 22 2017 10:54
Oh thanks, actually just /(\d+)\s\1\s\1/ works ! Which seems logical, now I get what they meant by reuse. Had no idea you could do that.
Thanks again @Blauelf
CamperBot
@camperbot
Jun 22 2017 10:54
qazare sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: qazare already gave blauelf points
Blauelf
@Blauelf
Jun 22 2017 10:55
Oh, there's a bug, it should not pass!
Brice Afonso
@Qazare
Jun 22 2017 10:55
Oh... and here I was thinking I understood
Blauelf
@Blauelf
Jun 22 2017 10:55
It matches "42 42 42 42", which it shouldn't. I guess the logic is inversed on that test case.
It matches if there's a substring of that type, even "12 2 23" would cause a match.
That's why I included ^ and $, as that matches the task description more closely.
Brice Afonso
@Qazare
Jun 22 2017 10:56
http://regexr.com/3g7ci it doesn't seem to match 42 42 42 42
Blauelf
@Blauelf
Jun 22 2017 10:57
It matches a part of that, and here we used test, which does not care about which part caused the match, just that it did.
Oh, the test case descriptions and the task description are just different. So it might be a problem with the wordings only.
Definitely a bug in the challenge, just not sure which kind of ;)
Brice Afonso
@Qazare
Jun 22 2017 11:00
I don't really understand your code though, why ^ and $ ?
Blauelf
@Blauelf
Jun 22 2017 11:01
To make it match the whole string or not at all. Often one would not want "12 2 23" to match if one were asked for the same number three times.
Brice Afonso
@Qazare
Jun 22 2017 11:04
Oh ok
Nicholas Chong
@nicholaschong12
Jun 22 2017 11:46
Hello
Stephen James
@sjames1958gm
Jun 22 2017 11:49
@nicholaschong12 Hi
benjamenhogben
@benjamenhogben
Jun 22 2017 11:49

hey guys what am I doing wrong here!?
function titleCase(str) {

var arr = str.split(/\b\s/);

for(i = 0; i < arr.length; i++){
arr[i].toLowerCase();
arr[i].charAt(0).toUpperCase();
}

console.log(i);
console.log(arr);

return arr;
}

titleCase("I'm a little tea pot");

Stephen James
@sjames1958gm
Jun 22 2017 11:49
@benjamenhogben toLowerCase and toUpperCase don't modify the string they return a modified string.
Diego Mayer
@Chrono79
Jun 22 2017 11:50
@benjamenhogben toLowerCase and toUpperCase don't mutate your string
benjamenhogben
@benjamenhogben
Jun 22 2017 11:50
Ha! of course what a fool. Thanks @Chrono79 @sjames1958gm
CamperBot
@camperbot
Jun 22 2017 11:53
benjamenhogben sends brownie points to @chrono79 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4368 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 7847 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Vali
@valimikayilov
Jun 22 2017 11:55
Guys can give me any hints on "Counting Cards " challenge ?
var count = 0;

function cc(card) {
  // Only change code below this line
  switch (card){
    case 2, 3, 4, 5, 6:
      count++;
      break;
    case 7, 8, 9:
      count=count+0;
      break;

    case 10, 'J', 'Q', 'K', 'A':
      count--;
      break;

  }
  if(count >0){
  return "Bet";
  } else {
    return "Hold";
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Nicholas Chong
@nicholaschong12
Jun 22 2017 11:57
Hello how do you paste the code with the black background like a text editor ?
@Geek-Killer your 'case' is wrong
Kervtuza
@Kervtuza
Jun 22 2017 11:59
Hey guys, I am working on the random quote machine in codepen.io, I am using a getJSON request which is successful, I am parsing the data into a quotes variable, which appears to be working because if I test quotes.length is returns the right number of quotes. My problem is that I have a randomNumber variable which is also working to get a random number within the range of objects I have in my json file, but when I try to actually test the quotes[randomNumber], I get nothing back... any ideas? Here is my code below.
Vali
@valimikayilov
Jun 22 2017 12:03
@nicholaschong12 there is an "M" sign on the right, it shows how to paste in different styles. For code I used ``` on both sides
@nicholaschong12 why it is wrong ?
Markus Kiili
@Masd925
Jun 22 2017 12:04
@Kervtuza quotes[randomNumber] is an object like {id: 1, champion: "Master Yi", quote-content: "In me, Wuju lives on.", champion-image: "url goes here"}
Maybe you need to access the quote-content?
Nicholas Chong
@nicholaschong12
Jun 22 2017 12:04
@Geek-Killer switch(args) case 1: case 2: <- for your info
WAINGOR
@WAINGOR
Jun 22 2017 12:05
working @ the office now... coding under pressure sure is a lot less fun 8*(
Vali
@valimikayilov
Jun 22 2017 12:09
@nicholaschong12 I didn't got it :worried:
Kervtuza
@Kervtuza
Jun 22 2017 12:10
@Masd925 thanks! Ill give that a shot
CamperBot
@camperbot
Jun 22 2017 12:10
kervtuza sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4276 | @masd925 |http://www.freecodecamp.com/masd925
Nicholas Chong
@nicholaschong12
Jun 22 2017 12:11
@Geek-Killer did u check is your Switch working ?
Markus Kiili
@Masd925
Jun 22 2017 12:11
@Kervtuza You can console.log the contents of those variables and see them on the browser developer tools console.
Vali
@valimikayilov
Jun 22 2017 12:13
@nicholaschong12 it halfly works, but it returns wrong values
@nicholaschong12 is it a syntax mistake or did I mixed something with places ?
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:19
hi everyone,i'm having a bit of difficulty on doing the mutation algoritm test.i'm having problem on how to return the result of the indexOf inside of my for loop.can anybody help me out?
Kervtuza
@Kervtuza
Jun 22 2017 12:19
@Masd925 can I not access the data of an object the same way I would access the data of a simple array? Ex: var arr = [1,2,3] ...arr[0] would return 1. Will quotes[0] not return the full first object?
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:19
here is my code
Nicholas Chong
@nicholaschong12
Jun 22 2017 12:19
@Geek-Killer the case should behave like this
case 10: case 'J' case 'Q'
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:19

function mutation(arr) {
var second =arr[1].toLowerCase();
var first=arr[0].toLowerCase();
var result=0;
for(var i=0;i<second;i++){
var loop=second[i];
result=first.indexOf(loop);
}
if(result==-1){
result=-1;
return false;
}else{
return true;
}
}

mutation(["hElLo", "Hello"]);

Vali
@valimikayilov
Jun 22 2017 12:21
@nicholaschong12 I did it, thanks dude )
CamperBot
@camperbot
Jun 22 2017 12:21
geek-killer sends brownie points to @nicholaschong12 :sparkles: :thumbsup: :sparkles:
:cookie: 218 | @nicholaschong12 |http://www.freecodecamp.com/nicholaschong12
koder3
@koder3
Jun 22 2017 12:22
@idonthavefriend you dont need var loop = second[i] just use second[i] as it is
Kervtuza
@Kervtuza
Jun 22 2017 12:22
@Masd925 ohhh i get it!! quotes[randomNumber].id returns the id! For some reason quotes[randomNumber].quote-content doesnt return anything
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:22
@koder3 okay,i'll change that
but now what
Ronique Ricketts
@RoniqueRicketts
Jun 22 2017 12:23
hello guys I am working on the algorithms, I want to know if I am on the right track with the basic algorithms (although these algorithms feels so hard).
koder3
@koder3
Jun 22 2017 12:23
@idonthavefriend and u probably want to use result+=first.indexOf(second[i])
kris
@krishnamanieee
Jun 22 2017 12:23

// Initialize these three variables
var a=6;
var b=15;

var c= "I am a String";

// Do not change code below this line

c should not contain undefined and should have a value of "I am a String!"
Do not change code below the line
Valdovas1
@Valdovas1
Jun 22 2017 12:23

function mutation(arr) {
for (var i = 0; i < arr.length; i++){
  if (arr[0].indexOf(arr[1][i]) === -1){
  return false;

}else if (arr[0].indexOf(arr[1][i]) != -1){

} return true;

}
}


mutation(["hello", "hey"]);
What is missing ?
David
@deitcode
Jun 22 2017 12:24
@Valdovas1 your return true isn't inside the curly braces for the else if
Valdovas1
@Valdovas1
Jun 22 2017 12:25
Does not change the end result :/
koder3
@koder3
Jun 22 2017 12:25
@idonthavefriend if you find a value of second that is in first, you should push that value in an empty array variable such as var arr = []
Markus Kiili
@Masd925
Jun 22 2017 12:25
@Kervtuza Try ["quote-content"]
Valdovas1
@Valdovas1
Jun 22 2017 12:25
@deitcode
Ronique Ricketts
@RoniqueRicketts
Jun 22 2017 12:25
for the longest word. Can I:
1. convert from string to array
2. use forEach() to find each words length
3. Sort the array
4. Return the word based on it length
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:26
@koder3 i've done that
but still not working
Kervtuza
@Kervtuza
Jun 22 2017 12:26
@Masd925 same as if I test quotes[randomNumber].champion it works to return the name but for some reason quotes[randomNumber].quote-content returns nothing
koder3
@koder3
Jun 22 2017 12:28
@idonthavefriend post the code you have now inside 3 backticks followed by another 3 backticks at the end. this is a backtick `
Valdovas1
@Valdovas1
Jun 22 2017 12:30

function mutation(arr) {
  var lower = arr.toLowerCase();
  var pushy = [];
  var begel = pushy.push(lower);
for (var i = 0; i < lower.length; i++){
  if (lower[0].indexOf(lower[1][i]) === -1){
  return false;

}else if (lower[0].indexOf(lower[1][i]) != -1){
  return true;
} 

}
}


mutation(["hello", "hey"]);
koder3
@koder3
Jun 22 2017 12:30
'''
CamperBot
@camperbot
Jun 22 2017 12:30
:bulb: to format code use backticks! ``` more info
Valdovas1
@Valdovas1
Jun 22 2017 12:31
Tried with push and to lower case sit notwork
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:31
@koder3 wait i'm still trying to figure out how to push the value of second that is in first inside an empty array
koder3
@koder3
Jun 22 2017 12:34
@idonthavefriend emptyArr.push(first.indexOf(second[i])) now if emptyArr has any -1 then you need to return false. because second has a value that is not in first.
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:36
alright,wait for a moment
Valdovas1
@Valdovas1
Jun 22 2017 12:37

function mutation(arr) {
 var sorted = [];
for (var i = 0; i < arr.length; i++)
sorted.push(arr[i].toLowerCase());{
  if (arr[0].indexOf(arr[1][i]) === -1){
  return false;

}else if (arr[0].indexOf(arr[1][i]) != -1){
  return true;
} 

}
}


mutation(["hello", "hey"]);
Okey stil does not wokr
work
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:40

function mutation(arr) {
var second =arr[1].toLowerCase();
var first=arr[0].toLowerCase();
var array=[];
for(var i=0;i<second;i++){
second=second[i];
array.pushfirst.indexOf(second[i]);

}
if(arr==-1){
return false;
}else{
return true;
}
}

mutation(["hElLo", "Hello"]);

@koder3 like this?
i think there something wrong with my if statement
David
@deitcode
Jun 22 2017 12:41
@Valdovas1 what are you trying to do exactly? i ran your original snippet and it returned true
koder3
@koder3
Jun 22 2017 12:41
@idonthavefriend you made a error in line 7
Valdovas1
@Valdovas1
Jun 22 2017 12:41
@deitcode Mutations
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
koder3
@koder3
Jun 22 2017 12:41
@Valdovas1 what is the point of using sorted?
Valdovas1
@Valdovas1
Jun 22 2017 12:42
@koder3 it was adviced in stackoverflow as viable solution to lower all the cases
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:42
@koder3 what error? am i not suppose to delete it because i declare it again in line 8?
*am i suppose
koder3
@koder3
Jun 22 2017 12:43
@idonthavefriend array.pushfirst.indexOf(second[i]); whats this ?
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:43
that is line 8
alright i get it
koder3
@koder3
Jun 22 2017 12:43
@idonthavefriend and your if statemen should check if arr has a -1 or not. do that by using indexOf.
mitron6
@mitron6
Jun 22 2017 12:43
@idonthavefriend The pushfirst is not a property of array.
David
@deitcode
Jun 22 2017 12:44
@Valdovas1 you don't need to lower because hello and hey are all lower case already
Valdovas1
@Valdovas1
Jun 22 2017 12:44
@deitcode mutation(["hello", "hey"]) should return false.
mutation(["hello", "Hello"]) should return true.
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) should return true.
mutation(["Mary", "Army"]) should return true.
mutation(["Mary", "Aarmy"]) should return true.
mutation(["Alien", "line"]) should return true.
mutation(["floor", "for"]) should return true.
mutation(["hello", "neo"]) should return false.
mutation(["voodoo", "no"]) should return false.
it was also adviced to lowerthem :/
koder3
@koder3
Jun 22 2017 12:45
@Valdovas1 1. make 2 varaibles including both the arguemtns provided (hello, hey) in lowercase. THEN loop through those variables
abraham anak agung
@padunk
Jun 22 2017 12:45
@Valdovas1 how long is arr.length? You dont need sort. U never use it in that function
koder3
@koder3
Jun 22 2017 12:46
@Valdovas1 looping though the arguments does not result in you looping through them all in lowercase. you just loop through the arguments
Valdovas1
@Valdovas1
Jun 22 2017 12:46
like this ? var words = "hello, hey";
var groom = []
@koder3
koder3
@koder3
Jun 22 2017 12:47
@Valdovas1 var sanitized = arr[0].toLowerCase()
@Valdovas1 var sanitized2 = arr[1].toLowerCase()
@Valdovas1 THEN loop through the second variable
@Valdovas1 use index of to see if sanitized has all values of sanitized2, if theres a single -1 return false
Valdovas1
@Valdovas1
Jun 22 2017 12:49

@koder3 ```
function mutation(arr)

{

for (var i = 0; i < arr.length; i++)
var lower = arr[0].toLowerCase();
var higher = arr[1].toLowerCase();
{
if (arr[0].indexOf(arr[1][i]) === -1){
return false;

}else if (arr[0].indexOf(arr[1][i]) != -1){
return true;
}

}
}

mutation(["hello", "hey"]);

function mutation(arr) 


{

for (var i = 0; i < arr.length; i++)
   var lower = arr[0].toLowerCase();
  var higher = arr[1].toLowerCase();
{
  if (arr[0].indexOf(arr[1][i]) === -1){
  return false;

}else if (arr[0].indexOf(arr[1][i]) != -1){
  return true;
} 

}
}


mutation(["hello", "hey"]);
koder3
@koder3
Jun 22 2017 12:49
@Valdovas1 make the variables outside the loop.
Valdovas1
@Valdovas1
Jun 22 2017 12:49
it brings undefined
var lower = arr[0].toLowerCase();
var higher = arr[1].toLowerCase();
Unexpected token
Jayne
@jayne88
Jun 22 2017 12:50
Any idea what I am doing wrong here??

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "The " + myAdjective + myNoun + " took my sandwich and " + myVerb + " away " + myAdverb;
// Your code below this line
myNoun = " dog";
myAdjective = "big ";
myVerb = "ran";
myAdverb = "quickly";
// Your code above this line
return result;
}

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

koder3
@koder3
Jun 22 2017 12:51
@Valdovas1 did you return them?
Valdovas1
@Valdovas1
Jun 22 2017 12:52

function mutation(arr) 

  var lower = arr[0].toLowerCase();
  var higher = arr[1].toLowerCase();
{

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

{
  if (arr[0].indexOf(arr[1][i]) === -1){
  return false;

}else if (arr[0].indexOf(arr[1][i]) != -1){
  return true;
} 

}

}


mutation(["hello", "hey"]);
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:52
okay now i'm confused @koder3
Valdovas1
@Valdovas1
Jun 22 2017 12:52

function mutation(arr) {

  var lower = arr[0].toLowerCase();
  var higher = arr[1].toLowerCase();


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

{
  if (arr[0].indexOf(arr[1][i]) === -1){
  return false;

}else if (arr[0].indexOf(arr[1][i]) != -1){
  return true;
} 

}

}


mutation(["hello", "hey"]);
@koder3 I did return true and false
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:53
@Valdovas1 how do you post your code like that?
koder3
@koder3
Jun 22 2017 12:53
@Valdovas1 loop through higher and then use indexOf to see if lower includes all values of second
@idonthavefriend '''
CamperBot
@camperbot
Jun 22 2017 12:53
:bulb: to format code use backticks! ``` more info
koder3
@koder3
Jun 22 2017 12:53
click more info
Valdovas1
@Valdovas1
Jun 22 2017 12:54
Use then press shift and enter at the same time and paste the code between and then ctrl and enter at thesaem time
@koder3 But i am looping
koder3
@koder3
Jun 22 2017 12:54
@Valdovas1 are you looping though higher?
Valdovas1
@Valdovas1
Jun 22 2017 12:54
``` @idonthavefriend these are the symbols
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:55
okay
Valdovas1
@Valdovas1
Jun 22 2017 12:55
@koder3 by hihger you ,mean arr[0] ?
koder3
@koder3
Jun 22 2017 12:55
@idonthavefriend what are you confused with?
@Valdovas1 i mean arr[1]
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:55
i'm trying to find it on my keyboard
David
@deitcode
Jun 22 2017 12:55
@Valdovas1 i have a solution using your original code, minus the toLower
koder3
@koder3
Jun 22 2017 12:55
@idonthavefriend below ESC
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:56

```js function mutation(arr) {
var second =arr[1].toLowerCase();
var first=arr[0].toLowerCase();
var array=[];
for(var i=0;i<second;i++){
second=second[i];
array.push(first.indexOf(second));
}
if(array.indexOf(-1)===false){
return false;
}else{
return true;
}
}

mutation(["hElLo", "Hello"]);

i failed
lol
but here's my code
David
@deitcode
Jun 22 2017 12:57
@Valdovas1 would you like the answer or shall i try to explain it to you? :)
Valdovas1
@Valdovas1
Jun 22 2017 12:57
@koder3 so you mean i have to change arr[1][i] to higher[i] and do the same with lower ?
justarandominternetuser
@idonthavefriend
Jun 22 2017 12:57
i know i mess up my if statement
Jayne
@jayne88
Jun 22 2017 12:58

could anyone help me with this please? I am not sure what I am doing wrong.
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "The " + myAdjective + " smelly"+ myNoun + " took my sandwich and " + myVerb + " away " + myAdverb + " without remorse.";
// Your code below this line
myNoun = " dog";
myAdjective = "big ";
myVerb = "ran";
myAdverb = "quickly";
// Your code above this line
return result;
}

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

Valdovas1
@Valdovas1
Jun 22 2017 12:58
@deitcode I understadn what i must do yet i prefer to take the hard path :D
Diego Mayer
@Chrono79
Jun 22 2017 12:58
@jayne88 why are you overwriting the function params?
Your real problem is you missed some spaces in the strings, modify result between the comments
koder3
@koder3
Jun 22 2017 12:58
@idonthavefriend what you need to do is loop though second then make a indexOf to see if first includes all values of second. indexof returns -1 if false and anythin else if true. if your array variable has any -1 then return false
David
@deitcode
Jun 22 2017 12:58
@Valdovas1 ok!
koder3
@koder3
Jun 22 2017 12:58
@Valdovas1 yes. if higher is arr[1] in lowercase. then use higher
Valdovas1
@Valdovas1
Jun 22 2017 12:58
@deitcode Thank you !
CamperBot
@camperbot
Jun 22 2017 12:58
valdovas1 sends brownie points to @deitcode :sparkles: :thumbsup: :sparkles:
:cookie: 37 | @deitcode |http://www.freecodecamp.com/deitcode
Jayne
@jayne88
Jun 22 2017 12:58
@Chrono79 I really don't know. I did?
Valdovas1
@Valdovas1
Jun 22 2017 12:59
@koder3

function mutation(arr) {

  var lower = arr[0].toLowerCase();
  var higher = arr[1].toLowerCase();


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

{
  if (lower.indexOf(higher[i]) === -1){
  return false;

}else if (lower.indexOf(higher[i]) != -1){
  return true;
} 

}

}


mutation(["hello", "hey"]);
Diego Mayer
@Chrono79
Jun 22 2017 12:59

@jayne88

myNoun = " dog";
myAdjective = "big ";
myVerb = "ran";
myAdverb = "quickly";

You did, there

koder3
@koder3
Jun 22 2017 12:59
@idonthavefriend push the results of your indexof in the empty array
Diego Mayer
@Chrono79
Jun 22 2017 12:59
Not that it matters when you set result above that
David
@deitcode
Jun 22 2017 13:00
@Valdovas1 your original solution was pretty close actually!

function mutation(arr) {
for (var i = 0; i < arr.length; i++){
  if (arr[0].indexOf(arr[1][i]) === -1){
  return false;

}else if (arr[0].indexOf(arr[1][i]) != -1){

} return true;

}
}


mutation(["hello", "hey"]);
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:00
array.push(first.indexOf(second)); @koder3
like this right?
Diego Mayer
@Chrono79
Jun 22 2017 13:00
@jayne88 " smelly"+ myNoun add a space after smelly and before the double quote
Valdovas1
@Valdovas1
Jun 22 2017 13:00
@deitcode Aham, just needed two variables :D
koder3
@koder3
Jun 22 2017 13:00
@Valdovas1 for the fourth time loop through higher. for(var i = 0; i < higher.length; i++ this is what you need to loop though higher
Jayne
@jayne88
Jun 22 2017 13:00
Okay, thanks @Chrono79
CamperBot
@camperbot
Jun 22 2017 13:00
jayne88 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4369 | @chrono79 |http://www.freecodecamp.com/chrono79
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:00
and the i create a if statement outside of the loop like this:
David
@deitcode
Jun 22 2017 13:01
@Valdovas1 actually you don't need any variables!
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:01
if(array.indexOf(-1)===false){
return false;
}else{
return true;
}
Valdovas1
@Valdovas1
Jun 22 2017 13:01
@deitcode What ? :o:
koder3
@koder3
Jun 22 2017 13:01
@idonthavefriend array.push(first.indexOf(second[i])) this what you need. post your code
Valdovas1
@Valdovas1
Jun 22 2017 13:01
@koder3 it is still does not pass
function mutation(arr) {

  var lower = arr[0].toLowerCase();
  var higher = arr[1].toLowerCase();


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

{
  if (lower.indexOf(higher[i]) === -1){
  return false;

}else if (lower.indexOf(higher[i]) != -1){
  return true;
} 

}

}


mutation(["hello", "hey"]);
David
@deitcode
Jun 22 2017 13:02
@Valdovas1 one sec, i'll just check if i can do the to lower part really quick
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:02

function mutation(arr) {
var second =arr[1].toLowerCase();
var first=arr[0].toLowerCase();
var array=[];
for(var i=0;i<second;i++){
second=second[i];
array.push(first.indexOf(second[i]));
}
if(array.indexOf(-1)===false){
return false;
}else{
return true;
}
}

mutation(["hElLo", "Hello"]);

Folkert
@folkert89
Jun 22 2017 13:02

Why doesnt the following work?

var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};
var myCar = new Car();
console.log(myCar.engines);

I thought now myCar has all the some properties and values as Car

Valdovas1
@Valdovas1
Jun 22 2017 13:02
@idonthavefriend use in front ``` of your code and in the back
Diego Mayer
@Chrono79
Jun 22 2017 13:03
@folkert89 what is the goal of the challenge?
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:03
@Valdovas1 i tried
Folkert
@folkert89
Jun 22 2017 13:03
to Construct JavaScript Objects with Functions
Valdovas1
@Valdovas1
Jun 22 2017 13:03
use ``` in front and the same three symbols at the end of your code :)
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:03
okay,letme test this out
Diego Mayer
@Chrono79
Jun 22 2017 13:04
@folkert89
Is this one? https://www.freecodecamp.com/challenges/construct-javascript-objects-with-functions
Have your MotorBike constructor describe an object with wheels, engines and seats properties and set them to numbers.
Mark Ryo
@MarkRyo
Jun 22 2017 13:04

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

function lookUp(firstName, prop){
// 请把你的代码写在这条注释以下
var i=0;
var j=0;
for(var k=0;k<4;k++){
if(contacts[k]['firstName']==firstName){
if(contacts[k].hasOwnProperty(prop)){
return contacts[k].prop;
}else{
i+=1;
}
}else{
j+=1;
}
}
if(i==4){
return "No such property";
}
if(j==4){
return "No such contact";
}
}

koder3
@koder3
Jun 22 2017 13:05
@Valdovas1 your only checking for the first value. lower.indexOf(higher[i]) push the results you get from that into an empty array. the array should be a bunch of numbers including -1. if your empty array has a -1 return false. because -1 means that theres a value in higher that is not in lower.
Mark Ryo
@MarkRyo
Jun 22 2017 13:05
why my function doesn't work?
David
@deitcode
Jun 22 2017 13:05
@Valdovas1 yeah it's possible without variables! but of course if you can get a solution with variables i'm sure thats fine too
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:05
function mutation(arr) {
 var second =arr[1].toLowerCase();
 var first=arr[0].toLowerCase();
  var array=[];
for(var i=0;i<second;i++){
   second=second[i];
  array.push(first.indexOf(second[i]));
 }
  if(array.indexOf(-1)===false){
    return false;
  }else{
    return true;
  }
}
     mutation(["hElLo", "Hello"]);
koder3
@koder3
Jun 22 2017 13:05
@deitcode i did that and got it in about 10 lines
justarandominternetuser
@idonthavefriend
Jun 22 2017 13:05
finally