These are chat archives for FreeCodeCamp/HelpJavaScript

15th
May 2016
Jemal Mohammed
@JemalMoha
May 15 2016 00:01
@bensm1th i did
Ben Smith
@bensm1th
May 15 2016 00:02
@JemalMoha thanks
CamperBot
@camperbot
May 15 2016 00:02
bensm1th sends brownie points to @jemalmoha :sparkles: :thumbsup: :sparkles:
:cookie: 192 | @jemalmoha |http://www.freecodecamp.com/jemalmoha
Stephen James
@sjames1958gm
May 15 2016 00:03
@hjernefrys Is it acting like it is only operating on the last element of the list
http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example
hjernefrys
@hjernefrys
May 15 2016 00:07
@sjames1958gm the problem is that I can't "place" the images before the class for them are created. How it is now they are loaded before they can be placed in the document
Tones
@tonyszhang
May 15 2016 00:11
thanks @DanCouper @Masd925
CamperBot
@camperbot
May 15 2016 00:11
tonyszhang sends brownie points to @dancouper and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1489 | @masd925 |http://www.freecodecamp.com/masd925
:cookie: 82 | @dancouper |http://www.freecodecamp.com/dancouper
Trenton Stiles
@blzre
May 15 2016 00:13

I have to detect palindromes with my code and it needs to return a True or a False.
Everything works for regular words like "racecar" or "eye"
But when its tested against

palindrome("0_0 (: /-\ :) 0-0")

this will return false, when its supposed to return true.....

heres my code:


function palindrome(str) {
  // Good luck!
  var arrayHold = [];
  var revString;
  var revHold;

  // clean up input

  //lowercase str
  str = str.toLowerCase();
  //remove spaces from str
  str = str.replace(/ +/g, "");
  //remove non alpha numeric chars from str
  str = JSON.stringify(str).replace(/\W/g, '');
  //reversing the lowered str...

  //put str into an array
  for (var i = 0; i < str.length; i++) {
    arrayHold.push(str[i]);
  }

  //reversed the array
  arrayHold = arrayHold.reverse();

  //turn array into a string
  revString = arrayHold.join("");

  // palindrome check
  if (revString === str) {
    return true;
  } else {
    return false;
  }
}



palindrome("eye");
hjernefrys
@hjernefrys
May 15 2016 00:14
wouldn't this cause the problem? //remove non alpha numeric chars from str
Trenton Stiles
@blzre
May 15 2016 00:16
I think that is actually the problem but the challenge wants me to take our characters like "," out
and even if its filtering this out it should still come out as true to equal the same thing
WAIT A SECOND
I see what the issue is
the filter that handles the non alpha characters does something special with Underscore.. so thats probably why its not returning True..
ayyyyyyyyyyyyyyyyyy
I solved it...
hjernefrys
@hjernefrys
May 15 2016 00:19
great!
Trenton Stiles
@blzre
May 15 2016 00:19
str = JSON.stringify(str).replace(/[^0-9a-z]/gi, '');
Aryan
@aryandua
May 15 2016 00:19
@hjernefrys remember me?
hjernefrys
@hjernefrys
May 15 2016 00:19
yes
hjernefrys
@hjernefrys
May 15 2016 00:19
:-)
Aryan
@aryandua
May 15 2016 00:19
Look what I got because of you :)
It doesnt work in chrome though :(
hjernefrys
@hjernefrys
May 15 2016 00:20
ah, I'm on chrome right now
Aryan
@aryandua
May 15 2016 00:20
Just copy the link into internet explorer
Stephen James
@sjames1958gm
May 15 2016 00:21
@hjernefrys I put a return before $.deferred
hjernefrys
@hjernefrys
May 15 2016 00:23
@aryandua glad that you figured out API's!
Aryan
@aryandua
May 15 2016 00:23
Its only because of you
I cannot thank you enough :)
that video was descriptive
hjernefrys
@hjernefrys
May 15 2016 00:24
:+1:
96street
@96street
May 15 2016 00:25
Can someone help me on Seek and Destroy:
function destroyer(arr) {

  var remove = 0;

  for(var i = 0; i < arr.length; i++){
    if(arguments[i] == arguments[1] || arguments[2]) {
      remove = arr.splice(arguments[i]);
    }
  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
hjernefrys
@hjernefrys
May 15 2016 00:25

@sjames1958gm like this?

´´´js
if (online === null) {
$("#users").append('<div class="col-lg-12">' + '<a href="https://www.twitch.tv/' + currentUser + '"' + '>' + currentUser + '</a>' + '<span class="profile-img' + [i] + '">' + '<span class="offline"> offline </span> </span>' + '</div>')
return;

                $.deferred.then(function() {

                  $.ajax({
            dataType: "json",
            url: "https://api.twitch.tv/kraken/channels/" + users[i],
            success: function(data) {

                var userLogo = data.logo;
                var profileImgNumber = ".profile-img" + [i];
                $('<img src="' + userLogo + '">').appendTo(profileImgNumber);
            }
        });

´´´

Stephen James
@sjames1958gm
May 15 2016 00:27
@hjernefrys Sorry I meant hit enter - there was not space between)$
@96street Your if does not have valid syntax, and you have to support more than just two trailing arguments.
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 00:28
@96street What is the problem ?
hjernefrys
@hjernefrys
May 15 2016 00:28
@96street I would have a look at array.filter
96street
@96street
May 15 2016 00:28
What isn't valid? @sjames1958gm
Jamie C
@jamiec92
May 15 2016 00:29
Need help on the 'Word Blanks' challenge? The previous challenges dont really help much or am I just being really thick.
Moisés Man
@moigithub
May 15 2016 00:29
@hjernefrys u ahve 2 $("#users").append( etc etc whats the difference.. can u refactor ? extract the diference on another variable...
96street
@96street
May 15 2016 00:30
I'm trying to say in my code if an object from the first array is the same from the 2nd or 3rd argument (2 or 3) remove it from the array
Moisés Man
@moigithub
May 15 2016 00:31
@hjernefrys
somethin like
if (online){
   status = '<span class="online"> online </span>';
}else{
   status = '<span class="offline"> offline </span>';
}
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 00:32
@96street Array.filter is worth a look. If you want to do it manually be carreful of what the function returns.
96street
@96street
May 15 2016 00:32
But what bit is actually wrong in my code? @GuillaumeRobbe
hjernefrys
@hjernefrys
May 15 2016 00:33

@moigithub yes, I could refactor it, but wouldn't the problem still be this: <span class="profile-img' + [i] + '">
and this:
´´´
$.ajax({
dataType: "json",
url: "https://api.twitch.tv/kraken/channels/" + users[i],
success: function(data) {

                var userLogo = data.logo;
                var profileImgNumber = ".profile-img" + [i];
                $('<img src="' + userLogo + '">').appendTo(profileImgNumber);
            }
        });

´´´

Guillaume Robbe
@GuillaumeRobbe
May 15 2016 00:33
@96street I assume you want you filtered array in your remove variable ? And you are returning arr instead.
96street
@96street
May 15 2016 00:34
i thought arr.splice() makes it's own array of the removed variables?
just the removed variables
Moisés Man
@moigithub
May 15 2016 00:36
@hjernefrys put ur login inside the second ajax success function
n forget about ajax promises :P (cuz easier with nested functions)
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 00:36
@96street Oh yes you are right, my bad.. But you must also tell how many elements you want to remove as second parameter.
96street
@96street
May 15 2016 00:37
right
Moisés Man
@moigithub
May 15 2016 00:37
@hjernefrys
$ajax(  .... success:function(data1){
  /// do NOT html append here
   $ajax( ...success:function(data2){
             here mix data1 + data2
                 /// apend all ur html here
   })
})
96street
@96street
May 15 2016 00:37
i'm unsure how to do that as the number of elements to remove is unknown
@GuillaumeRobbe
hjernefrys
@hjernefrys
May 15 2016 00:39
@moigithub thanks!
CamperBot
@camperbot
May 15 2016 00:39
hjernefrys sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 1141 | @moigithub |http://www.freecodecamp.com/moigithub
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 00:41
That's why you have your if statement to check if the current element of the array is similar to 2nd or 3rd arguments. If so you have to remove this specific element. So the number to remove is one. @96street
Jamie C
@jamiec92
May 15 2016 00:41
Help on Word Blank challenge?
CamperBot
@camperbot
May 15 2016 00:41
no wiki entry for: on word blank challenge
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 00:42
@96street Also be carreful the first parameter of splice is the position of the element to delete not the element itself.
Jamie C
@jamiec92
May 15 2016 00:48
Word Blank Challenge?
Skerins
@Skerins
May 15 2016 01:03
Help on Word Blank challenge?
What did you need help with?
Dylan Zitzmann
@dtzitz
May 15 2016 01:03
hello everyone
Jamie C
@jamiec92
May 15 2016 01:04
@Skerins I am just a little unsure of what to put in?
Marvin Andara
@babycakez
May 15 2016 01:04
Hello guys. Im currently working on the weather app challenge. If anyone could help me with the js for the getJSON part. It won’t even say its an object. Doesnt seem like its returning anything. I tried other JSON and I would at least get a response. http://codepen.io/Babycakez/pen/jqRaaB
Dylan Zitzmann
@dtzitz
May 15 2016 01:04
hey @babycakez i am in a similar situation lol
Marvin Andara
@babycakez
May 15 2016 01:05
I think im doing it correctly and probably have for a while but its making me think im wrong lol.
Dylan Zitzmann
@dtzitz
May 15 2016 01:06
lol, you can take a look at mine... i am stuck with a closure problem
well, i could push on but it's going to cause problems later
Skerins
@Skerins
May 15 2016 01:06
@jamiec92 If I recall correctly, you need to build a new string, using the variables, and add space in between them . You can add + " " + for blank spaces.
need to look at the console for the interesting bits
Aparna
@Aparna-S
May 15 2016 01:08
am still stuck with Nesting For Loops .. can anyone help me understand this part ?
Dylan Zitzmann
@dtzitz
May 15 2016 01:08
hey @babycakez you never define Coords
I don't think
Marvin Andara
@babycakez
May 15 2016 01:08
@dtzits I think the weatherapi thing doesnt work properly because if you paste the link in browser it there but it wont return it to me so I can use it. I tried other api to verify I was doing it correctly and it returned an object.
Aparna
@Aparna-S
May 15 2016 01:08
myc ode :

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 1; i<arr.length; i++) {
for (var j=1; j < arr[i].length; j++){
product = (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]]);

Jamie C
@jamiec92
May 15 2016 01:13
@Skerins How do I go about that? I bet its pretty straughtforward and I am just being a bit thick.
Islam Ibakaev
@dagman
May 15 2016 01:14
@Aparna-S product = (i * j);
Dylan Zitzmann
@dtzitz
May 15 2016 01:15
@babycakez i'm just saying that $.getJSON(Coords maybe should be $.getJSON(finalCoords
Islam Ibakaev
@dagman
May 15 2016 01:15
@Aparna-S arr[i] is a every inner array
Skerins
@Skerins
May 15 2016 01:15

@jamiec92 Essentially , you need to give the, "result" variable a string of items to call back when, "return result;" is called. So, result = function variable + " " + function variable + etc.

Let me know if you need further explanation. I'm trying not to to give away the game for you. ;D

Islam Ibakaev
@dagman
May 15 2016 01:15
@Aparna-S arr[i][j] elements in every inner array
Joshua Swift
@joshuaswift
May 15 2016 01:17
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
hey guys, I need to access the first 2 which isn't inside the square brackets. How would I go about this?
96street
@96street
May 15 2016 01:18
@GuillaumeRobbe thanks that definately helps, getting close now
CamperBot
@camperbot
May 15 2016 01:18
96street sends brownie points to @guillaumerobbe :sparkles: :thumbsup: :sparkles:
:cookie: 300 | @guillaumerobbe |http://www.freecodecamp.com/guillaumerobbe
Aparna
@Aparna-S
May 15 2016 01:18
@dagman can you tell me if this is correct? - here - multiplyAll([[1,2],[3,4],[5,6,7]]); --> arr[i] refers to number of rows i.e. 1 and j = arr[i].length refers to no of columns that is 3?
96street
@96street
May 15 2016 01:19
This is my code atm (Seek and Destroy)
function destroyer(arr) {

  for(var i = 0; i < arr.length; i++){
    if(arguments[i] == arguments[1] || arguments[2]) {
      arr.splice(arguments[i], 1);
    }
  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
it's logging: [2,3,2] - not sure why
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:20
@96street Thanks! Once you're done with the splice method you should try with the filter one. That the best for removing elements in arrays.
CamperBot
@camperbot
May 15 2016 01:20
:cookie: 250 | @96street |http://www.freecodecamp.com/96street
guillaumerobbe sends brownie points to @96street :sparkles: :thumbsup: :sparkles:
96street
@96street
May 15 2016 01:20
Yes I will
do you know why it's logging [2,3,2]? @GuillaumeRobbe
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:20
@96street Yes =)
@96street splice first arguments is the position of the element to remove, not the element itself.
96street
@96street
May 15 2016 01:22
arr.arguments[i]?
or arguemnts[arr[i]]?
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:23
in arr.splice(arguments[i ), 1)
Jamie C
@jamiec92
May 15 2016 01:23
@Skerins I cant get it man sorry :(
96street
@96street
May 15 2016 01:24
arr.splice(arguments[arr[i]], 1)
is logging [1,2,3] so i think that's right
Skerins
@Skerins
May 15 2016 01:24

@jamiec92 No worries. Don't get discouraged.

// Your code below this line

result = myNoun + " " + myAdjective + " " + myVerb + " " + myAdverb;

96street
@96street
May 15 2016 01:24
just needa remove the number if they appear more than once
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:24
what you want is the position of the element to remove.
Since you are processing arr with the i variable...
96street
@96street
May 15 2016 01:25
I thought you said the element itself, not 'the position of the element to remove'
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:25
help Caesars Cipher
CamperBot
@camperbot
May 15 2016 01:25

:point_right: algorithm caesars cipher [wiki]

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :memo:

:checkered_flag: Problem Explanation:

  • You need to write a function, which will take a string encoded with
    Caesar cipher as a parameter and decode it.
  • The one used here is ROT13 where the value of the letter is
    shifted by 13 places.
    e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
  • You have to shift it back 13 positions, such that 'N' ↔ 'A'.

:pencil: read more about algorithm caesars cipher on the FCC Wiki

Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:27
You also have a problem in your if
96street
@96street
May 15 2016 01:28
What's the problem?
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:29
your i variable is used to process arr not arguments
96street
@96street
May 15 2016 01:31
ahh yep
will fix that now
still giving the same result
this is what i've got now:
function destroyer(arr) {

  for(var i = 0; i < arguments.length; i++){
    if(arguments[i] == arguments[1] || arguments[2]) {
      arr.splice(arguments[i], 1);
    }
  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:32
Basically the algorithm is process trhoug arr and if arr[i) === arguments[1 or arr[i) === arguments[2) then you remove it
Norvin Burrus
@ndburrus
May 15 2016 01:32
@Aparna-S were you able to resolve nesting for loops?
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:33
hey on ceasers cipher, how do i check if the ascii code for the character is a letter or not?
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:33
Look at the ascii table ^^
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:33
where can i find that?
Diego Mayer
@Chrono79
May 15 2016 01:34
@96street use array filter instead of loop
96street
@96street
May 15 2016 01:34
function destroyer(arr) {

  for(var i = 0; i < arguments.length; i++){
    if(arr[i] == arguments[1] || arr[i] == arguments[2]) {
      arr.splice(arr[i], 1);
    }
  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@GuillaumeRobbe is this close?
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:34
@GuillaumeRobbe ty
CamperBot
@camperbot
May 15 2016 01:34
isaacabrahamson sends brownie points to @guillaumerobbe :sparkles: :thumbsup: :sparkles:
:cookie: 301 | @guillaumerobbe |http://www.freecodecamp.com/guillaumerobbe
96street
@96street
May 15 2016 01:35
i will just wanna finish this first @Chrono79
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:35
you're wellcome
Diego Mayer
@Chrono79
May 15 2016 01:36
@96street I think that way won't work with this test case:
destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1]
llamatarianism
@llamatarianism
May 15 2016 01:36
@96street splice takes an index as its first argument
so just write arr.splice(i ,1);
that'll remove the value at the current index
@96street @Chrono79 is also correct.
96street
@96street
May 15 2016 01:37
function destroyer(arr) {

  for(var i = 0; i < arguments.length; i++){
    if(arr[i] == arguments[1] || arr[i] == arguments[2]) {
      arr.splice(i, 1);
    }
  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
ok so it removes the number, but not more than once
it's logging [1,3,1,2,3]
llamatarianism
@llamatarianism
May 15 2016 01:37
@96street that's because you're iterating over arguments, not the array.
i < arguments.length;
you stop after the 3rd element.
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:38
Yes that is because you have remove elements from arr and then change the index of the remaining element.
That's the touchy part
Diego Mayer
@Chrono79
May 15 2016 01:39
@96street you can add another condition over arguments[3], but I think using array.filter is better
Aparna
@Aparna-S
May 15 2016 01:39
@ndburrus not yet.. can you tell me if this is correct? - here - multiplyAll([[1,2],[3,4],[5,6,7]]); --> arr[i] refers to number of rows i.e. 1 and j = arr[i].length refers to no of columns that is 3?
Guillaume Robbe
@GuillaumeRobbe
May 15 2016 01:39
completely better =)
96street
@96street
May 15 2016 01:39
can someone give me the answer to this method? then i'm gonna try filter()
llamatarianism
@llamatarianism
May 15 2016 01:39
I got it down to 1 line of actual code using filter
Diego Mayer
@Chrono79
May 15 2016 01:39
@96street add another condition
Norvin Burrus
@ndburrus
May 15 2016 01:40
@Aparna-S that code is for another challenge? i can help with the nested for loops, if you still need some guidance.
Norman Croan
@normancroan
May 15 2016 01:40
Anyone have a moment to look at a JSON object with me to assist with targeting some of the nested values to filter on?
Aparna
@Aparna-S
May 15 2016 01:40
@ndburrus for nesting loops only..belo w is the full code :

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 1; i<arr.length; i++) {
for (var j=1; j < arr[i].length; j++){
product = (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]]);

96street
@96street
May 15 2016 01:41
@Chrono79 not sure what
Norman Croan
@normancroan
May 15 2016 01:41
Looking at this:
{ "player": [{ "key": "10605339", "accountId": 10605339, "data": [{ "id": "HeroBattleTag", "string": "Linfinite#3282" }, { "id": "GameAccount", "number": 10605339 }, { "id": "HeroClass", "string": "demon hunter" }, { "id": "HeroGender", "string": "m" }, { "id": "HeroLevel", "number": 70 }, { "id": "ParagonLevel", "number": 1942 }, { "id": "HeroClanTag", "string": "暗黑空董團" }, { "id": "ClanName", "string": "空氏集團" }, { "id": "HeroId", "number": 74162885 }] }], "order": 1, "data": [{ "id": "Rank", "number": 1 }, { "id": "RiftLevel", "number": 88 }, { "id": "RiftTime", "timestamp": 771116 }, { "id": "CompletedTime", "timestamp": 1460009411000 }, { "id": "BattleTag", "string": "Linfinite#3282" }] }
Diego Mayer
@Chrono79
May 15 2016 01:41

@96street

function destroyer(arr) {

  for(var i = 0; i < arr.length; i++){
    if(arr[i] == arguments[1] || arr[i] == arguments[2] || arr[i] == arguments[3]) {
      arr.splice(i, 1);
      i--;
    }
  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Now do it with filter (this way is not recommended)

Norvin Burrus
@ndburrus
May 15 2016 01:42
@Aparna-S ok, let's take care of some simple housekeeping first. can you review/check your punctuation for completeness? hint: match your curly braces...
96street
@96street
May 15 2016 01:42
what's i-- doing? @Chrono79
Diego Mayer
@Chrono79
May 15 2016 01:43
@96street it's the index of the ith element of the array, you're comparing that value to each of the values you seek to destroy
i-- it's substracting 1 from i because you removed one element of the array with splice
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:43
Ok, I'm confused. This is what I got, but its not working. some characters translate corectly, and others are still char codes... Help?

function rot13(str) {
  var codeArr = [];
  var letters;

  // change to code
  for (var i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) < 65) {
      codeArr.push(str.charAt(i));
    } else {
      codeArr.push(str.charCodeAt(i) - 13);
    }   
  }

  // change back to string
  for (i = 0; i < str.length; i++) {
    if (codeArr[i] < 65) {
      letters += codeArr[i];
    } else {
      letters += String.fromCharCode(codeArr[i]);
    } 
  }

  return letters;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Aparna
@Aparna-S
May 15 2016 01:44
@ndburrus i could find some spacing problem and filled that

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 1; i< arr.length; i++) {
for (var j=1; j < arr[i].length; j++) {
product = (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]]);

anything i missed here regarding the punctuations?
llamatarianism
@llamatarianism
May 15 2016 01:44
@IsaacAbrahamson
if (codeArr[i] < 65) {
  letters += codeArr[i];
}
you're not converting it back into a letter.
Norvin Burrus
@ndburrus
May 15 2016 01:44
@Aparna-S next, we can examine the follownig statement: {in particular, we want to ensure the syntax for accessing an arry element is accurate/correct}
for (var j=1; j < arr[i].length; j++){
llamatarianism
@llamatarianism
May 15 2016 01:45
@Aparna-S you're not mutating product
well you are but
not in the way it wants
Diego Mayer
@Chrono79
May 15 2016 01:45
@IsaacAbrahamson think about the cases where charCodeAt(i) - 13 isn't a letter
llamatarianism
@llamatarianism
May 15 2016 01:45
it wants you to multiply product by each element in the array
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:45
@Chrono79 i did
llamatarianism
@llamatarianism
May 15 2016 01:45
so you need to use *=
Islam Ibakaev
@dagman
May 15 2016 01:45
function destroyer(arr) {
      var toCheck = [arr[1], arr[2]];
      return arr.filter(function(el) {
          return toCheck.indexOf(el) === -1;
      });
}
96street
@96street
May 15 2016 01:46
@Chrono79 oh that's tricky. also why do you have arguments[3] in the if statement if there's only 0, 1 and 2 indexes in the array?
llamatarianism
@llamatarianism
May 15 2016 01:46
@dagman still doesn't work with more than just 2 elements to remove.
Diego Mayer
@Chrono79
May 15 2016 01:46
@IsaacAbrahamson no, I mean is the letter is a B, what ae you doing?
llamatarianism
@llamatarianism
May 15 2016 01:46
since @dagman already basically posted the solution
is it alright if I post mine?
because I like it a lot
Islam Ibakaev
@dagman
May 15 2016 01:47
@llamatarianism yep
llamatarianism
@llamatarianism
May 15 2016 01:47
I just don't really want to give it away
Islam Ibakaev
@dagman
May 15 2016 01:47
@llamatarianism wanna see
llamatarianism
@llamatarianism
May 15 2016 01:47
@96street would you mind if I posted the solution or would you rather figure it out for yourself
Diego Mayer
@Chrono79
May 15 2016 01:47
@96street arguments[0] is arr, arguments 1 to 3 are the rest of the arguments, look at this test case:
destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1]
the 5 is arguments[3]
Aparna
@Aparna-S
May 15 2016 01:48
@llamatarianism oh ok..let me try to crack it up..will c :) @ndburrus yeah..for this line of code .. j++ is not required right? because we are not counting the rows/coluns, we want the value from the table..- is my thinking correct?
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:48
@Chrono79 oh I'm subtracting 13 like im supposed to. I'm confused
Islam Ibakaev
@dagman
May 15 2016 01:48
@llamatarianism does your solution based on es6 stuff?
llamatarianism
@llamatarianism
May 15 2016 01:48
@dagman yeah
arrow functions and Array.includes
Islam Ibakaev
@dagman
May 15 2016 01:49
@llamatarianism this is unfair :smile:
llamatarianism
@llamatarianism
May 15 2016 01:49
all's fair in love and javascript
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:49
@Chrono79 what should I do then
Diego Mayer
@Chrono79
May 15 2016 01:49
@IsaacAbrahamson when you substract 13 it falls before A, and it should fall before Z
you have to do some math to do that
96street
@96street
May 15 2016 01:49
@llamatarianism that makes sense, ty
CamperBot
@camperbot
May 15 2016 01:49
96street sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 596 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
96street
@96street
May 15 2016 01:49
and do you mean mean the proper solution? @Chrono79
Islam Ibakaev
@dagman
May 15 2016 01:49
@llamatarianism u may not show in this case :smile:
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:50
@Chrono79 so str.charCodeAt(i) + 13?
llamatarianism
@llamatarianism
May 15 2016 01:50
function destroyer(arr) {
  return arr.filter(val => !Array.from(arguments).slice(1).includes(val));
}
Norvin Burrus
@ndburrus
May 15 2016 01:51
@Aparna-S oops. i erred. both of the following lines need a little attention (but not what i was thinking previously). the issue is how the counter is working - do you see it? to answer your question, (both) the i++ & j++ are needed/correct - they are simply indicating that the counter value/s be incremented by a value of one for each loop.
for (var i = 1; i<arr.length; i++) {
  for (var j=1; j < arr[i].length; j++){
Islam Ibakaev
@dagman
May 15 2016 01:51
@llamatarianism it's looks elegant but not efficient at all
llamatarianism
@llamatarianism
May 15 2016 01:51
it's JS
Diego Mayer
@Chrono79
May 15 2016 01:51
@IsaacAbrahamson yes
llamatarianism
@llamatarianism
May 15 2016 01:51
it's never gonna be efficient
also keep in mind
yours only works for a known number of arguments
96street
@96street
May 15 2016 01:52
@llamatarianism well that looks much easier
Islam Ibakaev
@dagman
May 15 2016 01:52
@llamatarianism !Array.from(arguments).slice(1) this part is so unefficient
llamatarianism
@llamatarianism
May 15 2016 01:52
what's inefficient about bloody slice
what else am I supposed to do
Diego Mayer
@Chrono79
May 15 2016 01:52

and do you mean mean the proper solution? @Chrono79

I'm lost here, please ask again because I'm looking an another problem right now

llamatarianism
@llamatarianism
May 15 2016 01:52
degrade myself to the level of using shift?
Aparna
@Aparna-S
May 15 2016 01:53
@ndburrus here i refers to rows..it goes like 1, 2..and j refers to column it goes upto 4? because it starts with 1
Islam Ibakaev
@dagman
May 15 2016 01:53
@llamatarianism on every iteration you will be making an array from your arguments object and slicing it
@llamatarianism every time
llamatarianism
@llamatarianism
May 15 2016 01:53
true
Jamie C
@jamiec92
May 15 2016 01:53
@Skerins Thanks a lot I have managed to do it :)
CamperBot
@camperbot
May 15 2016 01:53
jamiec92 sends brownie points to @skerins :sparkles: :thumbsup: :sparkles:
:cookie: 223 | @skerins |http://www.freecodecamp.com/skerins
Aryan
@aryandua
May 15 2016 01:53
Can someone tell me if this tells the weather right for your place
Norvin Burrus
@ndburrus
May 15 2016 01:54
@Aparna-S aah... see revised comments above. an important point here is that the for loop array counter value begins/starts at/with zero... :)
Aryan
@aryandua
May 15 2016 01:54
Follow the link
Islam Ibakaev
@dagman
May 15 2016 01:54
@llamatarianism it is much better just cache it like var toDestroy = [].slice.call(arguments, 1);
and use in your filter
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:55

@Chrono79 here I tried this,


function rot13(str) {
  var codeArr = [];
  var letters;

  // change to code
  for (var i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) < 65) {
      codeArr.push(str.charAt(i));
    } if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 65 + 13) {
      codeArr.push(str.charCodeAt(i) + 13);
    } else {
      codeArr.push(str.charCodeAt(i) - 13);
    }   
  }

  // change back to string
  for (i = 0; i < str.length; i++) {
    if (codeArr[i] < 65) {
      letters += codeArr[i];
    } else {
      letters += String.fromCharCode(codeArr[i]);
    } 
  }

  return letters;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

it works better, but still errors, returns: undefinedFREE 19CODE 19CA instead of FREE CODE CAMP

Bobby McDonald
@BobbyMcWho
May 15 2016 01:55
yes it does @aryandua
Aryan
@aryandua
May 15 2016 01:55
thanks @BobbyMcWho
CamperBot
@camperbot
May 15 2016 01:55
aryandua sends brownie points to @bobbymcwho :sparkles: :thumbsup: :sparkles:
:cookie: 295 | @bobbymcwho |http://www.freecodecamp.com/bobbymcwho
Aparna
@Aparna-S
May 15 2016 01:55
@ndburrus oh right...but you know what, even if i give 1 ..its giving me the same dfault answer as 4 :P

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 = (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]]);

Islam Ibakaev
@dagman
May 15 2016 01:56
@Aparna-S product = (i * j);
Justin Woodward
@jwoo92
May 15 2016 01:56
@aryandua it showed the correct temperature for my location.
Norvin Burrus
@ndburrus
May 15 2016 01:56
@Aparna-S ok, we're making progress. there is another item that can be cleaned up. the item is the way in which the result is being generated. can you spot how to correct the result calculation? here is what we're after: "Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr"
Diego Mayer
@Chrono79
May 15 2016 01:56
@IsaacAbrahamson why don't you convert all to codes and then convert all to string? You're not converting all back
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 01:56
This message was deleted
Aryan
@aryandua
May 15 2016 01:57
thx @jwoo92
CamperBot
@camperbot
May 15 2016 01:57
aryandua sends brownie points to @jwoo92 :sparkles: :thumbsup: :sparkles:
:cookie: 320 | @jwoo92 |http://www.freecodecamp.com/jwoo92
Ben Smith
@bensm1th
May 15 2016 01:59
can anyone help me on a codewars code challenge?
and this is my answer:
function autocomplete(input, dictionary) {
var matches = [];
var re = new RegExp('\^' + input, 'gi');
dictionary.forEach(e=>((e.replace(/[^a-zA-Z]/g,"")).match(re))?matches.push(e):matches=matches);
return matches.slice(0,5);
}
Diego Mayer
@Chrono79
May 15 2016 02:00
@IsaacAbrahamson letters is undefined, define it like this: var letters = "";
also use else if here: } if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 65 + 13) {
Joseph
@revisualize
May 15 2016 02:00
@bensm1th You're in the FreeCodeCamp.com/HelpJavaScript for getting help on basic JavaScript and Algorithms Challenges. And you're asking for help on CodeWars challenges?
Norvin Burrus
@ndburrus
May 15 2016 02:00
@Aparna-S since the for loop statements provide the means to loop through each value of the array (& sub-array) - we use those variables to calculate the result....
Ben Smith
@bensm1th
May 15 2016 02:01
@revisualize I don't see why that's a problem...
Norvin Burrus
@ndburrus
May 15 2016 02:01
@Aparna-S now, would be a good time to revisit the following example code:
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]);
  }
}
Aparna
@Aparna-S
May 15 2016 02:01
@ndburrus ok..so here 1 is [1,2] and j is [3,4] ?
here i is [1,2] *
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 02:02

@Chrono79 changed some math,

function rot13(str) {
  var codeArr = [];
  var letters;

  // change to code
  for (var i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) < 65) {
      codeArr.push(str.charAt(i));
    } if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 65 + 13) {
      codeArr.push(str.charCodeAt(i) + 13);
    } if (str.charCodeAt(i) >= 65 + 13) {
      codeArr.push(str.charCodeAt(i) - 13);
    }   
  }

  // change back to string
  for (i = 0; i < str.length; i++) {
    if (codeArr[i] < 65) {
      letters += codeArr[i];
    } else {
      letters += String.fromCharCode(codeArr[i]);
    } 
  }

  return letters;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

it all works fine, but I got an undifined at the start? undefinedFREE CODE CAMP...

Joseph
@revisualize
May 15 2016 02:02
@bensm1th I'd help you but, I don't have a codewars account.
Diego Mayer
@Chrono79
May 15 2016 02:03
@IsaacAbrahamson see my previous post
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 02:03
ok
Diego Mayer
@Chrono79
May 15 2016 02:03
@IsaacAbrahamson this test case won't pass: rot13("SERR YBIR?")
I suggest (keeping the way you did it) add conditions to only convert Letters
if (str.charCodeAt(i) < 65) { //add a limit here
Norvin Burrus
@ndburrus
May 15 2016 02:04
@Aparna-S ok, let's not think about what the array is. the format of the array is illustrated as the varying test inputs shown. we're focusing on the concept of working with multidimensional arrays & iterating through them...
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 02:04
it looks like the final punctuation ain't working let me test it one sec @Chrono79
Joseph
@revisualize
May 15 2016 02:05
@bensm1th I can't pass the challenge to even create an account.
Moisés Man
@moigithub
May 15 2016 02:06
@IsaacAbrahamson why 65 + 13 ??? what those numbers mean ?
Aparna
@Aparna-S
May 15 2016 02:06
@ndburrus ok... so how s the next step ??
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 02:07
@moigithub makes sure subtracting 13 from letter won't be less than A, Example: 65 -13 is a punctuation mark not letter
Norvin Burrus
@ndburrus
May 15 2016 02:07
@Aparna-S to answer your question, though, i refers to the number of arrays in the input array. j refers to the number of elements (or position of the elements) in the sub-array. does this make sense?
Diego Mayer
@Chrono79
May 15 2016 02:08
@bensm1th don't you have to filter input before creating the regex?
Aparna
@Aparna-S
May 15 2016 02:08
@ndburrus here i is the array count and elements refers tot he number of values refered in that i array??
Ben Smith
@bensm1th
May 15 2016 02:09
@Chrono79 i will reread it, I thought you just had to filter the dictionary
Diego Mayer
@Chrono79
May 15 2016 02:09

@bensm1th
Important note:

Any input that is NOT a letter should be treated as if it is not there. For example, an input of "$%^" should be treated as "" and an input of "ab*&1cd" should be treated as "abcd".

(Thanks to wthit56 for the suggestion!)

Norvin Burrus
@ndburrus
May 15 2016 02:09
@Aparna-S ok, so since we are able to iterate through each element in the array/subarray, can you see in the example how we can calculate the product result needed?.... sidetrack: yes, to answer your question. i think you're getting it.
Ben Smith
@bensm1th
May 15 2016 02:10
@Chrono79 I misread that as anythingin the citionary
*dictionary
lol, the var name was confused with a regular word
Diego Mayer
@Chrono79
May 15 2016 02:10
@bensm1th I think with that it will pass
Norvin Burrus
@ndburrus
May 15 2016 02:11
@Aparna-S alright. let's go to the example code to see how we can use what we've got to generate the answer...
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]);
  }
}
Ben Smith
@bensm1th
May 15 2016 02:11
@Chrono79 now I pass, thanks
CamperBot
@camperbot
May 15 2016 02:11
bensm1th sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 737 | @chrono79 |http://www.freecodecamp.com/chrono79
Aparna
@Aparna-S
May 15 2016 02:12
@ndburrus multipyling using * ...?
@ndburrus
Norvin Burrus
@ndburrus
May 15 2016 02:12
@Aparna-S ...this is the line you want to focus on:
console.log(arr[i][j]);
@Aparna-S ...and this is the associated text (instructions): "...multiplies the product variable by each number in the sub-arrays of arr"
Chris Lacaille
@ChrisL108
May 15 2016 02:14
Just figured the Twitch.tv API out. Is it okay to nest 2 getJSON()'s?
https://codepen.io/chris1545/pen/YqMjNg?editors=1111
Like I did*
Isaac Abrahamson
@IsaacAbrahamson
May 15 2016 02:14

@Chrono79 got it working


function rot13(str) {
  var codeArr = [];
  var letters = "";

  // change to code
  for (var i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) < 65) {
      codeArr.push(str.charAt(i));
    } if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) < 65 + 13) {
      codeArr.push(str.charCodeAt(i) + 13);
    } if (str.charCodeAt(i) >= 65 + 13) {
      codeArr.push(str.charCodeAt(i) - 13);
    }   
  }

  // change back to string
  for (i = 0; i < str.length; i++) {
    if (codeArr[i] >= 65) {
      letters += String.fromCharCode(codeArr[i]);
    } else {
      letters += codeArr[i];
    }
  }

  return letters;
}

function isLetter(str) {
  return str.length === 1 && str.match(/[a-z]/i);
}
// Change the inputs below to test
rot13("SERR CVMMN!");

Thx a lot!

CamperBot
@camperbot
May 15 2016 02:14
isaacabrahamson sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 738 | @chrono79 |http://www.freecodecamp.com/chrono79
Marvin Andara
@babycakez
May 15 2016 02:15
@dtzitz my bad I went to the grocery store. No that parameter is just a parameter name. Im actually passing in finalCoord. For example function(para1) can be used like this function(whatevernameforvariablebeingpassedin); if you an alert(Coords); inside the function youll see that it has finalCoords data.
Aparna
@Aparna-S
May 15 2016 02:15
@ndburrus does it mean its multiplying the values of j availablein 1 array and logging its result?
available in i array*
Norvin Burrus
@ndburrus
May 15 2016 02:16
@Aparna-S yes. ...and that value is conveiently encapsulated in the element arr[i][j], make sense?
Aparna
@Aparna-S
May 15 2016 02:16
@ndburrus hmmm ya...
Diego Mayer
@Chrono79
May 15 2016 02:17
@IsaacAbrahamson :+1:
Did you use isLetter anywhere?
Norvin Burrus
@ndburrus
May 15 2016 02:17
@Aparna-S so, how would we calculate the product value?
Aparna
@Aparna-S
May 15 2016 02:18
@ndburrus product = arr[i][j]; ?
cdandro
@cdandro
May 15 2016 02:19
@Aparna-S arr[i][j] is the equalivant of doing this
@Aparna-S
var someVarName  = arr[i];
var newValue = someVarName[j];
Norvin Burrus
@ndburrus
May 15 2016 02:20
@Aparna-S hmmm.... the arr[i][j] element value changes because it is within two for loops. we need each of the changed values (as the loops occur) to interact with the product value... see where we're going?
Aparna
@Aparna-S
May 15 2016 02:21
@cdandro in this example it is giving value of i array in newValue?
Diego Mayer
@Chrono79
May 15 2016 02:22
@OneRandomJamie what is troubling you?
cdandro
@cdandro
May 15 2016 02:22
@Aparna-S arr[i] is the outer array while j is being used to ask that value in array[i] about a sub item
Aparna
@Aparna-S
May 15 2016 02:22
@ndburrus so j is sub array of i array.. but j is actually having values of i array..i refers to just the array itself?
Moisés Man
@moigithub
May 15 2016 02:23
@IsaacAbrahamson [SERR CVMMN] with ur code what that returns ??
should be [FREE PIZZA]
OneRandomJamie
@OneRandomJamie
May 15 2016 02:23
@Chrono79 The entire thing. I don't even understand the instructions. it is something about finding a remainder in Javascript.
Aparna
@Aparna-S
May 15 2016 02:24
@cdandro ok i is the array..j is all the values available in i array?
cdandro
@cdandro
May 15 2016 02:24
var primaryArr = [[1,2],[3,4]];
var i = 0;
var j=0;
var someVarName = primaryArr[0]; 
// someVareName will be equal to [1,2]
var someValue = someVarName[j];
//someValue will equal to 1
// Say j gets incremented to 1
someValue = someVarName[j];
// someValue now equals 2
Diego Mayer
@Chrono79
May 15 2016 02:24
@OneRandomJamie let's do it step by step
Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator.
Set remainder equal to <- how do you do this part?
Norvin Burrus
@ndburrus
May 15 2016 02:25
@Aparna-S ... in @cdandro 's example - think of someVarName as the product variable. sidetrack (question response): arr represents the total input array. i represents the number of arrays within arr. j represents the number of elements in each i array... getting clearer?
OneRandomJamie
@OneRandomJamie
May 15 2016 02:26
@Chrono79 var remainder = 11/3;
Diego Mayer
@Chrono79
May 15 2016 02:26
@OneRandomJamie almost right, but you are assigning the actual result of the division there, not the remainder
5 % 2 = 1 because
Math.floor(5 / 2) = 2 (Quotient)
2 * 2 = 4
5 - 4 = 1 (Remainder)
cdandro
@cdandro
May 15 2016 02:26
@OneRandomJamie Try using the % (modulus) operator
It gives you the left overs 5 % 2 = 1
Diego Mayer
@Chrono79
May 15 2016 02:27
@OneRandomJamie replace / for % in what you posted
Aparna
@Aparna-S
May 15 2016 02:28
@ndburrus hmmm..now its getting clearer!!..
OneRandomJamie
@OneRandomJamie
May 15 2016 02:28
@Chrono79 var remainder = 11 % 3;
Diego Mayer
@Chrono79
May 15 2016 02:28
@OneRandomJamie yes, like that
Norvin Burrus
@ndburrus
May 15 2016 02:29
@Aparna-S ok, super! now, let's take another look at that code posted earlier to see if you can identify how to get the product value:
var someVarName  = arr[i];
var newValue = someVarName[j];
OneRandomJamie
@OneRandomJamie
May 15 2016 02:30
@Chrono79 Thank you. I have no idea why I could not understand that. I think it was because of the way the example is set up.
CamperBot
@camperbot
May 15 2016 02:30
onerandomjamie sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 739 | @chrono79 |http://www.freecodecamp.com/chrono79
Norvin Burrus
@ndburrus
May 15 2016 02:30
@Aparna-S remember, the product value can be thought of as similar to the someVarName variable in the sample code... :smile: hmmm.... this isn't an exact match example. we need to remember that we are using nested loops with two variables (i, j).
@Aparna-S use this 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]);
  }
}
cdandro
@cdandro
May 15 2016 02:34
@ndburrus What item is this in the course?
Aparna
@Aparna-S
May 15 2016 02:34
@ndburrus look at this = i know its wrong, but shows tick for one result out of 3 :P
for (var i = 0; i< arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
product = i*arr[i];
}
}
// On
Norvin Burrus
@ndburrus
May 15 2016 02:35
@Aparna-S let me see if i can word a better answer for your earlier question. i represents the elements [1,2] , [3,4], and [5,6] of arr - iterations one through three. j represents the elements 1, 3, and 5.... then (for the next iteration 2, 4, and 6)
Aparna
@Aparna-S
May 15 2016 02:35
here i thought like i array count is multiplied with the values of its elements that is refering to arr[i]
@ndburrus ohh...then what about 2,4,6??
i thoughght it was1,2,3,4,...
Diego Mayer
@Chrono79
May 15 2016 02:36
@ndburrus I think that arr[i] represents the elements [1,2] , [3,4], and [5,6]
Norvin Burrus
@ndburrus
May 15 2016 02:37
@Chrono79 that's what i thought i was saying - maybe it isn't clear... i added "of arr" perhaps that's better...
Marvin Andara
@babycakez
May 15 2016 02:37
hehe so I just spent like 6 hours rewriting code that was never wrong. I just forgot to add http:// to my link hahahahHAHAHA. BREAKS EVERYTHING IN HOUSE
Norvin Burrus
@ndburrus
May 15 2016 02:37
@babycakez kudos to you!! :+1:
Diego Mayer
@Chrono79
May 15 2016 02:39
@babycakez it will not be the last time you'll fix something that's isn't broken :)
Norvin Burrus
@ndburrus
May 15 2016 02:39
@Aparna-S ok, are we getting closer to the finish line? i think once you review the example code, you'll see how the get the product result!
Aparna
@Aparna-S
May 15 2016 02:41
@ndburrus so does it mean..135 = 15 then 246=58..then 15*58??
cdandro
@cdandro
May 15 2016 02:42
@Aparna-S in general yes, but 246=48 ;)
Aparna
@Aparna-S
May 15 2016 02:43
@cdandro soory for the poor math
:P
cdandro
@cdandro
May 15 2016 02:44
@Aparna-S It really wants you to do 123456, since multiplication doesn't matter on order, doing 135 =15 then 246=48, 1548 is fine
@Aparna-S So as long as product (or whatever your variable is) is multiplied by all numbers it can happen in any order
Aparna
@Aparna-S
May 15 2016 02:46
@cdandro right.. but javascript goes like alternatives na?
diaokarolyn
@diaokarolyn
May 15 2016 02:46
how do you make a decaration assignment
declaration
cdandro
@cdandro
May 15 2016 02:46
@Aparna-S ?not sure what you mean?
Norvin Burrus
@ndburrus
May 15 2016 02:46
@Aparna-S this may be helpful: "Dynamic Web Coding" {ref: http://www.dyn-web.com/javascript/arrays/multidimensional.php }
Looping through Multidimensional Arrays

When you want to iterate over the elements of a multidimensional array, use nested for loops:

// outer loop applies to outer array
for (var i=0, len=ar.length; i<len; i++) {
    // inner loop applies to sub-arrays
    for (var j=0, len2=ar[i].length; j<len2; j++) {
        // accesses each element of each sub-array in turn
        console.log( ar[i][j] ); 
    }
}
Notice the variables initialized and used by each for loop, i.e., the counter variables (i and j) and test expressions (len and len2). The inner loop iterates through each element (ar[i][j]) in the current sub-array (ar[i]); console.log is used to display the value of each element in turn.
cdandro
@cdandro
May 15 2016 02:48
@diaokarolyn
```
var someVariableName = 0;
// This creates a variable named someVariableName with the value of 0
Aparna
@Aparna-S
May 15 2016 02:50
@cdandro i mean as per the js..it is like 135..then246..then last multiple.....?
Norvin Burrus
@ndburrus
May 15 2016 02:50
@diaokarolyn "var = yourVariable"
Aparna
@Aparna-S
May 15 2016 02:51
@ndburrus here arr[i][j] is used right...but in our code it does not work
cdandro
@cdandro
May 15 2016 02:51
@Aparna-S per MATH it is fine, js doesn't change the rules of Math
Norvin Burrus
@ndburrus
May 15 2016 02:51
@Aparna-S are you using multiplication? be back in a few minutes....
Aparna
@Aparna-S
May 15 2016 02:51
one more doubt..last array meant has 3 values 5,6,7..but previous has only 2..1,2 and 3,4..is that ok?or do we have to do something for this?
@cdandro ok :)
cdandro
@cdandro
May 15 2016 02:52
@Aparna-S the console.log line is just "showing" you each number for a moment (only run the code once) change console.log[arr[i][j] to alert(arr[i][j])
Aparna
@Aparna-S
May 15 2016 02:53
@ndburrus i tried using arr[i][j] as wellas arr[i] arr[j] ..it doesnt work..but for some reason iarr[i] works for one of the 3 ticks..
cdandro
@cdandro
May 15 2016 02:53
@Aparna-S n/m don't do that FCC doesn't let it work
@Aparna-S change the console.log line to product *= arr[i][j];
@Aparna-S the arr[i][j] is just accessing the items in the arrays , you need to actually perform the multiplication
Aparna
@Aparna-S
May 15 2016 02:55
@cdandro it works now.. but want to clEAR MYSELF..FOR MULTIPLE YOU CAN PERFORM LIKE ARR[I] * ARR[J]..WE NEED To bring the expression with = sign itself?
sorry for the caps!!
cdandro
@cdandro
May 15 2016 02:57
This message was deleted
ugg, stupid code paste was wrong trying again
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++) {
      //Run once with this
      return arr[i];
      //Then comment/delete the line above and run this
      return arr[i][j];
    }
  }
  // Only change code above this line
  return product;
}
@Aparna-S That code will not pass but it may help you understand what arr[i] vs what arr[i][j] is
koest3r
@koest3r
May 15 2016 03:00

Hi, it looks like I came up with the correct solution for the Mutations challenge.. but the first call returns true when it should return false. Is there something wrong with my code?:

<script src="https://gist.github.com/koest3r/bd778f6df589b9ea1d64620d8216afa7.js"></script>

Aparna
@Aparna-S
May 15 2016 03:02
@cdandro ok so..i refer to [1,2]..[3,4]..so on..j refers to 1, 2, 3,4..so on..correct?
cdandro
@cdandro
May 15 2016 03:03
@Aparna-S yes~ish, i refers to the 1st level of the array while j accesses each element inside of the elements of i
Norvin Burrus
@ndburrus
May 15 2016 03:04
@Aparna-S are you using your variable (product) in your calculation?
Aparna
@Aparna-S
May 15 2016 03:05
@cdandro got it thanks :)
cdandro
@cdandro
May 15 2016 03:05
@koest3r I think your problem is that you return true to soon, remove it from for loop and it should help, currently your solution will return true if the a single character matches
CamperBot
@camperbot
May 15 2016 03:05
aparna-s sends brownie points to @cdandro :sparkles: :thumbsup: :sparkles:
:cookie: 356 | @cdandro |http://www.freecodecamp.com/cdandro
Aparna
@Aparna-S
May 15 2016 03:05

@ndburrus for (var i = 0; i< arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
product *= arr[i][j];

}

} this i used ....

Norvin Burrus
@ndburrus
May 15 2016 03:05
@Aparna-S excellent !! great persistence :+1:
Aparna
@Aparna-S
May 15 2016 03:05
all thease time i thoght proudct = arr[i] arr[j] instead product should be =....
@ndburrus thanks for your time and help!!!! :)
CamperBot
@camperbot
May 15 2016 03:06
aparna-s sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 356 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
May 15 2016 03:07
@Aparna-S you're very welcome. anytime! yes, you were so very close.... i knew you'd get it.... :sparkles: it is interesting how the iteration occurs... perhaps you can look for a graphic in your spare time....
cdandro
@cdandro
May 15 2016 03:07
@koest3r does that make sense?
Aparna
@Aparna-S
May 15 2016 03:08
@ndburrus :D ... will trouble yo guys sooner..let me try the next xhallenge :P
challenge*
Norvin Burrus
@ndburrus
May 15 2016 03:08
@Aparna-S ok
Aparna
@Aparna-S
May 15 2016 03:08
@ndburrus graphic??
koest3r
@koest3r
May 15 2016 03:09
@cdandro I tried your solution and it worked, thank you. Why is it exactly that moving return true out of the for loop makes it work properly?
CamperBot
@camperbot
May 15 2016 03:09
koest3r sends brownie points to @cdandro :sparkles: :thumbsup: :sparkles:
:cookie: 357 | @cdandro |http://www.freecodecamp.com/cdandro
Norvin Burrus
@ndburrus
May 15 2016 03:09
@Aparna-S yes, a picture
cdandro
@cdandro
May 15 2016 03:10
@koest3r the solution you had said as soon as you find a match return true, NOT wait until everything had been looked at
@koest3r looking at the test cases, the first character exists in every single one so it will return true on each one
dhuddleston
@dhuddleston
May 15 2016 03:11
I'm working on the "Profile Lookup" waypoint right now. Getting an error which says "Cannot read property 'firstName' of undefined." I've been trying to debug this for a while and I can't figure out exactly why I'm getting this behavior. Any pointers?

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

console.log(contacts[0].firstName);


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

var isFirstName = false;
var isProp = false;

  for(var i = 0; i <= contacts.length; i++)
  {
    if(firstName == contacts[i].firstName)
      {
        isFirstName = true;
        for(var j = 0; j <= contacts[i].length; j++)
          {
            if(prop == contacts[i][j])
              {
                isProp = true;
              }
          }
      }
  }

  if(isFirstName === false)
  {
      return "No such contact";
  }
  else if(isFirstName === true)
  {
      if(isProp === true)
      {
          return prop;
      }
      else
      {
          return "No such property";
      }
  }

}

// Change these values to test your function
console.log(lookUpProfile("Akira", "likes"));
cdandro
@cdandro
May 15 2016 03:14
@dhuddleston on line if(firstName == contacts[i].firstName) try ===
@dhuddleston n/m that doesn't fix the issue
Aparna
@Aparna-S
May 15 2016 03:19
@ndburrus you mean graphic for array iterations?..ok
Norvin Burrus
@ndburrus
May 15 2016 03:19
@Aparna-S yes, that's what i meant...
Coy Sanders
@coymeetsworld
May 15 2016 03:20
@dhuddleston your issue is with how you're checking for prop
you can't iterate through properties like you would an array
you should use the hasOwnProperty function for a contact
dhuddleston
@dhuddleston
May 15 2016 03:22
Thanks @coymeetsworld ! I'll try that
CamperBot
@camperbot
May 15 2016 03:22
dhuddleston sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 848 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
May 15 2016 03:23
np @dhuddleston
Aparna
@Aparna-S
May 15 2016 03:28
@ndburrus ok....
Vibhor Batra
@batravibhor
May 15 2016 03:35
hello guys
need help on a challenge
Norvin Burrus
@ndburrus
May 15 2016 03:40
@batravibhor which one?
OneRandomJamie
@OneRandomJamie
May 15 2016 03:40
how do I make b = 9+b; like a+= 12; but have it equal 26?
Norvin Burrus
@ndburrus
May 15 2016 03:41
@OneRandomJamie im not sure i understand what you're trying to do... is this for a challenge?
OneRandomJamie
@OneRandomJamie
May 15 2016 03:42
@ndburrus Convert the assignments for a, b, and c to use the += operator.
Norvin Burrus
@ndburrus
May 15 2016 03:42
@OneRandomJamie is that the challenge name?
dhuddleston
@dhuddleston
May 15 2016 03:43
@coymeetsworld I got it to work. Thanks again!
CamperBot
@camperbot
May 15 2016 03:43
dhuddleston sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: dhuddleston already gave coymeetsworld points
OneRandomJamie
@OneRandomJamie
May 15 2016 03:43
This message was deleted
@ndburrus Compound Assignment With Augmented Addition
Norvin Burrus
@ndburrus
May 15 2016 03:44
@OneRandomJamie ok, the example code is very useful for this challenge....:)
@OneRandomJamie
myVar = myVar + 5;
OneRandomJamie
@OneRandomJamie
May 15 2016 03:45
@ndburrus I tried b += 9 and b+=b. neither worked
Aparna
@Aparna-S
May 15 2016 03:46
@OneRandomJamie b+= 9; should work...
OneRandomJamie
@OneRandomJamie
May 15 2016 03:47
@Aparna-S thank you. for some reason it worked that time.
CamperBot
@camperbot
May 15 2016 03:47
onerandomjamie sends brownie points to @aparna-s :sparkles: :thumbsup: :sparkles:
:cookie: 232 | @aparna-s |http://www.freecodecamp.com/aparna-s
Aparna
@Aparna-S
May 15 2016 03:47
@OneRandomJamie np :D
Norvin Burrus
@ndburrus
May 15 2016 03:48
@OneRandomJamie did all the tests pass?
nickrsnow
@nickrsnow
May 15 2016 03:49
I need help for the factorialize challenge... why does this return 3125 and not 120?

function factorialize(num) {
var fact = 1;
for (var i = num; i > 0; i--) {
fact *= num;
}
return fact;
}

factorialize(5);

Quentin DeFrank
@QTDeFrank
May 15 2016 03:50
is factorialize bugged?
nickrsnow
@nickrsnow
May 15 2016 03:50
it should work, right?
Quentin DeFrank
@QTDeFrank
May 15 2016 03:51
var total = 1;
function factorialize(num) {
  if(num < 2){
    return total;
  }else{
    total *= num;
    return factorialize(num - 1);
  }
}
is not working anyone know why?
buiphuking
@buiphuking
May 15 2016 03:59
hi guys, where is "÷" in keyboard ?
nickrsnow
@nickrsnow
May 15 2016 03:59
/
@buiphuking - it is the / key
buiphuking
@buiphuking
May 15 2016 04:01
@nickrsnow so how can type ÷ , i',m copy this thing
Aparna
@Aparna-S
May 15 2016 04:02
@ndburrus help needed again :o:
nickrsnow
@nickrsnow
May 15 2016 04:02
you use the / key to represent division, there isn't a key for the division sign @buiphuking
Aparna
@Aparna-S
May 15 2016 04:03
@ndburrus Profile Lookup .... bbelow is my code :

function lookUpProfile(firstName, prop){
// Only change code below this line
if (contacts[firstName] == firstName && contacts[prop]== prop) {
return contacts[firstname][prop];
}
else if (contacts[firstName] != firstName) {
return "No such contact";
}
else if (contacts[prop] != prop) {
return "No such property";
}

// Only change code above this line
}

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

it is tick for ""Bob", "number" should return "No such contact"" alone
mostlind
@mostlind
May 15 2016 04:03
@QTDeFrank return num*factorialize(num-1) and fatorialize(0) should return 1
Diego Mayer
@Chrono79
May 15 2016 04:03
@QTDeFrank maybe it's because of the global var?
buiphuking
@buiphuking
May 15 2016 04:05
@Chrono79
if num =1 , what will function do ?
Diego Mayer
@Chrono79
May 15 2016 04:06
@buiphuking what are you asking about?
Coy Sanders
@coymeetsworld
May 15 2016 04:08
@Aparna-S contacts is an array of objects you need to iterate through
buiphuking
@buiphuking
May 15 2016 04:08
@Chrono79
ex ; num = 5 , you total = 1 5 432
Coy Sanders
@coymeetsworld
May 15 2016 04:08
also to find if a contact has a property you should use the hasOwnProperty function
buiphuking
@buiphuking
May 15 2016 04:08
1 x 5 x 4 x 3 x2
Diego Mayer
@Chrono79
May 15 2016 04:09
@buiphuking yes, that's a factorial, so if num = 1 it'll return 1
buiphuking
@buiphuking
May 15 2016 04:09
when num -> 1, return total , and total
so when factorial stop ?
Diego Mayer
@Chrono79
May 15 2016 04:11
@buiphuking if you're asking for the recursive solution, you have to stop when num = 0
forget total, that was in @QTDeFrank code and I think that's what was not validating
Aparna
@Aparna-S
May 15 2016 04:11
@coymeetsworld oh...like this? else if (contacts.hasOwnProperty(prop) === false) {
return "No such property";
}
Coy Sanders
@coymeetsworld
May 15 2016 04:12
better @Aparna-S, but contacts is an array of objects though
buiphuking
@buiphuking
May 15 2016 04:12
@Chrono79
i know, but computer know what you want with your code ?
Coy Sanders
@coymeetsworld
May 15 2016 04:12
your function needs to go through each contact to find what you're looking for
Diego Mayer
@Chrono79
May 15 2016 04:13

@buiphuking

function factorialize(num) {
  if(num === 0) return 1;
  return num * factorialize(num-1);
}

first ask if num=0 and like returning early challenge, you stop the recursion returning 1

buiphuking
@buiphuking
May 15 2016 04:14
@Chrono79
that how it done
Coy Sanders
@coymeetsworld
May 15 2016 04:14
could also do
function factorialize(num) {
  if (num == 0) return 1;
  if (num <= 2) return num;
  return num * factorialize(num-1);
}
Aparna
@Aparna-S
May 15 2016 04:14
@coymeetsworld hm..how do we do that...does this code already not alow to check each array in contacts??
Coy Sanders
@coymeetsworld
May 15 2016 04:15
This message was deleted
This message was deleted
bennyphi
@bennyphi
May 15 2016 04:16

function getIndexToIns(arr, num) {
// Find my place in this sorted array.
var newArr = arr.push(num);
newArr = newArr.sort;
num = newArr.indexOf(num);
return num;
}

Why is it whenever I run this that it says "newArr.indexOf" is not a function?

Islam Ibakaev
@dagman
May 15 2016 04:17
if(num <= 0) return 1;
DJ
@qualitymanifest
May 15 2016 04:17
@bennyphi you're using .sort() wrong
Coy Sanders
@coymeetsworld
May 15 2016 04:17
how do you normally go through an array @Aparna-S ?
yeah @dagman probably better that way
Diego Mayer
@Chrono79
May 15 2016 04:17
@bennyphi .sort, you're missing (), also sorting need a function inside to work with numbers
Coy Sanders
@coymeetsworld
May 15 2016 04:18
who cares if you make a recursive call for just 2 i guess
bennyphi
@bennyphi
May 15 2016 04:18
Really? When I use () with it, it says thats wrong syntax
DJ
@qualitymanifest
May 15 2016 04:18
even with () you will still need to provide a function to get it to sort numerically rather than alphabetically
bennyphi
@bennyphi
May 15 2016 04:18
It says newArr.sort is not a function
Frank XC
@tenkdayz
May 15 2016 04:18
trying to drag something using this.. but it doesnt work..
function _(x){return document.getElementById(x);}
var mouseX, mouseY, slider = 0,i=0;
_("display").addEventListener("mousemove",function(event){
  mouseX = event.clientX - _("display").offsetLeft;
  mouseY = event.clientY - _("display").offsetTop;
  if(hold){
    if(slider<mouseX){
      i++;
      this.style.left += i+"px";
    }else if(slider>mouseX){
      i--;
      this.style.left -= i+"px";
    }
  }
  _("mouse-coords").innerHTML = mouseX+" | "+i +" | "+slider;//+" | "+mouseY;
});

var hold = false;
_("display").addEventListener("mousedown",function(event){
  hold = true;
  mouseX = event.clientX;// - _("display").offsetLeft;
  slider = mouseX - _("display").offsetLeft;;
  this.style.background = "red";
});
bennyphi
@bennyphi
May 15 2016 04:18
Do I need to put something in the parenthesis?
DJ
@qualitymanifest
May 15 2016 04:18
@bennyphi oh
Frank XC
@tenkdayz
May 15 2016 04:19
can someone point me to the right direction.. i dont why it's not working
DJ
@qualitymanifest
May 15 2016 04:19
@bennyphi you're assigning newArr to the push
Diego Mayer
@Chrono79
May 15 2016 04:19
@bennyphi did you checked newArr value before applying sort?
bennyphi
@bennyphi
May 15 2016 04:19
Wait let me redo it, I think I did the assigning wrong
Aparna
@Aparna-S
May 15 2016 04:20
@coymeetsworld for (var i = 0; i < contacts.length; i++) { ??
bennyphi
@bennyphi
May 15 2016 04:20
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.push(num);
arr.sort();
num = arr.indexOf(num);
return num;
}
I fixed it
Coy Sanders
@coymeetsworld
May 15 2016 04:20
@bennyphi what @qualitymanifest said, you need to supply sort with a function to sort the items in the array
@bennyphi no it will still fail tests
bennyphi
@bennyphi
May 15 2016 04:20
So this code is partly correct, it solves half of the things but not the other half
Coy Sanders
@coymeetsworld
May 15 2016 04:21
yes @Aparna-S
bennyphi
@bennyphi
May 15 2016 04:21
Alright @coymeetsworld
buiphuking
@buiphuking
May 15 2016 04:21
@nickrsnow
i use PC alt 0247 on keypad, but my pc doesn't has keypad ,
what should i do?
Aparna
@Aparna-S
May 15 2016 04:21

@coymeetsworld function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {

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

else if (contacts.hasOwnProperty(prop) === false) {
return "No such property";
}

// Only change code above this line
}
}

Coy Sanders
@coymeetsworld
May 15 2016 04:21
gives a pretty good explanation of why the numbers don't sort the way you want them to
bennyphi
@bennyphi
May 15 2016 04:21
Ah, since I didn't specify a function, it's sorting based on unicode and not actual value
Coy Sanders
@coymeetsworld
May 15 2016 04:22
@Aparna-S you're iterating through the array but not using your index at all in the for loop
DJ
@qualitymanifest
May 15 2016 04:22
Coy Sanders
@coymeetsworld
May 15 2016 04:22
remember, contacts is an array
you don't access items in array by string, you access by an index
so contacts[firstName] won't work
DJ
@qualitymanifest
May 15 2016 04:22
nevermind you got that part
.sort() sorts alphabetically so it thinks 9 > 10. you need to give it a numerical sort function
bennyphi
@bennyphi
May 15 2016 04:24
So how do I do the numerical sort function? I see it on the link but I don't quite understand how it works, and that's what I think is important to know
Trenton Stiles
@blzre
May 15 2016 04:24
Does anyone know why I get the error "TypeError: str.split is not a function when line 8 is reached.
function titleCase(str) {

  str = str.split(" ");

  // for every string we capitlaze the first letter..
  for (var i = 0; i < str.length; i++) {
    // This is where the code stops working...........
    str[i] = str.split("");
  }

  return str;
}

titleCase("I'm a little tea pot");
buiphuking
@buiphuking
May 15 2016 04:24
can JS calculate with ( and ) ?????????????
DJ
@qualitymanifest
May 15 2016 04:25
@bennyphi here's some easier documentation: http://www.w3schools.com/jsref/jsref_sort.asp
bennyphi
@bennyphi
May 15 2016 04:25
@qualitymanifest Thanks
CamperBot
@camperbot
May 15 2016 04:25
bennyphi sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1163 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
Coy Sanders
@coymeetsworld
May 15 2016 04:26
@blzre its because you're running split on an array
Diego Mayer
@Chrono79
May 15 2016 04:26
@blzre maybe you missed [i] there
DJ
@qualitymanifest
May 15 2016 04:26
np. you'll have to read through it to find it but it's in there. it's important to get comfortable with docs
Coy Sanders
@coymeetsworld
May 15 2016 04:26
Array doesn't have a split method, String has a split method, you may be confusing yourself by reassigning str to str.split("");. Result of str.split() is an array
bennyphi
@bennyphi
May 15 2016 04:26
Ok, so I finished it by using the sort function(a, b) { return a - b } but I don't know how it works. Can someone explain it to me?
Trenton Stiles
@blzre
May 15 2016 04:27
@coymeetsworld I was missing the other [i]
@coymeetsworld thanks
CamperBot
@camperbot
May 15 2016 04:27
blzre sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 851 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
bennyphi
@bennyphi
May 15 2016 04:27
Does sort() automatically place "a" lower than "b" if a - b is a negative value?
and vice versa for a positive value?
Diego Mayer
@Chrono79
May 15 2016 04:27
@bennyphi read the links @coymeetsworld and @qualitymanifest gave you
Aparna
@Aparna-S
May 15 2016 04:27

@coymeetsworld function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {

if ([contacts.length].hasOwnProperty(firstName) === true && [contacts.length].hasOwnProperty(prop) === true) {
return contacts[firstname][prop];
}
else if
([contacts.length].hasOwnProperty(firstName) === false) {
return "No such contact";
}

else if ([contacts.length].hasOwnProperty(prop) === false) {
return "No such property";
}

// Only change code above this line
}

bennyphi
@bennyphi
May 15 2016 04:27
I did
I read both of them
Diego Mayer
@Chrono79
May 15 2016 04:28
@bennyphi and isn't that what they said?
DJ
@qualitymanifest
May 15 2016 04:28
@bennyphi basically, you got the gist of it
bennyphi
@bennyphi
May 15 2016 04:28
Ok, just checking in
Yes, @Chrono79 , yes ...
Coy Sanders
@coymeetsworld
May 15 2016 04:28
your syntax is off @Aparna-S
how do you access the first contact in an array called contacts?
Bobby McDonald
@BobbyMcWho
May 15 2016 04:29
contacts[0]
Coy Sanders
@coymeetsworld
May 15 2016 04:29
@BobbyMcWho I was asking aparna :)
Aparna
@Aparna-S
May 15 2016 04:29
@BobbyMcWho @coymeetsworld haha :P
Coy Sanders
@coymeetsworld
May 15 2016 04:30
but yeah, thats how you would access the first item in the contact, which is an object
and the second would be contacts[1], and so on
Skerins
@Skerins
May 15 2016 04:33
@jamiec92 Happy to help.
Aparna
@Aparna-S
May 15 2016 04:35
@coymeetsworld i dono how to implement :(

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

if ([contacts.length].hasOwnProperty(firstName) === true && [contacts.length].hasOwnProperty(prop) === true) {
return contacts[firstname][prop];
}
else if
([contacts.length].hasOwnProperty(firstName) === false) {
return "No such contact";
}

else if ([contacts.length].hasOwnProperty(prop) === false) {
return "No such property";
}
}

Coy Sanders
@coymeetsworld
May 15 2016 04:36
you will only need one for loop for this @Aparna-S
so you can remove that 2nd one
also it's only a one-dimensional array, not 2 td so contacts[i] wouldn't work
so if you printed out what contacts[0] was you would get this:
{
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    }
shubham shukla
@shubhdo
May 15 2016 04:38
i am doing "everything be true" assignment.here is my code.now some combinations are not giving correct output.
function truthCheck(collection, pre) {
// Is everyone being true?
for(var i=0;i<collection.length;i++) {
if(!(collection[i].hasOwnProperty(pre))) {
return false;
}
else {
if(collection[i][pre]===""|| collection[i][pre]===undefined|| collection[i][pre]===null|| isNaN(collection[i][pre])|| collection[i][pre])
return false;
}
}
return true;
}
truthCheck([{"single": "yes"}], "single"); //this gives false but it should returns true
Coy Sanders
@coymeetsworld
May 15 2016 04:38
and if you wanted to get the firstName of it you would print out contacts[0].firstName @Aparna-S
since contacts[0] is an object you can access a known property using dot notation
I guess I should say JSON object when i say object too
Aparna
@Aparna-S
May 15 2016 04:39
@coymeetsworld ok...so you dont need to measure the contacts.length??
Coy Sanders
@coymeetsworld
May 15 2016 04:39
no, but you need it in your for loop to know how many times to iterate through the array
and you have that part right
(var i = 0; i < contacts.length; i++)
some people i've seen hardcode the 2nd value to 4, but that would only work if your contacts array had 4 objects in it
if you put in a contacts array with 10 objects only the first 4 would be checked, if you put in an array with less than 4 your code would error out when trying to access an object at an index beyond the array length
Aparna
@Aparna-S
May 15 2016 04:42
@coymeetsworld oh ok..got that part now..
Coy Sanders
@coymeetsworld
May 15 2016 04:44
@shubhdo i think its the last check in your if statement giving you problems
also you don't need that many checks to see if something should be false
you can simplify that quite a bit, but yeah check your last statement first
shubham shukla
@shubhdo
May 15 2016 04:48
@coymeetsworld i have checked many times.
Trenton Stiles
@blzre
May 15 2016 04:49
Is there a way I could interact with js code interactively on the spot? Kind of like how you can open up a python shell and type python code on the fly.
Aparna
@Aparna-S
May 15 2016 04:50
@coymeetsworld now contacts[0] refer to firstname..contact[1] refer to last name..that way?
Coy Sanders
@coymeetsworld
May 15 2016 04:50
no @Aparna-S contacts[1] would refer to the 2nd object in the array
contacts[0] has a firstName property, contacts[1] also has a firstName property
Aparna
@Aparna-S
May 15 2016 04:51
@coymeetsworld ohh..the contacts[0] has {
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
}, and contacts[1] has {
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
Coy Sanders
@coymeetsworld
May 15 2016 04:51
@shubhdo what did you do for Falsy Bouncer?
Aparna
@Aparna-S
May 15 2016 04:51
?
Coy Sanders
@coymeetsworld
May 15 2016 04:52
yes! @Aparna-S
buiphuking
@buiphuking
May 15 2016 04:54
how can i call a span tag with id ="ac" to do something?
$("#ac").click(function()){
}
am i right?
Coy Sanders
@coymeetsworld
May 15 2016 04:55
close @buiphuking, brackets go inside the last parenthesis
click takes in a function, either you give it a function you already defined or like what you're trying here an anonymous function
$("#ac").click(function() {


});
shubham shukla
@shubhdo
May 15 2016 04:56
@coymeetsworld function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr.filter(function (val) {
return Boolean(val);
});
}
Coy Sanders
@coymeetsworld
May 15 2016 04:56
or
function someFunction() {

}

$("#ac").click(someFunction);
shubham shukla
@shubhdo
May 15 2016 04:56
now i have change the code but still same condition
Coy Sanders
@coymeetsworld
May 15 2016 04:57
how did you change it?
buiphuking
@buiphuking
May 15 2016 04:58
@coymeetsworld
and i define button C, mean remove last number, and i use a div to show result, so how can i do that?
Jenni
@silverrain64
May 15 2016 04:58
help Arguments Optional
CamperBot
@camperbot
May 15 2016 04:58

:point_right: algorithm arguments optional [wiki]

Explanation:

It can be quite complicated to understand what needs to be done. There are always many ways to do something when coding but regardless of the algorithm used, we have to create a program that does the following:

  • It has to add two numbers passed as parameters and return the sum.
  • It has to check if any of the numbers are actual numbers, otherwise return undefined and stop the program right there.
  • It has to check if it has one or two arguments passed. More are ignored.
  • If it has only one argument then it has to return a function that uses that number and expects another one, to then add it.

:pencil: read more about algorithm arguments optional on the FCC Wiki

shubham shukla
@shubhdo
May 15 2016 04:58
function truthCheck(collection, pre) {
// Is everyone being true?
for(var i=0;i<collection.length;i++) {
if(!(collection[i].hasOwnProperty(pre))) {
return false;
}
else {
if(!(Boolean(collection[i].pre)))
return false;
}
}
return true;
}
truthCheck([{"single": "yes"}], "single");
Coy Sanders
@coymeetsworld
May 15 2016 04:59
not sure what you're trying to do @buiphuking, remove last number of what?
for adding some result to your page you can use jQuery for that, google jQuery add to DOM or something like that
Damos Kalaitzidis
@DamostheGreek
May 15 2016 05:01

// Setup
var a =7;
var b = var a;

// Only change code below this line

can anybody help with that
contents of car a need to go where var b assignment is
var*
buiphuking
@buiphuking
May 15 2016 05:01
@coymeetsworld
i do calculator
i use <div id ="result"> </div> // show number here
now div have : 2345,
i click C button and div remain : 234 ,
any advice , how can i remove last number
Coy Sanders
@coymeetsworld
May 15 2016 05:02
look up jQuery html() function
@buiphuking
Damos Kalaitzidis
@DamostheGreek
May 15 2016 05:03
Can someone help me with this?
Aparna
@Aparna-S
May 15 2016 05:03
@coymeetsworld i still cant finish this :(
Coy Sanders
@coymeetsworld
May 15 2016 05:04
@shubhdo you put some errors in your code with pre
pre isn't the name of a key in the object, so you can't use dot notation
look at how you accessed the pre property before in your older code
what's the problem @Aparna-S ?
@DamostheGreek you only use keyword var to define a variable, and you only define a variable one time
so the word var should never be on the right side of an assigment operator (i.e. equals sign)
Damos Kalaitzidis
@DamostheGreek
May 15 2016 05:07
so 7 goes there?
how do i get the contents of var a there?
Coy Sanders
@coymeetsworld
May 15 2016 05:11
just var b = a;
since a = 7, b will set itself to that value as well so both will be 7
buiphuking
@buiphuking
May 15 2016 05:12
@DamostheGreek
put your code here and click step by step, computer will run your code step by step
Markus Kiili
@Masd925
May 15 2016 05:14
@coymeetsworld I finally figured out why Object.length is 1. Dark secret of JavaScript.
Coy Sanders
@coymeetsworld
May 15 2016 05:15
yeah @Masd925 ? why?
TanYiXun
@TanYiXun
May 15 2016 05:17
Guys I'm trying my first el
Markus Kiili
@Masd925
May 15 2016 05:18
@coymeetsworld It haunted me for quite some time, because ECMAScript standard just says it is 1. But actually functions length property tells the number of parameters it has, and for Object constructor it is one, because it only expects one value to turn into an object.
Marv Cook
@c0987k
May 15 2016 05:19
how do you use this room?
Markus Kiili
@Masd925
May 15 2016 05:19
@c0987k By asking a JavaScript related questions and perhaps posting some relevant code.
Coy Sanders
@coymeetsworld
May 15 2016 05:21
oh I see, and the 1 parameter is this @Masd925 ?
Markus Kiili
@Masd925
May 15 2016 05:24
@coymeetsworld The only parameter is the value to be objectified:
var obj = Object("cat"); // { '0': 'c', '1': 'a', '2': 't' }
typeof obj; // 'object'
Object only expects one arguement because on the Object declaration, there is only one parameter. Therefore Object.length is 1.
Damos Kalaitzidis
@DamostheGreek
May 15 2016 05:27
thank you @coymeetsworld and @buiphuking
CamperBot
@camperbot
May 15 2016 05:27
:cookie: 8 | @buiphuking |http://www.freecodecamp.com/buiphuking
:cookie: 853 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
damosthegreek sends brownie points to @coymeetsworld and @buiphuking :sparkles: :thumbsup: :sparkles:
Coy Sanders
@coymeetsworld
May 15 2016 05:28
interesting @Masd925, but what if you make an object with no parameters, length still 1?
Robert Richey
@0x0936
May 15 2016 05:29
function foo() {}; foo.length; // 0
:dog:
function foo(bar, baz) { }; foo.length ; // 2
Markus Kiili
@Masd925
May 15 2016 05:31
@coymeetsworld Functions length tells the number of parameters on the declaration. Objects don't have length property by default.
@coymeetsworld All objects inherit properties from Object.prototype, not Object, which is the object constructor function (makes objects with new keyword).
Robert Richey
@0x0936
May 15 2016 05:32
thanks for the discussion @coymeetsworld @Masd925
CamperBot
@camperbot
May 15 2016 05:32
0x0936 sends brownie points to @coymeetsworld and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1490 | @masd925 |http://www.freecodecamp.com/masd925
:cookie: 854 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
May 15 2016 05:36
got it @Masd925, definitely need to start reading some of that material we discussed :)
thanks also @0x0936 and @Masd925 for that conversation, quite a bit i still need to learn
CamperBot
@camperbot
May 15 2016 05:36
coymeetsworld sends brownie points to @0x0936 and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1315 | @0x0936 |http://www.freecodecamp.com/0x0936
:star2: 1491 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
May 15 2016 05:38
@coymeetsworld Yes, objects, functions, constructors and prototypes gives you something to chew on for quite some time.
Aparna
@Aparna-S
May 15 2016 05:38
@coymeetsworld how can we eturn contact[0] alone..we ened to go through until last ocntact right..how do we link it up here?
my code is still same :

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

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

if ([contacts.length].hasOwnProperty(firstName) === true && [contacts.length].hasOwnProperty(prop) === true) {
return contacts[0];
}
else if
([contacts.length].hasOwnProperty(firstName) === false) {
return "No such contact";
}

else if ([contacts.length].hasOwnProperty(prop) === false) {
return "No such property";
}

// Only change code above this line
}
}
// Change these values to test your function
lookUpProfile("Akira", "likes");

Markus Kiili
@Masd925
May 15 2016 05:39
@Aparna-S The simplest structure is two nested if clauses inside contact loop. The first checks if the firstname matches and the second one if the property exists.
@Aparna-S One contact being looped is contacts[i].
Aparna
@Aparna-S
May 15 2016 05:42
@Masd925 still cant get it... is it this way?

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

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

but dint initiate contact[i].length in for stt
Markus Kiili
@Masd925
May 15 2016 05:43
@Aparna-S The first if should only test if the contacts firstName property value matches the value of the firstName parameter. If it does, we know that it is the contact we are looking for.
Greg
@GregJacoby
May 15 2016 05:44
can someone tell me what's wrong with my card counting function? -.-
function cc(card) {
  // Only change code below this line
  var count = 0;
  if(card === 2 || card === 3 || card === 4 || card === 5 || card === 6) {
    count++;
  }
    else if (card === 10 || card === 'J' || card === 'Q' || card === 'K' || card === 'A') {
    count--;
  }
  if(count > 0) {
    return count + " Bet";
  } else {
    return count + " Hold";
  }
  // Only change code above this line
}
when I test it on my own, it works perfectly
Markus Kiili
@Masd925
May 15 2016 05:44
@GregJacoby The count is supposed to be a global variable.
Greg
@GregJacoby
May 15 2016 05:45
oh oh oh oh
so it doesn't reset each time the function is run
thank you
@Masd925 thanks
CamperBot
@camperbot
May 15 2016 05:45
gregjacoby sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1492 | @masd925 |http://www.freecodecamp.com/masd925
Greg Duncan
@GregatGit
May 15 2016 05:46
@GregJacoby You really should try implementing a switch here - it would make your code easier to read
Greg
@GregJacoby
May 15 2016 05:46
@GregatGit ah, you're right. i'm more used to working with if statements so that's what i ended up doing
Aparna
@Aparna-S
May 15 2016 05:47
@Masd925 if ([contacts[i].length].hasOwnProperty(firstName) === true) {
//if [contacts[i].length].hasOwnProperty(prop) === true) {
return contacts[i];
}
i think again some misanke
Greg
@GregJacoby
May 15 2016 05:47
@GregatGit it seems better suited for situations like these though where lots of or statements are needed
Aparna
@Aparna-S
May 15 2016 05:47
mistake*
Greg Duncan
@GregatGit
May 15 2016 05:47
@GregJacoby Also your if and else if are not quite right
Greg
@GregJacoby
May 15 2016 05:48
@GregatGit ?
Greg Duncan
@GregatGit
May 15 2016 05:48
@GregJacoby the second if and else is done correctly - but the first one is incorrect
Greg
@GregJacoby
May 15 2016 05:49
@GregatGit like I should've just done two if statements or something instead?
Greg Duncan
@GregatGit
May 15 2016 05:51
@GregJacoby the way your last half is how if an else statements should be handled
@GregJacoby if you start using the final statement should always be else and have no condition
Greg
@GregJacoby
May 15 2016 05:52
@GregatGit that would mess the purpose of the function up though!
@GregatGit i could add else { count += 0; } but that's just extra, un-needed code. it's what happens anyway!
Greg Duncan
@GregatGit
May 15 2016 05:53
@GregJacoby the moment you start using else something has to been done -
@GregJacoby
if (this is true){
    //do this
}else if (if that is true){
    // do this
}else{
    // for everthing else do this
}
@GregJacoby so
function cc(card) {
  // Only change code below this line
  var count = 0;
  if(card === 2 || card === 3 || card === 4 || card === 5 || card === 6) {
    count++;
  }
    else {
    count--;
  }
  if(count > 0) {
    return count + " Bet";
  } else {
    return count + " Hold";
  }
  // Only change code above this line
}
Eldar Tinjić
@EldarT90
May 15 2016 06:17
if(!res.ok) return cb(res.text); - this causes error
any idea what this is?
TypeError: Cannot read property 'ok' of null
Chris Cullen
@123xylem
May 15 2016 06:30
Hey Im doing a wiki search.. Can some1 advise me on how to use the wiki api with JSON? Maybe just a link or rough advise... Im not too sure how to use it or what taht api does...http://codepen.io/123xylem/pen/aNxREJ?editors=0111
yisca26
@yisca26
May 15 2016 06:46
hi
how to create select with image ?
Aryan
@aryandua
May 15 2016 06:53
How do you change the src of an img using JS?
Ankur sharma
@ankur1163
May 15 2016 07:16
@aryandua point of challenge is to sum all prime numbers
so sumprimes(10) should return sum of all prime numbers till the number 10
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:16
Good morning!
Ankur sharma
@ankur1163
May 15 2016 07:16
@GregatGit from where did you find this url?
On their mediawiki page , this isnt the url they are asking you to use
@GregatGit can you tell me exact page from where you pulled up this url
Greg Duncan
@GregatGit
May 15 2016 07:18
@ankur1163 just click on it and see the results it gives
Ankur sharma
@ankur1163
May 15 2016 07:18
thats ok.
this will work
Greg Duncan
@GregatGit
May 15 2016 07:18
@123xylem your url is fine - jquery was the issue
Ankur sharma
@ankur1163
May 15 2016 07:18
but how do you know this is the url we have to use?
i can append search term in the end
but what about the rest of the url
which wikipedia documentation you look at it?
@kristoferarnthors good morning
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:19
Can someone help me with Nesting For Loops? I'm not getting what I am supposed to do. It says to multiply with the variable product, but product = 1 so everything should just be 12, 13 etc. and that doesn't do anything.
Aryan
@aryandua
May 15 2016 07:19
@GregatGit can you help me?
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:19
I'm really not getting what I am supposed to do there.
Ankur sharma
@ankur1163
May 15 2016 07:19
@kristoferarnthors whats the exercise name?
Markus Kiili
@Masd925
May 15 2016 07:20
@kristoferarnthors You must change the product variable value inside the loop
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:20
@ankur1163 Nesting For Loops
@Masd925 The project says to not do that
´´´

´´´
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]; j++) {

}

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
´´´

Markus Kiili
@Masd925
May 15 2016 07:21
@kristoferarnthors No it doesn't.
Chris Cullen
@123xylem
May 15 2016 07:21
@GregatGit Can u check my current JSON.. I know im a million miles off getting that json to search wikipedia but Could you tell me why its not console.logging anything?
Rishi Wadekar
@Rishi17996
May 15 2016 07:21
Has anyone here implemented parallax scrolling?
Chris Cullen
@123xylem
May 15 2016 07:21
batchcomplete
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:22
@Masd925 It says //Only change code below this line
Rada
@Radascript
May 15 2016 07:22
@kristoferarnthors it wants you to say "product = 1. Now, for each array in the large array do the follow: for each element in this array, multiply product by its value."
@kristoferarnthors your set up is correct
Markus Kiili
@Masd925
May 15 2016 07:23
@kristoferarnthors The variable is declared and initialized at the top, and you use the variable inside the loop.
Rada
@Radascript
May 15 2016 07:23
@kristoferarnthors now just say product *= arr[i][j]; inside the curly braces
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:23
That doesn't work
Ankur sharma
@ankur1163
May 15 2016 07:23
@kristoferarnthors here's the solution
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]]);
let me explain
there are two for loops
please help me... with escape characters
Ankur sharma
@ankur1163
May 15 2016 07:24
because in first loop we are accessing [1,2] ; [3,4] etc
Rada
@Radascript
May 15 2016 07:24
@kristoferarnthors oh yeah your issue is j < arr[i]
Greg Duncan
@GregatGit
May 15 2016 07:24
@123xylem for now just use the one that gave you - I found that understanding wikipedia api is more art than science
Rada
@Radascript
May 15 2016 07:24
that doesn't make sense
you need to set it to j<arr[i].length
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:25
@Radascript Wow yeah I forgot .length!
Ankur sharma
@ankur1163
May 15 2016 07:25
in second loop we are accesing inner elements like 1 then 2 then 3 , 4
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:25
@Radascript Wow thank you for noticing this, I have been stuck on this since yesterday
CamperBot
@camperbot
May 15 2016 07:25
kristoferarnthors sends brownie points to @radascript :sparkles: :thumbsup: :sparkles:
:cookie: 338 | @radascript |http://www.freecodecamp.com/radascript
Chris Cullen
@123xylem
May 15 2016 07:25
@GregatGit Could u post that link again then... What is the difference with your link and the URL i used
?
Rada
@Radascript
May 15 2016 07:25
@kristoferarnthors np we've all been there. GL coding!
Kristófer Arnþórsson
@kristoferarnthors
May 15 2016 07:26
@ankur1163 I know what it does, just a head scratcher :) But thank you for helping!
CamperBot
@camperbot
May 15 2016 07:26
kristoferarnthors sends brownie points to @ankur1163 :sparkles: :thumbsup: :sparkles:
:cookie: 304 | @ankur1163 |http://www.freecodecamp.com/ankur1163
Ankur sharma
@ankur1163
May 15 2016 07:27
cool
I need some help , I think this program is to check whether a number is prime or not
function isPrime(n) {
    if (n < 2) { return false; }
    if (n !== Math.round(n)) { return false; }
    var result = true;
    for (var i = 2; i <= Math.sqrt(n); i++) {
        if (n % i === 0) {
            result = false;
        }
    }
    return result;
}
we are using math round function to check parameter isnt decimal or anything else
I hope I am correct there
why we used sqrt function
Chris Cullen
@123xylem
May 15 2016 07:28
@GregatGit what is the link you gave me though? I kind of know the wiki api gives access to wiki database and functions (i think) but Im not sure what your url is
Aryan
@aryandua
May 15 2016 07:29
if u run the loop till the sqrt then itll be much faster than running through the whole thing
Markus Kiili
@Masd925
May 15 2016 07:29
@ankur1163 Just a bit of math. You can stop the testing at the square root of n.
Greg Duncan
@GregatGit
May 15 2016 07:30

@123xylem

$.getJSON(myUrl, function(json) {
    console.log(json);
  });

try using this with the url - then change the word germany to something else

buiphuking
@buiphuking
May 15 2016 07:30
which preprocessor javascript should i go with ??
Ankur sharma
@ankur1163
May 15 2016 07:30
@Masd925 we stopped at i <= Math.sqrt(n)
hmm, what it does
Fatma Ali
@Fatmali
May 15 2016 07:31
Hi guys...after displaying my search results..." read more "links are nt working any ideas http://codepen.io/fatmali/pen/ZWZEqR
Aditya Giridhar
@agiridh
May 15 2016 07:42

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

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

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

I don't get why this doesn't ork
work
Fatma Ali
@Fatmali
May 15 2016 07:55
Hi @agiridh I think the problem is the double quotes....try this: if(myObj.hasOwnProperty(checkprop)) return myObj[checkprop];
Ankur sharma
@ankur1163
May 15 2016 08:02
I am seriously stuck in sum all prime numbers
can someone tell me how this should be done
Sanchit
@skhattar
May 15 2016 08:08

Hi,
Can someone please help me with the following code.-
$(document).ready(function() {
$('#location').click(function() {
$.getJSON("http://ipinfo.io", function(response) {

  $("#ip").html("IP: " + response.ip);
  $("#address").html("Location: " + response.city + ", " + response.region);
  $("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");

});
});
Its not showing anything

Tatum
@OrmusELdesu
May 15 2016 08:16
can anyone help me with Word Blanks?
nevermind I figured it out
Keone Martin
@Athaman
May 15 2016 08:24
@ankur1163 Which part are you stuck on?
Akash Verma
@akashvermaofskt
May 15 2016 08:34
How do you post codes here?
Catalin Scripcariu
@CatalinScr
May 15 2016 08:34
help post code
CamperBot
@camperbot
May 15 2016 08:34

:point_right: how to post code [wiki]

How to post code

use backticks `

posting

:pencil: read more about how to post code on the FCC Wiki

Keone Martin
@Athaman
May 15 2016 08:34
help format
CamperBot
@camperbot
May 15 2016 08:34

: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

Keone Martin
@Athaman
May 15 2016 08:34
whoops >.>
Ankur sharma
@ankur1163
May 15 2016 08:36
@Athaman I finished that exercise
I am into smallest common multiple
Keone Martin
@Athaman
May 15 2016 08:36
cool. sorry i wasn't quicker, just logged in for the day.
Akash Verma
@akashvermaofskt
May 15 2016 08:36
Hello, can someone help me out with this?
function rot13(str) { // LBH QVQ VG!

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

   if(str.charAt(i)>='A' && str.charAt(i)<='M') {
    str= str.replace(str.charAt(i),String.fromCharCode(str.charCodeAt(i)+13));
   }else if(str.charAt(i)>='N' && str.charAt(i)<='Z'){
    str= str.replace(str.charAt(i),String.fromCharCode(str.charCodeAt(i)-13));
   }

  }
  return str;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Chris Cullen
@123xylem
May 15 2016 08:37
@GregatGit IM thinking of just using wiki url and appending search input to the end to give a link to wikipedia http://codepen.io/123xylem/pen/aNxREJ?editors=1010
Keone Martin
@Athaman
May 15 2016 08:37
I think Javascript doesn't handle characters as numbers very well.
Chris Cullen
@123xylem
May 15 2016 08:37
Is that cheating?
Akash Verma
@akashvermaofskt
May 15 2016 08:38
Ohh
Keone Martin
@Athaman
May 15 2016 08:38
@akashvermaofskt I used charCodeAt for the comparisons
and since you need to translate it to change it anyway i just set up a variable and stored the character as its code at the start of the loop
also your replace method will look for the first example of the letter and replace that right? so if you had the string "this string has multiple i's" then it would replace the first i it found with the substitution character
Akash Verma
@akashvermaofskt
May 15 2016 08:42
@Athaman Oh yes, I have to use another thing instead of replace method
@Athaman Should I do it by converting to an array?
Keone Martin
@Athaman
May 15 2016 08:42
can replace take an index argument?
personally i just used an empty string answer
and answer += charCodeAt + 13;
although this isn't my favourite of my algorithm solutions so you can probably come up with a better option
Akash Verma
@akashvermaofskt
May 15 2016 08:44
Yes,Okay I was failing at replace method. I'll try with array and your method too! Thanks :)
Keone Martin
@Athaman
May 15 2016 08:44
No problem bud, let me know how you solve it in the end if you'd be so kind.
Akash Verma
@akashvermaofskt
May 15 2016 08:44
Yes sure!
Daniel Kelvich
@Daniel-Kelvich
May 15 2016 08:45
var myStr = '<a href= "http://www.example.com" target="_blank">Link</a>'; there is the mistake?
heey
Markus Kiili
@Masd925
May 15 2016 08:47
@akashvermaofskt Using split and map is one option.
Akash Verma
@akashvermaofskt
May 15 2016 08:49
@Masd925 Oh yes! Do they work on strings too?
Markus Kiili
@Masd925
May 15 2016 08:50
@akashvermaofskt No, but .split("") makes an array.
Akash Verma
@akashvermaofskt
May 15 2016 08:50
@Masd925 Yes! Thanks. I am looking into it.
CamperBot
@camperbot
May 15 2016 08:50
akashvermaofskt sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1493 | @masd925 |http://www.freecodecamp.com/masd925
Akash Verma
@akashvermaofskt
May 15 2016 08:51
@Daniel-Kelvich I guess you should use the escape sequence for the double quotes("").
Keone Martin
@Athaman
May 15 2016 08:52
the string is held in single quotes though so using the doubles shouldn't break out of it
that said i don't know what's wrong with it so maybe try that :P
Markus Kiili
@Masd925
May 15 2016 08:52
@akashvermaofskt Another way is to use the fact that string wrapper is an array-like object and force map on a string by: Array.prototype.map.call(str,function(char){...}
Essentially it is the same as splitting and mapping.
Akash Verma
@akashvermaofskt
May 15 2016 08:54
@Masd925 Oh Yes, lots of alternatives :)

Okay I got it, @Masd925 @Athaman

function rot13(str) { // LBH QVQ VG!
var l=str.length,ans="";

  for(var i=0;i<l;i++){
    if(str.charCodeAt(i)>=65 && str.charCodeAt(i)<=77) { // 65 char code of 'A', 77 is of 'M'
    ans+=String.fromCharCode(str.charCodeAt(i)+13);
   }else if(str.charCodeAt(i)>=78 && str.charCodeAt(i)<=90){ // 78 of 'N' and 90 of 'Z'
    ans+=String.fromCharCode(str.charCodeAt(i)-13);
   }else{
       ans+=String.fromCharCode(str.charCodeAt(i));
     }

  }
  return ans;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

Thanks! :)

CamperBot
@camperbot
May 15 2016 08:57
akashvermaofskt sends brownie points to @masd925 and @athaman :sparkles: :thumbsup: :sparkles:
:warning: akashvermaofskt already gave masd925 points
:cookie: 358 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 15 2016 08:58
you should put comments in at the if's to tell people what the numbers mean ;)
but yeah neat, better than mine, i just +13 to everything then check if it's over 90 and subtract 26... a bit clunky in retrospect
Akash Verma
@akashvermaofskt
May 15 2016 09:02
@Athaman Haha yep!
Tatum
@OrmusELdesu
May 15 2016 09:03
can someone help me with this?
Wiktor
@Wkredz1
May 15 2016 09:04
Why doesnt this set the background image for me?
wrong pen try this :
nevermind both are the one
Akash Verma
@akashvermaofskt
May 15 2016 09:05
@OrmusELdesu Please post the code
Keone Martin
@Athaman
May 15 2016 09:05

function nextInLine(arr, item) {
  // Your code here
  var q = arr.value * item.value;
  return q;  // 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));

nextInLine([2], 1);
that's @OrmusELdesu code
Tatum
@OrmusELdesu
May 15 2016 09:06
@akashvemaofskt it's in the link along with the topic I'm stuck with....
Keone Martin
@Athaman
May 15 2016 09:07
@OrmusELdesu, the example is on how to build a queue in javascript. the idea is to take in an arrar arr, add a number to the end, item, then remove the first element of the array and return it
you should look into the Array.push() and Array.shift() methods for this one.
Wiktor
@Wkredz1
May 15 2016 09:08
Can ssomeone answer?
Akash Verma
@akashvermaofskt
May 15 2016 09:08
@Wkredz1 The URL is not the direct URL of the image.
http://globe-views.com/dcim/dreams/clouds/clouds-01.jpg this brings you to the website
Wiktor
@Wkredz1
May 15 2016 09:08
OHH TY SO MUCH
Keone Martin
@Athaman
May 15 2016 09:09
damn, beat me to it :P
Akash Verma
@akashvermaofskt
May 15 2016 09:09
haha!
Robin Versloot
@EvilDutchrebel
May 15 2016 09:09

hey guys, I'm at a total loss here. I have to use dot and bracket notation to access myStorage. But with the given instructions I have no idea what to do next.

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

// Only change code below this line
myStorage.car.inside["glove box"];

rphares
@rphares
May 15 2016 09:10
@EvilDutchrebel , think you were meant to store that in the var they provided...
Tatum
@OrmusELdesu
May 15 2016 09:10
@Athaman ok I will try to pass this test, I will give you brownie points if I did 0_0
Keone Martin
@Athaman
May 15 2016 09:10
yay brownie points :)
if you want advice on the specific methods let me know after you'd had a shot at googling them.
rphares
@rphares
May 15 2016 09:10
something like var gloveBoxContents? been a while...
Robin Versloot
@EvilDutchrebel
May 15 2016 09:11
@rphares I can't change anything above the line that says "only change code below this line
rphares
@rphares
May 15 2016 09:11
yes, i know--
should have given you something like var gloveBoxContents // Change this line right?
Keone Martin
@Athaman
May 15 2016 09:12
what's the challenge called @EvilDutchrebel ?
rphares
@rphares
May 15 2016 09:12
and you were supposed to write
Wiktor
@Wkredz1
May 15 2016 09:12
ok wtf it still doesnt work
i hosted the image
rphares
@rphares
May 15 2016 09:12
var gloveBoxContents = your.code["here"];
Robin Versloot
@EvilDutchrebel
May 15 2016 09:12
@Athaman Acessing Nested Objects in JSON
Akash Verma
@akashvermaofskt
May 15 2016 09:12
@EvilDutchrebel you have to assing it to a variable
var gloveBoxContents = myStorage.car.inside["glove box"];
Robin Versloot
@EvilDutchrebel
May 15 2016 09:13
@akashvermaofskt thank you my good sir! it's strange that the instructions do not say to use a variable
CamperBot
@camperbot
May 15 2016 09:13
evildutchrebel sends brownie points to @akashvermaofskt :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @akashvermaofskt |http://www.freecodecamp.com/akashvermaofskt
Keone Martin
@Athaman
May 15 2016 09:13
@Wkredz1 should the body have the . before it?
Wiktor
@Wkredz1
May 15 2016 09:13
i guess not. Thanks
Keone Martin
@Athaman
May 15 2016 09:14
no problem
Akash Verma
@akashvermaofskt
May 15 2016 09:14
haha alright!
Wiktor
@Wkredz1
May 15 2016 09:21
what is the best way to set a background in css?
Rohan Gayen
@WapmasterRohan
May 15 2016 09:25
what is the problem with this code?
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var newArr=[];
  var len = arr.length;
  for(var i=0;i<len;i+=size) {
    newArr.push(arr.slice(i,size));/*
    if(i+size<=len) {
      for(var j=0;j<size;j++) {
        arr.shift();
      }
    }*/
  }
  return newArr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2);
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
Keone Martin
@Athaman
May 15 2016 09:25
oh wow... opening someone elses link resets your code solution to the algorithm. dammit
at the moment @WapmasterRohan you'll just grab the first size elements of the array and put it into a new one... but you won't reset your counter and get the next lot of them.
wait... sorry, misread that.
the second element in your slice function isn't changing
it should be size + i
Tatum
@OrmusELdesu
May 15 2016 09:28
@Athaman I still can't figure it out...
Rohan Gayen
@WapmasterRohan
May 15 2016 09:28
thanks @Athaman
CamperBot
@camperbot
May 15 2016 09:28
wapmasterrohan sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 359 | @athaman |http://www.freecodecamp.com/athaman
Joshua Swift
@joshuaswift
May 15 2016 09:31
function getIndexToIns(arr, num) {
  var arrInsert = arr.push(num);
  var sortedArr = arrInsert.sort(function(a,b){
    return a - b;
  });
  var index = sortedArr.indexOf(num);
  return index;
}

getIndexToIns([40, 60], 50);
Hey guys, so I was getting the error message "arrInsert is not a function" on this challenge
Keone Martin
@Athaman
May 15 2016 09:32
@OrmusELdesu so the first thing you want to do is put the item that is passed into the array that is passed
Krzysztof Borowy
@Krizzu
May 15 2016 09:32
@Joshuaswift declare arrInsert as array first
Joshua Swift
@joshuaswift
May 15 2016 09:32
I've since passed it by just not declaring a variable and using "arr.push(num);"
Keone Martin
@Athaman
May 15 2016 09:33
JS doesn't know it's an array until you say var arrInsert = [];
Joshua Swift
@joshuaswift
May 15 2016 09:33
@Krizzu Ahhh I see
Silly me
Krzysztof Borowy
@Krizzu
May 15 2016 09:33
@Joshuaswift Happens ! :P
Wiktor
@Wkredz1
May 15 2016 09:33
How do I set a border around a background image?
Joshua Swift
@joshuaswift
May 15 2016 09:33
@Krizzu @Athaman Thanks guys!
CamperBot
@camperbot
May 15 2016 09:33
joshuaswift sends brownie points to @krizzu and @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 360 | @athaman |http://www.freecodecamp.com/athaman
:cookie: 353 | @krizzu |http://www.freecodecamp.com/krizzu
Keone Martin
@Athaman
May 15 2016 09:33
No problem
@OrmusELdesu you can do that using arr.push(item);
Tatum
@OrmusELdesu
May 1