These are chat archives for FreeCodeCamp/HelpJavaScript

21st
Apr 2016
Zachary
@White7292
Apr 21 2016 00:00
anyone know how to reset the code in an exercise without opening it....? I accidentally created an infinite loop with // noprotect xD
My browser runs the code as soon as it's loaded... and it freezes xD
rkDeason
@rkDeason
Apr 21 2016 00:01
help infinite loop
CamperBot
@camperbot
Apr 21 2016 00:01
no wiki entry for: infinite loop
Chase Webb
@jerrybaggin
Apr 21 2016 00:01
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(value !== "" && prop !== collection[id].tracks){

    }else if( value === ""){
      delete prop;
    }


  return collection;
}
could anyone tell me how close I am? also, im supposed to update or set the value for prop? im not too sure how to go about that.
Justin Woodward
@jwoo92
Apr 21 2016 00:01
@White7292 clear your cache/internet history maybe?
Luke
@lhovee
Apr 21 2016 00:01
function titleCase(str) {
  var lowerCase = str.toLowerCase();

  var splitStr = lowerCase.split(" ", [str.length-1]);

  for (var i=0; i<splitStr.length; i++) {splitStr[i].substring(0, 1).toUpperCase();}

  var joinStr = splitStr.join(' ');

  return joinStr;
}

titleCase("I'm a little tea pot");
I can't figure out why my for loop isn't doing anything to my array. Help?
Zachary
@White7292
Apr 21 2016 00:01
lol.. I'll try that!
Success!! Thanks! :)
@jwoo92 thanks
thanks @jwoo92
CamperBot
@camperbot
Apr 21 2016 00:02
white7292 sends brownie points to @jwoo92 :sparkles: :thumbsup: :sparkles:
:star: 241 | @jwoo92 | http://www.freecodecamp.com/jwoo92
Zachary
@White7292
Apr 21 2016 00:03
there we go! :P
rkDeason
@rkDeason
Apr 21 2016 00:03
good to know! thanks @jwoo92
CamperBot
@camperbot
Apr 21 2016 00:03
:star: 242 | @jwoo92 | http://www.freecodecamp.com/jwoo92
rkdeason sends brownie points to @jwoo92 :sparkles: :thumbsup: :sparkles:
Justin Woodward
@jwoo92
Apr 21 2016 00:03
@White7292 @rkDeason it was more or less a guess on how to, im glad it worked!
Tharun James
@xplorejames
Apr 21 2016 00:04
function palindrome(str) {
  // Good luck!


 var non=str.replace(/\W/g,"");

  var convert=non.toLowerCase();
  var reversing=convert.split("").reverse().join("");

  if(convert===reversing)
    {
      return true;
    }
  else
    {
      return false;
    }






}

palindrome("Eye");
whats the code for special charectors to get rid of ("0_0 (: /-\ :) 0-0")
Frank XC
@tenkdayz
Apr 21 2016 00:05
@xplorejames add underscore to the regex
Luke
@lhovee
Apr 21 2016 00:06
@xplorejames it looks like this (/[\W_]/g, "")
Tharun James
@xplorejames
Apr 21 2016 00:08
@lhovee Thank you :)
CamperBot
@camperbot
Apr 21 2016 00:08
xplorejames sends brownie points to @lhovee :sparkles: :thumbsup: :sparkles:
:star: 259 | @lhovee | http://www.freecodecamp.com/lhovee
Tharun James
@xplorejames
Apr 21 2016 00:08
@tenkdayz Thank you :)
CamperBot
@camperbot
Apr 21 2016 00:08
xplorejames sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 427 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
Tharun James
@xplorejames
Apr 21 2016 00:09
where can i find the source for these regex?
rphares
@rphares
Apr 21 2016 00:10
help regex
CamperBot
@camperbot
Apr 21 2016 00:10

:point_right: js regex resources [wiki]

Links to useful RegEx resources.

See also: :clipboard: Tutorials | :syringe: Testing | :soccer: Games | :newspaper: Blogs | :package: Software

:pencil: read more about js regex resources on the FCC Wiki

Tharun James
@xplorejames
Apr 21 2016 00:11
@rphares Thank you
rphares
@rphares
Apr 21 2016 00:11
@xplorejames , regex will come up alot. those may be of some help :blush:
CamperBot
@camperbot
Apr 21 2016 00:11
xplorejames sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 4055 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Apr 21 2016 00:11
sure thing~
zico
@zico0o
Apr 21 2016 00:13
@jerrybaggin there is another condition is missed
if (prop === 'tracks')
push(value);
any help with profile lookup
 var res="";
  for (var i=0 ;i<= contacts.length;i++){
  if (firstName === contacts[i].firstName && contacts[i].hasOwnProperty(prop)){
    res =  contacts[prop];

  }
  else if (firstName !== contacts[i].firstName){
    res= "No such contact";
  }
  else if (prop !== contacts[i].hasOwnProperty(prop)){
    res= "No such property";
  }
// Only change code above this line
    return res;
  }

}
jonathanzach
@jonathanzach
Apr 21 2016 00:17
Add ["Paul",35] to the beginning of the myArray variable using unshift(). myArray.unshift("Paul");
IS MY CODE WRONG ?
Chase Webb
@jerrybaggin
Apr 21 2016 00:17
@zico0o thanks im pretty close now
CamperBot
@camperbot
Apr 21 2016 00:17
jerrybaggin sends brownie points to @zico0o :sparkles: :thumbsup: :sparkles:
:star: 236 | @zico0o | http://www.freecodecamp.com/zico0o
Frank XC
@tenkdayz
Apr 21 2016 00:18
@jonathanzach just adding "Paul" ? or the whole array?
Reginald Davis
@madblkman
Apr 21 2016 00:19
On the wikipedia search viewer does anyone have an idea on how to add a link to the divs? I'm struggling with this last part of the project. Here's my pen...
http://codepen.io/madblkman/full/VadWoJ/
Alhaji Turay
@Alhaji24
Apr 21 2016 00:23
can I uplaod a picture on codpen
jonathanzach
@jonathanzach
Apr 21 2016 00:25
@tenkdayz paul and 35
Frank XC
@tenkdayz
Apr 21 2016 00:28
@jonathanzach myArray.unshift(["Paul",35]);
or just array.concat(myArray);
Tyler Moeller
@TylerMoeller
Apr 21 2016 00:32
@Alhaji24 You need CodePen pro to do that. I use GitHub. Lots of people use postimg.org too
rkDeason
@rkDeason
Apr 21 2016 00:33
@Alhaji24 I don't think so, I'm using the website cloudinary to upload pics
vínαч puppαl
@vinaypuppal
Apr 21 2016 00:33
@madblkman i changed some the parts in js and css(your scss) to convert them in to links , look at here http://codepen.io/vinaypuppal/pen/PNaLbg if u dont understand any thing feel free to ask
rkDeason
@rkDeason
Apr 21 2016 00:33
@TylerMoeller how do you keep pics in GitHub?
Tyler Moeller
@TylerMoeller
Apr 21 2016 00:34
@rkDeason You create a repo for your project and make a gh-pages branch to convert it to a web page
rkDeason
@rkDeason
Apr 21 2016 00:35
thanks @TylerMoeller! I've got to spend some time getting to know github!
CamperBot
@camperbot
Apr 21 2016 00:35
rkdeason sends brownie points to @tylermoeller :sparkles: :thumbsup: :sparkles:
:star: 508 | @tylermoeller | http://www.freecodecamp.com/tylermoeller
Tyler Moeller
@TylerMoeller
Apr 21 2016 00:35
@rkDeason Then you access the image at http://rkDeason.github.io/your-repo-name/img/myimg.png
(for example)
rkDeason
@rkDeason
Apr 21 2016 00:35
niice!
Matthew Robertson
@mrmatt1877
Apr 21 2016 00:43
Other than it being a dumb ai tell me what you think!! http://codepen.io/mrmatt1877/pen/zqabKw
Luke
@lhovee
Apr 21 2016 00:45
function titleCase(str) {
  var lowerCase = str.toLowerCase();

  var splitStr = lowerCase.split(" ", [str.length-1]);

  for (var i=0; i<splitStr.length; i++) {return splitStr[i].substring(0, 1).toUpperCase();}

  var joinStr = splitStr.join(' ');

  return joinStr;
}

titleCase("I'm a little tea pot");
can anyone tell me what I'm doing wrong?
Rafael J. Rodriguez
@Rafase282
Apr 21 2016 00:46
you are welcome @White7292
Luke
@lhovee
Apr 21 2016 00:46
I'm supposed to make the first letter of each word capitalized
Dustin
@dustininkster
Apr 21 2016 00:51
@lhovee strings are immutable. You cant alter just one letter within the string. You'll have to shift the letter off, caps it, then stick it back on.
Erik Maurer
@MauPow
Apr 21 2016 00:54

var Car = function(wheels, seats, engines) {
this.wheels = 4;
this.seats = 1;
this.engines = 1;
};

var myCar = new Car(6, 3, 1);

Why does this not work?
Tharun James
@xplorejames
Apr 21 2016 00:54
function findLongestWord(str) {

  var long=0;
  var spliting=str.split(" ");
for(var i=0;i<=spliting.length;i++)
  {
    if(long<spliting[i].length)
      {
        long=spliting[i].length;
      }

    else
      {
        return long;
      }
  }




}

findLongestWord("The quick brown fox jumped over the lazy dog");
whats the error
Any help
Moisés Man
@moigithub
Apr 21 2016 00:57
for(var i=0;i<=spliting.length;i++)
should be < only... cuz index start on 0 and ends on length-1
Frank XC
@tenkdayz
Apr 21 2016 00:58
@xplorejames shouldn't you return the word ?
Moisés Man
@moigithub
Apr 21 2016 00:58
and returning too soon.. should be outside the loop... else it will not go through all the words
@xplorejames
rkDeason
@rkDeason
Apr 21 2016 00:59
@lhovee I used .substr instead of . substring
Tyler Moeller
@TylerMoeller
Apr 21 2016 00:59
@xplorejames Also, with that sentence, long will be 0, then 3, then 5, and for the fourth word 5 = 5, so you return long. You don't get to the word jumpedin that sentence before exiting the for loop.
Moisés Man
@moigithub
Apr 21 2016 00:59
@MauPow cuz u hardcoding the values...
u should "store" the values u passing
Tom DeFrank
@TomDeFrank
Apr 21 2016 01:00
@xplorejames you don't need an "else" there
Tharun James
@xplorejames
Apr 21 2016 01:00
@moigithub Thank you . I always does the return too early . im in hurry lo;
CamperBot
@camperbot
Apr 21 2016 01:00
xplorejames sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 976 | @moigithub | http://www.freecodecamp.com/moigithub
Tharun James
@xplorejames
Apr 21 2016 01:01
@TomDeFrank I cleared it thank you
CamperBot
@camperbot
Apr 21 2016 01:01
xplorejames sends brownie points to @tomdefrank :sparkles: :thumbsup: :sparkles:
:star: 222 | @tomdefrank | http://www.freecodecamp.com/tomdefrank
rkDeason
@rkDeason
Apr 21 2016 01:03
@lhovee I also used the charAt(0) method to get to the first letter then used toUpperCase
Vyani
@vyani
Apr 21 2016 01:26
This message was deleted
This message was deleted
// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

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

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var total = 0;

for (var i = 0; i < myArr.length; i++) {
  total += myArr[i];
}
Can anyone help this? Instructions
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
Ross
@AnInsaneScientist
Apr 21 2016 01:28

What does

while (array.length)

do? I'm having trouble understanding an example.

bitgrower
@bitgrower
Apr 21 2016 01:30
it checks to see if array.length is non-zero -- the while loop executes until it's zero ... (which means there's got to be something within the loop adjusting the length of the array ...
@vyani -- um ... is there a line which defines the multiplyAll function ?
Ross
@AnInsaneScientist
Apr 21 2016 01:32
Thanks @bitgrower I understand the example now.
CamperBot
@camperbot
Apr 21 2016 01:32
aninsanescientist sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 1006 | @bitgrower | http://www.freecodecamp.com/bitgrower
Vyani
@vyani
Apr 21 2016 01:33
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0; i< arr.length; i++){
    for (var j=0; j< arr[i].length; j++){
      console.log(arr[i][j]);
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
@bitgrower I copy the wrong code :D sorry
bitgrower
@bitgrower
Apr 21 2016 01:33
yeah, I was wondering ... what you posted didn't look like the multiplyAll example we know and love ...
so @vyani -- what do you THINK you should do? I mean, it helps if it looks like you've tried to solve the challenge on your own ...
Dustin
@dustininkster
Apr 21 2016 01:37
@lhovee If you're still wondering. Here's mine:
<code>

function titleCase(str) {
return str.toLowerCase().split(" ").map(function(val){
var word = val.split("");
return word.shift().toUpperCase() + word.join("");
}).join(" ");
}

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

<code>function titleCase(str) {
return str.toLowerCase().split(" ").map(function(val){
var word = val.split("");
return word.shift().toUpperCase() + word.join("");
}).join(" ");
}

titleCase("I'm a little tea pot");</code>

facepalm
Moisés Man
@moigithub
Apr 21 2016 01:40
with 3 backticks ```
Dustin
@dustininkster
Apr 21 2016 01:41
code
Moisés Man
@moigithub
Apr 21 2016 01:41
```js
code here
```
Dustin
@dustininkster
Apr 21 2016 01:41
code
@moigithub thanks. I definitely made that harder than it needed to be.
CamperBot
@camperbot
Apr 21 2016 01:42
dustininkster sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 977 | @moigithub | http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Apr 21 2016 01:42
:D
Vyani
@vyani
Apr 21 2016 01:44
@bitgrower I think added (multiply) to the code. Tried [i][j] but doesn't work
Tyler
@tylergross
Apr 21 2016 01:46
does anyone have a good article for pulling json from api's? I've come across small tidbits but i swear every API I use i have to use a different infrastructure to initiate the call
and I run into the callback=? a lot as well which im not sure what this does
@vyani [i][j] will only pull one of the numbers from the array
Coy Sanders
@coymeetsworld
Apr 21 2016 01:49
getJSON should be the only function you need to use @tylergross
Tyler
@tylergross
Apr 21 2016 01:51

@coymeetsworld okay that's basically what I've been using but I've seen so many variations of it IE

$.ajax({
  url : "http://api.wunderground.com/api/38195373fe1adfb8/geolookup/q/autoip.json",
  dataType : "jsonp",
  success : function(parsed_json) {
}
});

and

$.getJSON('http://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=?', function(data){
    var items = [], $ul;
    $.each(data, function(key,val){
});
});
Coy Sanders
@coymeetsworld
Apr 21 2016 01:54
they will do similar things
ajax just can be used for other formats besides json
bitgrower
@bitgrower
Apr 21 2016 01:54

@vyani [i][j] will only pull one of the numbers from the array

it won't pull ANY numbers out of the array ... those are just indexes -- they point to a place RELATIVE to the start of the array of arrays ... but you DO need to reference the array name so the interpreter knows where to start ... :)

Coy Sanders
@coymeetsworld
Apr 21 2016 01:54
thats why you cap specify the dataType there
you can use either/or
Ross
@AnInsaneScientist
Apr 21 2016 01:54
Any ideas what I'm doing wrong with my code?
function mutation(arr) {
  var lettersChecked = arr[1].split('');
  var result;
  for (var i = 0; i < lettersChecked; i++) {
    if (arr[0].indexOf(lettersChecked[i]) == -1) {
      result = false;
    }
    else {
      result = true;
    }
    return result;
  } 
}

mutation(["hello", "hey"]);
Tyler
@tylergross
Apr 21 2016 01:56
@AnInsaneScientist have you returned lettersChecked to find out what the value returns?
Moisés Man
@moigithub
Apr 21 2016 01:56
returning too soon @AnInsaneScientist
it only loop 1 time and exit.. remember return exit the function
Tyler
@tylergross
Apr 21 2016 01:56
@AnInsaneScientist also in you if else you will get false positives if the last number results true even if the first two letters arent in the string
Ross
@AnInsaneScientist
Apr 21 2016 01:57

I know I definitely have the right idea with using

arr[0].indexOf(lettersChecked[i])

I tested it outside the loop with a number instead of 'i' and it would give expected results.

Tyler
@tylergross
Apr 21 2016 01:59
@AnInsaneScientist yeah thats right ... like @moigithub said you are returning too try, so you return after the first iteration runs, also you are really only getting the results of the last iteration
because the last iteration will set your true/false and could give you a false positive
Ross
@AnInsaneScientist
Apr 21 2016 01:59
Okay @moigithub . I put the return statement outside the for loop but I still don't get any result returned?
Moisés Man
@moigithub
Apr 21 2016 02:00
well... it should return true.. when ALL characters from 2nd are on 1st
Tyler
@tylergross
Apr 21 2016 02:01
@AnInsaneScientist for(var i = 0; i < lettersChecked.......
what does lettersChecked output?
Ross
@AnInsaneScientist
Apr 21 2016 02:01
function mutation(arr) {
  var lettersChecked = arr[1].split('');
  var result = true;
  for (var i = 0; i < lettersChecked; i++) {
    if (arr[0].indexOf(lettersChecked[i]) == -1) {
      result = false;
    }
  } 
  return result;
}

mutation(["hello", "hey"]);
Fixed. This seems to pass all tests except two.
Moisés Man
@moigithub
Apr 21 2016 02:01
or.... return false.. as soon as u can.. if find some character who dont belong to the other element
Tyler
@tylergross
Apr 21 2016 02:02
@AnInsaneScientist your function is only passing because the result is true to begin with.... you for() loop is never ran
i swear mr "r"'s dont work 100% of the time
Ross
@AnInsaneScientist
Apr 21 2016 02:02
Ahhh! The confusion!
Tyler
@tylergross
Apr 21 2016 02:03

@AnInsaneScientist you have

i < lettersChecked

lettersChecked returns ["h", "e", "y"]

lettersChecked.length will return 3
Ross
@AnInsaneScientist
Apr 21 2016 02:04
forgot .length
Moisés Man
@moigithub
Apr 21 2016 02:04
if find a letter who isnt on the other elem (ie. "y").. u can break the loop.. no need to check the rest, cuz its already mutated... so u can return true or false whatever the case is
evolutionus
@evolutionus
Apr 21 2016 02:04
On the Record Collection exercise; one of the instructions is- If value is blank, delete that prop. The following is the code I came up with and of course it's not working. I thought this code would be one way of deleting a property. Can anyone help? else if (value === "") {
delete collection[id].prop;
}
Ross
@AnInsaneScientist
Apr 21 2016 02:05
Got it! Found a working solution. Thanks @tylergross and everyone else.
CamperBot
@camperbot
Apr 21 2016 02:05
aninsanescientist sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:star: 337 | @tylergross | http://www.freecodecamp.com/tylergross
Moisés Man
@moigithub
Apr 21 2016 02:06
@AnInsaneScientist u can also use .every method
bitgrower
@bitgrower
Apr 21 2016 02:06
.prop is a variable .. .you can't use dot notation with prop
Ken Haduch
@khaduch
Apr 21 2016 02:07
@evolutionus - prop is a variable, one of the function arguments. When you have a property name in a variable, you have to use bracket notation to apply it to the object...
oops - I see @bitgrower also saying the same thing - review the lesson on "Accessing Objects Properties with Variables" if you have need of a reminder.
Ross
@AnInsaneScientist
Apr 21 2016 02:08
Thanks @moigithub Maybe I'll try refactoring it later and try that method.
CamperBot
@camperbot
Apr 21 2016 02:08
aninsanescientist sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 978 | @moigithub | http://www.freecodecamp.com/moigithub
evolutionus
@evolutionus
Apr 21 2016 02:09
Ok thanks guys.
Charles Lang
@Nojil
Apr 21 2016 02:17
Can someone help me with the javascript assignment "Using objects for lookups" i cant seem to pass the "VAL" from the function to my object

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

lookup.val;

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

// Change this value to test
phoneticLookup("charlie");

rphares
@rphares
Apr 21 2016 02:17
@Nojil -- two things,
try bracket, not dot
and, then,
you also need to make sure to store that,
in what you will return
otherwise, its just sitting there, not doing anything...
Charles Lang
@Nojil
Apr 21 2016 02:18
bingo, forgot the results = :)
thanks @rphares
CamperBot
@camperbot
Apr 21 2016 02:18
nojil sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 4057 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Apr 21 2016 02:20
anytime~
ewpratt
@ewpratt
Apr 21 2016 02:20
Also thanks @rphares (for answering) and @Nojil (for asking)... that was just the issue i was having
CamperBot
@camperbot
Apr 21 2016 02:20
ewpratt sends brownie points to @rphares and @nojil :sparkles: :thumbsup: :sparkles:
:star: 226 | @nojil | http://www.freecodecamp.com/nojil
:star: 4059 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Apr 21 2016 02:20
Awesome! Congrats @Nojil and @ewpratt ! Happy coding :)
buonarfcc
@buonarfcc
Apr 21 2016 02:23

Hello anyone would mine to give me a hint for the following: function palindrome(str) {

var com ="";
var resB="";
var res = str.replace (/[\W_" "]/gi, "");

function reverse(str) {
com = resB.split("").reverse().join("");

 return com;}

if( com === resB){
return true;}
else {return false;}
}

palindrome("almostomla");
I kept getting 'true' only!? txs....

Tyler
@tylergross
Apr 21 2016 02:24
@buonarfcc I'm seeing resB doesn't equal anything and you are applying the functions to resB
So "" will always equal ""
Also, why do you have a function nested in another function? I don't believe your function reverse() is ever initiated
buonarfcc
@buonarfcc
Apr 21 2016 02:30
Very good Tyler ....duuuh my eyes...txs alot:)
Tyler
@tylergross
Apr 21 2016 02:30
Np
evolutionus
@evolutionus
Apr 21 2016 02:34
reviewed "Accessing Objects Properties with Variables and still not able to delete property if value is blank. I'm able to access the object with bracket notation but can't delete if value is blank. Can someone let me know if this part is correct as far as my else if? else if (value === "")
Tyler
@tylergross
Apr 21 2016 02:36
@evolutionus }else if (value === ""){ should be fine
rphares
@rphares
Apr 21 2016 02:36
@evolutionus , you can use that else if(value === "") { yes :)
Tyler
@tylergross
Apr 21 2016 02:37
@rphares how did you do the code block
rphares
@rphares
Apr 21 2016 02:38
Also, maybe check out delete ;) @evolutionus ... dunno where you are at and not great at explaining that exercise, but... i know that stumped a lot of people... there is a delete, and he's useful :blushL
@tylergross -- the grey? just one backtick,` before and after what you want in grey :blush:
Tyler
@tylergross
Apr 21 2016 02:39
@rphares awesome that'll help a lot when trying to give examples
rphares
@rphares
Apr 21 2016 02:39
you know how to do the black, right?
evolutionus
@evolutionus
Apr 21 2016 02:39
@rphares I've been working on it all day and still no luck.
no I don't know how
Brett Guillory
@kurzninja
Apr 21 2016 02:40
hey all, is anyone using Pug with Express yet, or still using Jade?
rphares
@rphares
Apr 21 2016 02:40
yeah, its a hard one... if you post what you have, i can take a look, but... I'm really not great at explaining that one...
explain format
CamperBot
@camperbot
Apr 21 2016 02:40

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

rphares
@rphares
Apr 21 2016 02:40
@evolutionus :point_up:
Tyler
@tylergross
Apr 21 2016 02:41
@evolutionus what challenge are you on?
rphares
@rphares
Apr 21 2016 02:41
record collection
evolutionus
@evolutionus
Apr 21 2016 02:41
@tylergross record collection
rphares
@rphares
Apr 21 2016 02:41
i know my answer and a few others, but not great at explaining. sounds like he is down to the last step...
buonarfcc
@buonarfcc
Apr 21 2016 02:41
what the correct regex to not include space " " ? txs
Hello since this not quite correct , how to make it legit for -> str.replace (/[\W_" "]/g, ""); ? anyone txs. ( to replace space with "")?
Tyler
@tylergross
Apr 21 2016 02:44
@evolutionus @rphares sounds like on the last little bit of it, I used the delete object property as well might be an error with some of the if/else statements I haven't seen the code though
cmf89
@cmf89
Apr 21 2016 02:44
@buonarfcc use \s for space
Moisés Man
@moigithub
Apr 21 2016 02:45
\s <-- space
\S <-- non space
@buonarfcc
Tyler
@tylergross
Apr 21 2016 02:45
@buonarfcc https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp good resource and for the challenge you are on and will need to fully understand it for upcoming challeneges
evolutionus
@evolutionus
Apr 21 2016 02:45
```

function updateRecords(id, prop, value) {
if(prop === "album" && value !== "") {
collection[id].album = (value);
return collection[id];
}
else if(prop === "artist" && value !== "") {
collection[id].artist = (value);
}
else if(prop !== "" && value !== "") {
collection[id].tracks.push(value);
}

else if (value === "") {
delete collection[id][artist];
}

return collection;
}

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

buonarfcc
@buonarfcc
Apr 21 2016 02:47
txs cmf89,Moises Man, Tyler!!!
Tyler
@tylergross
Apr 21 2016 02:47
you have delete collection[id][artist] @evolutionus however artist is not a variable
so you should place quotes around it to denote that you want it to find the "artist" property
Moisés Man
@moigithub
Apr 21 2016 02:49
@evolutionus u checking if the variable prop is equal to "album"
if(prop === "album" && value !== "") {
but what u need to check IS if the collection have the property u passing through the variable prop
Tyler
@tylergross
Apr 21 2016 02:50
@moigithub code is fully functional, I just placed it into the challenge just has one small syntax error with the collection[id][artist]
alternatively, could have used delete collection[id].artist
evolutionus
@evolutionus
Apr 21 2016 02:51
got 3 out of 4 guys
Moisés Man
@moigithub
Apr 21 2016 02:51
that code only pass the test cases.. hardcoding values.. a function should be more generic.. for ANY kind of properties (not only album and artist)
thats why u need to use the variables provided.. instead of hardcoding
evolutionus
@evolutionus
Apr 21 2016 02:52
so am I hardcoding? new to this
Tyler
@tylergross
Apr 21 2016 02:53
@moigithub yeah true, I was just looking for errors within i didn't really look at the functionality of it
evolutionus
@evolutionus
Apr 21 2016 02:55
so I need to use prop and value rather than artist and album?
Tyler
@tylergross
Apr 21 2016 02:55
@moigithub seems like for part of the challenge they want it hardcoded anyway "If value is non-blank (value !== "") and prop is not "tracks" then update or set the value for the prop."
@evolutionus I'm not seeing your function for if prop is not "tracks"
evolutionus
@evolutionus
Apr 21 2016 02:58
@tylergross I'm still trying to figure that out. I thought it would be the same as if value is blank.
Tyler
@tylergross
Apr 21 2016 02:59
@evolutionus but the value is not blank it is equal to "tracks"
I guess it would be prop != "tracks" and value != ""
Erik Maurer
@MauPow
Apr 21 2016 03:01

Working on the palindrome challenge. My code works for everything except for the last one with the symbols. why not?

'''
function palindrome(str) {
var stripped = str.replace(/[\s,.]/ig, "").toLowerCase();
var reverse = stripped.split('').reverse().join('');
return (stripped === reverse);
}

palindrome("not a palindrome");

CamperBot
@camperbot
Apr 21 2016 03:01
:bulb: to format code use backticks! ``` more info
Erik Maurer
@MauPow
Apr 21 2016 03:02
function palindrome(str) {
  var stripped = str.replace(/[\s,.]/ig, "").toLowerCase();
  var reverse = stripped.split('').reverse().join('');
  return (stripped === reverse);
}

palindrome("not a palindrome");
Tyler
@tylergross
Apr 21 2016 03:03
@evolutionus I would suggest relooking over the conditions your code doesnt quite match what they are looking for
evolutionus
@evolutionus
Apr 21 2016 03:03
@tylergross I guess I was taking track, "" as blank. which I tried to tie to else if(value === "")
Tyler
@tylergross
Apr 21 2016 03:03
if(prop !== "" && value !== "") {
collection[id].tracks.push(value);
should be "If the prop is "tracks" and value is non-blank, push the value onto the end of the tracks array."
but you have it to "If prop is blank and value is non-blank"

@evolutionus also this function you have

if(prop === "artist" && value !== "") {
collection[id].artist = (value);

not sure why that is in there? not seeing it as part of the challenge, I would suggest rewriting all your If / else statements and start from the challenge guideline of what they expect and go down the list.

evolutionus
@evolutionus
Apr 21 2016 03:06
@tylergross Ok I see what you're talking about.
Tyler
@tylergross
Apr 21 2016 03:07
good luck to you though im off for the night, you're on the right path just need to update your if/else statements and you'll be good
evolutionus
@evolutionus
Apr 21 2016 03:08
@tylergross ok thanks for your help.
CamperBot
@camperbot
Apr 21 2016 03:08
evolutionus sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:star: 338 | @tylergross | http://www.freecodecamp.com/tylergross
robertky
@robertky
Apr 21 2016 03:08

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
case 1:
answer="alpha";
break;
case 2:
answer="beta";
break;
case 3:
answer="gamma";
break;
case 4:
answer="delta";
break;

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

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

Any reason this switch case won't pass?
I see no reason why this doesn't work.
Tyler
@tylergross
Apr 21 2016 03:09
@MauPow your regexp is incorrect... it leaves characters that are not supposed to be there
@MauPow your regexp should only leave the string with alphanumeric characters
@robertky switch(val) case 1:.....
@robertky you are missing the switch() to begin the cases
robertky
@robertky
Apr 21 2016 03:11
sigh.......ic now, thanks.
@Tyler, thanks.
CamperBot
@camperbot
Apr 21 2016 03:11
robertky sends brownie points to @tyler :sparkles: :thumbsup: :sparkles:
:star: 27 | @tyler | http://www.freecodecamp.com/tyler
buonarfcc
@buonarfcc
Apr 21 2016 03:14
AnyOne pls help me -> this regex still not eliminating space " " correctly? ->str.replace (/\w\s/gi, "");
Frank XC
@tenkdayz
Apr 21 2016 03:16
@buonarfcc /\s/g
youre adding \w so it's looking for \w and \s
Tiffany White
@twhite96
Apr 21 2016 03:18
I am working on the Counting Cards challenge. I thought I could use a switch/case here to get the results but I am not certain I am using it right.
Here is my code:
var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count = count++;
      return count + " Bet";
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count = count--;
      return count + " Hold";
  }

  return "Change Me";
  // 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');
I could probably use…those return statments shouldn’t be there but I was trying to debug
Tyler
@tylergross
Apr 21 2016 03:20
@twhite96 your case is correct however
Your count is not... Count--; count++; not count = count--;
I believe this is the problem everything else looks good so far
Oh wait one more thing
Frank XC
@tenkdayz
Apr 21 2016 03:21
@twhite96 you dont have break; after the case is match
Tyler
@tylergross
Apr 21 2016 03:21
Instead of returning in the switch, do break; and return your count below where it says "change me"
nguyễn lan anh
@loglamo
Apr 21 2016 03:21
i am doing" sift through text with regular expressions.
buonarfcc
@buonarfcc
Apr 21 2016 03:21

Tyler I still get false with revision of code to this -> function palindrome(str) {

var com ="";

var res = str.replace (/\s/gi, "");
var res2 = res.replace(/\w/gi,"");

com = res2.split("").reverse().join("");

if( com === res2){
return true;}
else {return false;}
}

palindrome("A man, a plan, a canal. Panama"); got 'false'?

nguyễn lan anh
@loglamo
Apr 21 2016 03:22
i dont understand it
Tiffany White
@twhite96
Apr 21 2016 03:22
Okay. Thanks @tylergross and @tenkdayz
CamperBot
@camperbot
Apr 21 2016 03:22
twhite96 sends brownie points to @tylergross and @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 429 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
:star: 339 | @tylergross | http://www.freecodecamp.com/tylergross
Tyler
@tylergross
Apr 21 2016 03:23
@buonarfcc why do you have var res in your function? I'm not seeing you use it at all.
Frank XC
@tenkdayz
Apr 21 2016 03:24
@buonarfcc youre replacing all alphanumeric chars with replace(/\w/g,"");
Tyler
@tylergross
Apr 21 2016 03:24
@buonarfcc you are doing palindromes? You want to remove everything that is not alphanumeric ... Try /[^a-z
Tiffany White
@twhite96
Apr 21 2016 03:24
@tylergross how do I get the string output? I need “Bet” and “Hold"
Tyler
@tylergross
Apr 21 2016 03:25
At the bottom where it says return "change me" place your count there you will need an if else statement
@twhite96
@buonarfcc sorry try [^a-z0-9]\ to remove all non alphanumerical characters including whites pace
Frank XC
@tenkdayz
Apr 21 2016 03:26
@buonarfcc you want something like this /[\W_]/g
Tyler
@tylergross
Apr 21 2016 03:26
@buonarfcc /[^a-z0-9]/g
@twhite96 if counter greater than return xxxx else if count less than to return xxxx else return xxxx
Sorry on my phone makes a lot of auto corrections hard to write code now
buonarfcc
@buonarfcc
Apr 21 2016 03:30
Tyler -> This revision -> still got it -> 'false' only answer : str.replace (/\s[^\a-z0-9]/gi, "");
Justin Woodward
@jwoo92
Apr 21 2016 03:30
can anyone assist me with the challenge "nesting for loops" at the end of the basic javascript catagory please?
Tyler
@tylergross
Apr 21 2016 03:32
@buonarfcc looks improper try res2 = str.toLowerCase().replace(/[^0-9a-z]/g, "");
@buonarfcc also make sure you are sending all characters to lowercase or you will never return a true statement as A != a
@jwoo92 what's the challenge?
Or problem
From the name it sounds like for(condA){ for(condB){ .... } }
Ozan Araz
@haraldur12
Apr 21 2016 03:36
does anyone have any tips for the factorials challenge=
Justin Woodward
@jwoo92
Apr 21 2016 03:36
@tylergross it is the "nesting for loops" challenge at the end of basic javascript catagory. i am just confused on where to start. may be partly due to brain being fried for the day by now..
buonarfcc
@buonarfcc
Apr 21 2016 03:36
Tyler you hit it home run !!!! Owsome:):):)
Justin Woodward
@jwoo92
Apr 21 2016 03:37
@tylergross it is nesting a for inside a for loop.
Tyler
@tylergross
Apr 21 2016 03:37
@buonarfcc sounds like it was the lowercase that got you, good job!
@jwoo92 yeah I feel you I'm on my phone chat now so I can't really pull the challenges up
Joshua Abu
@Absolutestunna
Apr 21 2016 03:38
has anyone used materializecss as opposed to bootstrap? im having problems with the media query
thanks in advance
Justin Woodward
@jwoo92
Apr 21 2016 03:38

If you have a multi-dimensional array, you can use the same logic as the prior waypoint to loop through both the array and any sub-arrays. Here is an example:
```
var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
This outputs each sub-element in arr one at a time. Note that for the inner loop, we are checking the .length of arr[i], since arr[i] is itself an array.

Instructions
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr

krisluu5695
@krisluu5695
Apr 21 2016 03:39
hello guys !!
Justin Woodward
@jwoo92
Apr 21 2016 03:39

If you have a multi-dimensional array, you can use the same logic as the prior waypoint to loop through both the array and any sub-arrays. Here is an example:

var arr = [
  [1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
  for (var j=0; j < arr[i].length; j++) {
    console.log(arr[i][j]);
  }
}

This outputs each sub-element in arr one at a time. Note that for the inner loop, we are checking the .length of arr[i], since arr[i] is itself an array.

Instructions
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
multiplyAll([1,2,[3]]); should return 6
multiplyAll([[1,2],[3,4],[5,6,7]]) should return 5040
multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]);) should return 54
krisluu5695
@krisluu5695
Apr 21 2016 03:39
can you guys introduce me some books that i can learn Javascript ?
Justin Woodward
@jwoo92
Apr 21 2016 03:40
@krisluu5695 jon duckets javascript & jquery, elegant js
WilliamDecker
@WilliamDecker
Apr 21 2016 03:41
help where do I belong
CamperBot
@camperbot
Apr 21 2016 03:41

:point_right: algorithm where do i belong [wiki]

Explanation:

This can be a tricky problem to understand. You need to find where in the array a number should be inserted by order, and return the index where it should go.

:pencil: read more about algorithm where do i belong on the FCC Wiki

Justin Woodward
@jwoo92
Apr 21 2016 03:41
krisluu5695
@krisluu5695
Apr 21 2016 03:41
@jwoo92 tks mennnnn.....
CamperBot
@camperbot
Apr 21 2016 03:41
krisluu5695 sends brownie points to @jwoo92 :sparkles: :thumbsup: :sparkles:
:star: 254 | @jwoo92 | http://www.freecodecamp.com/jwoo92
Tyler
@tylergross
Apr 21 2016 03:41
@jwoo92 so basically you have a 2-dimensional array. To access the first set of array you would create a for loop like the example and array[0] would return [1,2] to get inside of that second array you would go further creating another for loop with different variable so array[0][0] would return 1
The for loop takes you like this array0, array0, array1 and so on until the loops finish
That didn't come out properly
Justin Woodward
@jwoo92
Apr 21 2016 03:43
@tylergross thanks so far, i understand that much. i guess i just am having a hard time figuring out what to actually put within the for loops to make it work correctly. again, may just be brain overload for the day. i may take a break and revisit tomorrow.
CamperBot
@camperbot
Apr 21 2016 03:43
jwoo92 sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:star: 340 | @tylergross | http://www.freecodecamp.com/tylergross
Tyler
@tylergross
Apr 21 2016 03:44
Well you want to run the iteration of the arrays
So the first for loop you would have array.length, the second for loop you would have arr[i].length as in the example and you code functionality (getting the product) would exist in this second array
Justin Woodward
@jwoo92
Apr 21 2016 03:46
where are you getting the var i from?
Tyler
@tylergross
Apr 21 2016 03:46
I find it best to do a return wherever I want to see the value of what's going on. Or an alert which will show you in excess ... Like alert(array[i][j] with the second for loop
@jwoo92 var I is created in the loop
for(var I = 0; I < array.length; I++){
krisluu5695
@krisluu5695
Apr 21 2016 03:49
@tylergross is javascript control server side, isn't it ?
Tyler
@tylergross
Apr 21 2016 03:49
@krisluu5695 client side
PHP is server side
Not sure what JavaScript control is?
evolutionus
@evolutionus
Apr 21 2016 03:49
else if(value === "" && prop === "tracks") {
     delete collection[id].tracks;
krisluu5695
@krisluu5695
Apr 21 2016 03:50
@tylergross oh .... i'm beginner so don't know ^^ sry for stupid ques. ... :D
Tyler
@tylergross
Apr 21 2016 03:50
@krisluu5695 I'm new as well no worries
krisluu5695
@krisluu5695
Apr 21 2016 03:50
is this site teaching too ? @tylergross
Tyler
@tylergross
Apr 21 2016 03:51
@krisluu5695 what do you mean?
I've learned a lot from this site I have a strong foundation of other languages but never knew JavaScript just knew enough to get by
Justin Woodward
@jwoo92
Apr 21 2016 03:52

i have this so far, but how do i change it to do what is being asked..?

Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i = 0; i < arr.length; i++) {
    for (var j =0; j < arr[i].length; j++) {
      console.log(arr[i][j]);
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Tyler
@tylergross
Apr 21 2016 03:52
@jwoo92 see console log?
Justin Woodward
@jwoo92
Apr 21 2016 03:52
@tylergross yes
Tyler
@tylergross
Apr 21 2016 03:53
@jwoo92 get rid of that and place a code in there to update your product with the current value of the array
Justin Woodward
@jwoo92
Apr 21 2016 03:54
@tylergross im not sure exactly what i am doing or how im getting a result in this nested loop.
Tyler
@tylergross
Apr 21 2016 03:55
Okay change console.log to alert(arr[i][j]);
and run that and see what all that for loops returns ... It should return a lot of numbers
This problem wants us to take all those numbers and multiply it by product
Essentially they want product *= arr[i][j];
Justin Woodward
@jwoo92
Apr 21 2016 03:56
@tylergross got it
Tyler
@tylergross
Apr 21 2016 03:57
But it's nice to have a solid understanding of the for loops as you will use these quite frequently @jwoo92
Justin Woodward
@jwoo92
Apr 21 2016 03:57
@tylergross
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i = 0; i < arr.length; i++) {
    for (var j =0; j < arr[i].length; j++) {
      product = product * (arr[i][j]);
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Tyler
@tylergross
Apr 21 2016 03:57
@jwoo92 nice that works remember that product = product 5; is the same as product=5;
I hate this app sometimes
Justin Woodward
@jwoo92
Apr 21 2016 03:58
@tylergross i would say i am getting better overall with loops, not great, but better. throwing in the array is what messed me up on this one.
Tyler
@tylergross
Apr 21 2016 03:58
Meant to have my multiply star in there
Justin Woodward
@jwoo92
Apr 21 2016 03:59
@tylergross im still sketchy on the shorthand version so i type it out long ways just to make sure.
it has been a rougher road for me with javascript. html/css is cake compared to javascript. i guess just a lot more thinking involved by the nature of it.
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:01
I'm having trouble with Profile Lookup, is anyone willing to help out?
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:02
How does one find non-alphanumeric characters with regular expressions in JS?
I can help you Dylan.
@DylanNeil I can help if you would like.
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:05
thanks @TOAOIanSmith I tried using google, but all I could find are completed answers! I'd like to understand this. I appreciate it
CamperBot
@camperbot
Apr 21 2016 04:05
dylanneil sends brownie points to @toaoiansmith :sparkles: :thumbsup: :sparkles:
:star: 261 | @toaoiansmith | http://www.freecodecamp.com/toaoiansmith
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:06
function lookUp(firstName, prop){
// Only change code below this line
if (firstName == firstName && prop == prop){
return contacts;
}
// Only change code above this line
}
This was my initial instinct
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:06
No problem! Not familiar with how this site works, but I've gotten past it.
Sorry, browser went slow. So in your code you're pretty much comparing the same variables
Bhavin Thakkar
@thakkarbhavin
Apr 21 2016 04:08

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

return item; // Change this line
}

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

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

What comes in the next Line ? can some body help me the understand the process

Ian Smith
@TOAOIanSmith
Apr 21 2016 04:09
it would look something like contacts.firstName == firstName
@DylanNeil No problem! Not familiar with how this site works, but I've gotten past it.
Sorry, browser went slow. So in your code you're pretty much comparing the same variables
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:09
@TOAOIanSmith yes. I'm trying to figure out how to check if the variable being written in lookUp matches the value of firstName
okay
that makes sense
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:10
So I can say that you'll need a for loop as well
to iterate the length of your contacts object/array
Tiffany White
@twhite96
Apr 21 2016 04:10
My brain is mush. I have no idea what this exercise wants me to do. I have coded for 5 hours today. I just want to finish this one problem. It’s using Objects for Lookups.
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:11
Is it Profile Lookup?
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:11
because it's taking firstName in contacts and comparing it to firstName in lookUp. As far as terminology goes, are these considered two different variables? @TOAOIanSmith
Tiffany White
@twhite96
Apr 21 2016 04:11
code is as follows
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:11
@TOAOIanSmith yes
Tiffany White
@twhite96
Apr 21 2016 04:11
// 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",
  };

  val = lookup;

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

// Change this value to test
phoneticLookup("charlie");
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:12
The code you gave me doesn't access your contacts object. It just uses the parameter twice in your comparsion
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:12
right
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:12
a start would be
Jamie Lipschitz
@Jlipschitz
Apr 21 2016 04:12
@DylanNeil yes. the variable that you passed into your function is called in argument, thus firstName is different than contacts.firstName but can be compared to see if they equal the same.
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:12
sorry one sec
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:13
@TOAOIanSmith I will need a for loop you say? okay that's a good start. give me a minute, I'll see what I can come up with
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:13
Sounds good
going to try to figure the code posting... Sorry, might get messy in chat
```function lookUp(firstName, prop){
// Only change code below this line
if (firstName == firstName && prop == prop){
return contacts;
}
// Only change code above this line
}
1
function lookUp(firstName, prop){
// Only change code below this line
if (firstName == firstName && prop == prop){
return contacts;
}
// Only change code above this line
}
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:17
Thank you @Jlipschitz
CamperBot
@camperbot
Apr 21 2016 04:17
dylanneil sends brownie points to @jlipschitz :sparkles: :thumbsup: :sparkles:
:star: 126 | @jlipschitz | http://www.freecodecamp.com/jlipschitz
mnashrullah07
@mnashrullah07
Apr 21 2016 04:17
hello everyone
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:18
Hello!
mnashrullah07
@mnashrullah07
Apr 21 2016 04:18
i need held at "Testing Objects for Properties"
Jamie Lipschitz
@Jlipschitz
Apr 21 2016 04:18
function myTest(one, two) {
// one and two are both considered arguments
}

var myObj = {
one: "equals one",
two: "equals two"
}

myTest(4,5); // 4 takes the place of "one" inside myTest and 5 takes place for "two"
so you can see although the the obj shares a similar name that's being passed into the function they are indeed not the same. in order to traverse through an object you have to always call the object first myObj.one for example. the arguments that are passed into a function are arbitrary and be set to anything, what matters is the values you put in when calling the function callFunction(10,20) for example.
@DylanNeil
mnashrullah07
@mnashrullah07
Apr 21 2016 04:19
i can't return the value of the property
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:19
Do you have your code?
mnashrullah07
@mnashrullah07
Apr 21 2016 04:19

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

function checkObj(checkProp) {
// Your Code Here
myObj.hasOwnProperty("gift");
myObj.hasOwnProperty("pet");
myObj.hasOwnProperty("house");
return "Not Found";
}

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

@TOAOIanSmith can you help me?
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:20
Of course.
hasOwnObject() returns either true or false.
The only thing you are returning in your function is "Not Found"
That make sense?
you need to return the value of hasOwnPropertry()
Dylan Pagillo
@DylanNeil
Apr 21 2016 04:22
@TOAOIanSmith okay, I'm trying to figure out how to use a for loop in this situation. I'm guessing I need to have the loop search through the entire array until it finds the value for firstName that is entered
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:22
Sorry, meant property, not object.
Yes. I'll give you a hint. your condition will be i < contacts.lenght
mnashrullah07
@mnashrullah07
Apr 21 2016 04:23
I can't add return on each property .hasOwnProperty(), what should I do? @TOAOIanSmith
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:24
What is the name of your challenge @mnashrullah07
?
mnashrullah07
@mnashrullah07
Apr 21 2016 04:24
Testing Objects for Properties, its on javascript section @TOAOIanSmith
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:25
Okay. Give me a sec
Jamie Lipschitz
@Jlipschitz
Apr 21 2016 04:25

@twhite96 you're looking to change your result to equal what's being passed into val. this essentially means that you want to then search your object for something that matches. hmm, now how can this be done? for the purpose of this excercise we will assume the user always inputs a value that is indeed inside our lookup object.

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

in order to access one of these values we use bracket notation e.g. lookup["alpha"] and this will return "Adams". Now we know the user is passing in something by looking at our function function phoneticLookup(val). we want to then find what inside lookup is === toval. This means we want to look inside our lookup object and pass in the value of val using bracket notation. E.g. myObj[something]. You then want to change your return to equal this.

Ian Smith
@TOAOIanSmith
Apr 21 2016 04:26
Why are you checking for pet and house?
In your function you can use checkProp instead of using strings on their own
That is the purpose of passing in arguments
One hint. You need to return the property. Not hasOwnProperty method
Mark Howard
@iheartkode
Apr 21 2016 04:29
  var randColor = "#" + Math.random().toString(16).slice(2, 8);
  for (var i = 0; i < 6; i++) {
    $("body").append("<div class=\"dot\"><div></div></div>");
    $(".dot").css("background", randColor);
  }
//I'm trying to make each div that is created have a random color, but all the divs get the random color, not each
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:30
Also, would anyone be able to help me with the palindrome algorithm in JS?
Luis
@zdrifted
Apr 21 2016 04:30
How is my approach looking so far for the Return Largest Numbers in Arrays challenge?
function largestOfFour(arr) {
  // You can do this!
  var newArr = [];

  for(i = 0; i < arr.length; i++) {
    newArr.push( Math.max(arr[i]) );
  }
  return newArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
mnashrullah07
@mnashrullah07
Apr 21 2016 04:31
@TOAOIanSmith Okay, thanks buddy. it help me :)
CamperBot
@camperbot
Apr 21 2016 04:31
mnashrullah07 sends brownie points to @toaoiansmith :sparkles: :thumbsup: :sparkles:
:star: 262 | @toaoiansmith | http://www.freecodecamp.com/toaoiansmith
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:31
Sounds good! Did you get it? Or would you like example codE?
@mnashrullah07
mnashrullah07
@mnashrullah07
Apr 21 2016 04:33
@TOAOIanSmith hehe, not yet. I'm Still tryin' :D
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:35
@mnashrullah07 Alright! @me if you need anymore help. I know I wasn't very descriptive but I would feel bad if I made it too easy
mnashrullah07
@mnashrullah07
Apr 21 2016 04:37
it's okay buddy @TOAOIanSmith
Shuey95
@Shuey95
Apr 21 2016 04:40
hey guys
this is an embarassing question but im on the javascript incrementing map part.
it says change the code to use ++ opertor on myVar.

var myVar = 87;

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

I tried myVar =myVar++;
but im not sure what to do.
nvm
figured it out
hate myself so much rn.
Tiffany White
@twhite96
Apr 21 2016 04:42
thanks @Jlipschitz Got it
CamperBot
@camperbot
Apr 21 2016 04:42
twhite96 sends brownie points to @jlipschitz :sparkles: :thumbsup: :sparkles:
:star: 127 | @jlipschitz | http://www.freecodecamp.com/jlipschitz
Jamie Lipschitz
@Jlipschitz
Apr 21 2016 04:45
@twhite96 awesome!
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:51
Is there anyone that can help me with palindrome function in JS? Code:
function palindrome(str) {
  // Good luck!
  var compare;
  str = str.replace(/\W+/gi, '');
  str = str.toLowerCase();
  compare = str.split('').reverse().join('');
  compare.toLowerCase();
  if(str == compare) return true;
  return false;
}
I pass every test other than: palindrome("0_0 (: /-\ :) 0-0")
This message was deleted
This message was deleted
:) == ":)"
Herbert Zurita
@Doodymir
Apr 21 2016 04:54
Hey guys, I'm in challenge "Stand In Line" and I can't realy understand how to write the code, any help?
function nextInLine(arr, item) {
  // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
This is the text for the challenge:
"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."
Jamie Lipschitz
@Jlipschitz
Apr 21 2016 04:56
lookup the native methods that are provided in the tooltip @Doodymir . E.g. push() and pop(). this will help you get through this exercise
Ian Smith
@TOAOIanSmith
Apr 21 2016 04:59
Help not needed anymore. Finally completed
CamperBot
@camperbot
Apr 21 2016 04:59
no wiki entry for: not needed anymore finally completed
Herbert Zurita
@Doodymir
Apr 21 2016 05:00
I understand that I should do something like arr = arr.push(item); , but I don't know whta to do after that
Jamie Lipschitz
@Jlipschitz
Apr 21 2016 05:00
@Doodymir sorry, you want to be looking at shift methods and not pop()
V Arun Kumar
@arunvkumr
Apr 21 2016 05:01
@Doodymir you are given a array named arr. using this array you have to do this operations..
  • Insert the element at the end of array. (Read about push function)link
  • Remove the first element from the array. (Read about shift function) link
Jamie Lipschitz
@Jlipschitz
Apr 21 2016 05:01
you can actually just call arr.push(item) without the =. you want to use shift() to remove that first element and only return that. this is where you would store it into a variable or just return what you shift.
V Arun Kumar
@arunvkumr
Apr 21 2016 05:03
@Doodymir you are close.. don't use the = in push method. as push returns the length of new array, which is a number. this will replace the array with a number. remove arr =
Herbert Zurita
@Doodymir
Apr 21 2016 05:04
Ahh, just got it now. Thanks, @Jlipschitz and @arunkumrv !
CamperBot
@camperbot
Apr 21 2016 05:04
doodymir sends brownie points to @jlipschitz and @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 128 | @jlipschitz | http://www.freecodecamp.com/jlipschitz
:star: 493 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
friesenet21
@friesenet21
Apr 21 2016 05:04
Help switch statements
CamperBot
@camperbot
Apr 21 2016 05:04

:point_right: challenge adding a default option in switch statements [wiki]

Challenge: Adding a default option in Switch statements

In a switch statement you may not be able to specify all possible values as case statements. Instead, you can add the default statement which will be executed if no matching case statements are found. Think of it like the final else statement in an if/else chain.

A default statement should be the last case.

switch (num) {
  case value1:
    statement1
    break;
  case value2:
    statement2;
    break;
...
  default:
    defaultStatement;
}

:pencil: read more about challenge adding a default option in switch statements on the FCC Wiki

Jenny
@jennylien
Apr 21 2016 05:27

Anyone know if I did anything wrong here? my .ajax is not calling.. both success and error messages are not showing up in console..

// id for random button is "random"
// id for search box is "search"
// id for search enter button is "enter"
// id for display area is print
$(document).ready(function(){
var searchurl="";
//random page
$("#random").on("click", function(){
var randomurl= "https://en.wikipedia.org/wiki/Special:Random";
window.open(randomurl, "_blank");
});

// change the code below

$("#enter").on("click",function(){
var searchvalue=document.getElementById("search").value;
console.log(searchvalue);
var enter = "#enter";
searchurl="https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch="+ searchvalue;
console.log(searchurl);

 $.ajax({ 
    dataType:jsonp,
    tyle:"POST",
         jsonp:"jsonp",
    url:searchurl,
    success:function(jsonp){

     console.log("success");          

     //change the code above 
    },  
    error:function(e){
    console.log(e.message);    
    document("print").getElementById.innerHTML="Unable to access to Wikipedia. Please try later."  
    }

 });

});

});
@jennylien
my calling .ajax is not working...can anyone let me know if i did anything wrong here??
// id for random button is "random"
// id for search box is "search"
// id for search enter button is "enter"
// id for display area is print
$(document).ready(function(){
var searchurl="";
//random page
$("#random").on("click", function(){
var randomurl= "https://en.wikipedia.org/wiki/Special:Random";
window.open(randomurl, "_blank");
});

// change the code below

$("#enter").on("click",function(){
var searchvalue=document.getElementById("search").value;
console.log(searchvalue);
var enter = "#enter";
searchurl="https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch="+ searchvalue;
console.log(searchurl);

 $.ajax({ 
    dataType:jsonp,
    tyle:"POST",
         jsonp:"jsonp",
    url:searchurl,
    success:function(jsonp){

     console.log("success");          

     //change the code above 
    },  
    error:function(e){
    console.log(e.message);    
    document("print").getElementById.innerHTML="Unable to access to Wikipedia. Please try later."  
    }

 });

});

});

Erik Maurer
@MauPow
Apr 21 2016 05:29

Doing the Capitalizing First Letter challenge. Am I on the right track?
```
function titleCase(str) {
var splitStr = str.toLowerCase().split(' ');

for (i=0;i<splitStr.length;i++) {
return splitStr[i].charAt(0).toUpperCase() + splitStr[i].slice(1);
}
}

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

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

  for (i=0;i<splitStr.length;i++) {
    return splitStr[i].charAt(0).toUpperCase() + splitStr[i].slice(1);
  }
}

titleCase("I'm a little tea pot");
Right now it's only returning the first word
Markus Kiili
@Masd925
Apr 21 2016 05:33
@MauPow Instead of return you should do splitStr[i]=... <- construct titlecased word here.
Erik Maurer
@MauPow
Apr 21 2016 05:37
Oh ok great that got it
Can't figure out how to join it back together
Markus Kiili
@Masd925
Apr 21 2016 05:37
@MauPow .join(" ");
Erik Maurer
@MauPow
Apr 21 2016 05:37
Oof I had that haha but in the wrong place
I got it now, thanks
Ian Smith
@TOAOIanSmith
Apr 21 2016 05:55
Anyone here?
Luis
@zdrifted
Apr 21 2016 05:59
Why isn't this working? (Return Largest Number in an Array)
function largestOfFour(arr) {
  // You can do this!
  var newArr = [];

  for(i = 0; i < arr.length; i++) {
    newArr.push( Math.max(arr[i]) );
  }
  return newArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Markus Kiili
@Masd925
Apr 21 2016 06:01
@Rushh Math.max don't work on arrays. You can do Math.max.apply(null,arr) to get the largest number on an array.
Luis
@zdrifted
Apr 21 2016 06:02
@Masd925 thanks!
CamperBot
@camperbot
Apr 21 2016 06:02
rushh sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1393 | @masd925 | http://www.freecodecamp.com/masd925
Erik Maurer
@MauPow
Apr 21 2016 06:03
Blurgh I'm trying to do that one too but in a different way
Anthony
@iDrinkTooMuchCoffee
Apr 21 2016 06:03
I'm having some trouble with the wikipedia viewer. I'm not really sure how to get the json back from the page. The console is not logging 'success', so it must not be going through for some reason.
codebtn.on('click', function(){
var query = searchBox.val();
var data = $.ajax({
type: "GET",
url: api + query + cb,
async: true,
dataType: "jsonp",
headers: { 'http://codepen.io' : 'Access-Control-Allow-Origin' },
success: function(data) {
console.log('success');
var results = data.query.pages;
/
$.each(results, function(){
console.log(results.title);
});
/
}
});
});code
huh, figured the code tag worked like most other sites. my b lol.
Erik Maurer
@MauPow
Apr 21 2016 06:05
Why is it telling me that charAt() isn't a function
I'm trying to get the first number of an array
How the heck do you sort number?
I've tried this:
```
  function compareNumbers(a, b){
    return a - b;
  }

  var sorted = arr.sort(compareNumbers);
Markus Kiili
@Masd925
Apr 21 2016 06:08
@MauPow That works.
Erik Maurer
@MauPow
Apr 21 2016 06:09
Well... maybe I have the wrong idea about what it's doing then
Doing the largest of 4 challenge
when I return sorted... it hasn't changed
function largestOfFour(arr) {

  var largest = [];

  function compareNumbers(a, b){
    return a - b;
  }

  var sorted = arr.sort(compareNumbers);

  for (var i = 0;i<4;i++) {
    largest.push(sorted[i].charAt(0));
  }

  return largest;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Aleksej
@tip14
Apr 21 2016 06:14
hello! i need help. my map method should replace null with " " - space, but doesn't do it. can someone explain why?
function rot13(str) { 
  var input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(/\s*/);
  var output = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm".split(/\s*/);
  var sp = str.split(/\s*/);
  var unc =[];
  var sun=[];
  for (i=0;i<str.length;i++){
    unc.push(input.indexOf(str[i]));
    sun.push(output[unc[i]]);
  }


var map = sun.map(function(elem){
    if (elem===null) {
      return " ";

    }
    return elem;
});                
return map;


}


// Change the inputs below to test
rot13("SERR PBQR PNZC");
Christian Bertram
@cbertram
Apr 21 2016 06:14

Hello, can anyone tell why this bit of code isn't working?

var dates = [{
  name: "TalentWeek",
  grade7: true,
  grade89: true,
  english: true,
  danish: true,
  math: true,
  dateFrom: "7/31/2016 10:00 AM",
  dateTo: "8/5/2016 03:00 AM",
  textDate: "Fra 31. jul. 2016 til 5. aug. 2016"
}];

window.onload = function() {
  var nextCamp; // index
  for (nextCamp = 0; nextCamp < dates.length; nextCamp++) {
    if (new Date() > new Date(dates[nextCamp].dateTo)) break;
  }
  var currCamp = nextCamp;
  document.getElementById("camp").innerHTML = dates[currCamp].name;
};

The DOM element with id "camp" is not updating.. document.getElementById("camp").innerHTML = dates[0].name; works fine..

Markus Kiili
@Masd925
Apr 21 2016 06:16
@tip14 It is not null, you have trouble with.
DJ
@qualitymanifest
Apr 21 2016 06:18
@MauPow you're trying to sort an array of arrays. that sort won't look into the sub-arrays. if you want to use sort, you need to sort each sub-array. you can access each sub-array in the for loop.
also, it works for this instance, but rather than hardcoding i<4 you ought to use i<arr.length so it would work for any number of sub-arrays
and you don't want charAt. that's for strings. just access the first part of each sub array using bracket notation.
Tharun James
@xplorejames
Apr 21 2016 06:22
Help me out how chunky Monkey works
CamperBot
@camperbot
Apr 21 2016 06:22
no wiki entry for: me out how chunky monkey works
Tharun James
@xplorejames
Apr 21 2016 06:23
what is the logic behind chunkymonkey
help array
CamperBot
@camperbot
Apr 21 2016 06:23

:point_right: algorithm diff two arrays [wiki]

Explanation:

Check two arrays and return a new array that contains only the items that are not in either of the original arrays.

:pencil: read more about algorithm diff two arrays on the FCC Wiki

Erik Maurer
@MauPow
Apr 21 2016 06:28
Woo~! got it
thanks @qualitymanifest
CamperBot
@camperbot
Apr 21 2016 06:30
maupow sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 1138 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
jirkae
@jirkae
Apr 21 2016 06:32
Hi, anyone who has experience with RequireJS and r.js please? I need help with something. Thanks a loot
Naguib Bouchibi ⚡️
@naguib101
Apr 21 2016 06:39
Hi everyone, someone has an idea to how resizing an image for HTML5 canvas but proportionally keeping a good quality ? Preferably in JS
Rahul Nayak
@pragyes31
Apr 21 2016 06:45
Hi People, need a hint(not the solution) to move forward the "chunky monkey" binfire.
Markus Kiili
@Masd925
Apr 21 2016 06:47
@pragyes31 Make a loop and push slices of arr into result array.
Boyce
@Yijianc
Apr 21 2016 06:49
help Show the Local Weather
CamperBot
@camperbot
Apr 21 2016 06:49
no wiki entry for: show the local weather
missNasser
@missNasser
Apr 21 2016 06:57
@tenkdayz hey how are you doing with my challenge
Frank XC
@tenkdayz
Apr 21 2016 06:58
@missNasser hm.. refresh my memory
missNasser
@missNasser
Apr 21 2016 06:58
comment box
Frank XC
@tenkdayz
Apr 21 2016 06:59
@missNasser the localStorage yeah
missNasser
@missNasser
Apr 21 2016 06:59
yes
Frank XC
@tenkdayz
Apr 21 2016 07:00
@missNasser I didnt do much after I showed you how I stored the string..
@missNasser I'm working on a ranking system using sql right now..
missNasser
@missNasser
Apr 21 2016 07:00
okay
would there be anyway i could get it to work offline
Frank XC
@tenkdayz
Apr 21 2016 07:02
@missNasser you have to load some kind of UI first so I dont think there's a way as far as I know.
missNasser
@missNasser
Apr 21 2016 07:03
can i have the link again please to see what you have done
Frank XC
@tenkdayz
Apr 21 2016 07:05
@missNasser I overwrote that file content.. but I just googled localStorage w3
missNasser
@missNasser
Apr 21 2016 07:06
ok
well what i wanted was it to work the same way as this code dose il just it you

<!DOCTYPE html>

<html>
<head>
<script>
function clickCounter() {
if(typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)+1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " + localStorage.clickcount + " time(s).";
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
</script>
</head>
<body>
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p>
</body>
</html>

Frank XC
@tenkdayz
Apr 21 2016 07:09
@missNasser read up on .setItem() and .getItem()
Miguel T Rivera
@mtrivera
Apr 21 2016 07:39
wiki where art thou
CamperBot
@camperbot
Apr 21 2016 07:39

:point_right: algorithm where art thou [wiki]

Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

:pencil: read more about algorithm where art thou on the FCC Wiki

Eldar Tinjić
@EldarT90
Apr 21 2016 07:43
what the heck ... i did something that is maybe infinite loop, but even if it is, why am i getting "semi-crashed" browser every time i open that challenge
evne if i dont click to check challenge
i cant do anything on that page, its frozen
like this?
@kirbyedy k tnx it worked with ?also
CamperBot
@camperbot
Apr 21 2016 07:51
eldart90 sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 902 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
Eldar Tinjić
@EldarT90
Apr 21 2016 07:51
so can anyone tell me how is this infinite loop
function pairwise(arr, arg) {
  for (i=0;i<arr.length;i++) {
    for (j=0;i<arr.length;j++)

      if (arr[i]+arr[j] == arg) {
        return arr[i]+arr[j];
      }
  }
}

pairwise([1,4,2,3,0,5], 7);
kirbyedy
@kirbyedy
Apr 21 2016 07:51
:thumbsup:
Markus Kiili
@Masd925
Apr 21 2016 07:52
@EldarT90 j=0;i<arr.length;j++ Something wrong here.
Eldar Tinjić
@EldarT90
Apr 21 2016 07:54
@Masd925 nice catch, good eye ^^ tnx
CamperBot
@camperbot
Apr 21 2016 07:54
eldart90 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1394 | @masd925 | http://www.freecodecamp.com/masd925
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 07:54
Please in this code, in the first if statement below the for loop, please how do I make the string replace result[i] with - result[i] e g if string[i] === A I want it replaced with -A
function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
var result=str;
for (var i=1; i<str.length; i++){
if (result[i]==result[i].toUpperCase()){

var che = "-";
che+=result[i];
result=result.replace(result[i], che);
}
}
//if (result.indexOf("") ===-1){
//result.charAt(0).toLowerCase();
  if (result.indexOf(" ")>0){
 var re2 = new RegExp(" ","g");
 result = result.replace(re2, "-");
}
if (result.indexOf("_")>0){
   var re =new RegExp("_","g");
 result = result.replace(re, "-");
}
if (result.indexOf("--")>0){
var con= new RegExp("--","g");
  result=result.replace(con,"-");
}


//if (result.indexOf(
 return result.toLowerCase(0);
}


//spinalCase('This Is Spinal Tap');
//spinalCase("AllThe-small Things");
spinalCase("thisIsSpinalTap");
alpox
@alpox
Apr 21 2016 08:09
@Itsdenty -A? what do you expect a string gets if you put there a -? :D (I don't quite get what you want to achieve with that)
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:10
@alpox yes -A would be a string
More like inserting - before the uppercase character
Blauelf
@Blauelf
Apr 21 2016 08:11
@Itsdenty For testing whether a character is uppercase, test whether it is unequal to the lowercased version, as lowercase and uppercase is the same for most characters. Or use something like /[A-Z]/.test(result[i]), which matches those uppercase letters used in English.
alpox
@alpox
Apr 21 2016 08:13
@Itsdenty ah you mean "-" + result[i]?
Eldar Tinjić
@EldarT90
Apr 21 2016 08:14
why is this not working ?
function pairwise(arr, arg) {
  var newArr = [];
  for (i=0;i<arr.length;i++) {
    for (j=0;j<arr.length;j++)
      if (arr[i]+arr[j] == arg) {
        arr[j] = 9999;
        newArr.push([arr.indexOf(arr[i]) +arr.indexOf(arr[j])]);
      }
  }
  var count = 0;
  for (var c = 0;c<newArr.length;c++) {
    count += parseInt(newArr[c]);
  }

  return count/2;
}
pairwise([1, 4, 2, 3, 0, 5], 7);
@alpox morning
^^
alpox
@alpox
Apr 21 2016 08:15
@EldarT90 yeah morning :D
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:15
@Blauelf the if statement worked n it only selected d uppercase alphabets if I replaced the returned letter from the loop with - it worked perfectly however I don't need a direct replacement but more like an insert
Blauelf
@Blauelf
Apr 21 2016 08:15
@EldarT90 You don't track the indexes you already used?
Eldar Tinjić
@EldarT90
Apr 21 2016 08:16
@Blauelf but i do by chacnging value of j to 9999, which means it will never be used again
it cant be used twice with 9999 value
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:17
May be splice method might work there but not sure
Because I might need to change it to array then
Eldar Tinjić
@EldarT90
Apr 21 2016 08:19
im trying to add this
Sumeet Batheja
@bathejasumeet
Apr 21 2016 08:19
Morning all
Eldar Tinjić
@EldarT90
Apr 21 2016 08:19
function pairwise(arr, arg) {
  var newArr = [];
  for (i=0;i<arr.length;i++) {
    for (j=0;j<arr.length;j++)
      if (arr[i]+arr[j] == arg) {
        if (arr[i] !== arg && arr[j] && arg) {
        newArr.push([arr.indexOf(arr[i]) +arr.indexOf(arr[j])]);
        arr[j] = 9999;
      }}
  }
  return newArr;
  var count = 0;
  for (var c = 0;c<newArr.length;c++) {
    count += parseInt(newArr[c]);
  }

  return count;
}
pairwise([1, 3, 2, 4], 4);
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:19
Yes @alpox exactly that
alpox
@alpox
Apr 21 2016 08:19
@EldarT90 I just looked bit over it but don't you have to test for that you don't add the same index? I mean
if(i !== j)
Eldar Tinjić
@EldarT90
Apr 21 2016 08:20
i fixed it for the most part atm , sec but i have problem with it adding number that is equal to arg
im not sure how is that happening
function pairwise(arr, arg) {
  var newArr = [];
  for (i=0;i<arr.length;i++) {
    for (j=0;j<arr.length;j++)
      if (arr[i]+arr[j] == arg) {
        if (arr[i] !== arg && arr[j] !== arg) {
        newArr.push([arr.indexOf(arr[i]) +arr.indexOf(arr[j])]);
        arr[j] = 9999;
      }}
  }
  return newArr;
  var count = 0;
  for (var c = 0;c<newArr.length;c++) {
    count += parseInt(newArr[c]);
  }

  return count;
}
pairwise([1, 3, 2, 4], 4);
so in this case he is adding to array both 1 and 4
i understand why he adds 1, perfectly
index of 1 is 0 , index of 3 is 1
so that is 0+1 = 1
but where the hell this 4 comes from
alpox
@alpox
Apr 21 2016 08:21
@EldarT90 2 + 2?
Blauelf
@Blauelf
Apr 21 2016 08:21

@Itsdenty You might want to learn more about regular expressions, I find them very useful for that challenge. Also, you mix str and result a lot in indexing, and that first replace should better be something like

  for (var i = 1; i < result.length; i++) {
    if (result[i] !== result[i].toLowerCase()) {
      result = result.slice(0, i) + "-" + result.slice(i);
      i++; // as the next character is now at another index
    }
  }

(still needs some better regular expression that replaces multiple space or dash characters by one dash)

Eldar Tinjić
@EldarT90
Apr 21 2016 08:21
@alpox so it is adding same number -,- , k let me try adding that statement
Sumeet Batheja
@bathejasumeet
Apr 21 2016 08:22
anybody done with convertToRoman?
can anybody explain me the logic
can anybody explain the logic to me *
Eldar Tinjić
@EldarT90
Apr 21 2016 08:22
@alpox oke tnx mate, that fixed alot of problems
CamperBot
@camperbot
Apr 21 2016 08:22
eldart90 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star: 573 | @alpox | http://www.freecodecamp.com/alpox
alpox
@alpox
Apr 21 2016 08:22
@EldarT90 np
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:23
@bathejasumeet
Sumeet Batheja
@bathejasumeet
Apr 21 2016 08:23
yes
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:23
Create arrays that deals with units, tens, hundredths n thousands letters
Sumeet Batheja
@bathejasumeet
Apr 21 2016 08:23
ok
one array for each demical location
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:24
Then check the unit of the given number via the .length method
alpox
@alpox
Apr 21 2016 08:24
@bathejasumeet Go sure you go these steps: 1000, 900, 500, 400...
Luis
@zdrifted
Apr 21 2016 08:24
This message was deleted
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:25
With each unit, use the push method to append appropriate letters from the arrays
Blauelf
@Blauelf
Apr 21 2016 08:25
@EldarT90 Instead of checking if arr[i]!==arg, you should check whether i!==j
Also, why not use undefined instead of 9999? That way, the sum could never be arg.
Luis
@zdrifted
Apr 21 2016 08:25
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  var check = str.indexOf(target);
  if (check === -1) {
    return false;
  } if (target === str[str.indexOf(target)] )

  return true;

}

confirmEnding("Bastian", "n");
Any hints here? Confirm The Ending Challenge
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:25
That worked for me
Sumeet Batheja
@bathejasumeet
Apr 21 2016 08:25
okay @Itsdenty thanks , @alpox thanks , that's enough to get me started
CamperBot
@camperbot
Apr 21 2016 08:25
bathejasumeet sends brownie points to @itsdenty and @alpox :sparkles: :thumbsup: :sparkles:
:star: 302 | @itsdenty | http://www.freecodecamp.com/itsdenty
:star: 574 | @alpox | http://www.freecodecamp.com/alpox
Eldar Tinjić
@EldarT90
Apr 21 2016 08:25
@Blauelf yep that worked as alpox pointed out ^^ tnx to you as well
CamperBot
@camperbot
Apr 21 2016 08:25
eldart90 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1696 | @blauelf | http://www.freecodecamp.com/blauelf
Eldar Tinjić
@EldarT90
Apr 21 2016 08:26
but now i think my code is too simple for this problem :
pairwise([0, 0, 0, 0, 1, 1], 1) should return 10.
Blauelf
@Blauelf
Apr 21 2016 08:26
What is too simple? Problem is too simple?
alpox
@alpox
Apr 21 2016 08:26
@EldarT90 Too simple? Not really. Maybe there is somewhere another little mistake :-) (Sry i'm in lesson so cannot look closely)
Sumeet Batheja
@bathejasumeet
Apr 21 2016 08:26
Anybody used Aurelia?
Eldar Tinjić
@EldarT90
Apr 21 2016 08:27
@alpox nah, the thing is if there are numerous combinations, i have to pick the one that gives lowest sum ; this problem has about 10 solutions , since we have 3 zeros and 2 1s
4 zeros*
alpox
@alpox
Apr 21 2016 08:28
@EldarT90 Your two for loops alread test all possible combinations
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:28
Please in this code, in the first if statement below the for loop, please how do I make the string replace result[i] with - result[i] e g if string[i] === A I want it replaced with -A
function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
var result=str;
for (var i=1; i<str.length; i++){
if (result[i]==result[i].toUpperCase()){

var che = "-";
che+=result[i];
result=result.replace(result[i], che);
}
}
//if (result.indexOf("") ===-1){
//result.charAt(0).toLowerCase();
  if (result.indexOf(" ")>0){
 var re2 = new RegExp(" ","g");
 result = result.replace(re2, "-");
}
if (result.indexOf("_")>0){
   var re =new RegExp("_","g");
 result = result.replace(re, "-");
}
if (result.indexOf("--")>0){
var con= new RegExp("--","g");
  result=result.replace(con,"-");
}


//if (result.indexOf(
 return result.toLowerCase(0);
}


//spinalCase('This Is Spinal Tap');
//spinalCase("AllThe-small Things");
spinalCase("thisIsSpinalTap");
Eldar Tinjić
@EldarT90
Apr 21 2016 08:28
@alpox yes, but they find the first one, not the best one
and they return first one they find
Blauelf
@Blauelf
Apr 21 2016 08:28
@EldarT90 Tried arr[i]=arr[j]=undefined; (instead of the 9999 part) and remove that check for arr[i]!==arg (same for j)? Also, push i+j or arg, not some indexOf (but should be the same as you change arr).
Eldar Tinjić
@EldarT90
Apr 21 2016 08:28
not the one with lowest intex score
Sumeet Batheja
@bathejasumeet
Apr 21 2016 08:29
is Aurelia JS better than angular? anybody has hands on experience?
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:29
This code returned this-------isspinaltap instead of this-is-spinal-tap
alpox
@alpox
Apr 21 2016 08:30
@EldarT90 Does it have to find the best one? As i understand it it just adds all indices of possible pairs
Mooli
@Mooli88
Apr 21 2016 08:30
hi, i need help understanding 'Smallest Common Multiple' please. i understand what find the smallest common multiple means but i dont understand the next bit 'find the smallest common multiple of both 1 and 3 that is evenly divisible by all numbers between 1 and 3.'
Eldar Tinjić
@EldarT90
Apr 21 2016 08:30
@alpox "return the smallest sum of indices. "
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:31
Which means the - in the for loop only worked for the first occurrence of the uppercase letter which Is what I wish to fix
alpox
@alpox
Apr 21 2016 08:32
@EldarT90 Funny, i don't even test for that in my code :D
Eldar Tinjić
@EldarT90
Apr 21 2016 08:32
@alpox hmm ^^ well this challenge would look too simple, i literally did it in 15-20 mins with lil bit of help here, but certainly not advanced challenge
alpox
@alpox
Apr 21 2016 08:32
@bathejasumeet I never even heard of that and i did a lot of research on such tools... So i guess not :D if it was as good as angular it would be more popular
Eldar Tinjić
@EldarT90
Apr 21 2016 08:32
if it was without the "lowest sum" part
Mooli
@Mooli88
Apr 21 2016 08:32
hi, i need help understanding 'Smallest Common Multiple' please. i understand what find the smallest common multiple means but i dont understand the next bit 'find the smallest common multiple of both 1 and 3 that is evenly divisible by all numbers between 1 and 3.'
@Itsdenty you dont need to use loops
Blauelf
@Blauelf
Apr 21 2016 08:34
6 would be that, is evenly dividable by 1, 2, and 3 (and is the smallest number of that property). Those pairs of integers mark ranges.
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:35
I wouldn't have used loops but a general Regex however the first letter with uppercase would have been the problem
It would be selected by a regex
Eldar Tinjić
@EldarT90
Apr 21 2016 08:36
i have no idea how to fix this without scractching almost everything
since i change index of j
sec
Mooli
@Mooli88
Apr 21 2016 08:37
@Itsdenty you can solve it solely with regex
@Blauelf so it supposed to be evenly dividable by args numbers too or just those in between ?
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:38
Ok, then how do I avoid the Regex selecting the first uppercase @Mooli88
Blauelf
@Blauelf
Apr 21 2016 08:38
By those in the range 1..3 (which includes both 1 and 3)
Eldar Tinjić
@EldarT90
Apr 21 2016 08:40
can some1 explain why is this giving me array with 16 [4] or something like that
Blauelf
@Blauelf
Apr 21 2016 08:40
@Itsdenty For example /(?!^)[A-Z]/
Eldar Tinjić
@EldarT90
Apr 21 2016 08:40
function pairwise(arr, arg) {
  var newArr = [];
  for (i=0;i<arr.length;i++) {
    for (j=0;j<arr.length;j++)
      if (arr[i]+arr[j] == arg) {
        if (arr[i] !== arr[j]) {
        newArr.push([arr.indexOf(arr[i]) +arr.indexOf(arr[j])]);

      }}
  }
  return newArr;
  var count = 0;
  for (var c = 0;c<newArr.length;c++) {
    count += parseInt(newArr[c]);
  }

  return count;
}
pairwise([0, 0, 0, 0, 1, 1], 1)
Blauelf
@Blauelf
Apr 21 2016 08:40
@EldarT90 You push arrays. Plus operator on arrays converts them to string.
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:41
Thanks @Blauelf
CamperBot
@camperbot
Apr 21 2016 08:41
itsdenty sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1697 | @blauelf | http://www.freecodecamp.com/blauelf
alpox
@alpox
Apr 21 2016 08:41
@EldarT90 You still don't test for i !== j but instead for arr[i] !== arr[j]!
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:41
Let me try Regex only then
alpox
@alpox
Apr 21 2016 08:41
@Blauelf Tatsache? :D wiedermal was, das ich nicht wusste
Eldar Tinjić
@EldarT90
Apr 21 2016 08:41
aaa
@Blauelf why i push arrays? i mean in other examples i dont, i push only numbers
but for this example it looks totally weird
Blauelf
@Blauelf
Apr 21 2016 08:43
@EldarT90 [] marks an array literal.
Eldar Tinjić
@EldarT90
Apr 21 2016 08:43
shouldnt it push 4,5,6 , etc
yes
but thats not problem
problem are values
i get 4,,4,4,4,4,4,
i should get different values
because indexes are different
Blauelf
@Blauelf
Apr 21 2016 08:44
You lost your "tracking" code of assigning something impossible to arr[i] and arr[j].
alpox
@alpox
Apr 21 2016 08:44
@EldarT90 Wie @Blauelf sagte, du pushst arrays. Wenn du parseInt() auf nen array anwendest (was du tust) nimmt das nur das erste element
Mooli
@Mooli88
Apr 21 2016 08:45
@Itsdenty just a heads up. it wasn't easy for me. i had to watch 50min video on regex before i was able to put something together. and even than, the answer of the FCC wiki was more elegant but thats because i wan't aware of some of replace() functionality s
@Blauelf thanks
CamperBot
@camperbot
Apr 21 2016 08:45
mooli88 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1698 | @blauelf | http://www.freecodecamp.com/blauelf
Eldar Tinjić
@EldarT90
Apr 21 2016 08:47
@Blauelf yes , but i will never be able to solve it with it
i dont know
Blauelf
@Blauelf
Apr 21 2016 08:47
@EldarT90 So something like that should work
    for (j=i+1;j<arr.length;j++) { // so no need to test whether i!==j
      if (arr[i]+arr[j] == arg) {
        newArr.push(i,j); // or push(i+j)
        arr[i]=arr[j]=undefined;
      }
    }
Eldar Tinjić
@EldarT90
Apr 21 2016 08:47
@alpox ich weiss nicht
alpox
@alpox
Apr 21 2016 08:47
@EldarT90 Oh ne sry im mixing languages again :D hell
Luis
@zdrifted
Apr 21 2016 08:47
Here is my second attempt
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  var arr = [];
  arr = str.split(" ");
  var lengthArr = arr.length;
  var index = arr.length - 1;
  if (lengthArr[index] === target) {
    return true;
  }
  return false;
}
Eldar Tinjić
@EldarT90
Apr 21 2016 08:48
@Blauelf yes it is working but why is this line doing such a big change :
arr[i]=arr[j]=undefined;
Luis
@zdrifted
Apr 21 2016 08:48
Any hints here? Confirm The Ending Challenge . I've been reading about substring at the moment but I'm not sure how to apply it here. This is my attempt without it
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  var check = str.indexOf(target);
  if (check === -1) {
    return false;
  } if (target === str[str.indexOf(target)] )

  return true;

}

confirmEnding("Bastian", "n");
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:49
@Mooli88 I had been on this challenge and have read close to four or five articles on Regex. However none, was detailed enough to help me patch the needed Regex statement up.
Markus Kiili
@Masd925
Apr 21 2016 08:49
@Rushh You could take a substring of str so that it is the end part of str with the same length as target. Then compare the substring to target.
Blauelf
@Blauelf
Apr 21 2016 08:49
@EldarT90 That's where you track the numbers you already used. If you push i and j separately instead of i+j, then you could instead test whether both i and j were not contained in newArr.
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:50
If you have an explanatory tutorial that might help, you can as well share me @Mooli88
Luis
@zdrifted
Apr 21 2016 08:50
@Masd925 Thanks! That didn't even cross my mind for some reason. I'll try it right now
CamperBot
@camperbot
Apr 21 2016 08:50
rushh sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
Eldar Tinjić
@EldarT90
Apr 21 2016 08:50
@Blauelf so if you add undefined to an element, it will somehow "mark" it for future use in loop?
CamperBot
@camperbot
Apr 21 2016 08:50
:star: 1395 | @masd925 | http://www.freecodecamp.com/masd925
Eldar Tinjić
@EldarT90
Apr 21 2016 08:51
@Blauelf @alpox and tnx to both of you once again
CamperBot
@camperbot
Apr 21 2016 08:51
eldart90 sends brownie points to @blauelf and @alpox :sparkles: :thumbsup: :sparkles:
:warning: eldart90 already gave blauelf points
:warning: eldart90 already gave alpox points
Markus Kiili
@Masd925
Apr 21 2016 08:51
@Rushh indexOf might not work because it returns the index of first occurence of given string.
alpox
@alpox
Apr 21 2016 08:51
@EldarT90 Was i was saying is, that when you add an array to newArr and then do a parseInt(newArr[c]), it will only take out the first element of the array given (newArr[c] is an array too since you push that)
Blauelf
@Blauelf
Apr 21 2016 08:51
@Rushh It's easier to use slice or substr here instead of substring, as those have some special treatment for negative string start: It counts from the end. So str.slice(-3) is same as str.slice(str.length-3)
Codemzy
@codemzy
Apr 21 2016 08:51
@Rushh the problem you will have is if target is more than one letter... you can use substring, to get the ending of the passed in string (str), that starts at str.length-target.length and is the length of target.length and then compare that to target, and see if it matches
Eldar Tinjić
@EldarT90
Apr 21 2016 08:52
@alpox so its looping somehow, but what undefined has to do with anything
undefined , what undefined represent
Mooli
@Mooli88
Apr 21 2016 08:53
@Itsdenty also when i said you can solve it only with regex it was a bit inaccuracy. you will also need match(), join() and replace() to use along with regex (but that also goes without saying)
alpox
@alpox
Apr 21 2016 08:53
@EldarT90 It represents nothing:D
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:53
Thanks @Mooli88
CamperBot
@camperbot
Apr 21 2016 08:53
itsdenty sends brownie points to @mooli88 :sparkles: :thumbsup: :sparkles:
:star: 248 | @mooli88 | http://www.freecodecamp.com/mooli88
Markus Kiili
@Masd925
Apr 21 2016 08:53
@EldarT90 undefined is a special placeholder value in JS.
alpox
@alpox
Apr 21 2016 08:53
It says something like: here is no value @EldarT90
Blauelf
@Blauelf
Apr 21 2016 08:53
@EldarT90 Sum of undefined and a number will never equal a number (you could also use NaN, or a string, or some other things that are not coerced to some reasonable number). That's why those elements won't be used in another iteration.
Eldar Tinjić
@EldarT90
Apr 21 2016 08:53
but how then it figured out which combo has lowest sum
Codemzy
@codemzy
Apr 21 2016 08:53
or as @Blauelf says another option is to use slice just slice off the end str, to the length of target, and compare that sliced section with target to see if it matches. Both those options will then work, no matter the length of target @Rushh
Eldar Tinjić
@EldarT90
Apr 21 2016 08:53
or it was just happy accident ?
or rather coincidence?
Abd-afeez Abd-hamid Adedamola
@Itsdenty
Apr 21 2016 08:54
Not withstanding I will need to check out that article, so I can understand Regex better, because I have been not been so confident with it @Mooli88
Blauelf
@Blauelf
Apr 21 2016 08:56
@EldarT90 You are looping forward in your array, so it will always pick the one with the lowest index first and search for a match that adds to arg (does not have to go backwards as those cases would already have been handled in previous iterations). In that case, it's that easy.
Eldar Tinjić
@EldarT90
Apr 21 2016 08:59
@Blauelf + excellent point i actually waas thinking the same but still it never hurts to ask professionals here :D
tnx for wonderful explanation, 9 algos to go
Frank XC
@tenkdayz
Apr 21 2016 09:01

trying to change the background color of tiles onmouseenter the tiles have transition: background .. this is the js

function hoverfunc(w){
  var temp = w.style.backgroundColor;
  w.style.backgroundColor = "#000";
  setTimeout(function(){
    w.style.backgroundColor = temp;
  },390);
}

I have temp because some tiles have different backgroundColor .. it works but sometimes the tiles stay back if onmouseenter the background color is #000 at that moment. anyone know how to fix this?

the tiles also have onmouseetner = hoverfunc(this);
Blauelf
@Blauelf
Apr 21 2016 09:02
@tenkdayz That happens when you trigger that function within those 390ms.
Frank XC
@tenkdayz
Apr 21 2016 09:03
@Blauelf yes.. that's the problem I'm trying to solve
Bane Tepavcevic
@banet
Apr 21 2016 09:05
Hello guys, I need a help with a lesson "Convert Celsius to Fahrenheit" JS
Blauelf
@Blauelf
Apr 21 2016 09:06
Maybe some check would work like if (w.style.backgroundColor !== "#000") { content of foverfunc }, or something that first detaches the listener and then re-attaches it.
Bane Tepavcevic
@banet
Apr 21 2016 09:06
function convertToF(celsius) {
  // Only change code below this line

  var fahrenheit = (9/5 + 32) ;

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

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

"Place your code between the indicated lines and it will be tested against multiple test cases.

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

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

Blauelf
@Blauelf
Apr 21 2016 09:07
@banet Use variable celsius in your formula.
Bane Tepavcevic
@banet
Apr 21 2016 09:08
but telling me that celsius variable is already declare...
Blauelf
@Blauelf
Apr 21 2016 09:09
You should use the one you got as an argument, not declare your own.
Bane Tepavcevic
@banet
Apr 21 2016 09:10
hmm...
Frank XC
@tenkdayz
Apr 21 2016 09:10
@Blauelf hm I tried that.. it looks like it would work but it doesnt.. I guess the transition is messing with it still.
Hanan Mufti
@h-ARTS
Apr 21 2016 09:12
Hi everyone
How should i interate odd numbers with for loop?
Samuel Cupidon
@Zerazera
Apr 21 2016 09:13
@h-ARTS Think about the parameters of your typical for loop
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:13
@h-ARTS to find if the number is odd num% ==1
Frank XC
@tenkdayz
Apr 21 2016 09:14
@h-ARTS i=1 .. i+=2
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:14
ah num%2 ==1
Frank XC
@tenkdayz
Apr 21 2016 09:14
@Blauelf thanks anyway!
CamperBot
@camperbot
Apr 21 2016 09:14
tenkdayz sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1699 | @blauelf | http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Apr 21 2016 09:15

@h-ARTS You could do something like

for (var num = 1; num < 42; num += 2) {
  // your code
}

or

for (var num = 0; num < 42; num++) {
  if (num % 1) {
    // your code
  }
}

(variable names and start/end need to be replaced by your values)

Bane Tepavcevic
@banet
Apr 21 2016 09:15
@Blauelf thanks anyway ...i am still confuse but will try to solve it. I triyied like var fahrenheit = (9/5 + 32) + celsius;
CamperBot
@camperbot
Apr 21 2016 09:15
banet sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1700 | @blauelf | http://www.freecodecamp.com/blauelf
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:16
@banet can you post your code?
Hanan Mufti
@h-ARTS
Apr 21 2016 09:16
@Blauelf @V1ad1m1r thx but is there any way to insert the code inside the braces?
CamperBot
@camperbot
Apr 21 2016 09:16
h-arts sends brownie points to @blauelf and @v1ad1m1r :sparkles: :thumbsup: :sparkles:
Blauelf
@Blauelf
Apr 21 2016 09:16
@banet celsius times 9/5, plus 32 ("times" means *, "plus" means +)
CamperBot
@camperbot
Apr 21 2016 09:16
:star: 1701 | @blauelf | http://www.freecodecamp.com/blauelf
:star: 285 | @v1ad1m1r | http://www.freecodecamp.com/v1ad1m1r
Hanan Mufti
@h-ARTS
Apr 21 2016 09:16
like
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:17
@h-ARTS not sure I understand. Code?
Hanan Mufti
@h-ARTS
Apr 21 2016 09:17
for (var i = 1; i <10; *here code*)?
Blauelf
@Blauelf
Apr 21 2016 09:17
Oh, I got my NCC-1701 :)
1701 brownie points. Is there a way to freeze those? :D
@h-ARTS That's the i+=2 version. (add-assign 2 to i, short for i = i + 2)
Markus Kiili
@Masd925
Apr 21 2016 09:18
@Blauelf Start giving bad advice ;)
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:18
@h-ARTS the 3rd section of the for loop states what happens at the end of the loop ie. for (variable is ; as long as ; do at the end)
Bane Tepavcevic
@banet
Apr 21 2016 09:19
@Blauelf Big thanks man! :)
CamperBot
@camperbot
Apr 21 2016 09:19
banet sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: banet already gave blauelf points
Hanan Mufti
@h-ARTS
Apr 21 2016 09:19
@V1ad1m1r thanks :+1:
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:19
yup :) hope that helps
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:26
Grrr.. this twitter API is messing with my mind.
This message was deleted
alpox
@alpox
Apr 21 2016 09:29
@V1ad1m1r Twitter api? you only need a link
Eldar Tinjić
@EldarT90
Apr 21 2016 09:29
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  for (i=0;i<arguments[0].length;i++) {
      if (arguments[0][i][1] == source) {
        return 1;
      }

  }


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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
why this wont return 1
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:29
@alpox to have it post the quote to twitter?
Dave Melia
@Dave-Melia
Apr 21 2016 09:29
How can you get form input data to store in a variable? I've tried getElementsByName and I've tried getElementbyId, but both return undefined
Eldar Tinjić
@EldarT90
Apr 21 2016 09:29
for this example ofc
alpox
@alpox
Apr 21 2016 09:30
@V1ad1m1r yup, you have to change the href of the link...
https://twitter.com/intent/tweet?url=" + <yourQuote> + "&original_referer=<your name>
Blauelf
@Blauelf
Apr 21 2016 09:31
@EldarT90 arguments[0][i] (why not use collection[i]?) is not an array. Also, source is an object.
alpox
@alpox
Apr 21 2016 09:31
@Dave-Melia Form input data? https://api.jquery.com/serialize/ may help you
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:31
@alpox hmm. I have it set up as a button instead of a link. was going to use the API to have js output the quote. But if thats all i need :)
Dave Melia
@Dave-Melia
Apr 21 2016 09:31
@alpox do you ever sleep?
alpox
@alpox
Apr 21 2016 09:32
@V1ad1m1r You can also do it with a button... set a click function to the button and let it window.open
@Dave-Melia I'm at university :D
@Dave-Melia And i did sleep! ^^
@Dave-Melia Sry it seems that this link wouldn't help you :-/ i got you wrong
Eldar Tinjić
@EldarT90
Apr 21 2016 09:34
@Blauelf so how do i target property without using string, because that way i cant make it general
alpox
@alpox
Apr 21 2016 09:35
@Dave-Melia you want var yourValue = $("#<yourinputid>").val();
Blauelf
@Blauelf
Apr 21 2016 09:36
@EldarT90 You can get source's property names for example by using var keys = Object.keys(source);. Using a for-in loop would do about the same.
Dave Melia
@Dave-Melia
Apr 21 2016 09:36
var inputData = document.getElementById("searchWiki")[0].value; is what I tried
alpox
@alpox
Apr 21 2016 09:36
@Dave-Melia That looks okay
Dave Melia
@Dave-Melia
Apr 21 2016 09:36
undefined :)
brb
alpox
@alpox
Apr 21 2016 09:37
@Dave-Melia Well i'm not sure what the [0] is for
@Dave-Melia I guess you should remove that part
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:37

@alpox like so

js
 $(.twitter).on("click", function(){
   $.getJSON(url, function(tweet) 
 $.window.open("https://twitter.com/intent/tweet?url=" + tweet.quoteText + "-" + tweet.quoteAuthor + "&original_referer=<your name>");

             });
  });

?

alpox
@alpox
Apr 21 2016 09:37
@V1ad1m1r You don't have to call the api with getJSON
Eldar Tinjić
@EldarT90
Apr 21 2016 09:38
@Blauelf and value of key?
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:38
@alpox ah. actually, I shouldnt. It would change the quote... good call.
Blauelf
@Blauelf
Apr 21 2016 09:39
@EldarT90 Value would be something like source[keys[0]] for first property, which should match collection[i][keys[0]]. Better use a loop instead of hard-coding 0.
alpox
@alpox
Apr 21 2016 09:40
@V1ad1m1r you can set the quote as example globally
var quote, author;
...
quote = "";
author = "";
$.getJSON(url, function(data) {
  quote = data.quoteText;
  author = data.quoteAuthor;
});
...
$(.twitter).on("click", function(){
   if(!quote || !author) return;
   window.open("https://twitter.com/intent/tweet?url=" +quote + "-" + author + "&original_referer=<your name>");
  });
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:41
@alpox is there a way to assign the retrieved json to a single variable?
alpox
@alpox
Apr 21 2016 09:42
@V1ad1m1r just use an object instead then
@V1ad1m1r You can also just store it as you get it
Kevin
@KevinBruland
Apr 21 2016 09:42
man, I came up with a completely different solution to one of the alogrithm exercises than I am finding online
Claudio Restifo
@Marmiz
Apr 21 2016 09:42

Hello lovely codes, I'd like some help on my Seek and Destroy filter:

I have correctly isolated the numbers i need to filter and stored them in:
var args.

I thought that once I had my elements all i needed to do was filtering out my values in such way:

function filter(arr){
    return arr !== args;
  }

But despite args is storing the correct values, my function fail to do its job... idea why?

Markus Kiili
@Masd925
Apr 21 2016 09:45
@Marmiz Post the whole code please.
shubham kanwal
@shubhamkanwal
Apr 21 2016 09:46
How to upload screenshots in FreeCodeCamp chats
Markus Kiili
@Masd925
Apr 21 2016 09:46
@Marmiz You should use .filter() method on arr.
Eldar Tinjić
@EldarT90
Apr 21 2016 09:46
@Blauelf tnx but i have another problem i think
CamperBot
@camperbot
Apr 21 2016 09:46
eldart90 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1703 | @blauelf | http://www.freecodecamp.com/blauelf
Eldar Tinjić
@EldarT90
Apr 21 2016 09:46
why is this giving me object objec
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  var k =  Object.keys(source);
  var real = source[k[0]];

  for (i=0;i<arguments[0].length;i++) {
      if (collection[i][k[0]] == real) {
        arr = arr + [collection[i]];
      }


  }


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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
i know i need to call it from inside function, but if i add arr inside, nothing will happen
if i add return collectioni - again it wont matter
Claudio Restifo
@Marmiz
Apr 21 2016 09:46
@Masd925 here it is:
function destroyer(arr) {
  // Remove all the values

  var args = Array.from(arguments); // create an array from the arguments.
  args.splice(0,1); //isolate the second part of the array.

  function filter(arr){
    return arr !== args;
  }

  var filtered = arr.filter(filter);
  //console.log(filtered);
  //console.log(args);
  return filtered;
  //return ;
}
destroyer(["tree", "hamburger", 53], "tree", 53);
Blauelf
@Blauelf
Apr 21 2016 09:47
@EldarT90 Use arr.push(collection[i]);, as plus with arrays converts to string.
Markus Kiili
@Masd925
Apr 21 2016 09:48
@Marmiz The filter callback parameter is going to be each arr element in its turn. You cannot check if it is not in args by !==. You are comparing a number or string to an array.
Claudio Restifo
@Marmiz
Apr 21 2016 09:49
@Masd925 so i should use indexOf() method?
Markus Kiili
@Masd925
Apr 21 2016 09:49
@Marmiz Yes.
Claudio Restifo
@Marmiz
Apr 21 2016 09:50
@Masd925 kappa! I'll try it out. Thanks for now :+1:
CamperBot
@camperbot
Apr 21 2016 09:50
marmiz sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1396 | @masd925 | http://www.freecodecamp.com/masd925
Blauelf
@Blauelf
Apr 21 2016 09:51
@EldarT90 And while probably not doing any harm, your variable i is undeclared (read: global)
Eldar Tinjić
@EldarT90
Apr 21 2016 09:52
@Blauelf ye i forget to write var too often i think inside for statements
why .length wont work on source @Blauelf ?
Blauelf
@Blauelf
Apr 21 2016 09:53
source is an object, not an array.
You can use k.length for the number of enumerable properties you got as that array.
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:53
This message was deleted
Claudio Restifo
@Marmiz
Apr 21 2016 09:54
@Masd925 It worked perfectly!! Thanks a lot :clap:
CamperBot
@camperbot
Apr 21 2016 09:54
marmiz sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: marmiz already gave masd925 points
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:54

@alpox

js
 $(.social).on("click", function(){

 window.open("https://twitter.com/intent/tweet?url=" + newJson.quoteText + "-" + newJson.quoteAuthor + "&original_referer=RQM");


  });

i think i have the code, but now I am seeing an unexpected token. not sure what it thinks is "unexpected"

Blauelf
@Blauelf
Apr 21 2016 09:55
Use ".social", not .social
Hanan Mufti
@h-ARTS
Apr 21 2016 09:56
//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 === firstName) {
      return contacts[i][prop];
    }
    else if (firstName !== contacts[i].firstName) {
      return "No such contact";
    }
    else if (contacts[i].firstName && contacts[i][prop] !== prop) {
      return "No such property";
    }
  }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "number");
I can't return the number of Kristian
the first statement is correct but the other two...
V1ad1m1r
@V1ad1m1r
Apr 21 2016 09:56
@Blauelf oh. wow. it must be getting late.
Markus Kiili
@Masd925
Apr 21 2016 09:57
@h-ARTS You are returning no such contact based on one contact.
Kevin
@KevinBruland
Apr 21 2016 09:57
Is anyone familiar enough with the bonfires and able check my code for problems? My answer for Seek and Destroy is very different from other solutions... and I just want to verify that its acceptable
Markus Kiili
@Masd925
Apr 21 2016 09:57
@Benalron Sure.
Vishesh
@vishesh-shrivastav
Apr 21 2016 09:58
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var falsyArr = [false,null,0,"",undefined,NaN];
function checkFalsy(x){
if(falsyArr.indexOf(x) === -1){
return true;
}
return false;
}
return arr.filter(checkFalsy);
}
Hi. This is my solution for Falsy Bouncer bonfire. I am storing the falsy values in an array and then filtering the input array's elements if they are not in the falsy array. It passes the first two test cases, however returns [NaN] and [1, Nan,2] for the third and fourth test cases respectively. Why is this happening ? Is it because of some property of NaN ?
Kevin
@KevinBruland
Apr 21 2016 09:58
thanks, @Masd925 ... ill post it
CamperBot
@camperbot
Apr 21 2016 09:58
benalron sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1397 | @masd925 | http://www.freecodecamp.com/masd925
Kevin
@KevinBruland
Apr 21 2016 09:58
function destroyer(arr) {
  for (x=0; x<arguments[0].length; x++){
    for (y=1; y<arguments.length; y++){
      if (arguments[0][x] === arguments[y]){
        delete arguments[0][x];
      }
    }
  }
  arr = arr.filter(Boolean);
  return arr;
}

destroyer([3, 5, 1, 2, 2], 2, 3, 5);
Hanan Mufti
@h-ARTS
Apr 21 2016 09:58
@Masd925 yes and now should I return the number of Kristian?
Blauelf
@Blauelf
Apr 21 2016 09:58
@h-ARTS That first condition is right, but it says nothing about the existence of that property. That second - you cannot tell whether that person is in the array unless you have tested them all (so move that return after your loop). You might want to do a nested if instead of if-elseif to avoid && (if-elseif requires both conditions to contain &&). And review the challenge Testing Objects for Properties
Markus Kiili
@Masd925
Apr 21 2016 09:58
@vishesh-shrivastav Yes, NaN===NaN is false.
@Benalron Your code doesn't work if arr contains zeros.
Kevin
@KevinBruland
Apr 21 2016 10:01
@Masd925 oh, good point... because it would remove them with Boolean
@Masd925 could I then just switch it to remove nulls specifically, and would it be fine?
Hanan Mufti
@h-ARTS
Apr 21 2016 10:01
@Blauelf Thank you so much i was searching this method :smile:
CamperBot
@camperbot
Apr 21 2016 10:01
h-arts sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: h-arts already gave blauelf points
Markus Kiili
@Masd925
Apr 21 2016 10:02
@Benalron Try: function(){return true;} as a callback. It removes holes.
Kevin
@KevinBruland
Apr 21 2016 10:02
@Masd925 good idea, thanks
CamperBot
@camperbot
Apr 21 2016 10:02
benalron sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: benalron already gave masd925 points
V1ad1m1r
@V1ad1m1r
Apr 21 2016 10:04
thanks @Blauelf @alpox I finally got it :)
CamperBot
@camperbot
Apr 21 2016 10:04
v1ad1m1r sends brownie points to @blauelf and @alpox :sparkles: :thumbsup: :sparkles:
:star: 1704 | @blauelf | http://www.freecodecamp.com/blauelf
:star: 576 | @alpox | http://www.freecodecamp.com/alpox
Markus Kiili
@Masd925
Apr 21 2016 10:05
@Benalron Because your code uses an array with holes, the code becomes somewhat hard to understand.
Kevin
@KevinBruland
Apr 21 2016 10:06
@Masd925 that makes sense also, I think I am going to try and redo it using .filter
@Masd925 I tried using .splice instead of delete... but I was having issues with that deleting more than one occurrence of numbers
Markus Kiili
@Masd925
Apr 21 2016 10:08
@Benalron Using .filter() on arr is a good idea.
Blauelf
@Blauelf
Apr 21 2016 10:08
Splice messes with the index, so one would need to adjust that one. I still don't like splice that much (at least not if it introduces unspecified side-effects to the function)
Vishesh
@vishesh-shrivastav
Apr 21 2016 10:08
@Masd925 thanks
CamperBot
@camperbot
Apr 21 2016 10:08
vishesh-shrivastav sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1398 | @masd925 | http://www.freecodecamp.com/masd925
Kevin
@KevinBruland
Apr 21 2016 10:09
@Masd925 the reason I switched to doing it the way I did was struggling to figure out how to use.filter() with a variable amount of arguments. I tried initially putting it inside a loop, but learned you can not do that
Blauelf
@Blauelf
Apr 21 2016 10:11
@Benalron Why should one not be able to do that? The only thing to remember is that inner function (unless they are ES6 arrow functions) have their own arguments object, so one has to make the outer function's arguments (or its content) accessible in some way.
Kevin
@KevinBruland
Apr 21 2016 10:11
@Blauelf huh, maybe I will try it again. I got an error saying you can not put functions inside of for loops
Markus Kiili
@Masd925
Apr 21 2016 10:12
@Benalron It is better to filter only once and loop the arguments inside filter callback.
Blauelf
@Blauelf
Apr 21 2016 10:12
@Benalron What you did was get a warning that one should not create functions inside loops, as in every iteration a new function object is created. You could create the function outside and pass it via some variable, or do the looping inside the callback instead.
Kevin
@KevinBruland
Apr 21 2016 10:13
@Masd925 @Blauelf ahhh... that completely makes sense now, thanks.
CamperBot
@camperbot
Apr 21 2016 10:13
benalron sends brownie points to @masd925 and @blauelf :sparkles: :thumbsup: :sparkles:
:warning: benalron already gave masd925 points
:star: 1705 | @blauelf | http://www.freecodecamp.com/blauelf
Chris N
@lymeswold
Apr 21 2016 10:14
Is there any way within the code editor to move the cursor without moving my hand from the 'home' position? I'm finding it quite physically painful after a few hours of reaching for the End key to move beyond eg a right parenthesis, and then having to go back to the home position. What IS this editor?
Liu Zhiqun
@lzhiqun
Apr 21 2016 10:17
I cant find my mistake :(

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

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

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

Chris N
@lymeswold
Apr 21 2016 10:17
(sorry if I'm asking this in the wrong forum)
Markus Kiili
@Masd925
Apr 21 2016 10:17
@lzhiqun The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
So .checkProp doesn't work. It looks for property key "checkProp".
Liu Zhiqun
@lzhiqun
Apr 21 2016 10:18
ahhh I see. Ok I'll try the bracket notation. Thanks alot Markus!
Dave Melia
@Dave-Melia
Apr 21 2016 10:21
@alpox still can't get it to work :(
Claudio Restifo
@Marmiz
Apr 21 2016 10:22

Have I found a bug or something is wrong in my code?
In Where do I belong I come up with this code:

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.

  //sort the array in ascending order.
  arr.sort(function(a, b){
    return a-b;
  });
  //compare the number to the array and return the index while found.
  for (var a in arr){
    if (arr[a] >= num){
      return a;
    } 
  }

  return arr.length;
}

The values that are returned all all correct for the test cases... bus somehow it does not pass.
Something wrong in my code or is a known issue?

Blauelf
@Blauelf
Apr 21 2016 10:27
@Marmiz While for-in is not guaranteed to work that way (for-in loops in arbitrary order, for arrays this usually is the same order as you expect, just not guaranteed, for object it is usually the order of property creation), I don't see something really wrong. Have you tried reloading the page?
Hanan Mufti
@h-ARTS
Apr 21 2016 10:29
//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 === firstName) {
      if (contacts[i].firstName != firstName) {
        return "No such contact";
      }
      if (contacts[i].firstName && contacts[i].hasOwnProperty(prop) === false) {
        return "No such property";
      }
      return contacts[i][prop];
    }
  }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Bob", "number");
Now why is the 2nd condition not working?
Markus Kiili
@Masd925
Apr 21 2016 10:29
@h-ARTS Return no such contact only after checking all the contacts.
Claudio Restifo
@Marmiz
Apr 21 2016 10:31

@Blauelf Tried that already. Nothing changed, It's weird because I checked all the condition manually and seems to work.

Regarding the while in loop, the outcome should be fine since the array is sorted before reaching the loop (or at lea