These are chat archives for FreeCodeCamp/HelpJavaScript

5th
May 2017
Aizaz Shahid
@aizazshahid
May 05 2017 00:00
@rugano where you stuck ?
rugano
@rugano
May 05 2017 00:00
@forwebtech the question that i have posted
Aizaz Shahid
@aizazshahid
May 05 2017 00:00
post it again ?
haven't remembered.
Mohamed Derhalli
@derhallim
May 05 2017 00:01
@forwebtech good nite man
rugano
@rugano
May 05 2017 00:01
@forwebtech ok,
Mohamed Derhalli
@derhallim
May 05 2017 00:01
@rugano what do u need?
Aizaz Shahid
@aizazshahid
May 05 2017 00:01
@derhallim good night !
Mohamed Derhalli
@derhallim
May 05 2017 00:02
@forwebtech oops, bymistake
@forkerino good nite man
@forwebtech ur names look like each other
Aizaz Shahid
@aizazshahid
May 05 2017 00:02
:+1:
rugano
@rugano
May 05 2017 00:02
@derhallim help on 'where do i belong'
Mohamed Derhalli
@derhallim
May 05 2017 00:02
@rugano that's a hard question, u have to find urself man
kidding
let me see
Aizaz Shahid
@aizazshahid
May 05 2017 00:03
@rugano but that's the point, did you come up with any code ??
Mohamed Derhalli
@derhallim
May 05 2017 00:03
@rugano ok I saw it
what don't u understand with it
rugano
@rugano
May 05 2017 00:05
@forwebtech @derhallim yes,right there,can't seem to figure out where am failing in my interpretation
Aizaz Shahid
@aizazshahid
May 05 2017 00:07
or changed something ?
rugano
@rugano
May 05 2017 00:08
@forwebtech i corrected as you guided,but had some little progress
Aizaz Shahid
@aizazshahid
May 05 2017 00:08
@rugano paste the new one !
Randy
@rsmorin2
May 05 2017 00:10
function titleCase(str) {
var titleArr = str.toLowerCase().split(" ");
var titleStr = "";
for (i = 0; i < titleArr.length; i++) {
titleStr = titleArr[i][0].toUpperCase(/\w\S*/g);
}
return titleStr;
}
titleCase("I'm a little tea pot");
var code = "formatted";
still having issues with title case a sentence..... can someone point me in the right direction? All I'm returning is the last capitalized letter of the array vs the whole array with cap letters.
Anuradha Singh
@anuradhabunu
May 05 2017 00:11
hi doing this chapter Return a Value from a Function with Return.. but whatever value i give in timesFive,i get 25
is there something wrong during compilation
??
Aizaz Shahid
@aizazshahid
May 05 2017 00:11
@anuradhabunu i think you are returning wrong value !
check your return statement !
Anuradha Singh
@anuradhabunu
May 05 2017 00:11
@forwebtech return(arg1*5);
Madhusudanan Nagesh Sai
@nsaimadhusudanan2801
May 05 2017 00:12

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

return removed; // Change this line
}

Aizaz Shahid
@aizazshahid
May 05 2017 00:12
@anuradhabunu arg1 ??
Madhusudanan Nagesh Sai
@nsaimadhusudanan2801
May 05 2017 00:12
some thing seems to be wrong with this
Anuradha Singh
@anuradhabunu
May 05 2017 00:12
@forwebtech function timesFive(arg1){
return(arg1*5);
}
timesFive(0);
Aizaz Shahid
@aizazshahid
May 05 2017 00:12
@anuradhabunu paste your code here ?
what is the task name ?
@anuradhabunu
Madhusudanan Nagesh Sai
@nsaimadhusudanan2801
May 05 2017 00:13

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

return removed; // 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));
upon execution, i am getting an error which says arr.shift is not a function.

Anuradha Singh
@anuradhabunu
May 05 2017 00:13
@forwebtech Return a Value from a Function with Return
Aizaz Shahid
@aizazshahid
May 05 2017 00:14
@anuradhabunu actually your syntax of return(..) wrong
@anuradhabunu it should be written as return arg1 * 5;
rugano
@rugano
May 05 2017 00:15
Menulearn to code javascript at Free Code Camp logo

freeCodeCamp is a small nonprofit with a big mission. Become a Supporter.
Where do I belong
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number.

For example, getIndexToIns([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1).

Likewise, getIndexToIns([20,3,5], 19) should return 2 because once the array has been sorted it will look like [3,5,20] and 19 is less than 20 (index 2) and greater than 5 (index 1).

Remember to use Read-Search-Ask if you get stuck. Write your own code.

Here are some helpful links:

Array.prototype.sort()
Run tests (ctrl + enter)
  Reset      Help      Bug

0

getIndexToIns([10, 20, 30, 40, 50], 35) should return 3.
getIndexToIns([10, 20, 30, 40, 50], 30) should return 2.
getIndexToIns([40, 60], 50) should return 1.
getIndexToIns([3, 10, 5], 3) should return 0.
getIndexToIns([5, 3, 20, 3], 5) should return 2.
getIndexToIns([2, 20, 10], 19) should return 2.
getIndexToIns([2, 5, 10], 15) should return 3.


1Help JavaScript
Aizaz Shahid
@aizazshahid
May 05 2017 00:15
return is not a method actually we use () in methods,
Lázaro Avelino Santos de Castro
@lazarocastro
May 05 2017 00:15
hello everyone
Aizaz Shahid
@aizazshahid
May 05 2017 00:15
@rugano to paste the code, why delaying ??
@lazarocastro Welcome !
Anuradha Singh
@anuradhabunu
May 05 2017 00:15
@forwebtech tried that way also, but i am always getting a 25 as an answer
Lázaro Avelino Santos de Castro
@lazarocastro
May 05 2017 00:15
in politrome challenge
rugano
@rugano
May 05 2017 00:16
@forwebtech the editor is stuck
Nguyen Hoang
@honnhien12h
May 05 2017 00:16
case 7:
case 8:
case 9:
count= "0 Hold";
break;
Aizaz Shahid
@aizazshahid
May 05 2017 00:16
@anuradhabunu press the reset button !
and then try !
Lázaro Avelino Santos de Castro
@lazarocastro
May 05 2017 00:16
only test my algoritm dont pass was palindrome("1 eye for of 1 eye.") should return false.
can i past my code here for looking?
Aizaz Shahid
@aizazshahid
May 05 2017 00:17
@honnhien12h paste your code, but you don't have to make your count string, count contains the numbers actually !
Lázaro Avelino Santos de Castro
@lazarocastro
May 05 2017 00:17

function palindrome(str) {
// Good luck!
// Here put my Regex expression
var replaced = str.replace(/\s+|\W+|\d+/ig, '');

// I split() my var and reverse() replaced var into splited var
var splited = replaced.split('');
splited.reverse();
var reversed = splited.join('');

// now I'll test my two variables
if (reversed.toLowerCase() !== replaced.toLowerCase()) {
return false;
}

return true;
}

Aizaz Shahid
@aizazshahid
May 05 2017 00:17
count = "0 Hold" make it a string, it uses as a counter of playing !
Anuradha Singh
@anuradhabunu
May 05 2017 00:17
@forwebtech not working, my code is correct anyway as it is letting me pass to the next challenge ,i suppose it is an error on the compile log
Aizaz Shahid
@aizazshahid
May 05 2017 00:18
@anuradhabunu copy that and try

// Example
function minusSeven(num) {
  return num - 7;
}

// Only change code below this line
function timesFive(a) {
  return a * 5;
}
i think you have changed the name of something ! so that's why not working !
Lázaro Avelino Santos de Castro
@lazarocastro
May 05 2017 00:18
anyone?
Nguyen Hoang
@honnhien12h
May 05 2017 00:19
@forwebtech i can not copy my code = code formatting?
Aizaz Shahid
@aizazshahid
May 05 2017 00:19
use backticks to enqoute ```

@honnhien12h
:bulb: To format your code, please follow:
Code Formatting

More details..

@lazarocastro first test your regex there http://regexr.com/
HeebieGeeBee
@HeebieGeeBee
May 05 2017 00:20
@lazarocastro your regex doesnt remove underscores but youre removing numbers and youre meant to leave them in
Aizaz Shahid
@aizazshahid
May 05 2017 00:21
@rugano i think you have still some issue in copy and pasting ?? is your computer slow ??
Nguyen Hoang
@honnhien12h
May 05 2017 00:22

case 7:
    case 8:
    case 9:
      count= "0 Hold";
      break;
@forwebtech ```js
Aizaz Shahid
@aizazshahid
May 05 2017 00:24
@honnhien12h in case 7, 8, 9 you don't need to do anything just remove it from your switch !
+1 => 2, 3, 4, 5, 6 in these cases increment your count variable by
and 10, 'J', 'Q', 'K', 'A' in these, decrement your count
Nguyen Hoang
@honnhien12h
May 05 2017 00:25

var count = 0;

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

    case 2:
    case 2:
    case 10:

     count =1;
      break;

    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count = -5;
      break;
    case 3:
    case 7:
    case "Q":
    case 8:
    case "A":

      break;
    case 3:
    case 2:
    case "A":
    case 10:
    case "K":
     count= -1;}



  if (count === 0){
    return "0 Hold";
  }else if (count == 5){
    return "5 Bet";
  }else if (count == -5){
    return "-5 Hold";
  }else if (count ==1){
    return "1 Bet";
  }else if (count == -1){
    return "-1 Hold";
  }


  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Aizaz Shahid
@aizazshahid
May 05 2017 00:26
@honnhien12h why did you declare so much cases!
you need just that:
switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;

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

  }
after that you have to test your count, if positive it will return , count + " bet" if negative or zero, then it will return count + " hold"
rugano
@rugano
May 05 2017 00:27

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

  var c = num;

  var d = num;

  arr.push(num);
  arr.sort(function(c, d){
    return c- d;
  });

  return c - d;
}

getIndexToIns([40, 60], 50);
Aizaz Shahid
@aizazshahid
May 05 2017 00:28
@rugano hmm you take too much time to paste that code, what's the problem, didn't you get copy and paste ??
rugano
@rugano
May 05 2017 00:28
@forwebtech there it is
Aizaz Shahid
@aizazshahid
May 05 2017 00:28
@rugano did you type that code ??
for here !
sumeetghosh
@sumeetghosh
May 05 2017 00:29

var myVar = 87;

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

myVar = myVar++;

Aizaz Shahid
@aizazshahid
May 05 2017 00:29
well now you have to return the index of that inserted number !
rugano
@rugano
May 05 2017 00:29
@forwebtech yes,after the code editor couldn't move
Nguyen Hoang
@honnhien12h
May 05 2017 00:29
@forwebtech i don't understand, i'am stupid but will try it..
Aizaz Shahid
@aizazshahid
May 05 2017 00:30
@honnhien12h well try it !
sumeetghosh
@sumeetghosh
May 05 2017 00:30

"myVar = myVar should be changed"

can anybody help me with this point

Aizaz Shahid
@aizazshahid
May 05 2017 00:30
@rugano with ctrl + c ??
@rugano your pc is slow ??
rugano
@rugano
May 05 2017 00:30
@forwebtech yes
Aizaz Shahid
@aizazshahid
May 05 2017 00:31
oh , well it's ok
i was thinking you had issue with copy and pasting !
rugano
@rugano
May 05 2017 00:31
@forwebtech network,slow
Aizaz Shahid
@aizazshahid
May 05 2017 00:31
got it !
@rugano have to return the index of that inserted number !
rugano
@rugano
May 05 2017 00:33
@forwebtech i got it,copy and paste,let me correct it
sumeetghosh
@sumeetghosh
May 05 2017 00:33

var myVar = 87;

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

myVar = myVar++;

"myVar = myVar should be changed"

cannot understand this line, can anybody help me?

Gulsvi
@gulsvi
May 05 2017 00:33
@sumeetghosh myVar = myVar + 1 is the same as myVar++
var myVar = 400;
myVar++ // 401
myVar = myVar + 1 // 402
Aizaz Shahid
@aizazshahid
May 05 2017 00:34
@sumeetghosh if you use ++ operator only with that variable it will also add one, so try to use variable name with ++ operator !
Devon Thomas
@UmbraLegacy
May 05 2017 00:35
The following code works perfectly. But I'm interested in improving it - what problems can you see, and what would you recommend?
var Person = function(fullName) {
    var firstAndLast = fullName;
    var firstName = (firstAndLast.split(" "))[0];
    var lastName = (firstAndLast.split(" "))[1];


    this.getFirstName = function() {
        return firstName;
    };
    this.getLastName = function() {
        return lastName;
    };
    this.getFullName = function() {
        return firstAndLast;
    };

    this.setFirstName = function(first) {
        firstName = first;
        firstAndLast = firstName + " " + lastName;
    };
    this.setLastName = function(last) {
        lastName = last;
        firstAndLast = firstName + " " + lastName;
    };
    this.setFullName = function(fullName) {
        firstAndLast = fullName;
        firstName = (firstAndLast.split(" "))[0];
        lastName = (firstAndLast.split(" "))[1];
    };
};

var bob = new Person('Bob Ross');
console.log(bob.getFullName());
Long Nguyen
@longnt80
May 05 2017 00:36
what is the website that show each step of your code? I remember it is python... something. Anyone knows?
rugano
@rugano
May 05 2017 00:36
return arr.indexOf(num);
@forwebtech thanks,got it
CamperBot
@camperbot
May 05 2017 00:36
:cookie: 412 | @forwebtech |http://www.freecodecamp.com/forwebtech
rugano sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
Aizaz Shahid
@aizazshahid
May 05 2017 00:36
@rugano did you pass it ?
rugano
@rugano
May 05 2017 00:37
@forwebtech yes ,
Aizaz Shahid
@aizazshahid
May 05 2017 00:37
don't know, but, feel happy after that :stuck_out_tongue:
Long Nguyen
@longnt80
May 05 2017 00:38
@SkyCoder01 thank you!
CamperBot
@camperbot
May 05 2017 00:38
longnt80 sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1273 | @skycoder01 |http://www.freecodecamp.com/skycoder01
pauloaguiar1
@pauloaguiar1
May 05 2017 00:39
Hey guys! :) pls help, Im trying to escape inside a string, buy my code is "missing a space", how do I fix It? var myStr = "FirstLine\n\SecondLine\\rThirdline";
Aizaz Shahid
@aizazshahid
May 05 2017 00:40
@UmbraLegacy did you make it by self ??
@UmbraLegacy means not for task ?
rugano
@rugano
May 05 2017 00:40

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

  var c = num;

  var d = num;

  arr.push(num);
  arr.sort(function(c, d){
    return c - d;
  });

  return arr.indexOf(num);
}

getIndexToIns([40, 60], 50);
@forwebtech there it is
Aizaz Shahid
@aizazshahid
May 05 2017 00:41
@rugano but now you passed it?
rugano
@rugano
May 05 2017 00:42
@forwebtech yes,thank you
CamperBot
@camperbot
May 05 2017 00:42
rugano sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:warning: rugano already gave forwebtech points
Aizaz Shahid
@aizazshahid
May 05 2017 00:42
:+1:
@UmbraLegacy why don't you accept first name and last name through arguments instead of taking in one argument fullName
Devon Thomas
@UmbraLegacy
May 05 2017 00:43
@forwebtech , I wrote it myself for the Make A Person task on FreeCodeCamp.
But I want to improve my skills; understanding best practices is my goal.
Gulsvi
@gulsvi
May 05 2017 00:43
@rugano Good job. You can simplify it a bit - for example, you don't use the variable newArr anywhere in your code. And the variables c and d are not used by the sort function.
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  arr.push(num);
  arr.sort(function(c, d){
    return c - d;
  });

  return arr.indexOf(num);
}
Aizaz Shahid
@aizazshahid
May 05 2017 00:43
@UmbraLegacy great so stick with me i will go throw you !
Devon Thomas
@UmbraLegacy
May 05 2017 00:44
@forwebtech , the requirements are that I accept a single argument.
Aizaz Shahid
@aizazshahid
May 05 2017 00:45
i see..
ok lets move on !
@UmbraLegacy if you split your full name like:
var firstAndLast = fullName.split(" ");
then below codes makes easy !
   var firstName = firstAndLast[0];
    var lastName = firstAndLast[1];
Donnie
@Donnie-D
May 05 2017 00:47
function mutation(arr) {
 var str0 = arr[0].toLowerCase();
 var str1 = arr[1].toLowerCase();
 var result;
  for(i=0; i<=str1.length; i++){
    if(str1[i]==str0[str1.indexOf(str1[i])]){
      result = true;
    }
    else{
      return false;
    }
  }return result;
}

mutation(["mary", "army"]);
i can't seem to find any errors in the above code i wrote but it throws a 'false' whereas it should be resulting in a 'true'. Anyone?
Aizaz Shahid
@aizazshahid
May 05 2017 00:48
@UmbraLegacy also change your var firstAndLast to var fullName
because, names should be readable as well
Devon Thomas
@UmbraLegacy
May 05 2017 00:50
@forwebtech , Yes, I completely agree. That simplifies much. Then the getFullName is simply
this.getFullName = function() {
        return firstAndLast.join(" ");
    };
Aizaz Shahid
@aizazshahid
May 05 2017 00:51
@UmbraLegacy now look at this, using ES6 syntax:
var Person = function(fullName) {
    var fullName = fullName.split(" ");
    var firstName = fullName[0];
    var lastName = fullName[1];


    this.getFirstName = () => firstName;
    this.getLastName = () =>  lastName;
    this.getFullName = () =>  fullName.join(" ");
=> that operator used to return something !

@UmbraLegacy well if you change the third line:

this.getFullName = () =>  firstName + " " + lastName;

so then you don't have to care about the fullName variable !

like below:
this.setFirstName = function(first) { firstName = first; };
this.setLastName = function(last) { lastName = last; };
juwels19
@juwels19
May 05 2017 00:57
im in need of help with a program
HeebieGeeBee
@HeebieGeeBee
May 05 2017 00:57
@Donnie-D if(str1[i]==str0[str1.indexOf(str1[i])]) what are you doing here?
Donnie
@Donnie-D
May 05 2017 00:58
@HeebieGeeBee trying to see if a letter in string1 is present in string0
HeebieGeeBee
@HeebieGeeBee
May 05 2017 00:58
but anyway dont have <= for your loop conditional
just <
@Donnie-D
Donnie
@Donnie-D
May 05 2017 00:58
@HeebieGeeBee pardon? i dont know what you mean sorry
HeebieGeeBee
@HeebieGeeBee
May 05 2017 00:59
i<=str1.length not this but i<str1.length
juwels19
@juwels19
May 05 2017 00:59
it is the profile lookup of the javascript lessons
Aizaz Shahid
@aizazshahid
May 05 2017 01:00
@UmbraLegacy and you should to make your setFullName as :
this.setFullName = function(fullName) {
    var name = fullName.split(" ");
    firstName = name[0];
    lastName = name[1];
};
Donnie
@Donnie-D
May 05 2017 01:00
@HeebieGeeBee i took out the = sign but still same result shown
HeebieGeeBee
@HeebieGeeBee
May 05 2017 01:00
@Donnie-D and i dont see why you dont just do if(str0.indexOf(str1[i]) !== -1)
@Donnie-D looks like you if statement needs them to be in the rightorder too, but cant quite get my head around it lol
Donnie
@Donnie-D
May 05 2017 01:01
@HeebieGeeBee now thats interesting. could you please share why this !== -1 for?
HeebieGeeBee
@HeebieGeeBee
May 05 2017 01:02
if it doesnt find an index of the element in the string it will return -1
Donnie
@Donnie-D
May 05 2017 01:02
@HeebieGeeBee haha you are kind enough to help . :+1:
HeebieGeeBee
@HeebieGeeBee
May 05 2017 01:02
the indexOf method that is
Donnie
@Donnie-D
May 05 2017 01:05
@HeebieGeeBee but in the above code all the letters in both strings are similar then why a 'false' result?
HeebieGeeBee
@HeebieGeeBee
May 05 2017 01:05
@Donnie-D cuase it looks like youre trying to match the letters in the same index
Donnie
@Donnie-D
May 05 2017 01:06
@HeebieGeeBee sounds like i messed up big time there lol
@HeebieGeeBee i tried asking guys here this afternoon as well regarding this one. now i know why no one dared jumping into this lol
HeebieGeeBee
@HeebieGeeBee
May 05 2017 01:09
@Donnie-D maybe, but sometimes questions or requests for help get missed by ppl
Donnie
@Donnie-D
May 05 2017 01:09
@HeebieGeeBee may be yeah
juwels19
@juwels19
May 05 2017 01:10
can someone help with the profile lookup?
HeebieGeeBee
@HeebieGeeBee
May 05 2017 01:10
@juwels19 i need to go for a few minutes but post your code,
Donnie
@Donnie-D
May 05 2017 01:10
@HeebieGeeBee cheers though. i shall keep on 'hit and try' with this hahah
HeebieGeeBee
@HeebieGeeBee
May 05 2017 01:11
@Donnie-D pretty sure you just have to use the if statement i showed you instead of yours
Donnie
@Donnie-D
May 05 2017 01:11
@HeebieGeeBee :+1:
Aizaz Shahid
@aizazshahid
May 05 2017 01:14
can we short our setter:
var sample = function( arg ) {
var a;
    this.setVar = function( val ) { a = val; };

}
王想想
@wxxxxxxxx
May 05 2017 01:15
呵呵
bitcoinabdi
@bitcoinabdi
May 05 2017 01:18
good afternoon guyz
i need help folks th algorithim is killing me !
Joseph
@revisualize
May 05 2017 01:19
Hey hey.
juwels19
@juwels19
May 05 2017 01:20

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

// Only change code above this line
}

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

Joseph
@revisualize
May 05 2017 01:20
@bitcoinabdi which?
bitcoinabdi
@bitcoinabdi
May 05 2017 01:20
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var aa = [];
  var a1 =arr.slice(0,i);
  var a2 = arr.slice(size,size*2);
  var i = size;

  for(i=0;i<arr.length;i++){
    return aa.concat([a1]);
  }




}


chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2);
juwels19
@juwels19
May 05 2017 01:20

i have to do the following instructions: The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

Joseph
@revisualize
May 05 2017 01:20
@juwels19 you havent done anything.
juwels19
@juwels19
May 05 2017 01:20
i know, im not sure what to do
i know i have to compare the parameters to the array to check for firstName and to see if the parameter is apart of the object i just dont know how to write it
bitcoinabdi
@bitcoinabdi
May 05 2017 01:23
@revisualize i can increase the size by using the for loop but how do i group the results into chucks?
Joseph
@revisualize
May 05 2017 01:23
@bitcoinabdi What?
Oh, I didnt see your code post.
You are trying to access variables before they are declared and defined.
a2 ... i is undefined
Sorry a1
bitcoinabdi
@bitcoinabdi
May 05 2017 01:27

function chunkArrayInGroups(arr, size) {
// Break it up.
var aa = [];
var a1 =arr.slice(0,i);
var a2 = arr.slice(size,size*2);
var i = size;

for(i=0;i<arr.length;i++){
return aa.concat([a1]);
}

}

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

@revisualize
Joseph
@revisualize
May 05 2017 01:28
a1 ... i ... what is its value?
undefined
the return in your for loop.. halts the function.
bitcoinabdi
@bitcoinabdi
May 05 2017 01:30
var a1 =arr.slice(0,i);
Joseph
@revisualize
May 05 2017 01:30
Your loop doesnt loop
Nguyen Hoang
@honnhien12h
May 05 2017 01:30
@forwebtech i don' can :(
var count = 0;

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

  if ((d+e)<=0){
    return count + "Hold";
  }else {
    return count + "Bet";
  }

  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
bitcoinabdi
@bitcoinabdi
May 05 2017 01:31
var a1=arr.slice(0,size); @revisualize
James Diaz
@clanmaster
May 05 2017 01:31
Hey all! Just thought and pop in to say hi :smile: :smile:
bitcoinabdi
@bitcoinabdi
May 05 2017 01:31
how else am i supposed to declare it ? @revisualize
Joseph
@revisualize
May 05 2017 01:31
@honnhien12h Return causes your function to HALT
Aizaz Shahid
@aizazshahid
May 05 2017 01:32
@honnhien12h first you should not to use return d; into your switch
instead use break;
Joseph
@revisualize
May 05 2017 01:32
@bitcoinabdi You have to take a top down approach to JavaScript.
Aizaz Shahid
@aizazshahid
May 05 2017 01:33
@honnhien12h there is no need for extra variables to test the condition, already you have global variable count, which will also used in your conditional statement !
Joseph
@revisualize
May 05 2017 01:33
@bitcoinabdi using the var key word in your function causes the variable to be hoisted to the top of the function for declaration. However, when the variable is hoisted. It has a value of undefined UNTIL (remember top down) ... down the code chain there is a value assigned to it.
Anuradha Singh
@anuradhabunu
May 05 2017 01:33
hi all, i am facing issues in javascript, i just wanna know if anyone else has faced the same issue . Issue is even though my code is correct and i am getting the correct answer in the compile log, i am not able to go way past the challenge....anyone ?? I have tried refreshing and reset my entire code.
Aizaz Shahid
@aizazshahid
May 05 2017 01:33
@anuradhabunu still there ??
Anuradha Singh
@anuradhabunu
May 05 2017 01:34
yes
got the same issue again
Aizaz Shahid
@aizazshahid
May 05 2017 01:34
on different challenge ??
Anuradha Singh
@anuradhabunu
May 05 2017 01:34
this time in Golf Code
Joseph
@revisualize
May 05 2017 01:34
@anuradhabunu What challenge? What issue?
Anuradha Singh
@anuradhabunu
May 05 2017 01:34
@revisualize Golf Code @revisualize
Joseph
@revisualize
May 05 2017 01:34
Show code?
Aizaz Shahid
@aizazshahid
May 05 2017 01:34
@anuradhabunu listen remove your cookies and cache !
Anuradha Singh
@anuradhabunu
May 05 2017 01:34

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

return "Change Me";
// Only change code above this line
}

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

Aizaz Shahid
@aizazshahid
May 05 2017 01:35
and then re login it to your FCC and try hope it will makes it clear !
@anuradhabunu
Joseph
@revisualize
May 05 2017 01:35
@anuradhabunu Your code isn't correct.
Jeff
@etisdew
May 05 2017 01:35

```function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i in contacts){
for (var j in contacts[i]){
return (contacts[i][j] == contacts[firstName][prop] ? contacts[i][prop] : "No such property");}
}
// Only change code above this line
}

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

Anuradha Singh
@anuradhabunu
May 05 2017 01:35
@revisualize could you help
Aizaz Shahid
@aizazshahid
May 05 2017 01:35
@revisualize guide her !
Joseph
@revisualize
May 05 2017 01:35
@anuradhabunu Yeah. Let me pull it up.
Aizaz Shahid
@aizazshahid
May 05 2017 01:35
:)
Joseph
@revisualize
May 05 2017 01:36
@anuradhabunu You have the string "Hole-in-one" Which is not correct. The value is "Hole-in-one!"
@anuradhabunu Strings need to be EXACT
Aizaz Shahid
@aizazshahid
May 05 2017 01:36
@etisdew your contact is single dimension array but though it stores objects!
@etisdew so you need just one loop to access contacts loop as contacts[i].firstName...
Jeff
@etisdew
May 05 2017 01:37
oh so use a dot notation
bitcoinabdi
@bitcoinabdi
May 05 2017 01:37
@revisualize please give an example ... of the declaration you are talking about
Joseph
@revisualize
May 05 2017 01:37
@bitcoinabdi sure.
Anuradha Singh
@anuradhabunu
May 05 2017 01:37
@revisualize oh oh so stupid of me ....thanks for looking in my code
CamperBot
@camperbot
May 05 2017 01:37
anuradhabunu sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3896 | @revisualize |http://www.freecodecamp.com/revisualize
Jeff
@etisdew
May 05 2017 01:38
@forwebtech thank you, brownie bot feed him
CamperBot
@camperbot
May 05 2017 01:38
etisdew sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 413 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
May 05 2017 01:38
@etisdew used dot notation because am directly getting the value from that global contacts but when you get properties from arguments then use bracket notation!
Jeff
@etisdew
May 05 2017 01:38
gotta screaming kiddo in the background so thank you
Aizaz Shahid
@aizazshahid
May 05 2017 01:39
:+1:
Joseph
@revisualize
May 05 2017 01:40
@bitcoinabdi https://repl.it/Hh9A
Nguyen Hoang
@honnhien12h
May 05 2017 01:42
@forwebtech It still does not work, why?
Aizaz Shahid
@aizazshahid
May 05 2017 01:43
paste code !
Nguyen Hoang
@honnhien12h
May 05 2017 01:43

var count = 0;

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

  }


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

  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Joseph
@revisualize
May 05 2017 01:43
@honnhien12h You're missing a space
@honnhien12h You're returning a value like "1Bet"
But, it should have a space.
Aizaz Shahid
@aizazshahid
May 05 2017 01:43
yes just need a space @revisualize as told count + " Hold";
@honnhien12h
Joseph
@revisualize
May 05 2017 01:44
Okay. Time for me to get that Youtube on.
:v:
bitcoinabdi
@bitcoinabdi
May 05 2017 01:48
@revisualize before you leave can you explain some more using my code
Jason G
@Jay33Canada
May 05 2017 01:51
how do i figure out if an algorithm for prime numbers? i googled it but it was really confusing
Stephen James
@sjames1958gm
May 05 2017 01:52
@Jay33Canada The brute force test for a prime number is testing that no number from 2 to square root of the number divide evenly into the number
use num % x === 0
Jason G
@Jay33Canada
May 05 2017 01:54
x being all the the numbers up to the square root of a number?
Stephen James
@sjames1958gm
May 05 2017 01:54
@Jay33Canada Yes
bitcoinabdi
@bitcoinabdi
May 05 2017 01:54
anyone help ,me with the ncky monkey al;gorithm ?
Stephen James
@sjames1958gm
May 05 2017 01:54
@bitcoinabdi What code do you have.
Jason G
@Jay33Canada
May 05 2017 01:54
i don't even remember how to get a square root @sjames1958gm lol google to my rescue?
Nguyen Hoang
@honnhien12h
May 05 2017 01:54
@revisualize @forwebtech i'am sorry but i don't understand...
Stephen James
@sjames1958gm
May 05 2017 01:54
@Jay33Canada Math.sqrt probably
Aizaz Shahid
@aizazshahid
May 05 2017 01:55
@honnhien12h return count + " bet" and return count + " hold" need a space after your first quotes
so the output will be as 0 bet , 4 hold like that
Stephen James
@sjames1958gm
May 05 2017 01:57
@honnhien12h @forwebtech is correct - just use Bet and Hold (not bet and hold)
Aizaz Shahid
@aizazshahid
May 05 2017 01:57
@sjames1958gm ohh yes i forgot about that thanks any way
CamperBot
@camperbot
May 05 2017 01:57
forwebtech sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7122 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Brian Arriaga
@BAXTOR95
May 05 2017 01:57
function lookUpProfile(firstName, prop){
// Only change code below this line

  var response = "";
  for (var i=0; i<contacts.length; i++) {
    if (firstName == contacts[i].firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        response = contacts[i].firstName + " likes: ";
        for(var j=0; j<contacts[i].likes.length; j++) {
          if (j!=(contacts[i].likes.length - 1)) {
            response = response + contacts[i].likes[j] + ", ";
          }else {
            response = response + contacts[i].likes[j] + ". ";
          }
        }
      }else {
        if (i==(contacts.length - 1)) {response = "No such property";}
      }
    }else {
      if (i==(contacts.length - 1)) {response = "No such contact";}
    }
  }
  return response;

// Only change code above this line
}
Can someone please tell me what's wrong with that function? It's not passing the "Run Test" and I don't know what are they asking me to do then. It's from this challenge title%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0A%0A%20%20var%20response%20%3D%20%22%22%3B%0A%20%20for%20(var%20i%3D0%3B%20i%3Ccontacts.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20if%20(firstName%20%3D%3D%20contacts%5Bi%5D.firstName)%20%7B%0A%20%20%20%20%20%20if%20(contacts%5Bi%5D.hasOwnProperty(prop))%20%7B%0A%20%20%20%20%20%20%20%20response%20%3D%20contacts%5Bi%5D.firstName%20%2B%20%22%20likes%3A%20%22%3B%0A%20%20%20%20%20%20%20%20for(var%20j%3D0%3B%20j%3Ccontacts%5Bi%5D.likes.length%3B%20j%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20%20%20if%20(j!%3D(contacts%5Bi%5D.likes.length%20-%201))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20response%20%3D%20response%20%2B%20contacts%5Bi%5D.likes%5Bj%5D%20%2B%20%22%2C%20%22%3B%0A%20%20%20%20%20%20%20%20%20%20%7Delse%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20response%20%3D%20response%20%2B%20contacts%5Bi%5D.likes%5Bj%5D%20%2B%20%22.%20%22%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7Delse%20%7B%0A%20%20%20%20%20%20%20%20if%20(i%3D%3D(contacts.length%20-%201))%20%7Bresponse%20%3D%20%22No%20such%20property%22%3B%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7Delse%20%7B%0A%20%20%20%20%20%20if%20(i%3D%3D(contacts.length%20-%201))%20%7Bresponse%20%3D%20%22No%20such%20contact%22%3B%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20response%3B%0A%20%20%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Akira%22%2C%20%22likes%22)%3B%0A). Thanks
bitcoinabdi
@bitcoinabdi
May 05 2017 01:58

function chunkArrayInGroups(arr, size) {
// Break it up.
var aa = [];
var a1 =arr.slice(0,i);
var a2 = arr.slice(size,size*2);
var i = size;

for(i=0;i<arr.length;i++){
return aa.concat([a1]);
}

}

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

function chunkArrayInGroups(arr, size) {
  // Break it up.
  var aa = [];
  var a1 =arr.slice(0,i);
  var a2 = arr.slice(size,size*2);
  var i = size;

  for(i=0;i<arr.length;i++){
    return aa.concat([a1]);
  }



}


chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2);
Brian Arriaga
@BAXTOR95
May 05 2017 01:59
challenge%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0A%0A%20%20var%20response%20%3D%20%22%22%3B%0A%20%20for%20(var%20i%3D0%3B%20i%3Ccontacts.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20if%20(firstName%20%3D%3D%20contacts%5Bi%5D.firstName)%20%7B%0A%20%20%20%20%20%20if%20(contacts%5Bi%5D.hasOwnProperty(prop))%20%7B%0A%20%20%20%20%20%20%20%20response%20%3D%20contacts%5Bi%5D.firstName%20%2B%20%22%20likes%3A%20%22%3B%0A%20%20%20%20%20%20%20%20for(var%20j%3D0%3B%20j%3Ccontacts%5Bi%5D.likes.length%3B%20j%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20%20%20if%20(j!%3D(contacts%5Bi%5D.likes.length%20-%201))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20response%20%3D%20response%20%2B%20contacts%5Bi%5D.likes%5Bj%5D%20%2B%20%22%2C%20%22%3B%0A%20%20%20%20%20%20%20%20%20%20%7Delse%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20response%20%3D%20response%20%2B%20contacts%5Bi%5D.likes%5Bj%5D%20%2B%20%22.%20%22%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7Delse%20%7B%0A%20%20%20%20%20%20%20%20if%20(i%3D%3D(contacts.length%20-%201))%20%7Bresponse%20%3D%20%22No%20such%20property%22%3B%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7Delse%20%7B%0A%20%20%20%20%20%20if%20(i%3D%3D(contacts.length%20-%201))%20%7Bresponse%20%3D%20%22No%20such%20contact%22%3B%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20response%3B%0A%20%20%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Akira%22%2C%20%22likes%22)%3B%0A)
bitcoinabdi
@bitcoinabdi
May 05 2017 01:59
@sjames1958gm please see my code
Stephen James
@sjames1958gm
May 05 2017 01:59
@BAXTOR95 Just set the response to the property value - contacts[i][prop] - don't do whatever that inner for loop is doing.
Nguyen Hoang
@honnhien12h
May 05 2017 02:00
@sjames1958gm @forwebtech @revisualize
I understand
I forgot that..!! Oh my God
I finished it after 1h!
Stephen James
@sjames1958gm
May 05 2017 02:00
@bitcoinabdi YOu need to take the slices inside the loop and add them to the result - and you need to return after the loop
Nguyen Hoang
@honnhien12h
May 05 2017 02:00
@sjames1958gm @forwebtech @revisualize Thanks So much!!
CamperBot
@camperbot
May 05 2017 02:00
honnhien12h sends brownie points to @sjames1958gm and @forwebtech and @revisualize :sparkles: :thumbsup: :sparkles:
:cookie: 414 | @forwebtech |http://www.freecodecamp.com/forwebtech
:star2: 3897 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 7123 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Nguyen Hoang
@honnhien12h
May 05 2017 02:01
if (count <= 0){
    return count + " Hold";
    }else {
    return  count + " Bet";
  }
Stephen James
@sjames1958gm
May 05 2017 02:01
@honnhien12h :+1: :checkered_flag:
@sjames1958gm You will need to loop only the number of slices times
bitcoinabdi
@bitcoinabdi
May 05 2017 02:02
@sjames1958gm how ?
Stephen James
@sjames1958gm
May 05 2017 02:03
@bitcoinabdi Well since you are going to slice size elements each time you can do i += size instead of i++
bitcoinabdi
@bitcoinabdi
May 05 2017 02:04
for(i=0;i<arr.length;i+=size){
return arr.slice(0,size);
} <----like so @sjames1958gm
bhalaswag
@bhalaswag
May 05 2017 02:05

// Setup
var myStr = "Jello World";

// Only change code below this line
myStr = "Hello World"
myStr[0] = "H"; // Fix Me

this isnt working
how do i fix it?
Stephen James
@sjames1958gm
May 05 2017 02:05
@bitcoinabdi The for loop part is ok, but you cannot return inside a loop like that and expect it too loop
@bhalaswag Fix the line it said to fix, not add a new line
Brian Arriaga
@BAXTOR95
May 05 2017 02:06
@sjames1958gm I'll try that. Thanks
CamperBot
@camperbot
May 05 2017 02:06
baxtor95 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7124 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 05 2017 02:06
@BAXTOR95 :+1:
@bhalaswag myStr[0] = "H"; this is an error that causes an exception and stops the tests from running.
bhalaswag
@bhalaswag
May 05 2017 02:07
i changed it to J
it says cannot assign to read only property '0'
Stephen James
@sjames1958gm
May 05 2017 02:08
@bhalaswag Yes, you were supposed to fix the assignment not add a new one,
For now just delete that line that say Fix Me
bhalaswag
@bhalaswag
May 05 2017 02:09
ok got it :D
thanks
bitcoinabdi
@bitcoinabdi
May 05 2017 02:11



function chunkArrayInGroups(arr, size) {
  // Break it up.
  var aa = [];
  var a1 =arr.slice(0,size);

  var i = "size";

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

  }

return arr.slice(0,size);


}


chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2);
@sjames1958gm
Stephen James
@sjames1958gm
May 05 2017 02:12
@bitcoinabdi You have to accumulate the slices in the for loop.
bitcoinabdi
@bitcoinabdi
May 05 2017 02:13
thats what am not able to do ;( @sjames1958gm
Benjamin Hike
@BenJess
May 05 2017 02:14
hey all. quick question. What is it about this function that returns a console log too big to display? It seems to be pulling every Dom element in the book. $('li').on('click', function() {
var x = $(this).html("X");
console.log(x);
});
Stephen James
@sjames1958gm
May 05 2017 02:15
@bitcoinabdi well slices are arrays and you need an array of arrays - so you will push the slices onto aa and return aa
@BenJess x is probably the jquery element which is a pretty big object when console.log'ed
Benjamin Hike
@BenJess
May 05 2017 02:16
@sjames1958gm ahhhh I get it now. Thanks. Is it ok to let it run like that or will it become a memory leak over time?
CamperBot
@camperbot
May 05 2017 02:16
benjess sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7125 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 05 2017 02:17
@BenJess Yeah it is ok. Dumping to the console might slow things down, but this is a user interaction element so probably not a big deal.
If you open the developer console (not the codepen console) you'd see the whole object logged out
Benjamin Hike
@BenJess
May 05 2017 02:18
@sjames1958gm awesome, thank you!
CamperBot
@camperbot
May 05 2017 02:18
benjess sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: benjess already gave sjames1958gm points
Stephen James
@sjames1958gm
May 05 2017 02:18
@BenJess :+1:
Mrdaniels3
@Mrdaniels3
May 05 2017 02:19
How do I add a large piece of code for others to see?
Joseph
@revisualize
May 05 2017 02:23
@Mrdaniels3 Get help on our basic JavaScript and Algorithms Challenges. If you are posting code that is large use Gist - https://gist.github.com/ paste the link here.
Mrdaniels3
@Mrdaniels3
May 05 2017 02:24
@revisualize Thank you
CamperBot
@camperbot
May 05 2017 02:24
mrdaniels3 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3898 | @revisualize |http://www.freecodecamp.com/revisualize
Danny Welstad
@GoonTwo
May 05 2017 02:25
has there been any kind of date set for the FCC beta going live?
Mrdaniels3
@Mrdaniels3
May 05 2017 02:25
function golfScore(par, strokes) {
  // Only change code below this line
  if(par>=1){
    return "Hole-in-one";   
  }else if (par<=par-2);{
    return "Eagle";
  }if (par<=-1){
    return "Birdie";
  }else if(par<=0);{
    return "Par";
  }if (par<=+1);{
    return"Bogey";
  }if (par<=+2);{
    return "Double Bogey";
  }if (par>=+3);{
    return "Go Home!";

} else {

  return "strokes";
}

  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);
SO Sorry
Stephen James
@sjames1958gm
May 05 2017 02:27
@Mrdaniels3 The ``` need to be on their own line - use shift-enter to get new line without post.
use up arrow to edit your last post
Brian Arriaga
@BAXTOR95
May 05 2017 02:27
Sorry but I can't get this to work...
Stephen James
@sjames1958gm
May 05 2017 02:28
@Mrdaniels3 The table is showing that you compare strokes to the first column and return the string.
You are not using strokes parameter
Brian Arriaga
@BAXTOR95
May 05 2017 02:28
function lookUpProfile(firstName, prop){
// Only change code below this line


  var response = "";
  for (var i=0; i<contacts.length; i++) {
    if (firstName == contacts[i].firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        response = contacts[i][prop];
      }else {
        if (i==(contacts.length - 1)) {response = "No such property";}
      }
    }else {
      if (i==(contacts.length - 1)) {response = "No such contact";}
    }
  }
  return response;

// Only change code above this line
}
What is wrong know?
now*
Stephen James
@sjames1958gm
May 05 2017 02:29
@BAXTOR95 So your code can only set no such property if the last name is the match.
If you match the name and the property is not there just set the result
Then break; you don't need to loop any more if you find the firstName
@BAXTOR95 If you initialize your response to no such contact then you don't need that last else
Mrdaniels3
@Mrdaniels3
May 05 2017 02:30
Thats what I figured I was doing wrong thanks.
Victoria Zambrano
@vzambrano98
May 05 2017 02:30
hey so regex struggle. is there a way to get regex to match in a strict manner? for example. the following returns true when i would like it to return false
function telephoneCheck(str) {
  var arrNum=str.replace(/[\D ]/g, "").split("");
  var reg= /\+?1?[- ]?(\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}/g;
if (arrNum.length<10||arrNum.length>11){
 return false; 
} else if (arrNum.length===11){
  if (arrNum[0]!=1){return false;}
  return reg.test(str);
} else if (arrNum.length===10){
  return reg.test(str);
}

}//fxn  


telephoneCheck("(5557775555)");
Jason G
@Jay33Canada
May 05 2017 02:33
I'm getting an error : TypeError: Reduce of empty array with no initial value. for some reason, my array isn't adding anything from filter?

function sumPrimes(num) {
  var sqrt = Math.sqrt(num);
  var numbs = [];
  for (var i = 0; i < sqrt; i++){
    numbs.push(i);
  }
  //console.log(numbs);
  var numbsToAdd = numbs.filter(function(n){
    return num % 2 !== 0;
  });
  console.log(numbsToAdd);
  var added = numbsToAdd.reduce(function(total, add){
    return total + add;
  });
  return added;
}

sumPrimes(10);
Nick Forlivio
@whackdev
May 05 2017 02:34
@forwebtech Thanks! I'll try that, I had it that was as first but must have messed it up
CamperBot
@camperbot
May 05 2017 02:34
whackdev sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 415 | @forwebtech |http://www.freecodecamp.com/forwebtech
Victoria Zambrano
@vzambrano98
May 05 2017 02:37
@Jay33Canada I think it might because what filter does is alter your original numbs array, it doesn't create a new array.
Stephen James
@sjames1958gm
May 05 2017 02:37
@Jay33Canada Your list of primes should be 2 to 10 - then filter away those that aren't
Jason G
@Jay33Canada
May 05 2017 02:37
filter does create a new array @vzambrano98
Stephen James
@sjames1958gm
May 05 2017 02:37
@Jay33Canada num % 2 !== 0; this is always false 10 % 2 is 0
Victoria Zambrano
@vzambrano98
May 05 2017 02:38
@Jay33Canada yeah you're right. it's weird because I plugged your fxn into python tutor and that's what happened.
Stephen James
@sjames1958gm
May 05 2017 02:38
@Jay33Canada Your filter function will need to be were you return true if every number from 2 to sqrt(n) don't divide.
you may just want to push 2 as a given prime?
Jason G
@Jay33Canada
May 05 2017 02:38
it's not always false @sjames1958gm . 7% 3 is 1 which is !== 0
Stephen James
@sjames1958gm
May 05 2017 02:39
@Jay33Canada you never change num it is still the input number (which in this case is 10)
Jason G
@Jay33Canada
May 05 2017 02:40
ohhhh let me change that and see what happens @sjames1958gm
Victoria Zambrano
@vzambrano98
May 05 2017 02:41
@Jay33Canada yeah he's so right lol, sorry about that :smile:
hey so regex struggle. is there a way to get regex to match in a strict manner? for example. the following returns true when i would like it to return false
function telephoneCheck(str) {
  var arrNum=str.replace(/[\D ]/g, "").split("");
  var reg= /\+?1?[- ]?(\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}/g;
if (arrNum.length<10||arrNum.length>11){
 return false; 
} else if (arrNum.length===11){
  if (arrNum[0]!=1){return false;}
  return reg.test(str);
} else if (arrNum.length===10){
  return reg.test(str);
}

}//fxn  


telephoneCheck("(5557775555)");
Jason G
@Jay33Canada
May 05 2017 02:41
np i appreciate any help i can get @vzambrano98
Victoria Zambrano
@vzambrano98
May 05 2017 02:46
nvm. im just gonna use match then join. then compare it to the string. if they equal true if not false. here's hopin'
Brian Arriaga
@BAXTOR95
May 05 2017 02:48
@sjames1958gm I finally made it work. Thank you very much :smile:
CamperBot
@camperbot
May 05 2017 02:48
baxtor95 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: baxtor95 already gave sjames1958gm points
Stephen James
@sjames1958gm
May 05 2017 02:48
@BAXTOR95 :+1:
Jason G
@Jay33Canada
May 05 2017 02:51
@sjames1958gm i'm so lost man.
Stephen James
@sjames1958gm
May 05 2017 02:51
@Jay33Canada I think your algorithm is flawed - you want to make an array of all the values from 2-num and then in the filter function
test 2 - n (assuming n is the current value) return false if any of these results in 0 remainder return true if non-do.
@Jay33Canada The initial array is candidate values and the filter removes the non-primes. (you may need to make special case for 2)
Khoa Le
@Zacele
May 05 2017 02:52
function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];
 function stillArray(index){
   if(index.isArray === true){
     newChar = index.shift();
      return newChar;
   }
 }
  stillArray(arr[0]);
Jason G
@Jay33Canada
May 05 2017 02:52
i don't understand. you said something about needing to find the square root and then dividing all of the numbers up to it?
Khoa Le
@Zacele
May 05 2017 02:53
why is my code cannot return the newChar
Stephen James
@sjames1958gm
May 05 2017 02:53
@Jay33Canada Yes
candidatePrimes.filter(function(n) { // if any number from 2 to sqrt of n divides into n then return false else return true }
So a loop inside the filter
@Zacele don't you need return stillArray(arr[0]); if I understand your question?
Khoa Le
@Zacele
May 05 2017 02:55
@sjames1958gm I didn't return stillArray(arr[0]); my stillArray function is pass an element into it; if it is an array, shift() it and return the new value
Jason G
@Jay33Canada
May 05 2017 02:55
@sjames1958gm what will that give me? i don't get it. i need to add all of the primes from 2 to 10. how can i test if 7 is a prime? it doesn't work with your logic. you said find the sqrt of 10. it's 3.16. I'd never get past 3.16.... so i'd never get to test 4,5,6,7,8,9
Khoa Le
@Zacele
May 05 2017 02:56
@sjames1958gm the stillArray(arr[0]) is to test that function
Stephen James
@sjames1958gm
May 05 2017 02:56
@Zacele I think it is Array.isArray(index)
Khoa Le
@Zacele
May 05 2017 02:58
@sjames1958gm new code still doesn't work

function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];
 function stillArray(index){
   if(Array.isArray(index) === true){
     newChar = index.shift();
      return newChar;
   }
 }
  stillArray(arr[0]);

}
Stephen James
@sjames1958gm
May 05 2017 02:58
@Jay33Canada
Make an array from 2 to num (these are you prime candidates)
then filter this array - for each number in this array test it for primeness using it's sqrt not sqrt of 10.
@Zacele What is arr value when you call steamrollArray?
Khoa Le
@Zacele
May 05 2017 02:59

function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];
 function stillArray(index){
   if(Array.isArray(index) === true){
     newChar = index.shift();
      return newChar;
   }
 }
  stillArray(arr[0]);

}

steamrollArray([[["a"]], [["b"]]]);
Stephen James
@sjames1958gm
May 05 2017 02:59
@Zacele The result of calling steamrollArray will be undefined - because you don't return anything
Khoa Le
@Zacele
May 05 2017 03:00
@sjames1958gm oh ok got it
forget to return it, thanks man
Stephen James
@sjames1958gm
May 05 2017 03:00
@Zacele :+1:
Jeff
@etisdew
May 05 2017 03:00
ugh, why doesnt this work?
function lookUpProfile(firstName, prop){ // Only change code below this line var j = 0; for(var i in contacts){ return (contacts[i]['firstName'] == firstName && contacts[i].hasOwnProperty(prop) ? contacts[i][prop] : j++ );} return "No such property"; // Only change code above this line }
PhoenixFarhan
@PhoenixFarhan
May 05 2017 03:01

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

return item; // Change this line
}

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

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

Manish Giri
@Manish-Giri
May 05 2017 03:01
@PhoenixFarhan item + arr;
PhoenixFarhan
@PhoenixFarhan
May 05 2017 03:01
does anyone know how to add item to array and then remove first element of array
Manish Giri
@Manish-Giri
May 05 2017 03:01
what does this do
Stephen James
@sjames1958gm
May 05 2017 03:01
@PhoenixFarhan There were four challenges about adding and removing from arrays
push, pop, shift and unshift
PhoenixFarhan
@PhoenixFarhan
May 05 2017 03:02

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

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

Jason Luboff
@JLuboff
May 05 2017 03:02
@Manish-Giri 👋🏻
PhoenixFarhan
@PhoenixFarhan
May 05 2017 03:02
thats the one one i am working on
Manish Giri
@Manish-Giri
May 05 2017 03:02
@JLuboff :wave:
how're ya
Jeff
@etisdew
May 05 2017 03:03
okay, I'm not trying to be annoying I restarted from the beginning because I was stuck on this profile-lookup challenge... the semantics are killing me
Jason G
@Jay33Canada
May 05 2017 03:03
@sjames1958gm i'm confused about the sqrt root part i'm sorry... here's what i have so far
function sumPrimes(num) {
  var numbs = [];
  for (var i = 2; i <= num; i++){
    numbs.push(i);
  }
  //console.log(numbs);
  var primeNumbers = numbs.filter(function(n){
    return n % 2 !== 0;
  });
  var added = primeNumbers.reduce(function(total, currentVal){
    return total + currentVal;
  });
  console.log(added);

}
Stephen James
@sjames1958gm
May 05 2017 03:03
@PhoenixFarhan There are 4 challenges, which you should have done Manipulate Arrays With push, etc.
They show how to add and remove from arrays
PhoenixFarhan
@PhoenixFarhan
May 05 2017 03:03
hmm ok
i think i may have missed them..
ill go back and check
Thanks @sjames1958gm
CamperBot
@camperbot
May 05 2017 03:03
phoenixfarhan sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7126 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jason Luboff
@JLuboff
May 05 2017 03:04
@Manish-Giri doing good..working out..yourself? You finish the udemy course yet?
Mrdaniels3
@Mrdaniels3
May 05 2017 03:04
@BAXTOR95 @sjames1958gm Added strokes parameter was there anything else I am missing ?
Stephen James
@sjames1958gm
May 05 2017 03:04
@Jay33Canada Its inside the filter function that you have to check that.
so for value n to test for it being prime you test every value from 2 to sqrt of n
@Mrdaniels3 Hard to say - make sure your strings are exact matches.
Show what you did.
@JLuboff @Manish-Giri Handing it off to you guys :sleeping: night all
Jason G
@Jay33Canada
May 05 2017 03:06
whaaaaat. can you give an example @sjames1958gm ? i don't understand. i reaaaaally don't get this sqrt step.. my code does work, but it's output is off
image.png
Brian Arriaga
@BAXTOR95
May 05 2017 03:09
@Mrdaniels3 ```
@Mrdaniels3 This is what I did
function lookUpProfile(firstName, prop){
// Only change code below this line


  var response = "No such contact";
  for (var i=0; i<contacts.length; i++) {
    if (firstName == contacts[i].firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        response = contacts[i][prop];
        break;
      }else {
        response = "No such property";
      }
    }
  }
  return response;

// Only change code above this line
}
Nahuel Ovejero
@NahuelOvejero
May 05 2017 03:11
@BAXTOR95 what test it doesn't pass?
Brian Arriaga
@BAXTOR95
May 05 2017 03:13
No, it works now. It has passed all the tests. I thought @Mrdaniels3 needed to know what I did
Nahuel Ovejero
@NahuelOvejero
May 05 2017 03:13
Oh, yeah, It seems oks
Jason G
@Jay33Canada
May 05 2017 03:16
@sjames1958gm i seriously don't understand the math :'( I've read a shit ton of articles. i have no idea what to do...
James Chhun
@jchhun23
May 05 2017 03:19
hhello world
im having problems with whats going on here on this challenge
can anyone help
Gabe Rotberg
@grotberg
May 05 2017 03:19
@Jay33Canada Yeah, it can be a bit tricky. Effectively the algorithm you need to do wants to test every multiple of every number between zero and the square root of the target. (the square root of the target is important because that is the point where you've already tested every other relevant number by testing its effective reciprocal - you could continue testing beyond then, but you'd just waste processor time).
James Chhun
@jchhun23
May 05 2017 03:20
a should be defined and have a value of 6
b should be defined and have a value of 15
c should not contain undefined and should have a value of "I am a String!"
var a;
var b;
var c;
Gabe Rotberg
@grotberg
May 05 2017 03:21
@Jay33Canada so in short, if you can set up a loop to increment i and then test every relevant multiple of i until the target number n (in effect, proving that it isn't a prime), the remaining number (ie the ones you haven't proven not-prime) will be prime. and then you can sum them.
Mr Songshiba
@792472461
May 05 2017 03:22
hello

谁能帮我一下

Who can help me

Who can help me
Jason G
@Jay33Canada
May 05 2017 03:23
@grotberg this is greek to me. what do you guys even mean? every multiple ? what does that mean exactly? what am i testing the numbers between 2 and the square root for? and why am i doing that? how do that tell me if the original number is a prime number?
Gabe Rotberg
@grotberg
May 05 2017 03:23
@jchhun23 This exercise is basically teaching you how to initialize variables. Check out the text on the side.
@Jay33Canada Don't worry, deep breaths. It definitely takes some... reorienting of your brain. Effectively, a prime number is one that can only be divided by 1 and itself, right? So that means, an number that you can get to by multiplying x * y (where x or y aren't 1 or the number in question) can't be prime. Yeah?
@Jay33Canada In short, if I can get to 6 by multiplying 2 * 3, that means 6 isn't prime.
@Jay33Canada So then, we just do that for everything. Instead of looking at each number and trying to figure out if it is prime, we just start from scratch, and eliminate all multiples of 2. 2x2 isn't prime. 2x3 isn't prime. 2x4 isn't prime. 2x5 isn't prime.
Jason G
@Jay33Canada
May 05 2017 03:27
ya i understand what a prime number is @grotberg. I do appreciate the explanation though
Gabe Rotberg
@grotberg
May 05 2017 03:27
(it parsed out a bunch of *'s but you get the idea)
@Jay33Canada I'm just starting from first principles for my own sake, don't mind me. But basically we do that for every number. After 2's, we do 3's. 3x2 isn't prime. 3x3 isn't prime. 3x4 isn't prime.
@Jay33Canada 4x2 isn't prime. 4x3 isn't prime. 5x2 isn't prime. some of these are repeats, obviously. But if we keep track of all this (ie, keep an array that tracks if each number is or is not prime and update it as you go)
Jason G
@Jay33Canada
May 05 2017 03:29
wait @grotberg 23 is a prime number. it's only divisible by 1 and itself
Gabe Rotberg
@grotberg
May 05 2017 03:29
@Jay33Canada sorry, that's one where it parsed out the * that was suppsoed to be 2x3
(just fixed it)
Jason G
@Jay33Canada
May 05 2017 03:30
sorry but i'm not following where you're going with this. I know how in plan english, to tell a prime number. divide it by 2 or 3. if it divides by one of them, then it's not prime
Gabe Rotberg
@grotberg
May 05 2017 03:31
@Jay33Canada Effectively, you loop through every (reasonable) multiple of every number in the range, and eliminate the products. Anything in that range you didn't eliminate is prime.
Khoa Le
@Zacele
May 05 2017 03:32

function steamrollArray(arr) {
  // I'm a steamroller, baby
  var newArr = [];
 function stillArray(index){
   if(Array.isArray(index) === true){
     if(index.length ==2){
       newChar = index.shift();
       lastChar = index.pop().shift();
       stillArray(newChar);
       stillArray(lastChar);
         } else{
       newChar = index.shift();
         stillArray(newChar);
         }
   }  else {
     newArr.push(index);
   }
 }
  arr.forEach(function(i){
   stillArray(i);
  });

return newArr.filter(function(x){
   return Boolean(x);
 });


}
Gabe Rotberg
@grotberg
May 05 2017 03:32
so if your target number is 10. you loop through every number in that range and you'll eliminate 4, 6, 8, 10 then 6, 9, then 8
Khoa Le
@Zacele
May 05 2017 03:32
here is the code for the stream roller challenge of mine
but it is too DRY in the logic where I repeat the process twice
Gabe Rotberg
@grotberg
May 05 2017 03:32
and wind up with 2, 3, 5, 7, which are the numbers you didn't eliminate
Khoa Le
@Zacele
May 05 2017 03:33
is there any way I could make that logic become recursion a little bit more
Jason G
@Jay33Canada
May 05 2017 03:33
what do you mean eliminate the "product"
i don't get how to loops through these numbers?
Gabe Rotberg
@grotberg
May 05 2017 03:34
@Jay33Canada the way I did it was set up an array equal to the target number, and each element was just "true"
Johnny Meza
@XLpacman805
May 05 2017 03:34
Hey guys I need an opinion. I'm doing the Wikipedia viewer project. Should I put 4 HTML elements, hide them with Jquery, and then show them when the result is called. Or should I clone a number of elements depending on the search results using jquery?
Gabe Rotberg
@grotberg
May 05 2017 03:34
@Jay33Canada so if the target is 5 you just have [true, true, true, true, true]
@Jay33Canada then you have a nested loop, var i = 2; var < 5; i++
Jason G
@Jay33Canada
May 05 2017 03:35
wow. ok. i feel bad for waiting your time @grotberg i'm COMPLETELY lost so... i'll just ask someone else
maybe they can dumb it down for me
Gabe Rotberg
@grotberg
May 05 2017 03:35
@Jay33Canada no worries. I'm sorry not being clear.
@Jay33Canada have you checked out this link? https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Jason G
@Jay33Canada
May 05 2017 03:37
i'll read through it again. I did check it out once. @grotberg
Gabe Rotberg
@grotberg
May 05 2017 03:38
@Jay33Canada OK - good luck!
Mrdaniels3
@Mrdaniels3
May 05 2017 03:39
@BAXTOR95 sorry had miclicked your name by accident
Gabe Rotberg
@grotberg
May 05 2017 03:39
@XLpacman805 really up to you. Either way could work, although creating the elements as you need them is probably better in practice.
Jeffrey Leung
@Fatpikachu
May 05 2017 03:39
Hi
has anyone done convertToRoman(num) yet?
Mrdaniels3
@Mrdaniels3
May 05 2017 03:40
@sjames1958gm Got it had too many semi colons Thanks for the help again
CamperBot
@camperbot
May 05 2017 03:40
mrdaniels3 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7127 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Johnny Meza
@XLpacman805
May 05 2017 03:41
@grotberg thanks
CamperBot
@camperbot
May 05 2017 03:41
xlpacman805 sends brownie points to @grotberg :sparkles: :thumbsup: :sparkles:
:cookie: 327 | @grotberg |http://www.freecodecamp.com/grotberg
Vicky Lai
@vickylai
May 05 2017 03:47

function diffArray(arr1, arr2) {
  var newArr = [];
  if (arr1.length >= arr2.length) {
    var bigArr = arr1;
    var smallArr = arr2;
  } else {
    var bigArr = arr2;
    var smallArr = arr1;
  }
  // find larger array
  // filter larger array by if contained by smaller array
  // output filtered array

  return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
for loop? forEach? Iunno.
Jason G
@Jay33Canada
May 05 2017 03:48
@grotberg i reread it. I"m not sure what to do with it? removing so many items from a list of numbers would quickly get confusing
Ogundele Olumide
@Lumexralph
May 05 2017 03:48
@vickylaiio you can use filter
Vicky Lai
@vickylai
May 05 2017 03:50
@Lumexralph Was banging my head against that one yesterday... I'll give it another go
Gabe Rotberg
@grotberg
May 05 2017 03:50
@Jay33Canada you can make a big array, initialize each element to true, and then set it false when you determine it isn't prime
jhobotuck
@jhobotuck
May 05 2017 03:50
So I'm working on the Caesar Cipher. Thought it was pretty straight forward but odd characters are not the correct characters. Bit bamboozled.
function rot13(str) { // LBH QVQ VG!

  var tempArray = [];
  var minus13Array = [];
  var resultString = "";

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

    tempArray.push(str.charCodeAt(i));

    if (tempArray[i] === 32) {
      minus13Array.push(tempArray[i]);
    } else {
      minus13Array.push(tempArray[i] + 13);
    }

    resultString += String.fromCharCode(minus13Array[i]);

  }

  return resultString;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Gabe Rotberg
@grotberg
May 05 2017 03:50
@Jay33Canada then when you finish, you can loop over that array and just total up the ones that are still 'true' (ie, prime)
Garo
@Garabed96
May 05 2017 03:51
guys shouldn't this be giving me the search result when I type something into the textbox ? https://codepen.io/CapGaro/pen/mmwQKb?editors=1111
Jason G
@Jay33Canada
May 05 2017 03:52
ok @grotberg i think i get that.... can you clear something up for me. lets say i'm doing the number 10. i want the numbers 2-10 right? then what's all this about the square root?
VladimirCW
@VladimirCW
May 05 2017 03:54

Hello! Can somebody help me with challenge "Falsy Bouncer"
I can' t filter NaN.
If I use !isNaN(value) - it filters not only NaN but also all string values.
This is my code
function bouncer(arr) {
var arra = arr.filter(function(value) {
return value!==false&&value!==""&&value!==0&&
value!==undefined&&value!==null&&!isNaN(value);
});
return arra;
}

bouncer([7, "ate", "", false, 9,0, undefined, NaN]);

jhobotuck
@jhobotuck
May 05 2017 03:57
@VladimirCW I struggled with this one also. I found the path of least resistance was learning about Boolean operation. The link can be found at the bottom of the instructions.
Christopher McCormack
@cmccormack
May 05 2017 03:57
@Garabed96 you need to put the submit listener on the form, not the input
Ogundele Olumide
@Lumexralph
May 05 2017 03:57
@VladimirCW your NaN function will treat string as NaN too.... use Number.isNaN(value)
Gabe Rotberg
@grotberg
May 05 2017 04:00
@Jay33Canada OK, so the square root basically just saves time. You can prove to yourself that for the number 25, you only need to check the multiples of 2-5 before you've eliminated all relevant non-primes
Csaba Balogh
@JasonCorp84
May 05 2017 04:00
good evening everyone!
Gabe Rotberg
@grotberg
May 05 2017 04:00
@Jay33Canada you COULD check all the way to 25, but you wouldn't eliminate anything else.
Csaba Balogh
@JasonCorp84
May 05 2017 04:02
var transform = str.toLowerCase().replace(/_/g,''); <-- what is the syntax to add more characters to this ? Is there any way to add a condition ?
like if != 'a-z' then replace it with '' ?
Gabe Rotberg
@grotberg
May 05 2017 04:02
@Jay33Canada so the square root part is basically an optimization - finding especially large primes is intensive enough that you need to look for tricks to optimize the process, otherwise it is slooooow.
Ogundele Olumide
@Lumexralph
May 05 2017 04:02
@JasonCorp84 \W non-alphanumeric characters
Jason G
@Jay33Canada
May 05 2017 04:03
do you mean like, instead of doing 2 4 6 8.. 3,6,9,12... 4,8,12,16.. ?? sorry @grotberg
Csaba Balogh
@JasonCorp84
May 05 2017 04:03
@Lumexralph thanks!
CamperBot
@camperbot
May 05 2017 04:03
jasoncorp84 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1631 | @lumexralph |http://www.freecodecamp.com/lumexralph
Gabe Rotberg
@grotberg
May 05 2017 04:05
@Jay33Canada mm, in addition to. Lets say your target number is 25. for multiples of 2 you eliminate 4,6,8,10,12,14,16,18,20,22,24. for multiples of 3 you eliminate 6,9,12,15,18,21,24. for multiples of 4 you eliminate 8,12,16,20,24. for 5 you eliminate 10,15,20,25. Past that, if you try it, you'll find you don't eliminate any additional numbers.
@Jay33Canada 6 gives you 12, 18, 24 (already eliminated). 7 gives you 14, 21 (already eliminated). same with 8, 9, 10 etc
@JasonCorp84 you could keep going, but it turns out that past the square root of your target, it doesn't net any more information
Jason G
@Jay33Canada
May 05 2017 04:07
oh that's pretty neat!
i get that now @grotberg :)
Gabe Rotberg
@grotberg
May 05 2017 04:08
@Jay33Canada it is pretty neat! if you think about it, those multiples already got eliminated in the lower numbers. and that is always true, regardless of what your target is
@Jay33Canada and while computers these days are pretty fast, it saves a HUGE amount of time, especially as the target number gets larger and larger
Garo
@Garabed96
May 05 2017 04:10
@cmccormack thanks dude !!
CamperBot
@camperbot
May 05 2017 04:10
garabed96 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 514 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
May 05 2017 04:10
@Garabed96 np
can someone help me? i amm getting errors from the ip-api.com\json call
jquery.min.js:4 GET http://ip-api.com/json net::ERR_BLOCKED_BY_CLIENT
Gabe Rotberg
@grotberg
May 05 2017 04:11
@leseanbiz are you using an adblocker? (ublocker blocks ip-api, I think)
LeSean Johnson
@leseanbiz
May 05 2017 04:11
oh snap
Gabe Rotberg
@grotberg
May 05 2017 04:12
@leseanbiz yup. i did the exact same thing.
LeSean Johnson
@leseanbiz
May 05 2017 04:12
@grotberg thanks!
CamperBot
@camperbot
May 05 2017 04:12
leseanbiz sends brownie points to @grotberg :sparkles: :thumbsup: :sparkles:
:cookie: 329 | @grotberg |http://www.freecodecamp.com/grotberg
Jason G
@Jay33Canada
May 05 2017 04:12
so basically @grotberg @Jay33Canada
using an array with all values set to true, and using the indexes, set them to false if they aren't prime numbers
then later, iterating over the array for the values left at true. which will be prime numbers.
Christopher McCormack
@cmccormack
May 05 2017 04:12
@leseanbiz you're using geo but never assigned it that I can see
Gabe Rotberg
@grotberg
May 05 2017 04:13
@Jay33Canada that's the idea!
LeSean Johnson
@leseanbiz
May 05 2017 04:14
@cmccormack could you elaborate? sorry, i had a dev friend over and asked him to look at it and he changed somethings and im trying to get it to just work again
do you mean in the function call?
Christopher McCormack
@cmccormack
May 05 2017 04:15

@leseanbiz

    $.getJSON("http://ip-api.com/json",function(){
      var latitude = geo.lat.toFixed(0);
      var longitude = geo.lon.toFixed(0);

you never defined geo - maybe put it in your function parameter

LeSean Johnson
@leseanbiz
May 05 2017 04:15
i just saved after updating that and im not getting the geo error anymore
Jason G
@Jay33Canada
May 05 2017 04:15
ok @grotberg i'll give it a go in the morning since i get the idea now. thanks a lot man. you were super patient with me :)
CamperBot
@camperbot
May 05 2017 04:15
jay33canada sends brownie points to @grotberg :sparkles: :thumbsup: :sparkles:
:cookie: 330 | @grotberg |http://www.freecodecamp.com/grotberg
LeSean Johnson
@leseanbiz
May 05 2017 04:15
@cmccormack thanks! now my error is about the openweatherapi call
Nahuel Ovejero
@NahuelOvejero
May 05 2017 04:16
anyone here know about grunt + yeoman + bower + angular stack?
LeSean Johnson
@leseanbiz
May 05 2017 04:16
anyone know how long the openweathermap api keys are good for?
Christopher McCormack
@cmccormack
May 05 2017 04:16
@leseanbiz you need to replace the lat=latitude and the longitude with actual values,
LeSean Johnson
@leseanbiz
May 05 2017 04:17
that should be happening from the two lines you showed above, right? the geo values are assigned into those variables
Christopher McCormack
@cmccormack
May 05 2017 04:20
@leseanbiz you're not calling the api with those variables, just a string literal
Coy Sanders
@coymeetsworld
May 05 2017 04:20
@leseanbiz should be good forever
you have a limited amount of calls you can make but its more than enough for what we need it for
Paulo Raoni
@paulo-raoni
May 05 2017 04:20
@leseanbiz Are you doing the weatherapp challenge? If I were in your shoes I wouldn't use openweathermap. It is confused and don't gives you good response.
For my challenge I used apixu.com. They work with https protocol so you don't have too many problems with insecure requests errors.
Coy Sanders
@coymeetsworld
May 05 2017 04:21
openweathermap was fine to use for me, and yeah you only get non-secure connection but thats fine
LeSean Johnson
@leseanbiz
May 05 2017 04:21
@paulo-raoni fortunately i have all of my logic working, or had rather, so i wont backtrack on it but i do see some inconsistencies
Christopher McCormack
@cmccormack
May 05 2017 04:21
I switched mine to darksky when I wanted to put it on a server with https
Jason G
@Jay33Canada
May 05 2017 04:22
I used darksky as well
LeSean Johnson
@leseanbiz
May 05 2017 04:22
@cmccormack have a look and the updated pen. im pretty sure i fixed that
Christopher McCormack
@cmccormack
May 05 2017 04:22
@leseanbiz your getJSON call for the weather api does not replace the words latitude and longitude with actual values
you'll need to break up the string and concatenate your strings into the url
LeSean Johnson
@leseanbiz
May 05 2017 04:23
right!
thanks
Christopher McCormack
@cmccormack
May 05 2017 04:23
or you can also put all the parameters of the url search string into an object and pass that as your second argument to the .getJSON function
Mauro
@mauronml
May 05 2017 04:46
Hello Everyone!
Paulo Raoni
@paulo-raoni
May 05 2017 04:49
@mauronml Hi
Mauro
@mauronml
May 05 2017 04:49
Heya @paulo-raoni
Paulo Raoni
@paulo-raoni
May 05 2017 04:50
@mauronml Time for bed. haha
Mauro
@mauronml
May 05 2017 04:50
@paulo-raoni lol. goodnight
Paulo Raoni
@paulo-raoni
May 05 2017 04:50
Thx
Mario A. Carlos
@MarioC3
May 05 2017 04:52
Hello Guys.
Quick question, when generating random whole numbers within a range we use this formula return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
my questions is why at the end we sum it plus one and plus mymin?
Ogundele Olumide
@Lumexralph
May 05 2017 04:55
@MarioC3 Math.random generates a float between 0 inclusive to 1 exclusive
Mario A. Carlos
@MarioC3
May 05 2017 04:55
ok I get now, why we sum it at the end by myMin, to ensure that it's within the range. But why do we sum te one?
Ogundele Olumide
@Lumexralph
May 05 2017 04:56
@MarioC3 (myMax - myMin + 1) is to give the range of values to be generated
Mario A. Carlos
@MarioC3
May 05 2017 04:56
but couldn't we just make it with myMax - myMin?
Ogundele Olumide
@Lumexralph
May 05 2017 04:57
@MarioC3 it's to make it never 0
Mario A. Carlos
@MarioC3
May 05 2017 04:58
ohhhh ok....
Mauro
@mauronml
May 05 2017 04:58
@MarioC3 I think if ur min = max then it would give you zero if u dont +1
Ogundele Olumide
@Lumexralph
May 05 2017 04:58
@MarioC3 myMax - myMin can be 0, + 1, removes that possibility
Mario A. Carlos
@MarioC3
May 05 2017 04:59
Not true myMax - myMin lowest value can be 1
Jason G
@Jay33Canada
May 05 2017 04:59
is there anyway to start an array at an index number? odd question i know but i want my array to start at index 2
Mario A. Carlos
@MarioC3
May 05 2017 04:59
but Math.random can return 0
Ogundele Olumide
@Lumexralph
May 05 2017 04:59
@MarioC3 it can also be 0
Mario A. Carlos
@MarioC3
May 05 2017 04:59
@Lumexralph how?
Mauro
@mauronml
May 05 2017 05:00
myMax = 15 and myMin = 15 will give you zero as well
Ogundele Olumide
@Lumexralph
May 05 2017 05:00
@MarioC3 sorry for the confusion, seen it now
Mario A. Carlos
@MarioC3
May 05 2017 05:00
@mauronml That's not a range though
Those are identical numbers
Mauro
@mauronml
May 05 2017 05:01
@MarioC3 no, but that doesnt mean someone couldnt put that in there :p
Mario A. Carlos
@MarioC3
May 05 2017 05:01
hhahahhaahaha @mauronml lol
Ogundele Olumide
@Lumexralph
May 05 2017 05:01
@MarioC3 that's not the case then myMin + 1 is to increase the myMin by 1
Mario A. Carlos
@MarioC3
May 05 2017 05:01
I think it's because Math.random can return 0
Ogundele Olumide
@Lumexralph
May 05 2017 05:03
@MarioC3 it's to make the difference of myMax and myMin never equal to zero
Mario A. Carlos
@MarioC3
May 05 2017 05:04
Right... but if it's a range of numbers, how can the difference of myMax and myMin be ever equal to 0?
Ogundele Olumide
@Lumexralph
May 05 2017 05:05
@MarioC3 it can be negative but never 0 cos that'll defeat the purpose of Math. random
Mauro
@mauronml
May 05 2017 05:05
what he said. If Math.random() returns 0, then * (myMax - myMin + 1) it still 0
Coy Sanders
@coymeetsworld
May 05 2017 05:05
isn't the 1 because Math.random with Math.floor would never be able to return maxValue?
Math.random() never returns 1 right?
goes from [0,1)
Mario A. Carlos
@MarioC3
May 05 2017 05:06
Right! That's why we add the + myMin at the end, to ensure it's within the range
Mauro
@mauronml
May 05 2017 05:06
Math.random()Return a random number between 0 (inclusive) and 1 (exclusive)
Mario A. Carlos
@MarioC3
May 05 2017 05:06
@coymeetsworld I think that's it
Mauro
@mauronml
May 05 2017 05:06
@MarioC3 exactly, that’s why they add the myMin at the end
Mario A. Carlos
@MarioC3
May 05 2017 05:07
I thin @coymeetsworld nailed it...
when I deleted + 1 from the function

// Example
function ourRandomRange(ourMin, ourMax) {

  return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
}

ourRandomRange(1, 9);

// Only change code below this line.

function randomRange(myMin, myMax) {

  return Math.floor(Math.random() * (myMax - myMin)) + myMin; // Change this line

}

// Change these values to test your function
var myRandom = randomRange(5, 15);
pelajarfcc
@pelajarfcc
May 05 2017 05:08
function checkEqual(a, b) {
  return a === b ? "true" : "false";
}

checkEqual(1, 2);

http://beta.freecodecamp.com/en/challenges/basic-javascript/use-the-conditional-ternary-operator

it doesn't let me pass the test :(

Mauro
@mauronml
May 05 2017 05:09
@pelajarfcc remember that anything between ” “ is considered a string
Mario A. Carlos
@MarioC3
May 05 2017 05:09
blob
This is what FCC outputs:
Victor T.
@vturcios90
May 05 2017 05:09
any tips on learning JS
Mario A. Carlos
@MarioC3
May 05 2017 05:10
@vturcios90
Ask questions
pelajarfcc
@pelajarfcc
May 05 2017 05:10
@mauronml ah i c thanks @mauronml
CamperBot
@camperbot
May 05 2017 05:10
pelajarfcc sends brownie points to @mauronml :sparkles: :thumbsup: :sparkles:
:cookie: 257 | @mauronml |http://www.freecodecamp.com/mauronml
Mario A. Carlos
@MarioC3
May 05 2017 05:10
a lot of them
Mauro
@mauronml
May 05 2017 05:10
@pelajarfcc You could also do without the shorthand if. a === b will return either true or false as well
Long Nguyen
@longnt80
May 05 2017 05:11
@vturcios90
practice, practice, practice
applied for almost anything
Coy Sanders
@coymeetsworld
May 05 2017 05:11
@pelajarfcc non-empty strings are a truthy value
WSCQSDADADAD
@WSCQSDADADAD
May 05 2017 05:11
blob
Mauro
@mauronml
May 05 2017 05:11
Lol. i had never heard truthy or falsy before FCC
Coy Sanders
@coymeetsworld
May 05 2017 05:11
so your function is always returning a true statement, remove the quotes and you should be good. Or as mentioned just return a === b
WSCQSDADADAD
@WSCQSDADADAD
May 05 2017 05:12
i need help
pelajarfcc
@pelajarfcc
May 05 2017 05:13
thanks @mauronml and @coymeetsworld for the insight :smile:
CamperBot
@camperbot
May 05 2017 05:13
pelajarfcc sends brownie points to @mauronml and @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: pelajarfcc already gave mauronml points
:star2: 2533 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Mario A. Carlos
@MarioC3
May 05 2017 05:18
Ok. Guys I'm going to start the Basic Algorithm Scripting in FCC. Wish me luck! lol
Mauro
@mauronml
May 05 2017 05:18
good luck!
Victor T.
@vturcios90
May 05 2017 05:22
thnx for the suggestions guys!
Long Nguyen
@longnt80
May 05 2017 05:22
@MarioC3 no you don't need luck, you'll need coffee
Devon Thomas
@UmbraLegacy
May 05 2017 05:26
@longnt80 , coffee = adult juice
Long Nguyen
@longnt80
May 05 2017 05:37
@UmbraLegacy oh, haa. I didn't notice
Garo
@Garabed96
May 05 2017 06:02
https://codepen.io/CapGaro/pen/mmwQKb?editors=1111
guys, for line 45, how would I return the data
whats MIME type
Julian Mansueto
@julianmnst
May 05 2017 06:04
guys, should if (x === undefined) {return undefined;} work? i only get ''
i expect to return undefined
Markus Kiili
@Masd925
May 05 2017 06:04
@julianmnst That should return undefined yes.
Julian Mansueto
@julianmnst
May 05 2017 06:06
@Masd925 ok thanks
CamperBot
@camperbot
May 05 2017 06:06
julianmnst sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4001 | @masd925 |http://www.freecodecamp.com/masd925
devpaaji
@devpaaji
May 05 2017 06:12
@m\ morning
how are you
have you sed map in any cases
if so why they should be used
when we have objects here
An Object has a prototype, so there are default keys in the map that could collide with your keys if you're not careful. As of ES5 can be bypassed by using map = Object.create(null), but is seldom done.
The keys of an Object are Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive.
You can get the size of a Map easily with the size property, while the size of an Object must be determined manually.
what does this mean
The keys of an Object are Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive.
let user = {
  name: "John",
  age: 30
};
let map = new Map();

map.set('1', 'str1');   // a string key
map.set(1, 'num1');     // a numeric key
map.set(true, 'bool1'); // a boolean key
mean like this
Markus Kiili
@Masd925
May 05 2017 06:15
@devpaaji JS objects and ES6 maps both hold key:value pairs, but a map has some benefits over an object.
Csaba Balogh
@JasonCorp84
May 05 2017 06:19
Good evening
str.toLowerCase().replace(/[_ ,.():-]/g,''); It is passing the assignment, however... :D this is non sense
someone mentioned to use W, but I do not get it
the syntax of it. Any idea ?
AKSHAY R
@akshayr369
May 05 2017 06:22
var myStr= "This is the start." + "This is the end.";
for string concatenation
whats wrong?
Csaba Balogh
@JasonCorp84
May 05 2017 06:23
it is working, but if the user would come up with any other characters, then it would fail
Markus Kiili
@Masd925
May 05 2017 06:23
@devpaaji If you only need string keys and don't use keys that are built-in property keys of objects like toString and constructor, and always use enumerable property keys of the object, an object can be used for storing information on key:value pairs. In ES6 maps make it easier.
Csaba Balogh
@JasonCorp84
May 05 2017 06:23
so it is kind of a half solution
AKSHAY R
@akshayr369
May 05 2017 06:24
image.png
Nazar
@IsaakNazar
May 05 2017 06:24
can I pass 2 different URL?
weatherCond.open('GET', url1, url2, true);
or help me with Local Weather
gerome0123
@gerome0123
May 05 2017 06:28
for example i have an object like this sample =[[id:1 , amount: 100], [id:2, amount:100]]
how can i get the total sample amount?
devpaaji
@devpaaji
May 05 2017 06:28
@Masd925 enumerable prop means my own property
like we check with hasOwnProperty()
correct
Markus Kiili
@Masd925
May 05 2017 06:29
@devpaaji It usually means the properties that you add to the object. Built-in properties are non-enumerable.
mcham246
@mcham246
May 05 2017 06:29
@akshayr369 you need to add a space between the quotation mark after the plus sign and "This"
devpaaji
@devpaaji
May 05 2017 06:29

let user = {
  name: "John",
  age: 30
};
so name and age are enumerable properties of user object
correct
Markus Kiili
@Masd925
May 05 2017 06:30
yes
devpaaji
@devpaaji
May 05 2017 06:30
how does maps differe in his
The keys of an Object are Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive.
it is flexible
Markus Kiili
@Masd925
May 05 2017 06:31
@devpaaji When you use such object, you can accidentally overwrite some non-enumerable property key like toString.
AKSHAY R
@akshayr369
May 05 2017 06:32
@mcham246 ya got it
xn_x
@ak4438
May 05 2017 06:32
hi
I got stuck in
Profilelookup
challange no. 216
Markus Kiili
@Masd925
May 05 2017 06:32
@devpaaji Maps are meant for storing info on key:value pairs. Objects were used sometimes as maps because there were no maps in JS.
devpaaji
@devpaaji
May 05 2017 06:33
When you use such object, you can accidentally overwrite some non-enumerable property key like toString.
you mean for JS Objects
let user = {
  name: "John",
  age: 30,
toString: true
};
like this
mcham246
@mcham246
May 05 2017 06:34
how do i send a picture in this chat
Markus Kiili
@Masd925
May 05 2017 06:35
@devpaaji Yes, then toString doesn't work anymore as expected. But if you use the object only for storing and accessing that information, overwriting toString is not a problem. You just have to know these limitations.
devpaaji
@devpaaji
May 05 2017 06:36
Maps are meant for storing info on key:value pairs. Are objects not mean t for same
mcham246
@mcham246
May 05 2017 06:36

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

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

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

//can anyone help me find the flaw in my code
Markus Kiili
@Masd925
May 05 2017 06:37
@devpaaji Objects are more complex things, and using them just to hold key:value pairs means that we must remember some limitations.
If you store such information and then use those non-enumerable properties like obj.toString(), then you can cause bugs. If you just access that data you will have no problems.
So if you use JS objects as key:value containers, don't use them as anything more.
devpaaji
@devpaaji
May 05 2017 06:41
yes
function BigUser() {

  this.name = "John";

  return { name: "Godzilla" };  // <-- returns an object
}

alert( new BigUser().name );  // Godzilla, got that object
another interesting and kind of confusing
here
return overrides this\
Markus Kiili
@Masd925
May 05 2017 06:44
Yes, it overrides the default way of this being the new object returned from new BigUser();
devpaaji
@devpaaji
May 05 2017 06:45
but when we use new this is created
Markus Kiili
@Masd925
May 05 2017 06:45
@devpaaji Engine makes a new plain object and puts it as value of this when the constructor is executed.
devpaaji
@devpaaji
May 05 2017 06:46
ok so { // code here // }
is given precedence
Masaki
@masaki1223
May 05 2017 06:47

function titleCase(str) {
   var words=str.split(" ");
  for(var i=0;i<words.length;i++){
    var result=[words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase()];

    return result;
  }

 }


titleCase("I'm a little tea pot");
Hi guys, I don't know how to return the string with the first letter of each word capitalized.... please give me help
Markus Kiili
@Masd925
May 05 2017 06:47
@devpaaji When you return an object from the constructor, it is the new object and not the object in this.
Mauro
@mauronml
May 05 2017 06:54
@masaki1223 at the moment you are returning an array of words result is still an array and not a joined string
@masaki1223 You are also returning inside your loop.
Masaki
@masaki1223
May 05 2017 07:01
@mauronml
I tried to join them but It didn't work.... var newArray=result.join'
Mauro
@mauronml
May 05 2017 07:05
@masaki1223 I would recommend you console.log(result) and look at what result is. As it stands, I think your loop is adding the same word and only one word to result
Nazar
@IsaakNazar
May 05 2017 07:07
guys I cant figure out why this project doesnt work on codepen?
http://codepen.io/NazarIsaak/pen/OmjqYV?editors=1010
Mauro
@mauronml
May 05 2017 07:07
@masaki1223 You also want var result to be outside the loop, so that you can return result outside the loop as well
Vicky Lai
@vickylai
May 05 2017 07:09
I know I can write if statements for the arrays being the same length, but I feel like there should be a more elegant method I'm missing. Help?

function diffArray(arr1, arr2) {
  var newArr = [];
  if (arr1.length >= arr2.length) {
    var bigArr = arr1;
    var smallArr = arr2;
  } else {
    var bigArr = arr2;
    var smallArr = arr1;
  }
  // filter larger array by if contained by smaller array
  return bigArr.filter(function(n) {
    return smallArr.indexOf(n) < 0;
  });
  // output filtered array
  return newArr;
}

diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
Markus Kiili
@Masd925
May 05 2017 07:10
@IsaakNazar HTTPS problem. Look at the error on browser developer tools console.
Vicky Lai
@vickylai
May 05 2017 07:10
Diff two arrays is the challenge if you couldn't tell..
Markus Kiili
@Masd925
May 05 2017 07:12
@vickylaiio Not sure if the lengths help here. You need to filter out elements of second array from the first and vice versa (and then concat the arrays). There are other ways too.
Nazar
@IsaakNazar
May 05 2017 07:13
@Masd925 but it works perfectly on Atom
devpaaji
@devpaaji
May 05 2017 07:13
@vickylaiio
Vicky Lai
@vickylai
May 05 2017 07:13
@Masd925 I guess I'm trying to shortcut doing both.
Markus Kiili
@Masd925
May 05 2017 07:13
@IsaakNazar There might be some http/https restrictions on codepen.
devpaaji
@devpaaji
May 05 2017 07:13
you can also use Math.max(arr1.length, arr2.length)
that way using a for loop it will find out how far to check
xn_x
@ak4438
May 05 2017 07:14
In Profile lookup
firstName == contacts[i][0] showing error
while
firstName == contacts[i].firstName is correct
Markus Kiili
@Masd925
May 05 2017 07:14
@vickylaiio I don't think there is such shortcut, but please surprise me ;)
Nazar
@IsaakNazar
May 05 2017 07:14
@Masd925 what I have to do then?
Vicky Lai
@vickylai
May 05 2017 07:14
@Masd925 Lol
@devpaaji Interesting, I'll try
xn_x
@ak4438
May 05 2017 07:15

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

      }
    else
      {
        res = "No such property";

      }
  }

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

Mauro
@mauronml
May 05 2017 07:15
@ak4438 firstName is the name of the property. [0] is an array index, note the name of the property
Markus Kiili
@Masd925
May 05 2017 07:15
@IsaakNazar I haven't done that project but there is talk about that problem here from time to time. Try asking on the general channel.
Nazar
@IsaakNazar
May 05 2017 07:16
@Masd925 ok thank you
CamperBot
@camperbot
May 05 2017 07:16
isaaknazar sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4002 | @masd925 |http://www.freecodecamp.com/masd925
devpaaji
@devpaaji
May 05 2017 07:17
@vickylaiio i think another way to try is create a separate function and use filter
Markus Kiili
@Masd925
May 05 2017 07:18
@vickylaiio You can filter both arrays and then concat them, or concat first and then filter.
devpaaji
@devpaaji
May 05 2017 07:19
function checkValues(firstArr, secondArr)
return firstArr.filter(function(val){
// code here
});
use this function inside the main function
@vickylaiio
Vicky Lai
@vickylai
May 05 2017 07:20
@Masd925 Wouldn't doing concat first deprive me of a way to filter?
Markus Kiili
@Masd925
May 05 2017 07:21
@vickylaiio You could remove those elements that occur more than once then.
You could use indexOf and lastIndexOf methods for that.
Vicky Lai
@vickylai
May 05 2017 07:22
Interesting.
Markus Kiili
@Masd925
May 05 2017 07:22
@vickylaiio The @devpaaji way of making a function that removes elements of one array from another, and using it twice is also good.
Coy Sanders
@coymeetsworld
May 05 2017 07:23
I actually redid that diff challenge, filter is definitely the way to go
my original soln had a ridiculous amount of lines, I think I was overthinking it
devpaaji
@devpaaji
May 05 2017 07:25
@vickylaiio
keeps those elements of the first array that are not found on second array.
Masaki
@masaki1223
May 05 2017 07:27
function titleCase(str) {
   str=str.toLowerCase();
   str=str.split(" ");

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

   str[i].charAt(0).toUpperCase() + str[i].slice(1);

  }
return str.join(" ");
 }


titleCase("I'm a little tea pot");
No clue why this isn't working.....
Coy Sanders
@coymeetsworld
May 05 2017 07:27
str[i].charAt(0).toUpperCase() + str[i].slice(1); this isn't doing anything
Markus Kiili
@Masd925
May 05 2017 07:27
@coymeetsworld Yes, I have seen some >40 line solutions here sometimes, and actually there are very elegant one-liners. So room to refactor usually.
Coy Sanders
@coymeetsworld
May 05 2017 07:28
I got mine to one line too @Masd925
easier using ES6 to do that
Vamp
@the-vampiire
May 05 2017 07:41
@masaki1223 you are very close. but as coy said you are not doing anything with that line…yet. you want to replace the currentl lowercase str[i] element with thhis new first letter uppercase version ya? how would you do that?
Vivek
@vivekmittal7
May 05 2017 07:42
can we split element of array like we do with strings
Vamp
@the-vampiire
May 05 2017 07:42
@masaki1223 also you can shorten str[i].charAt(0) to str[i][0]
split is a string method that returns an array
what do you mean @vivekmittal7
Masaki
@masaki1223
May 05 2017 07:44
@the-vampiire
@the-vampiire ```
ops
Vamp
@the-vampiire
May 05 2017 07:44
lol
Masaki
@masaki1223
May 05 2017 07:44

function titleCase(str) {
   str=str.toLowerCase;
   str=str.split(" ");

  for(var i=0;i<str.length;i++){
   str[i]=str[i].charAt(0).toUpperCase() + str[i].slice(i);
  }
  return str.join();
}

titleCase("I'm a little tea pot");
It shows str.split is not a function and cannot move on....
Vamp
@the-vampiire
May 05 2017 07:45
why did you change your return statement
Masaki
@masaki1223
May 05 2017 07:46
i've been trying to solve the error:str.split is not a function

function titleCase(str) {
   str=str.toLowerCase;
   str=str.split(" ");

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

titleCase("I'm a little tea pot");
Markus Kiili
@Masd925
May 05 2017 07:46
@masaki1223 It needs to be str=str.toLowerCase(); <- parens
Masaki
@masaki1223
May 05 2017 07:47
ohhhhh
it worked
Vamp
@the-vampiire
May 05 2017 07:47
:)
Vivek
@vivekmittal7
May 05 2017 07:47
@the-vampiire like str.split() returns different partf of strings in an array. is there any method that can split elements of an array into different arrays
Masaki
@masaki1223
May 05 2017 07:47
@the-vampiire @Masd925 thx
CamperBot
@camperbot
May 05 2017 07:47
masaki1223 sends brownie points to @the-vampiire and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4003 | @masd925 |http://www.freecodecamp.com/masd925
:cookie: 355 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
May 05 2017 07:48
sure
Angelo
@TheCodingMeatball
May 05 2017 07:49

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

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

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

// Test Setup
var testArr = [1,2,3,4,5];
return nextInLine([]);
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Vamp
@the-vampiire
May 05 2017 07:49
@vivekmittal7
var arr = [ ‘hello’, ‘split’];
for(var i in arr){
    arr[i] = [arr[i]];
}

console.log(arr) // [ [‘hello’], [‘split’] ]
Angelo
@TheCodingMeatball
May 05 2017 07:49
Im abit confused.. can someone explain please
Vamp
@the-vampiire
May 05 2017 07:50
@vivekmittal7 oh you asked for a method. no not one directly like .split()
@vivekmittal7 when in doubt you can always look up all the available methods https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Vivek
@vivekmittal7
May 05 2017 07:52
@the-vampiire sorry I am not familiar with terms
Markus Kiili
@Masd925
May 05 2017 07:52
@vivekmittal7 For transforming arrays into something, you can use array iterators like map, filter, reduce.
Tahir khan
@tahirkhaan
May 05 2017 07:52
hi i am facing some problem in javascript
Vivek
@vivekmittal7
May 05 2017 07:52
@Masd925 ok.
Vamp
@the-vampiire
May 05 2017 07:52
@Masd925 yes I thnk he meant a single method call like .split()
@vivekmittal7 often it is easier to describe what you are trying to accomplish.
Markus Kiili
@Masd925
May 05 2017 07:54
@the-vampiire Yeah.
Vamp
@the-vampiire
May 05 2017 07:54
what is your goal of splitting an array into arrays of elements
Vivek
@vivekmittal7
May 05 2017 07:54
@the-vampiire I have to complete the task of returning the largest number in an array
and the array has more subarrays in it
Markus Kiili
@Masd925
May 05 2017 07:56
@vivekmittal7 You need to transform each array element (an subarray) into the largest number of that subarray. The number of array elements stays the same, so using map method is the first thought if you plan to use iterators. Loops can do the same of course.
So you can loop the subarrays, figure out the largest number, and assign it back to the array , or push it into a result array.
Vivek
@vivekmittal7
May 05 2017 07:57

@Masd925

function largestOfFour(arr) {
 var result = []; // You can do this!
  for(var i=0; i<arr.length(); i++){
    return  result.push(arr[i])
  }
  return result;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

I tried this hoping to get something but result says function required

devpaaji
@devpaaji
May 05 2017 08:01
@Masd925
can we use Math.max.apply(null, arrayName)
inside map function?
console.log(Math.max.apply(null, list));
khanvuthy88
@khanvuthy88
May 05 2017 08:07
@vivekmittal7 correct this line
for(var i=0; i<arr.length(); i++){

TO 

for(var i=0; i<arr.length; i++){
Vivek
@vivekmittal7
May 05 2017 08:08
@khanvuthy88 ok thanks
CamperBot
@camperbot
May 05 2017 08:08
vivekmittal7 sends brownie points to @khanvuthy88 :sparkles: :thumbsup: :sparkles:
:cookie: 80 | @khanvuthy88 |http://www.freecodecamp.com/khanvuthy88
Vivek
@vivekmittal7
May 05 2017 08:11
function largestOfFour(arr) {
 var result = []; // You can do this!
     result.push(arr.map(function(arr[a]){
    return Math.max(arr[a]); 
   }));

  return result;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
I expected mycode to map every element of arr and then find the max of them and
then push it in the new array 'result'.
Dan Couper
@DanCouper
May 05 2017 08:12
Math.max doesn't take an array: it takes a series of arguments
devpaaji
@devpaaji
May 05 2017 08:12
@vivekmittal7 i think max does not accept arrays
use apply along with it
rugano
@rugano
May 05 2017 08:13

function rot13(str) { // LBH QVQ VG!
  idx = "idx" || 0;
  var code = str.charCodeAt(idx);
 var letters = [{A_M:-13},{N_Z:-13},{non_string:NaN}];

  if(A_M-13|| N_Z-13 == str){
    return str;
  }else if(non_string){

  }

  return NaN;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Vivek
@vivekmittal7
May 05 2017 08:13
@DanCouper , @devpaaji thank you both
CamperBot
@camperbot
May 05 2017 08:13
vivekmittal7 sends brownie points to @dancouper and @devpaaji :sparkles: :thumbsup: :sparkles:
:cookie: 692 | @dancouper |http://www.freecodecamp.com/dancouper
:cookie: 239 | @devpaaji |http://www.freecodecamp.com/devpaaji
rugano
@rugano
May 05 2017 08:13
how do i correct this code?
How can i correct caesars cipher to work properly?
Masaki
@masaki1223
May 05 2017 08:16

function largestOfFour(arr) {

  for(var i=0;i<arr.length;i++){
      arr[i]=arr[i].sort(function(a,b){
       return b-a;
  });

    return arr[i][0];
  }

}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
I tried to sort all the element in the arrays and return the first element in every arrays. But it only shows one element, not 4. This code is so close
I think the code it very close but cannot quite get there. Can anybody help me???
Vivek
@vivekmittal7
May 05 2017 08:17
@masaki1223 I am also on this stage.
Dan Couper
@DanCouper
May 05 2017 08:17
@vivekmittal7 Apply is a method available on all functions, basically it lets you call the function with an array instead of arguments - Math.max.apply(null, [1,2,3,4]). The first argument , doesn't matter here, so that's why null is passed (you could also pass undefined, doesn't make any difference)
Vivek
@vivekmittal7
May 05 2017 08:17
@DanCouper thanks
CamperBot
@camperbot
May 05 2017 08:17
vivekmittal7 sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: vivekmittal7 already gave dancouper points
Masaki
@masaki1223
May 05 2017 08:18
@vivekmittal7 I used function sort to align them in order and trying to extract each [0] out of array but only shows one element
Dan Couper
@DanCouper
May 05 2017 08:18
@masaki1223 make an empty array before the start of the loop, and push your values to that in the loop, then return that array at the end, not just the one value
Marco Galizzi
@Tezenn
May 05 2017 08:18
hello everyone, in the Sum All Primes number did you make an algorithm to find the primes or used one existing?
Dan Couper
@DanCouper
May 05 2017 08:19
Easiest to use an existing method (trial division is simplest)
Vivek
@vivekmittal7
May 05 2017 08:19

function largestOfFour(arr) {
 var result = []; // You can do this!
     result.push(arr.map(function(arr[a]){
    return Math.max.apply(null,arr[a]); 
   }));

  return result;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
result box says missing )
Marco Galizzi
@Tezenn
May 05 2017 08:20
@DanCouper ok i will go look for that. :)
Dan Couper
@DanCouper
May 05 2017 08:21
@vivekmittal7 either use map on arr, as you did before, and you don't need push, you just do math max in the callback. Or with the code here, you need a loop around the push that runs for the length of the array
Vivek
@vivekmittal7
May 05 2017 08:22
@DanCouper ok
Dan Couper
@DanCouper
May 05 2017 08:22
@vivekmittal7 so map means you don't need the result are, or the push. You just return arr.map(...math max callback here)
rugano
@rugano
May 05 2017 08:23

function largestOfFour(arr) {
  // You can do this!
var  myArr = [];
 var x = 0;
  for( x = 0;x < arr.length;x++){
    myArr.push(Math.max.apply(Math,arr[x]));

  }
  return myArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@vivekmittal7 check that
Vivek
@vivekmittal7
May 05 2017 08:24
@rugano works thanks
CamperBot
@camperbot
May 05 2017 08:24
vivekmittal7 sends brownie points to @rugano :sparkles: :thumbsup: :sparkles:
:cookie: 252 | @rugano |http://www.freecodecamp.com/rugano
rugano
@rugano
May 05 2017 08:25
@vivekmittal7 welcome
Vivek
@vivekmittal7
May 05 2017 08:25
@rugano why did we need to use for loop. doesn't map automatically uses every element of an array
gudipatisreenivasulu
@gudipatisreenivasulu
May 05 2017 08:25

function reusableFunction(){
console.log("Hi world");
}
reusableFunction();

is there any errors in this fucntion defining? I am not getting output#

Coy Sanders
@coymeetsworld
May 05 2017 08:26
@masaki1223 in the future please dont provide answers when people are asking for help
Rajkumar Tiwari
@rajqumar
May 05 2017 08:26
someone pls help me on this
challenge
Jonas Friedmann
@frdmn
May 05 2017 08:26
@gudipatisreenivasulu Notice that console.log() doesn't return any output
It just appends it to the console
Dan Couper
@DanCouper
May 05 2017 08:27
@vivekmittal7 using the loop and the result array is imperative - you're describing exactly how the programme should work - set up an empty array, loop through the given array, pushing a max value to that empty array each iteration, then return the result. map is declarative, you're saying take this array and run the max function on each value so that you get a new array that maps one-to-one from original -> new, but also that you don't care how the program does it.
Jonas Friedmann
@frdmn
May 05 2017 08:28
@rajqumar WHat do you not understand? I try to help you out :)
rugano
@rugano
May 05 2017 08:29
@vivekmittal7 you need loop to iterate through the sub-arrays locating the largest number ,then push them into myArr with myArr.push(Math.max.apply(Math,arr[x]));
gudipatisreenivasulu
@gudipatisreenivasulu
May 05 2017 08:29
@frdmn How to return it?
Jonas Friedmann
@frdmn
May 05 2017 08:29
@gudipatisreenivasulu
function reusableFunction(){
    return "Hi world";
}

reusableFunction();
Masaki
@masaki1223
May 05 2017 08:29
@coymeetsworld oh im sry
Coy Sanders
@coymeetsworld
May 05 2017 08:30
no worries
Rajkumar Tiwari
@rajqumar
May 05 2017 08:30
@frdmn should I use if else
Jonas Friedmann
@frdmn
May 05 2017 08:31
@rajqumar You can, but you can also use a switch-case if you like
There's more than one way to skin a cat.
gudipatisreenivasulu
@gudipatisreenivasulu
May 05 2017 08:31
@frdmn thanks.. but this was not explained in the given example.. :smile:
CamperBot
@camperbot
May 05 2017 08:31
gudipatisreenivasulu sends brownie points to @frdmn :sparkles: :thumbsup: :sparkles:
:cookie: 429 | @frdmn |http://www.freecodecamp.com/frdmn
Jonas Friedmann
@frdmn
May 05 2017 08:31
You're welcome!
Rajkumar Tiwari
@rajqumar
May 05 2017 08:31
@frdmn okay i'll try that
rugano
@rugano
May 05 2017 08:31
@coymeetsworld Hello,may i have your help on solving Caesars Cipher,am stuck?
Coy Sanders
@coymeetsworld
May 05 2017 08:32
sure
Rajkumar Tiwari
@rajqumar
May 05 2017 08:32
by the way thanks @frdmn
CamperBot
@camperbot
May 05 2017 08:32
rajqumar sends brownie points to @frdmn :sparkles: :thumbsup: :sparkles:
:cookie: 430 | @frdmn |http://www.freecodecamp.com/frdmn
Vivek
@vivekmittal7
May 05 2017 08:32
@DanCouper @rugano I tried the code without the "for" loop and it returned the highest number of first sub array i.e 5. what I don't understand is that doesn't "map" automatically iterates through the array so why didn't it this time
rugano
@rugano
May 05 2017 08:32
@coymeetsworld have posted it there
Jonas Friedmann
@frdmn
May 05 2017 08:32
@rajqumar no problem!
Dan Couper
@DanCouper
May 05 2017 08:33
@vivekmittal7 it's a toss-up, and what to use depends on context - sometimes it's useful to manually describe everything using imperative styles, and it's easier to understand a lot of the time because it's self-describing, you don't need any extra knowledge about how the language works. But declarative methods are a lot more concise, which is important as less code you have to write the less chance you have of making an error
Coy Sanders
@coymeetsworld
May 05 2017 08:33
var letters = [{A_M:-13},{N_Z:-13},{non_string:NaN}]; not sure what this is
rugano
@rugano
May 05 2017 08:34

function rot13(str) { // LBH QVQ VG!
  idx = "idx" || 0;
  var code = str.charCodeAt(idx);
 var letters = [{A_M:-13},{N_Z:-13},{non_string:NaN}];

  if(A_M-13|| N_Z-13 == str){
    return str;
  }else if(non_string){

  }

  return NaN;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Donnie
@Donnie-D
May 05 2017 08:34
function mutation(arr) {
 var str0 = arr[0].toLowerCase();
 var str1 = arr[1].toLowerCase();
 var result;
  for(i=0; i<str1.length; i++){
    if(str0[str1.indexOf(str1[i])] !==-1){
      result = true;    
    }
    else{
      return false;
    }
  }return result;
}

mutation(["hello", "hey"]);
Guys its way point 253. the code should return false as the string on 1st index doesn't match the string on 0 index but it returns true. Why? Anyone?
Coy Sanders
@coymeetsworld
May 05 2017 08:34
you should use fromCharCode and charCodeAt to solve
I would look at those functions on what they do first
gudipatisreenivasulu
@gudipatisreenivasulu
May 05 2017 08:35

@frdmn

function reusableFunction(){
return "Hi world";
}

reusableFunction();

Still it is not working.. The question asked in example is
reusableFunction should output "Hi World" to the dev console

rugano
@rugano
May 05 2017 08:37
@coymeetsworld i read the two functions at mdn but just don't quite understand how where to use them in this challenge
khanvuthy88
@khanvuthy88
May 05 2017 08:37
@Donnie-D for i didn't use indexOf. Here my example
```
for(var i=0;i<arr.length;i++{
Coy Sanders
@coymeetsworld
May 05 2017 08:37
character code will return the ASCII numeric value of the letter
Jonas Friedmann
@frdmn
May 05 2017 08:38
@gudipatisreenivasulu In this case you should use indeed console.log()!
Coy Sanders
@coymeetsworld
May 05 2017 08:38
letters in ASCII are in numeric order, i.e. a is 97, b is 98, etc
khanvuthy88
@khanvuthy88
May 05 2017 08:39
@Donnie-D sorry confuse hit Enter key
for(i=0; i<arr.length; i++){
    if(arr[i].length !==-1){
      result = true;    
    }
    else{
      return false;
    }
  }