These are chat archives for FreeCodeCamp/HelpJavaScript

24th
Jan 2017
Dan Couper
@DanCouper
Jan 24 2017 00:00
*JS not Has
Stupid autocorrect
grantknaver
@grantknaver
Jan 24 2017 00:00
here Ill post again
Joseph
@revisualize
Jan 24 2017 00:00
@DanCouper @UkrainianProtein OH! because if you did array[-1]; you'd be trying to access the -1 element.
grantknaver
@grantknaver
Jan 24 2017 00:00
I took at look trying to visualize the code, but that didn't help
here
//figure out how to sort currency with string and number
//deal with if dont have proper change to break
function checkCashRegister(price, cash, cid) {
  // Here is your change, ma'am.
  var moneyTypes = [
    {name:"PENNY", val: 0.01},
    {name: "NICKEL", val: 0.05},
    {name: "DIME", val: 0.10},
    {name: "QUARTER", val: 0.25},
    {name:"ONE", val: 1.00},
    {name: "FIVE", val: 5.00},
    {name:"TEN", val: 10.00},
    {name:"TWENTY", val: 20.00},
    {name: "ONE HUNDRED", val: 100.00}
];
  var answer = [];
  var howManyDenominations = [];
  for(var i = 0; i < cid.length; i++){
    answer.push(cid[i][1]);
    howManyDenominations.push(Math.round(cid[i][1] / moneyTypes[i].val));
  }
  var cashInDrawer = answer.reduce(function(a,b){return a + b;});
  var changeDo = cash - price;

  //var sortedChange = changeDo.sort(function(a,b){return b[1] < a[1];});
  var testFunction= function(cashCheck){
  for(a = 0; a < moneyTypes.length; a++){
   if(howManyDenominations[a] !== 0){
     for(b = 1; b < howManyDenominations[a]; b++){
       cashCheck = changeDo - (b * moneyTypes[a].val);
      alert(cashCheck);
     }//for statement 
    }//if statement
  }//for statement 
};


  }


checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
David Amanze
@GodKingShogun
Jan 24 2017 00:01
@grantknaver use the 20,10 rule i use. work for 20 mins and then take a 10 min break :+1:
Dan Couper
@DanCouper
Jan 24 2017 00:01
@revisualize yup, it doesn't even error either or return undefined, just does nothing! Not so clever design, has tripped me up a few times
grantknaver
@grantknaver
Jan 24 2017 00:01
well that hasn't been my go to @GodKingShogun lol
Max
@UkrainianProtein
Jan 24 2017 00:02

@DanCouper But then you'd just use

lastName [x];

instead of having the prog calculate the name length and then subtracting one.

grantknaver
@grantknaver
Jan 24 2017 00:02
@khaduch
yemicarter
@yemicarter
Jan 24 2017 00:02

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

 else {
   return "No such Contact";
 }

}

// Only change code above this line
}

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

Joseph
@revisualize
Jan 24 2017 00:02
@UkrainianProtein What if you want to get the last element in an array?
John Nunns
@johnnunns
Jan 24 2017 00:02
hey guys i think I'm close but just need a little direction here. Here's the problem:
function getCount(str) {
  var vowelsCount = 0;

  str.split(' ')
  switch (str){
    case "a": vowelsCount + 1;
    break;
    case "e": vowelsCount + 1;
    break;
    case "i": vowelsCount + 1;
    break;
    case "o": vowelsCount + 1;
    break;
    case "u": vowelsCount + 1;
    break;
    };

  return vowelsCount;
}
Dan Couper
@DanCouper
Jan 24 2017 00:02
@UkrainianProtein how do you get the.last item?
John Nunns
@johnnunns
Jan 24 2017 00:02
just need to return the count of vowels in a given string
grantknaver
@grantknaver
Jan 24 2017 00:03
Im trying update cashCheck again again.
Dan Couper
@DanCouper
Jan 24 2017 00:03
Ah, e/f/b
Max
@UkrainianProtein
Jan 24 2017 00:03

@revisualize Are we still talking about the

lastName[lastName.length - 1 ];

?

Joseph
@revisualize
Jan 24 2017 00:03
@UkrainianProtein Yes.
Dan Couper
@DanCouper
Jan 24 2017 00:03
Yup
grantknaver
@grantknaver
Jan 24 2017 00:03
basically subtracting form the same number again until. I cant with the change provided
yemicarter
@yemicarter
Jan 24 2017 00:04
i am sorry guys, trying to copy and paste the challenge but t isn't represented well. Can someone help me?
Max
@UkrainianProtein
Jan 24 2017 00:04
@revisualize Well I was supposed to find the letter that corresponded to the name length minus 1 so if the var was charles then the letter would be E
grantknaver
@grantknaver
Jan 24 2017 00:04
I cant get cashCheck to do anything but return a lot of weird
Ken Haduch
@khaduch
Jan 24 2017 00:04
@yemicarter - read the following camperbot link for help on posting the code ''' https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
CamperBot
@camperbot
Jan 24 2017 00:04
:bulb: to format code use backticks! ``` more info
grantknaver
@grantknaver
Jan 24 2017 00:04
@khaduch thanks for any help you can offer
CamperBot
@camperbot
Jan 24 2017 00:04
grantknaver sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2344 | @khaduch |http://www.freecodecamp.com/khaduch
Dan Couper
@DanCouper
Jan 24 2017 00:05
@UkrainianProtein zero-indexing means it should be length - 2, not - 1
Ken Haduch
@khaduch
Jan 24 2017 00:05
@grantknaver - I took a completely different approach - this looks interesting, but I will not have a lot of time to look right now, I'll give it a few minutes to try and understand what you've got.
Max
@UkrainianProtein
Jan 24 2017 00:05
@yemicarter There is a button on top of the "tab" button and that is to the left of "1" that it's like a squigly line. You hit that 3 times and then you write the code and then hit it 3 times again like you were closing your code
David Amanze
@GodKingShogun
Jan 24 2017 00:06
@DanCouper this is an example from the charCodeAt() link. can you tell me why it returns a number i thought it was suppose to return A
'ABC'.charCodeAt(0);
it returns 65
Dan Couper
@DanCouper
Jan 24 2017 00:07
charCode is a character code
David Amanze
@GodKingShogun
Jan 24 2017 00:07
@DanCouper :smile:
Jason Luboff
@JLuboff
Jan 24 2017 00:07
@GodKingShogun Becuase 65 is the acsii character number for A, you are testing at index 0
David Amanze
@GodKingShogun
Jan 24 2017 00:07
:worried:
grantknaver
@grantknaver
Jan 24 2017 00:07
@khaduch cool Im taking a break anyways
Jason Luboff
@JLuboff
Jan 24 2017 00:07
'ABC'.charCodeAt(1) would return 66, which is B
yemicarter
@yemicarter
Jan 24 2017 00:07
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

     else {
       return "No such Contact";
     }


   }


// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
lookUpProfile("Akira", "likes");
Ken Haduch
@khaduch
Jan 24 2017 00:08
@grantknaver - I can't even copy / paste the code from this chatroom... :(
Dan Couper
@DanCouper
Jan 24 2017 00:08
String.fromCharCode(65) will get you that A back again
Ken Haduch
@khaduch
Jan 24 2017 00:08
@yemicarter - good posting - you can go back and delete your old entries that are incorrect, will help to clean up the chat stream...
yemicarter
@yemicarter
Jan 24 2017 00:08
@UkrainianProtein thanks. gotten it
CamperBot
@camperbot
Jan 24 2017 00:08
yemicarter sends brownie points to @ukrainianprotein :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for ukrainianprotein
Max
@UkrainianProtein
Jan 24 2017 00:08

@DanCouper it was just an example because before it was asking me to use bracket notation

var firstName = "Ada";
var lastLetterOfFirstName = firstName[firstName.length - 1];

When they could have just written

var lastLetterOfFirstName = firstName[1]
grantknaver
@grantknaver
Jan 24 2017 00:09
Ill post codepen
Dan Couper
@DanCouper
Jan 24 2017 00:09
@UkrainianProtein they aren't the same
firstName[2] gives you the last letter
Joseph
@revisualize
Jan 24 2017 00:10
@yemicarter You're returning no contact too early.
Max
@UkrainianProtein
Jan 24 2017 00:10
@DanCouper But firstname1 gives you the 2nd letter
Dan Couper
@DanCouper
Jan 24 2017 00:10
You can't hardcode values in everywhere, it defeats the point of programming in the first place is the answer @UkrainianProtein
Joseph
@revisualize
Jan 24 2017 00:10
@UkrainianProtein Except one block of code returns an "a" and the other a "d"
What happens when you get a ReallyReallyLongStringOfCharactersThatYouHaveToGetTheLastCharacterOf?
Max
@UkrainianProtein
Jan 24 2017 00:12
@revisualize Okay yeah then it makes sense but then you'd still have to calculate the .length - X to get to the letter you want
Dan Couper
@DanCouper
Jan 24 2017 00:12
yes
but if you want the last letter, that’s length -1, the second last is length - 2 etc
David Amanze
@GodKingShogun
Jan 24 2017 00:13
@DanCouper ah ok i was thinking of charAt(). so charCodeAt() and charAt() do different things
Jason Luboff
@JLuboff
Jan 24 2017 00:13
@GodKingShogun Yes, one takes a EDIT: Should say character, not letter as characters are included* and changes to a number and the other does the opposite
Max
@UkrainianProtein
Jan 24 2017 00:13
@DanCouper okay so it's not length MINUS X?
Dan Couper
@DanCouper
Jan 24 2017 00:13
yup yup :thumbsup: one is the actual character, one is the code
yemicarter
@yemicarter
Jan 24 2017 00:14
@revisualize is that all? because while troubleshooting, the 2nd if statement to check if thr property "prop" isn't responding
Dan Couper
@DanCouper
Jan 24 2017 00:14
@UkrainianProtein
> var myString = ‘Hello’
> myString.length
5
> myString[0]
‘H’
> myString[4]
‘o’
> myString[myString.length - 1]
‘o'
c0d0er
@c0d0er
Jan 24 2017 00:15
var arr = [              
    [0,0,0]
];
var x=arr.concat([[1,1,1]]);
console.log(x)//[ [ 0, 0, 0 ], [ 1, 1, 1 ] ]
x[0][0]=1;
console.log(x)//[ [ 1, 0, 0 ], [ 1, 1, 1 ] ]
console.log(arr)//[ [ 1, 0, 0 ] ]---> why use concat, the arr element is still changed?
Max
@UkrainianProtein
Jan 24 2017 00:16

@DanCouper Yeah that makes more sense than using

[myString.length - 1];

Or it's just something I'm really not understanding as to why they would teach us that code instead of keeping it simple with

[myString[x]
Dan Couper
@DanCouper
Jan 24 2017 00:16
That isn’t simple except for single strings you already know the length of
CoryCMyers
@CoryCMyers
Jan 24 2017 00:16
I am not seeing it in any of the links I have dug through, where can I find a listing of commands like &&. I was thinking on the right way to solve this challenge and what I was thinking works, I just did not know the proper bits to make it work such as &&.
Max
@UkrainianProtein
Jan 24 2017 00:17
&& would mean that both statements have to be true and || means either or have to be true
blue && red are colors, if that's true then it works
blue || onions are colors, either one has to be true to work
Joseph
@revisualize
Jan 24 2017 00:17
@yemicarter How many times does this loop run:
for (var i = 0; i > 10000; i++) {
    if (i == 10) {
        return "truth";
    } else {
        return "lies";
    }
 }
CoryCMyers
@CoryCMyers
Jan 24 2017 00:18
Yeah, I just do not remember seeing them before and was hoping someone had a link to a list of them so I could brush up.
c0d0er
@c0d0er
Jan 24 2017 00:18
could anybody help for the following 2 questions?
var arr = [              
    [0,0,0]
];
var x=[...arr, [1,1,1,]]
console.log(x)//[ [ 0, 0, 0 ], [ 1, 1, 1 ] ]
x[0][0]=1;
console.log(x)//[ [ 1, 0, 0 ], [ 1, 1, 1 ] ]
console.log(arr)//[ [ 1, 0, 0 ] ]---> why use spread operator, the arr element is still changed?
var arr = [              
    [0,0,0]
];
var x=arr.concat([[1,1,1]]);
console.log(x)//[ [ 0, 0, 0 ], [ 1, 1, 1 ] ]
x[0][0]=1;
console.log(x)//[ [ 1, 0, 0 ], [ 1, 1, 1 ] ]
console.log(arr)//[ [ 1, 0, 0 ] ]---> why use concat, the arr element is still changed?
Brandon Achu
@bachu-dev
Jan 24 2017 00:19
@Joseph 0 times
CoryCMyers
@CoryCMyers
Jan 24 2017 00:19
@UkrainianProtein @JLuboff Thanks, I was not sure what to google :smile:
CamperBot
@camperbot
Jan 24 2017 00:19
:warning: could not find receiver for ukrainianprotein
:cookie: 682 | @jluboff |http://www.freecodecamp.com/jluboff
corycmyers sends brownie points to @ukrainianprotein and @jluboff :sparkles: :thumbsup: :sparkles:
Max
@UkrainianProtein
Jan 24 2017 00:19
Can't receive brownies :(
feels bad man
Jason Luboff
@JLuboff
Jan 24 2017 00:20
These brownies are delicious
Joseph
@revisualize
Jan 24 2017 00:20
@UkrainianProtein You have to link your FCC account to your github account.
grantknaver
@grantknaver
Jan 24 2017 00:21
sorry
Max
@UkrainianProtein
Jan 24 2017 00:21
@revisualize oh alright i'll do that when I get home. Have a good one guys and girls
grantknaver
@grantknaver
Jan 24 2017 00:21
internet went down @khaduch
here is the codepen
yemicarter
@yemicarter
Jan 24 2017 00:21
@revisualize eeerrrmm, it won't run because 10 !> 10000
Joseph
@revisualize
Jan 24 2017 00:21
@yemicarter No.
It will only run once.
Because i is 0 and if i is not 10 .. it triggers the else.
grantknaver
@grantknaver
Jan 24 2017 00:22
@khaduch here you go
Dan Couper
@DanCouper
Jan 24 2017 00:22

@UkrainianProtein If you only use the ‘simple’ method of putting a hardcoded value in to get the last character in a string, it becomes extremely complicated to do it for, say, an array of strings. In real life, it is far, far more likely you will not have the luxury of knowing in advance the length of every string. And even if you did, and they were of varying lengths, your code would be huge and complex

var someArrayOfStrings = ["here", "are", "a", "number", "of", "strings", "all", "of", "varying",
 "lengths”]

How do you deal with that? Say I want the last letter of all of those for some reason:

> someArrayOfStrings.map(str => str[str.length - 1])
[ 'e', 'e', 'a', 'r', 'f', 's', 'l', 'f', 'g', 's’ ]

The code is extremely simple; I don’t need to know anything about the string in advance, just that it is a string

yemicarter
@yemicarter
Jan 24 2017 00:23
@revisualize yeah true, what are you trying to point out?
Ken Haduch
@khaduch
Jan 24 2017 00:24
@grantknaver - now, it doesn't look like you're calling testFunction? Should I just put that in?
Joseph
@revisualize
Jan 24 2017 00:24
@yemicarter Look at your code.
@yemicarter Your loop is only running once.
Adam King
@awking11
Jan 24 2017 00:26
Hello! Any help on what I've done wrong?
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];
Sorry pasted wrong code.
Hamoud Khatar
@skhamoud
Jan 24 2017 00:28
@c0d0er I think that because arrays are just objects , that x assignment is just a refrence ? maybe ? I got confused that is actually a good question , If you find answer report back :grin:
Adam King
@awking11
Jan 24 2017 00:28
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[2][3][1];
yemicarter
@yemicarter
Jan 24 2017 00:29
@revisualize should i ditch the if statement and use switch?
Joseph
@revisualize
Jan 24 2017 00:29
@yemicarter No.
yemicarter
@yemicarter
Jan 24 2017 00:29
or could you clue me in what next?
Joseph
@revisualize
Jan 24 2017 00:29
@yemicarter You just need to change a bit of your logic.
If statements do NOT require an else.
Jason Luboff
@JLuboff
Jan 24 2017 00:30
@awking11 myArray[2] = [7,8,9] myArray[2][3] = Not valid etc
Joseph
@revisualize
Jan 24 2017 00:30
@yemicarter Let's say you were at a big business event and you're quite popular (with all those skills you have) throughout the event you got handed 200 business cards (Which will remain unordered). Now, I walk up to you at the end and ask you.. Do you have a Business Card for "Jane Smith"? Now you loop look through your stack of 200 business cards. When would you tell me that you didn't have a business card for Jane?
grantknaver
@grantknaver
Jan 24 2017 00:30
that looked like that might of have been it?
Adam King
@awking11
Jan 24 2017 00:30
Ok, i see it now. Thanks
grantknaver
@grantknaver
Jan 24 2017 00:30
But will that continually update with the subtraction
Jason Luboff
@JLuboff
Jan 24 2017 00:31
@awking11 I think you want to access myArray[3] = [[10,11,12], 13, 14]]
Adam King
@awking11
Jan 24 2017 00:31
it says myData should be equal to 8
Ken Haduch
@khaduch
Jan 24 2017 00:31
@grantknaver - I don't exactly know how you intend to use it. I just added a call to testFunction() - I'm not sure what the argument is supposed to be? I'm just trying to see what it would do by stepping through it.
Jason Luboff
@JLuboff
Jan 24 2017 00:32
@awking11 Ah. Then ya try and rework it. Your first number [2] is correct so go from there
yemicarter
@yemicarter
Jan 24 2017 00:32
@revisualize after looking through all the cards...
Joseph
@revisualize
Jan 24 2017 00:32
@yemicarter So, you're saying that after you loop look through all of the contacts cards in your array of object stack. That you'd tell me you don't have one for the individual?
  // code before a for loop.
for (..........) {
  // Code inside of a for loop.
}
  // code after a for loop.
grantknaver
@grantknaver
Jan 24 2017 00:33
gotcha well what I am trying to do is steadily subtract from changeDo the money types types times there worth to see if there is enough money to deal with the change.
Ive got to step away hopefully you can shoot me some tips thanks man
Adam King
@awking11
Jan 24 2017 00:34
@JLuboff Thanks!
CamperBot
@camperbot
Jan 24 2017 00:34
:cookie: 683 | @jluboff |http://www.freecodecamp.com/jluboff
awking11 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
Ken Haduch
@khaduch
Jan 24 2017 00:36
@grantknaver - I haVE TO Step away, too - got to get some grub... I think that this is going to take some doing to get this to work... for one thing, in my solution, I started with the highest denominations and worked my way down to make the change. Because they want it sorted in highest to lowest order, and it made sense to me to do it that way... I'll see what I see later.
kayjayhogan
@kayjayhogan
Jan 24 2017 00:36
Could someone please help me on "Word Blanks"? I have sentences that tick off either "wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib)." OR "wordBlanks("cat", "little", "hit", "slowly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib)." but I can't figure out how to get BOTH checked off. It's driving me nuts.
Joseph
@revisualize
Jan 24 2017 00:37
@kayjayhogan Gist by revisualize / FreeCodeCamp - Word_Blanks.js
The function declaration was set up as... function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) giving the function name as wordBlanks and with four parameter of myNoun, myAdjective, myVerb and myAdverb.
There is more that I could go into (if you want I can) but, I'll sum it up with:
Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).
David Amanze
@GodKingShogun
Jan 24 2017 00:37
@kayjayhogan you're giving params you have to use. concatenate the params to words of your own
@revisualize can you take a look at my code so far SENPAI

function rot13(str) { // LBH QVQ VG!
  for (var i=0; i<str.length; i++) {
 if (str.charCodeAt(i+13)<=92) {

 } else {
   return str.charCodeAt(i+13);
 }

  }


}
Joseph
@revisualize
Jan 24 2017 00:38
@GodKingShogun You're returning too early.
Damián Sánchez
@sanchezdam
Jan 24 2017 00:39
var code = "formatted";
Hi guys, i need help in this challenge https://www.freecodecamp.com/challenges/nesting-for-loops
David Amanze
@GodKingShogun
Jan 24 2017 00:39
@revisualize just caught a mistake. the < is suppose to go this way >
Damián Sánchez
@sanchezdam
Jan 24 2017 00:40
My code is this
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.length; i++){
for (var j = 0; j < arr[i].length; i++) {
product = product * arr[i][j];
}
}
// Only change code above this line
return product;
}
what i'm doing wrong?
Joseph
@revisualize
Jan 24 2017 00:40
@sanchezdam Your J loop.
Is incrementing i
Damián Sánchez
@sanchezdam
Jan 24 2017 00:40
oh yessss
thks joseph!
David Amanze
@GodKingShogun
Jan 24 2017 00:41
@revisualize i need help writing the code for my first if statement so my code knows to start counting at charCodeAt 65
@revisualize not sure how to write it
c0d0er
@c0d0er
Jan 24 2017 00:42
@DanCouper thanks!
CamperBot
@camperbot
Jan 24 2017 00:42
c0d0er sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 450 | @dancouper |http://www.freecodecamp.com/dancouper
David Amanze
@GodKingShogun
Jan 24 2017 00:42
@revisualize SENPAI are you still there
Joseph
@revisualize
Jan 24 2017 00:43
@GodKingShogun create a result variable.
That Senpai stuff is annoying.
David Amanze
@GodKingShogun
Jan 24 2017 00:43
@revisualize sorry
@revisualize ```

function rot13(str) { // LBH QVQ VG!
 var result;
 for (var i=0; i<str.length; i++) {
 if (str.charCodeAt(i+13)>=92) {

 } else {
   return str.charCodeAt(i+13);
 }

  }


}
Joseph
@revisualize
Jan 24 2017 00:44
Why are you returning?
Margaret
@Margaret2
Jan 24 2017 00:44
@GodKingShogun careful who you call senpai, you will make @Manish-Giri jealous :trollface:
Joseph
@revisualize
Jan 24 2017 00:44
Do you realize that return causes your function to HALT
David Amanze
@GodKingShogun
Jan 24 2017 00:44
:smile:
@Margaret2 :smile:
Joseph
@revisualize
Jan 24 2017 00:45
@GodKingShogun
for ( ..... ) {
    if (evaluation) {
        return "truth";
    } else {
        return "lies";
    }
 }

This loop.. Does not loop.

David Amanze
@GodKingShogun
Jan 24 2017 00:46
@revisualize i need the number to convert it back to its fromCharCode value
Joseph
@revisualize
Jan 24 2017 00:46
@GodKingShogun If you say so.
Jason Luboff
@JLuboff
Jan 24 2017 00:46
@GodKingShogun Why not push the new value into an array?
David Amanze
@GodKingShogun
Jan 24 2017 00:46
@revisualize i took it off

function rot13(str) { // LBH QVQ VG!
 var result;
 for (var i=0; i<str.length; i++) {
 if (str.charCodeAt(i+13)>=92) {

 } else {
   str.charCodeAt(i+13);
 }

  }


}
@JLuboff hello SENPAI
Joseph
@revisualize
Jan 24 2017 00:47
I need food.
revisualize @revisualize leaves.
David Amanze
@GodKingShogun
Jan 24 2017 00:47
@JLuboff I still need help with finishing my first if statement
Jason Luboff
@JLuboff
Jan 24 2017 00:47
@GodKingShogun Hello kohai
David Amanze
@GodKingShogun
Jan 24 2017 00:48
:smile:
Jason Luboff
@JLuboff
Jan 24 2017 00:49
@GodKingShogun So you want to test each individual letter of the string. We then need to determine where they are within our range. Remember that "A" is 65 and "Z" is 90
David Amanze
@GodKingShogun
Jan 24 2017 00:49
@JLuboff i need my first if statement to loop back to the Unicode value of 65 and start counting when it gets to 92
Jason Luboff
@JLuboff
Jan 24 2017 00:50
@GodKingShogun If we are shifting by 13, we can not exceed 90 when we do so. And if we are under 65, we should not be modifying it at all
David Amanze
@GodKingShogun
Jan 24 2017 00:51
@JLuboff lol simple arithmetic fail but yea. so i need to change my first if to 91
Jason Luboff
@JLuboff
Jan 24 2017 00:51
@GodKingShogun You should test each letter to see what value it returns instead. str[i].charCodeAt(0) remember, we are checking the index (0 in this case) for its letter. We could alternatively do str.charCodeAt(i) I beleive. I know I did it the first way
taithethai
@taithethai
Jan 24 2017 00:52

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


function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0;i<contacts.length;i++){
  if(contacts."firstName" === firstName){ //here
    return contacts[i][prop];    
    }
  }
fCC is saying that I should use dot notation where it says here, but when I switch it to dot notation, I'm getting Expected an identifier and instead saw 'firstName'. What am I missing?
Margaret
@Margaret2
Jan 24 2017 00:52
@taithethai you can't have quotes for dot notation, should be just contacts.firstName
Jason Luboff
@JLuboff
Jan 24 2017 00:52
contacts."firstName" is not valid
taithethai
@taithethai
Jan 24 2017 00:53
Thanks fCC
... so then bracket notation is the way to go.
@Margaret2 @JLuboff thanks
CamperBot
@camperbot
Jan 24 2017 00:53
taithethai sends brownie points to @margaret2 and @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 684 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 1335 | @margaret2 |http://www.freecodecamp.com/margaret2
David Amanze
@GodKingShogun
Jan 24 2017 00:54
@JLuboff i already know the values are going to be 65 to 90 so i just need to write an if statement to keep the Unicode count in between these numbers
Taylor
@treddson
Jan 24 2017 00:54
var myStr = "FirstLine\n\\Secondline\\\rThirdLine";
what's wrong with myStr variable?
taithethai
@taithethai
Jan 24 2017 00:54
@treddson secondline is improperly typed
Margaret
@Margaret2
Jan 24 2017 00:54
@treddson try capitalizing the L in SecondLine...
Jason Luboff
@JLuboff
Jan 24 2017 00:55
@GodKingShogun Yes along those lines. Good luck. I am out for the evening
David Amanze
@GodKingShogun
Jan 24 2017 00:55
@JLuboff good night SENPAI
Taylor
@treddson
Jan 24 2017 00:55
wow. Never ceases to amaze me how I miss the most simple things. Thanks, @taithethai and @Margaret2
CamperBot
@camperbot
Jan 24 2017 00:55
treddson sends brownie points to @taithethai and @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1337 | @margaret2 |http://www.freecodecamp.com/margaret2
:cookie: 223 | @taithethai |http://www.freecodecamp.com/taithethai
taithethai
@taithethai
Jan 24 2017 00:55
npnp
David Amanze
@GodKingShogun
Jan 24 2017 00:56
@Margaret2 all my senpais have left me lol. can you help
taithethai
@taithethai
Jan 24 2017 00:56
console.log("blah")
should this print out "blah" in the box to the left?
Edgar Pan
@edgaryp
Jan 24 2017 00:56
Hi I have a question about TwitchTV API. Is this Url correct https://api.twitch.tv/kraken/streams/sup3rson1k as sup3rson1k is online and streaming at the moment?
Margaret
@Margaret2
Jan 24 2017 00:58
@taithethai i think the box just prints out the final outcome of the tests :P But you should be able to open your browser console and see the log
taithethai
@taithethai
Jan 24 2017 00:59
:-1:
ok
alright
Edgar Pan
@edgaryp
Jan 24 2017 00:59
or how do I pass on the client id into the Url if I want to use .getJSON instead of .ajax.
David Amanze
@GodKingShogun
Jan 24 2017 00:59
@Margaret2 by the way you're allowed to have multiple SENPAIS. i only have two so far :smile:
Margaret
@Margaret2
Jan 24 2017 01:00
u have at least 3
reviz, manish, and jluboff
David Amanze
@GodKingShogun
Jan 24 2017 01:00
@revisualize is no longer SENPAI since he doesn't like it
Margaret
@Margaret2
Jan 24 2017 01:00
oh, i see :D
David Amanze
@GodKingShogun
Jan 24 2017 01:01
@Margaret2 but can you take a look at my first if statement and tell me how i can start my Unicode count back at 65 when i get to 91

function rot13(str) { // LBH QVQ VG!
 var result;
 for (var i=0; i<str.length; i++) {
 if (str.charCodeAt(i+13)>=92) {

 } else {
   str.charCodeAt(i+13);
 }

  }


}

function rot13(str) { // LBH QVQ VG!
 var result;
 for (var i=0; i<str.length; i++) {
 if (str.charCodeAt(i+13)>=91) {

 } else {
   str.charCodeAt(i+13);
 }

  }


}
Margaret
@Margaret2
Jan 24 2017 01:02
@GodKingShogun why don't you have an if statement for if it is between 65 and 91
Edgar Pan
@edgaryp
Jan 24 2017 01:02
anybody can help with API questions?
David Amanze
@GodKingShogun
Jan 24 2017 01:02
@Margaret2 that's what the else statement is for
@Margaret2 nvm i get why i need it
@Margaret2 okay after i add that i still need help with what i should write for the >=91
Ugur Ozcelik
@ugurozcelik
Jan 24 2017 01:06

function isLess(a, b) {
// Fix this code
switch(a,b){
case (a < b):
return true;
case(a>b):
return false;
}
}

// Change these values to test
isLess(10, 15);

can anyone help me with this ?

Margaret
@Margaret2
Jan 24 2017 01:06
@GodKingShogun to have a repeating pattern, i actually like to use the % operator.
so to make the letters repeat, i wrote a = a%26+65; (a is the character code btw). You can use that if you like or figure out a different way
David Amanze
@GodKingShogun
Jan 24 2017 01:07
@Margaret2 can you demonstrate. i don't think i have come across that before
Stephen James
@sjames1958gm
Jan 24 2017 01:07
@ugurozcelik Look at what the example code did - you should only have one line in that function.
Jceciliani
@Jceciliani
Jan 24 2017 01:08
Can anyone see the issue here? I need to "Add a new album to the myMusic array. Add artist and title strings, release_year number, and a formats array of strings."
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
[
{
"artist": "Coletrain",
"title": "Oh Yeah",
"release_year": 2002,
"formats": [
"DVD",
"CD",
"MP3"
],
"gold": true
}
];
Stephen James
@sjames1958gm
Jan 24 2017 01:09
@GodKingShogun If you want to make your code more readable.
```
var A = "A".charCodeAt(0);
var Z = "Z".charCodeAt(0);
Then you can use A and Z where you have the numbers.
Ugur Ozcelik
@ugurozcelik
Jan 24 2017 01:10
@sjames1958gm thank you
CamperBot
@camperbot
Jan 24 2017 01:10
ugurozcelik sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5500 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jan 24 2017 01:10
@Jceciliani Your added [] is creating another array, not needed. Also you need to put a comma between the two objects
Tiffany
@tiffanymakes
Jan 24 2017 01:12
@edgaryp use https://wind-bow.gomix.me/twitch-api/streams instead of https://api.twitch.tv/kraken/streams. That allows you to get access without needing an API key.
Andy
@amillion3
Jan 24 2017 01:18
Can anyone help me out? I feel like I'm so close, but I just can't see my mistake.
https://www.freecodecamp.com/challenges/truncate-a-string
function truncateString(str, num) {
  var strLength = str.length + 3; //adds 3 because of the ... that will be added 
  var output = "";

  if (strLength <= 3) {
    output = str + "...";
  }
  else {
    numDots = num - 3;
    output = str.slice(0,numDots) + "...";
  }
  return output;

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
David Amanze
@GodKingShogun
Jan 24 2017 01:24
anyone here that can help :smile:
Brian
@BrianCodes33
Jan 24 2017 01:25
does someone know how i turn an array into a binary representation
Stephen James
@sjames1958gm
Jan 24 2017 01:26
@BrianCodes33 Array of what?
Brian
@BrianCodes33
Jan 24 2017 01:26
ints @sjames1958gm
Stephen James
@sjames1958gm
Jan 24 2017 01:26
@amillion3 Should you test if str.length > num ?
David Amanze
@GodKingShogun
Jan 24 2017 01:26
@amillion3 if you add 3 to every string wont it screw up your results
Andy
@amillion3
Jan 24 2017 01:27
@sjames1958gm Yes, you are right...
David Amanze
@GodKingShogun
Jan 24 2017 01:27
@sjames1958gm can you take a look at what i have so far

function rot13(str) { // LBH QVQ VG!

 for (var i=0; i<str.length; i++) {
 if (str.charCodeAt(i+13)<65) {
   str.charCodeAt(i+13);
 } else if (str.charCodeAt(i+13)>90) {
 str.charCodeAt(i%26+65);
 } else if (str.charCodeAt(i+13)>=65) {
   str.charCodeAt(i+13);
 }
  return str.fromCharCode;
  }


}
Andy
@amillion3
Jan 24 2017 01:28
@GodKingShogun I'm adding 3 because the max string length has to include 3 periods (...). I think I'm on the right track?
Stephen James
@sjames1958gm
Jan 24 2017 01:28
@GodKingShogun charCodeAt(i+13) this doesn't make sense. Why add 13 here?
Brian
@BrianCodes33
Jan 24 2017 01:29
function bitsBattle(numbers) {
  var binRep = parseInt( numbers.split('').reverse().join(''), 2 );
  console.log(binRep);
}

bitsBattle([5, 3, 14])

@sjames1958gm do you see what im trying to do?

Stephen James
@sjames1958gm
Jan 24 2017 01:29
@johncooper1388 Turns out that it is actually NaN the FCC console shows NaN as null.
@BrianCodes33 split only works on strings, not arrays.
David Amanze
@GodKingShogun
Jan 24 2017 01:30
@amillion3 okay but your string length will always be greater than 3
@sjames1958gm i am on the Caesar cipher challenge so i have to add 13 to every Unicode number to get the right value
Stephen James
@sjames1958gm
Jan 24 2017 01:32
@GodKingShogun Sure, but why are you trying to access the i + 13 letter from the string?
Joseph
@revisualize
Jan 24 2017 01:32
@GodKingShogun You're loop isn't looping.
Andy
@amillion3
Jan 24 2017 01:33
@GodKingShogun Hmmm, yes... Guess I'm just having trouble following the instructions in this one.
Thanks @GodKingShogun @sjames1958gm
CamperBot
@camperbot
Jan 24 2017 01:33
amillion3 sends brownie points to @godkingshogun and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5501 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 55 | @godkingshogun |http://www.freecodecamp.com/godkingshogun
David Amanze
@GodKingShogun
Jan 24 2017 01:33
@sjames1958gm i am using the charCodeAt() so i thought it would convert the i into a Unicode and then add 13
Joseph
@revisualize
Jan 24 2017 01:33
Strings are immutable.
Stephen James
@sjames1958gm
Jan 24 2017 01:34
@GodKingShogun Maybe outside of charCodeAt() but inside the () you want to just use i to get the correct letter
@amillion3 Focus on the if statements in the instructions first.
Truncate a string (first argument) if it is longer than the given maximum string length (second argument).
This tells me that you need to test if (string length > num) then truncate
Andy
@amillion3
Jan 24 2017 01:36
Okay. I think I need to start from scratch on this one. I have an idea in my head how I should approach this now.
David Amanze
@GodKingShogun
Jan 24 2017 01:38
@sjames1958gm okay i can add the +13 outside the () for the if part but doing the same thing on the return part of the if brings up an error
 for (var i=0; i<str.length; i++) {
 if (str.charCodeAt(i)+13<65) {
   str.charCodeAt(i)+13;
ThierryRomain
@ThierryRomain
Jan 24 2017 01:38
hi! i need to split an array of strings into chunks. I decided to convert the array into a string, separate the string into chunks and pushing those chunks into an empty array but I get "1" as an output which makes no sense to me
Joseph
@revisualize
Jan 24 2017 01:38
@GodKingShogun Okay.. Do you realize that doing str.charCodeAt(i)+13; doesn't actually DO anything?
ThierryRomain
@ThierryRomain
Jan 24 2017 01:39
here is the line which seems to cause the "1" output
David Amanze
@GodKingShogun
Jan 24 2017 01:39
@revisualize i want it to
lol
Joseph
@revisualize
Jan 24 2017 01:39
@GodKingShogun So make it do something.
ThierryRomain
@ThierryRomain
Jan 24 2017 01:39
return chunks.push(str.substring(1, 1 +size));
David Amanze
@GodKingShogun
Jan 24 2017 01:39
@revisualize so how would you suggest i would write it so i would get +13 of the charCodeAt()
Joseph
@revisualize
Jan 24 2017 01:40
@GodKingShogun I'd suggest maybe pushing to an array.
David Amanze
@GodKingShogun
Jan 24 2017 01:41
@revisualize :worried:
Joseph
@revisualize
Jan 24 2017 01:43
@afrikhero You're using >= when you should be using ==
ThierryRomain
@ThierryRomain
Jan 24 2017 01:45

function chunkArrayInGroups(arr, size) {
var str = arr.join().replace(/,/g,"");
var chunks = [];
for (i = 0; i <= size; i += size){
return chunks.push(str.substring(i, i +size));
}
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);

why is this code giving me an output of "1"?
I explained what I was trying to achieve above
Joseph Uchenna
@afrikhero
Jan 24 2017 01:46
@revisualize Thanks I changed it
CamperBot
@camperbot
Jan 24 2017 01:46
afrikhero sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3081 | @revisualize |http://www.freecodecamp.com/revisualize
David Amanze
@GodKingShogun
Jan 24 2017 01:48
@revisualize will this work
 for (var i=0; i<str.length; i++) {
var davidAwesome=[];
   davidAwesome=davidAwesome.push(str.charCodeAt(i));
edplo
@edplo
Jan 24 2017 01:48
Is anyone familiar with the "Make Object Properties Private" challenge? I'm not sure what it is asking for
Joseph
@revisualize
Jan 24 2017 01:49
@GodKingShogun No.
David Amanze
@GodKingShogun
Jan 24 2017 01:49
@edplo just create the variable inside the function i believe
@revisualize but i pushed the Unicode into an array like you asked
Joseph
@revisualize
Jan 24 2017 01:50
@ThierryRomain Having a return inside of a for loop. Doesn't work like that.
@ThierryRomain Return statements cause functions to HALT
@GodKingShogun Tell me about .push()
David Amanze
@GodKingShogun
Jan 24 2017 01:51
@revisualize .push() pushes a value into an array :smile:
:+1:
ThierryRomain
@ThierryRomain
Jan 24 2017 01:52
@revisualize oh true, will creating a variable and returning it outside the loop work or its just repeating the same problem? I think I just need to restart anud use another method right?
Simon
@simonhlee97
Jan 24 2017 01:52
anyone else having trouble with "Using Objects for Lookups"?
Joseph
@revisualize
Jan 24 2017 01:52
@GodKingShogun Let me ask you something.
David Amanze
@GodKingShogun
Jan 24 2017 01:52
@revisualize ok
Joseph
@revisualize
Jan 24 2017 01:53

@GodKingShogun If I have this:

var arr = ["B", "D", "F", "H", "J", "L"];

arr = arr.push("M");

@GodKingShogun What is the value of arr after this code runs?

ThierryRomain
@ThierryRomain
Jan 24 2017 01:53
@revisualize yeah its outside of scope, is there a way to achieve it with my thinking or I should restart?
David Amanze
@GodKingShogun
Jan 24 2017 01:53
@simonhlee97 what is your question
@revisualize ok i am following
@revisualize it will have m on the end
Joseph
@revisualize
Jan 24 2017 01:54
@GodKingShogun No it won't.
David Amanze
@GodKingShogun
Jan 24 2017 01:54
@revisualize enlighten me
Joseph
@revisualize
Jan 24 2017 01:55
@GodKingShogun What does .push() do?
David Amanze
@GodKingShogun
Jan 24 2017 01:55
@revisualize does m have to be in an array for it to work
Simon
@simonhlee97
Jan 24 2017 01:55
@GodKingShogun trying to convert a switch stmt into a lookup
Joseph
@revisualize
Jan 24 2017 01:55
@GodKingShogun No. Look up what .push() actually does and what it returns.
Chris
@guest2
Jan 24 2017 01:56
plush
David Amanze
@GodKingShogun
Jan 24 2017 01:56
@revisualize okay i will be back
ThierryRomain
@ThierryRomain
Jan 24 2017 01:56
@revisualize Figured it out, I just need to recall my empty array after "loading" it with the for loop, thanks silly mistake on my part!
CamperBot
@camperbot
Jan 24 2017 01:56
thierryromain sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3082 | @revisualize |http://www.freecodecamp.com/revisualize
Raul Calzado
@raulprobeatz
Jan 24 2017 01:58
guys, I'm stuck at the remainder lesson on js
David Amanze
@GodKingShogun
Jan 24 2017 01:58
@revisualize it returns the array with the pushed value and new length
Joseph
@revisualize
Jan 24 2017 01:58
@raulprobeatz Okay. Can I ask you some side questions?
Raul Calzado
@raulprobeatz
Jan 24 2017 01:58
@revisualize yes!
David Amanze
@GodKingShogun
Jan 24 2017 01:59
@raulprobeatz just look at the example you're given
Joseph
@revisualize
Jan 24 2017 01:59
@raulprobeatz
What is the returned value of num ... var num = 4 + 3;
What is the returned value of num ... var num = 10 / 5;
What is the returned value of num ... var num = 5 * 3;
@GodKingShogun The push() method adds one or more elements to the end of an array and returns the new length of the array.

@GodKingShogun If I have this:

var arr = ["B", "D", "F", "H", "J", "L"];

arr = arr.push("M");

@GodKingShogun What is the value of arr after this code runs?

Raul Calzado
@raulprobeatz
Jan 24 2017 02:00
@revisualize Well, that'll be 7, 2 and 15
Joseph
@revisualize
Jan 24 2017 02:00
@raulprobeatz Okay.
@raulprobeatz % is just an arithmetic operator.
Remainder:
http://images.tutorvista.com/cms/images/38/remainder1.PNG
13 % 2 is 1 ... 26 % 5 is 1 ... 24 % 6 is 0
24 % 5 is 4 ... 219 % 20 is 19 ... Does that help?
Raul Calzado
@raulprobeatz
Jan 24 2017 02:02
@revisualize Got it! Thank you so much!
CamperBot
@camperbot
Jan 24 2017 02:02
raulprobeatz sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3083 | @revisualize |http://www.freecodecamp.com/revisualize
David Amanze
@GodKingShogun
Jan 24 2017 02:02
@revisualize are you trying to mind rape me lol. arr would now have "M" added to the end and the new length would be 7
Joseph
@revisualize
Jan 24 2017 02:02
@GodKingShogun What?
@GodKingShogun But, you're overwriting arr
So arr would be 7
It wouldn't actually be an array it would be a number.
Your commentary was inappropriate.
David Amanze
@GodKingShogun
Jan 24 2017 02:04
@revisualize i never knew that. i thought it just added whatever it was pushing to the end of the array
Joseph
@revisualize
Jan 24 2017 02:04
The documentation is HELPFUL.
taithethai
@taithethai
Jan 24 2017 02:04
for arrays, one cannot use strings in dot array, right? I may have asked a variation of this, I just wanted to be 100% sure.
Joseph
@revisualize
Jan 24 2017 02:04
@taithethai What?
David Amanze
@GodKingShogun
Jan 24 2017 02:05
@taithethai nani
@revisualize i am totally lost now lol. you told me to push the results of my charCodeAt(i) to an array and i did and now you're saying it is wrong lol
:worried:
Joseph
@revisualize
Jan 24 2017 02:07
@GodKingShogun Because you're overwriting
You keep overwriting your variable with the length of the array.
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 02:08
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(contacts[i].firstName === firstName){
if(contacts[i].prop != NULL){
console.log(contacts[i].prop);
}
else
console.log("No such property");
}
else
console.log("No such contact");
}
// Only change code above this line
}
Joseph
@revisualize
Jan 24 2017 02:08
@warcraft034 You're using console.log when you should be returning.
David Amanze
@GodKingShogun
Jan 24 2017 02:08
@revisualize is this better
 for (var i=0; i<str.length; i++) {
var davidAwesome=[];
   davidAwesome.push(str.charCodeAt(i));
Joseph
@revisualize
Jan 24 2017 02:08
@warcraft034 Your loop is only running once.
@GodKingShogun No. Because you're overwriting your array variable each time the loop runs.
David Amanze
@GodKingShogun
Jan 24 2017 02:09
@GodKingShogun sinks into an eternity of depression
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 02:09
I don't understand
David Amanze
@GodKingShogun
Jan 24 2017 02:09
:worried:
Joseph
@revisualize
Jan 24 2017 02:09
@warcraft034 Let me ask you...
David Amanze
@GodKingShogun
Jan 24 2017 02:09
@warcraft034 what dont you understand
Joseph
@revisualize
Jan 24 2017 02:10
@warcraft034 How many times does this loop run?
for ( ..... ) {
    if (evaluation) {
        return "truth";
    } else {
        return "lies";
    }
 }
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 02:10
I added "return" and it don't work
NULL is not defined
Joseph
@revisualize
Jan 24 2017 02:10
@warcraft034 because return statements cause functions to halt.
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 02:10
(y)
David Amanze
@GodKingShogun
Jan 24 2017 02:10
@warcraft034 because they just do lol
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 02:11
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(contacts[i].firstName === firstName){
if(contacts[i].prop != NULL){
return console.log(contacts[i].prop);
}
else
return console.log("No such property");
}
else
return console.log("No such contact");
}
// Only change code above this line
}
Joseph
@revisualize
Jan 24 2017 02:11
@warcraft034 You can't return console.log
@warcraft034 Oh. You're using dot notation.
@warcraft034 Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
David Amanze
@GodKingShogun
Jan 24 2017 02:12
@revisualize how do i stop overwriting my code
Joseph
@revisualize
Jan 24 2017 02:13
@GodKingShogun Move your array declaration outside of the for loop.
David Amanze
@GodKingShogun
Jan 24 2017 02:14
@revisualize will this suffice
 var davidAwesome=[];
 for (var i=0; i<str.length; i++) {
   davidAwesome.push(str.charCodeAt(i));
Joseph
@revisualize
Jan 24 2017 02:14
Yes.
David Amanze
@GodKingShogun
Jan 24 2017 02:14
:smile:
@revisualize do you have some extra information like you do everything on why that is a no no lol
Joseph
@revisualize
Jan 24 2017 02:16
@GodKingShogun What?
David Amanze
@GodKingShogun
Jan 24 2017 02:16
@revisualize do you have more detailed information on why i cant have my var declaration inside my loop
Joseph
@revisualize
Jan 24 2017 02:16
@GodKingShogun Logic.
David Amanze
@GodKingShogun
Jan 24 2017 02:16
and why it is considered overwritin
Joseph
@revisualize
Jan 24 2017 02:17
You just need to watch your code run.
David Amanze
@GodKingShogun
Jan 24 2017 02:18
@revisualize okay thanks
CamperBot
@camperbot
Jan 24 2017 02:18
:star2: 3084 | @revisualize |http://www.freecodecamp.com/revisualize
godkingshogun sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
Rafael Mateo
@rafaelmateo
Jan 24 2017 02:23
This is to hard
I cant anymore
Jesus
Ken Haduch
@khaduch
Jan 24 2017 02:24
@rafaelmateo - what's up...
Rafael Mateo
@rafaelmateo
Jan 24 2017 02:25
How can you guys concentrate without exploding? Whats the trick
I dont get it
Ken Haduch
@khaduch
Jan 24 2017 02:25
@rafaelmateo - sometimes you just have to walk away and take a break... even for a few hours!
Joseph
@revisualize
Jan 24 2017 02:26
@rafaelmateo +
LightningKeeper
@LightningKeeper
Jan 24 2017 02:30
How do I do the Nan?
Joseph
@revisualize
Jan 24 2017 02:30
@LightningKeeper How do you do the what?
Suraj
@suraj-davariya
Jan 24 2017 02:30
@LightningKeeper NotANumber ? describe the problem
LightningKeeper
@LightningKeeper
Jan 24 2017 02:31
For the undefined variable, I am supposed to define it, and then get a NaN, Not a Number, how do i do that?
Joseph
@revisualize
Jan 24 2017 02:31
What?
You're not describing the problem.
What are you trying to do?
Max Ho
@maxnathaniel
Jan 24 2017 02:32
Hi all, quick question. I have been using sequelize for nodejs. feels like a nightmare. What do you use for your ORM?
LightningKeeper
@LightningKeeper
Jan 24 2017 02:32
Define that variable A, 6.
Would it be var a = 6;?
Joseph
@revisualize
Jan 24 2017 02:33
@LightningKeeper Yes?
Suraj
@suraj-davariya
Jan 24 2017 02:34
@LightningKeeper
var a="Light";
var b=6;

a.isNan(a);
b.isNan(b);
`a.isNaN(a); //Sorry this one is true
Vizij
@Vizij
Jan 24 2017 02:35
@LightningKeeper If you want the number, it's var a = 6;. For the string "6", it'd be var a = "6";
Suraj
@suraj-davariya
Jan 24 2017 02:35
a.isNaN(b);
Vizij
@Vizij
Jan 24 2017 02:35
If that's what you mean when you mention NaN
Randy
@rsmorin2
Jan 24 2017 02:35

If someone could, please explain what it is that I am doing wrong in the below question.

https://www.freecodecamp.com/challenges/escape-sequences-in-strings#?solution=%0Avar%20myStr%3B%20(%22FirstLine%5CnSecondLine%5CrThirdLine%22)%0A%0A

Below is the code that I used to try to solve this. I don't understand what I am required to do when I am putting in an escape sequence into the sting, or what it actually does. I have come this far with very little help, but this concept has me stuck and it's pretty frustrating!

var myStr; ("FirstLine\nSecondLine\rThirdLine")

John Nunns
@johnnunns
Jan 24 2017 02:35
hey guys, was wanting to revisit a problem I was doing a little while ago. Anyone up for the challenge?
Joseph
@revisualize
Jan 24 2017 02:36
@rsmorin2 How do you assign a variable?
Suraj
@suraj-davariya
Jan 24 2017 02:36
yeah. @LightningKeeper
isNaN(value)

value
    The value to be tested.

Return value

true if the given value is NaN; otherwise, false.
Randy
@rsmorin2
Jan 24 2017 02:36
how do I enter the escape sequence into assignment
Suraj
@suraj-davariya
Jan 24 2017 02:37
@rsmorin2 use return
@johnnunns what challenge ?
Randy
@rsmorin2
Jan 24 2017 02:38
@revisualize How do I enter the escape sequence into the assignment? and what is the format for this? I have tried multiple combinations and don't understand what their function is.
John Nunns
@johnnunns
Jan 24 2017 02:39
@suraj-davariya ok so first things first I just completed a similar exercise I'll show you the code for. It's to produce the sum of all vowels in a string:
function getCount(str) {
var sum=0
var i = str.split('');
for(var x=0; x<i.length; x++){
if (i[x] === 'a' || i[x] === 'e' || i[x] === 'i' || i[x] === 'o' || i[x] === 'u'){
sum ++;
};

};

return sum;

}
Joseph
@revisualize
Jan 24 2017 02:39
@rsmorin2 Step 1. How do you assign a variable?
John Nunns
@johnnunns
Jan 24 2017 02:40
so this works, it could be made simpler, but it works

I don't know the higher level functions. With this in mind though, the next challenge is this:
```
Instructions from your teacher:
Write a function called "countAllCharacters".

Given a string, "countAllCharacters" returns an object where each key is a character in the given string. The value of each key should be how many times each character appeared in the given string.

Notes:

  • If given an empty string, countAllCharacters should return an empty object.

var output = countAllCharacters('banana');
console.log(output); // --> {b: 1, a: 3, n: 2}

Starter Code :
function countAllCharacters(str) {
// your code here
}
``

Instructions from your teacher:
Write a function called "countAllCharacters".

Given a string, "countAllCharacters" returns an object where each key is a character in the given string. The value of each key should be how many times each character appeared in the given string.

Notes:
* If given an empty string, countAllCharacters should return an empty object.

var output = countAllCharacters('banana');
console.log(output); // --> {b: 1, a: 3, n: 2}

Starter Code :
function countAllCharacters(str) {
  // your code here
}
Suraj
@suraj-davariya
Jan 24 2017 02:41
@rsmorin2
var myStr="FirstLine\n\\SecondLine\\\rThirdLine";
Joseph
@revisualize
Jan 24 2017 02:42
@suraj-davariya Instead of just giving away and answer. Can you explain why that is the answer?
paiztee
@paiztee
Jan 24 2017 02:42
wtf-howyoudoingtoday.png whats up with the, how you doing today, returned in the console??? I have no idea why it would log that.
Suraj
@suraj-davariya
Jan 24 2017 02:42
@revisualize i am searching the question buddy.
i'm sorry
paiztee
@paiztee
Jan 24 2017 02:43
well logged not returned i guess...
LightningKeeper
@LightningKeeper
Jan 24 2017 02:44
So it says to "Initialize the three variables a, b, And c, with 5, 10, and "I am a" respectively so that they will not be unidentified." How do I do that?
John Nunns
@johnnunns
Jan 24 2017 02:44
I'm not sure if the prior problem solution can be used in any way towards this one, but I do need help @suraj-davariya
hibaakel
@hibaakel
Jan 24 2017 02:44
how can check if varible is num or string inside the function ?
Joseph
@revisualize
Jan 24 2017 02:45
@hibaakel What?
LightningKeeper
@LightningKeeper
Jan 24 2017 02:45
A should be defined and have a value of 6. That's what I am supposed to do.
Joseph
@revisualize
Jan 24 2017 02:45
Come on people. The ability around here to ASK questions is getting lower and lower. Please ask better questions. Phrase your question.
paiztee
@paiztee
Jan 24 2017 02:46
i was hoping my question was pretty straight forward.
Suraj
@suraj-davariya
Jan 24 2017 02:46
/* Given a string, "countAllCharacters" returns an object where each key is a 
character in the given string. The value of each key should be how many times 
each character appeared in the given string. */

function countAllCharacters(str) {
  // your code here
    var array = str.split("")
  var object = {};

  if(str.length === 0) return object;
  else{
  for(var i = 0; i < array.length; i++){
    if(object[array[i]]) object[array[i]]++;
    else object[array[i]] = 1;
  }
  return object;
  }

}

var output = countAllCharacters('banana');
console.log(output); // --> {b: 1, a: 3, n: 2}
@johnnunns this one right
Joseph
@revisualize
Jan 24 2017 02:47
Look, I know that people have English as a second language. That's fine. But, you need to add context and phrasing to your question.
John Nunns
@johnnunns
Jan 24 2017 02:47
haha suraj did you just give me the answer man? :) @suraj-davariya
I'm trying to learn here bro!
Joseph
@revisualize
Jan 24 2017 02:48
Okay. I'm irritated now.
People giving away answers is NOT helping anyone learn.
I'm leaving.
good luck.
mhirt34
@mhirt34
Jan 24 2017 02:48

Anyone able to help me with the "Return Largest Numbers in Arrays" challenge? Currently I have this:

function largestOfFour(arr) {
  var largest = [0,0,0,0];
  for (var I = 0; I < arr.lenght; I++){
    for (var s = 0; s < arr[I].length; s++){
      if (arr[I][s] > largest[I]){
        largest[I] = arr[I][s];
      }
    }
  }
  // You can do this!
  return largest;
}

largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]);

I'm not sure where I messed up on my syntax however largest keeps returning as: [0,0,0,0].

Any suggestions?

CamperBot
@camperbot
Jan 24 2017 02:48
:bulb: to format code use backticks! ``` more info
John Nunns
@johnnunns
Jan 24 2017 02:48
@revisualize hey stay on
Randy
@rsmorin2
Jan 24 2017 02:48
@revisualize , I was looking it up. and going through the process of assigning a variable again, and I know that we first need to make sure that we define it as a variable, then we need to choose what we are going to call it. Then re-read the part about having to escape a variable before we can use an escape sequence
Suraj
@suraj-davariya
Jan 24 2017 02:48
Ops :( Sorry @johnnunns my bad .. :(
John Nunns
@johnnunns
Jan 24 2017 02:49
I didn't read his solution, let's work on it then @revisualize
Ken Haduch
@khaduch
Jan 24 2017 02:49
@johnnunns @suraj-davariya - delete it! :)
John Nunns
@johnnunns
Jan 24 2017 02:49
@suraj-davariya no worries brotha thanks for the effort! I can easily just not read it haha @suraj-davariya @suraj-davariya
CamperBot
@camperbot
Jan 24 2017 02:49
johnnunns sends brownie points to @suraj-davariya :sparkles: :thumbsup: :sparkles:
:cookie: 282 | @suraj-davariya |http://www.freecodecamp.com/suraj-davariya
Vizij
@Vizij
Jan 24 2017 02:49
@LightningKeeper Okay, if you're going for the value as a number, it's simply var a = 6;. Always remember var because if you omit that, it auto-declares the variable as global (and this is hugely bad practice and not something you want to do )
Suraj
@suraj-davariya
Jan 24 2017 02:49
@revisualize Hey joseph How can i help you budyy ?
Joseph
@revisualize
Jan 24 2017 02:50
@suraj-davariya You can't.
Suraj
@suraj-davariya
Jan 24 2017 02:50
To assign a value to a variable @revisualize you need to learn the first lesson.
suppose that the variable is an empty box. You can have different things into that box
Joseph
@revisualize
Jan 24 2017 02:51
@suraj-davariya What?
Suraj
@suraj-davariya
Jan 24 2017 02:51
like var box = "apple";
Joseph
@revisualize
Jan 24 2017 02:51
Do you realize I am not asking for help?
I sit in here and OFFER help.
Suraj
@suraj-davariya
Jan 24 2017 02:51
so this is how you can assign the value apple to the variable box .
Joseph
@revisualize
Jan 24 2017 02:51
I ask people questions to HELP them.
Suraj
@suraj-davariya
Jan 24 2017 02:51
i hope it help you
Joseph
@revisualize
Jan 24 2017 02:52
about @revisualize
CamperBot
@camperbot
Jan 24 2017 02:52
:star2: 3084 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jan 24 2017 02:52
@suraj-davariya I didn't need your help.
But thanks?
Suraj
@suraj-davariya
Jan 24 2017 02:53
@rsmorin2 How do you assign a variable?
i thought you asked this to someone
@revisualize my bad buddy :(
Daniel
@danielbyun
Jan 24 2017 02:54
AHHH BASIC ALGORITHMSSSSSS
Coding Machine
@EphremL
Jan 24 2017 02:55
Hello, I am recruiting people to work a project with the skills of HTML and CSS also Javascript. If you think your the right canidate, join : https://gitter.im/Project-Awesome-1/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link
Ken Haduch
@khaduch
Jan 24 2017 02:55
@danielbyun - is that a good "AHHH BASIC ALGORITHMSSSSSS" or a bad "AHHH BASIC ALGORITHMSSSSSS" ???
Suraj
@suraj-davariya
Jan 24 2017 02:55
i got you , i must not give him the answer but the hint
Daniel
@danielbyun
Jan 24 2017 02:55
can I give it a ‘terrible’? haha
LightningKeeper
@LightningKeeper
Jan 24 2017 02:57
I am so annoyed with this right now, what do I have to do to define a variable??
Or, "initialize.
hibaakel
@hibaakel
Jan 24 2017 02:57
@mhirt34 your mistake its you spell length in wrong way
mhirt34
@mhirt34
Jan 24 2017 02:58
Bleeeeeehhhhhh @hibaakel thank you so much.
hibaakel
@hibaakel
Jan 24 2017 02:58

function largestOfFour(arr) {
var largest = [0,0,0,0];
for (var I = 0; I < arr.length; I++){
for (var s = 0; s < arr[I].length; s++){
if (arr[I][s] > largest[I]){
largest[I] = arr[I][s];
console.log(largest[I]);
}
}
}
// You can do this!
return largest;
}

largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]);

CamperBot
@camperbot
Jan 24 2017 02:58
mhirt34 sends brownie points to @hibaakel :sparkles: :thumbsup: :sparkles:
:cookie: 68 | @hibaakel |http://www.freecodecamp.com/hibaakel
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 02:59
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(contacts[i].firstName === firstName){
if(contacts[i].prop != NULL){
return contacts[i].prop;
}
else
return "No such property";
}
else
return "No such contact";
}
// Only change code above this line
}
Daniel
@danielbyun
Jan 24 2017 03:00
@LightningKeeper if Im correct with what you’re asking for, the keyword is ‘var’
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 03:01
What is my error?
Suraj
@suraj-davariya
Jan 24 2017 03:01
@rsmorin2 still here ?
Joseph
@revisualize
Jan 24 2017 03:01
@warcraft034 Okay.
@warcraft034 You have a few issues.
@warcraft034 Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
Dan Sutton
@danthecardman
Jan 24 2017 03:01
how do you send brownie points?
Vizij
@Vizij
Jan 24 2017 03:02

@LightningKeeper
This is define:
var a;
This is initialize:
var a = 6;

The only difference is that initializing is giving the variable an initial value.

Randy
@rsmorin2
Jan 24 2017 03:02
@suraj-davariya , yes, and I reviewed the last few questions to get it. thank you though!
CamperBot
@camperbot
Jan 24 2017 03:02
:cookie: 283 | @suraj-davariya |http://www.freecodecamp.com/suraj-davariya
rsmorin2 sends brownie points to @suraj-davariya :sparkles: :thumbsup: :sparkles:
Joseph
@revisualize
Jan 24 2017 03:02
@warcraft034 Doing contacts[i].prop != NULL isn't correct.
Dan Sutton
@danthecardman
Jan 24 2017 03:03
I need to send brownie points to member fuqted who helped me solve a problem I was having yesterday
Suraj
@suraj-davariya
Jan 24 2017 03:03
please go through this lesson again. hasOwnProperty() @warcraft034
Joseph
@revisualize
Jan 24 2017 03:03
@warcraft034 Let me know when you've corrected those two issues.
thanks @me
CamperBot
@camperbot
Jan 24 2017 03:03
revisualize sends brownie points to @me :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for me
Joseph
@revisualize
Jan 24 2017 03:03
@danthecardman That is how you send a brownie point.
Dan Sutton
@danthecardman
Jan 24 2017 03:03
thanks Joseph
Randy
@rsmorin2
Jan 24 2017 03:04
thanks @revisualize
CamperBot
@camperbot
Jan 24 2017 03:04
rsmorin2 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3085 | @revisualize |http://www.freecodecamp.com/revisualize
Suraj
@suraj-davariya
Jan 24 2017 03:04
@rsmorin2 So \ is used for escape sequence.
Dan Sutton
@danthecardman
Jan 24 2017 03:04
send brownie points to @fuqted for his help yesterday
Joseph
@revisualize
Jan 24 2017 03:04
You need to THANK them.
Suraj
@suraj-davariya
Jan 24 2017 03:04
@revisualize thanks for improving the way I am helping people around.
CamperBot
@camperbot
Jan 24 2017 03:04
suraj-davariya sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3086 | @revisualize |http://www.freecodecamp.com/revisualize
Dan Sutton
@danthecardman
Jan 24 2017 03:05
thanks Joseph I will review the documentation
thanks @fugted
CamperBot
@camperbot
Jan 24 2017 03:06
danthecardman sends brownie points to @fuqted :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for fuqted
Joseph
@revisualize
Jan 24 2017 03:15
la la la
Dan Sutton
@danthecardman
Jan 24 2017 03:15
thanks @revisualize
CamperBot
@camperbot
Jan 24 2017 03:15
:star2: 3087 | @revisualize |http://www.freecodecamp.com/revisualize
danthecardman sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
msg-coder
@msg-coder
Jan 24 2017 03:17
Hi, i m working on local weather app. And i m facing CORS error.if i m using $.getJSON (url,xyz (),'jsonp') it shows syntax error..i don't know open weather map support jsonp or not. By default it return json or ( it support html,xml format).
Stephen James
@sjames1958gm
Jan 24 2017 03:21
@msg-coder I am not using jsonp with openweathermap and not getting CORS - do you have a link to your pen?
Edgar Pan
@edgaryp
Jan 24 2017 03:24
anybody familiar with .ajax()?
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 03:26
What I don't understand is the property in objects, sometimes it has a quotes, sometimes it not
I'm very confused
value, variable, ....
Margaret
@Margaret2
Jan 24 2017 03:27
@warcraft034 only strings have quotes, so the reason a property would have quotes is because it's a string
msg-coder
@msg-coder
Jan 24 2017 03:32
@sjames1958gm i m working offline. N i m outside.thanx for rply
@sjames1958gm you know how to solve cross domain error?
Stephen James
@sjames1958gm
Jan 24 2017 03:36
@msg-coder Normally the api has jsonp - but for this one I didn't so I am not sure.
msg-coder
@msg-coder
Jan 24 2017 03:38
@sjames1958gm how we know api return jsonp or not? Any idea.
Trakra
@trgme
Jan 24 2017 03:38
function functionWithArgs(a, b) {
  console.log(a + b);
}
functionWithArgs(7, 9);
Stephen James
@sjames1958gm
Jan 24 2017 03:38
@msg-coder Generally the API docs will say.
Trakra
@trgme
Jan 24 2017 03:38
Confused.. the challenge Passing Values to Functions with Arguments passes, but I don't know why since 2nd challenge isn't met.
Margaret
@Margaret2
Jan 24 2017 03:39
@trgme what do you mean
Trakra
@trgme
Jan 24 2017 03:39
1 - ''functionWithArgs(1,2) should output 3 ''
2 - functionWithArgs(7,9) should output 16
Margaret
@Margaret2
Jan 24 2017 03:39
@trgme and what does it output instead
Trakra
@trgme
Jan 24 2017 03:39
so, 2 outputs 16 but 1 doesn't out 3.
make sense?
1 doesn't output anything. But it passes?
Margaret
@Margaret2
Jan 24 2017 03:40
@trgme oh lol, the box probably just shows the last test to run
you could probably look in your browser console and see the output for the first test
Stephen James
@sjames1958gm
Jan 24 2017 03:40
@trgme The box shows the output of the first one.
Trakra
@trgme
Jan 24 2017 03:41
ok, well Hasta la vista, challenge!
thx
@Margaret2 actually, great idea.. thx. want to see what happens.
CamperBot
@camperbot
Jan 24 2017 03:41
trgme sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1346 | @margaret2 |http://www.freecodecamp.com/margaret2
msg-coder
@msg-coder
Jan 24 2017 03:43
@sjames1958gm i can try tomm. Once again thanx
CamperBot
@camperbot
Jan 24 2017 03:43
msg-coder sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5502 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jan 24 2017 03:44
@msg-coder good luck
Brian
@BrianCodes33
Jan 24 2017 03:48
did anyone else notice the bug with gitter
noobcodester
@noobcodester
Jan 24 2017 04:00

Can anyone help me with this one:

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

function trueOrFalse(wasThatTrue) {
if (wasThatTrue) {
return "Yes, that was true";
}
return "No, that was false";
}

// Only change code above this line.

}

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

Pramod Potdar
@ppmakeitcount
Jan 24 2017 04:00

function updateResto(req, res, next) {
    for (var i = 0; i < req.session.restos.length; i++) {
        console.log("i = " + i);
        Resto.findOne({
            'resto_id': req.session.restos[i].resto_id
        }, function(err, doc) {
            console.log("req.session.restos[i]" + req.session.restos[i])
            if (err) console.log(err);
            if (doc) {
                console.log(doc);
            }
        })
    }
    return next();
}


app.get('/', updateResto, function(req, res) {
    console.log("searchterm" + req.session.restos)
    console.log("login" + res.locals.login)

    res.render('index', {
        restos: req.session.restos,
        searchterm: req.session.search,
        user: req.user
    })
    console.log("page rendered");
})

This is my code. Let me show you console output.

i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
searchterm[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
logintrue
page rendered
req.session.restos[i]undefined
{ _id: 588562afe7a74051695a62c4,
  totalGoing: 1,
  resto_id: '11213',
  __v: 2,
  customers: [ 587f723524e6670aa1fe71e7 ] }
req.session.restos[i]undefined
req.session.restos[i]undefined
{ _id: 5885666f8ce7345628ca26ce,
  totalGoing: 1,
  resto_id: '12036',
  __v: 2,
  customers: [ 587f723524e6670aa1fe71e7 ] }
req.session.restos[i]undefined
req.session.restos[i]undefined
req.session.restos[i]undefined
req.session.restos[i]undefined
req.session.restos[i]undefined
req.session.restos[i]undefined

How come for loop output is executed at once? i am totally confused.

My page is rendered before my validation happens.
Zachary Orona-Calvert
@TheTRUEHoohah
Jan 24 2017 04:01

// Setup
var a;
var b = 2;

// Only change code below this line

a = 7;

Do not change code above the line
a should have a value of 7
b should have a value of 7
a should be assigned to b with =
what do i do
noobcodester
@noobcodester
Jan 24 2017 04:02
Create an if statement inside the function to return "Yes, that was true" if the parameter wasThatTrue is true and return "No, that was false" otherwise.
Joseph
@revisualize
Jan 24 2017 04:02
@TheTRUEHoohah How do you assign the value of 7 to a variable num? ... var num = 7;
Now if you want you can use a variable to store values.
Like in mathmatics. num + 3 = 10 What is the value of num?
var x = num + 3; ... That outputs 10
So, you can do several things with variables. But, you need to understand that variables hold values and variables can be used with other variables.
So, how do you assign the value of 5 to a variable x? ... x = 5; (Which is also overwriting the previous value of 10 from above.
How do you assign the value of x to a variable y?
Look at the way things are written. var y = x;
How do you assign the value of 42 to a variable answer? ... What is the answer?
Variables hold values. Just understand that.
Seb
@WantsToLearnCode
Jan 24 2017 04:08
How do I do this?

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

return item; // Change this line
}

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

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

Joseph
@revisualize
Jan 24 2017 04:08
@WantsToLearnCode Start by breaking the problem down.
Seb
@WantsToLearnCode
Jan 24 2017 04:08
It is telling me "nextInLine([2], 1) should return 2
"
Joseph
@revisualize
Jan 24 2017 04:08
@WantsToLearnCode It should. But, there are other instructions.
Seb
@WantsToLearnCode
Jan 24 2017 04:08
Yeah yeah
"Write a function nextInLine which takes an array (arr) and a number (item) as arguments"
Joseph
@revisualize
Jan 24 2017 04:09
@WantsToLearnCode What are the parameters?
Seb
@WantsToLearnCode
Jan 24 2017 04:09
Not sure tbh
Brahmbha
@Brahmbha
Jan 24 2017 04:09
in the counting cards challenge I'm not sure why I'm not getting the write answer Here is a my code:
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count += 1;
break;
case 7:
case 8:
case 9:
count += 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}
return count + (count > 0 ? " Bet ": " Hold ");
Seb
@WantsToLearnCode
Jan 24 2017 04:09
Nvm
Sean Kelly
@spkellydev
Jan 24 2017 04:10
oy vey, I'm having a tough time with the Caesar's Cipher
Seb
@WantsToLearnCode
Jan 24 2017 04:10
@revisualize I cracked it
Joseph
@revisualize
Jan 24 2017 04:10
@WantsToLearnCode Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).
Seb
@WantsToLearnCode
Jan 24 2017 04:10
Ahh! Thanks!
Sean Kelly
@spkellydev
Jan 24 2017 04:11
Would someone mind PMing with me to help walk me through where I'm going awry with my logic for the Caesar's Cipher? I think I have all the necessary ingredients, I'm just not understanding how to use them
Ken Haduch
@khaduch
Jan 24 2017 04:12
@Brahmbha - I think that it looks pretty good - I would just check the trailing space on your " Bet " and " Hold " - that might be a problem that the test code will not pass with those?
Teshawn Black
@teshawn
Jan 24 2017 04:13

var myVar = 87;

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

someone help
please
Ken Haduch
@khaduch
Jan 24 2017 04:13
@Brahmbha - because they explicitly show the example outputs as "-3 Hold" and "5 Bet" with no trailing spaces.
Teshawn Black
@teshawn
Jan 24 2017 04:13
myVar = myVar should be changed

var myVar = 87;

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

Joseph
@revisualize
Jan 24 2017 04:14

@teshawn

var num = 5;
num = num + 1; // 6
num += 1; // 7
num++; // 8

See how the one for getting num from 7 to 8 doesn't use the assignment operator (=)?

Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 04:14
yeah, the "return" need to be outside of for loop, so sad
vernon
@vernonkjr
Jan 24 2017 04:14
@spkellydev let's give it a try. what do you have so far
Lợi Nguyễn Văn
@warcraft034
Jan 24 2017 04:15
thank you @revisualize
CamperBot
@camperbot
Jan 24 2017 04:15
warcraft034 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3089 | @revisualize |http://www.freecodecamp.com/revisualize
vernon
@vernonkjr
Jan 24 2017 04:15
@spkellydev no problem
Sean Kelly
@spkellydev
Jan 24 2017 04:16
@vernonkjr I pm'd you, but I'm thinking you've seen that now that I see your response. I appreciate the help
Ken Haduch
@khaduch
Jan 24 2017 04:16
@teshawn - if you are using one of the increment operators, ++ either before or following the variable, you do not assign the value to the variable, just use the variable name alone with the operator, like myVar++ or ++myVar, whichever form of that operator and variable you are supposed to use. Assigning it to the same variable is rarely (if ever) the right thing to do.
Teshawn Black
@teshawn
Jan 24 2017 04:16
@revisualize Can you explain that again?
Joseph
@revisualize
Jan 24 2017 04:17
@teshawn Can you just re-read it?
Teshawn Black
@teshawn
Jan 24 2017 04:18
I had to refresh the page sorry about that thank you @revisualize @khaduch
CamperBot
@camperbot
Jan 24 2017 04:18
teshawn sends brownie points to @revisualize and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3090 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 2345 | @khaduch |http://www.freecodecamp.com/khaduch
Manish Giri
@Manish-Giri
Jan 24 2017 04:30
need some help.
If I've got two arrays - [5, 5] and [2, 3, 5], I need to remove all occurrences of the common numbers from both arrays and return the result array.
actually, just return the result array which has the common elements removed, doesn't really matter modifying the original arrays.
I've tried, .indexOf(), .includes(), etc.
ideas?
Dany
@Danylrs
Jan 24 2017 04:34
Hey does everones work reflect on thier github, im not seeing that on my end. Can anyone shed some light or help me fix this issue
Alexander Huynh
@caesarsalad93
Jan 24 2017 04:35
What is the difference between these two function calls?
function sliceArray(arr) {
  var x = Array.prototype.slice.call(arr);
  var y = arr.slice();
  console.log(x, y);
}
sliceArray([1,2,3]);
Why so I see so many people do x instead of y?
Ken Haduch
@khaduch
Jan 24 2017 04:35

@grantknaver - I was able to spend a little more time on this. It looks like you have some way to go to get this working, maybe you're on a good track, but I made a couple code changes to get a little bit of something going. First of all, as per my previous comment, after I saw the completion of the calculations through the changeDo variable, I reversed the moneyTypes and howManyDenominations arrays to put the higher amounts first in the arrays to prepare for the subsequent calculations.

Also, after your definition of the function with your var testFunction = function() { // stuff here }, I added a call of testFunction() to invoke the function. The last thing that I did was within the function, I changed the inner for loop control to be b <= howManyDenomations[a]; because if you only have 1 of a particular denomination, you would never process it.

So what that gets me (you) at this point is that it will pop up some alert boxes with calculations. But you have to deduct the amount from the changeDo and watch for overruns, etc.

@Danylrs - no, the work doesn't reflect on the github at all, by default. You can to and add code, the CodePen allows you to save gists, etc. At least that is my understanding of it.
arvin
@avllrl
Jan 24 2017 04:37
var myList = [["Xonrox", 65], ["Ground Pork", 250], ["Fita", 68], ["Cheez Whiz", 73], "Tacos", 45];
whats the problem here
Reggie
@Reggie01
Jan 24 2017 04:37
@Manish-Giri Create a new array. Loop through arrays. Push unique numbers to array after checking if number unique.
arvin
@avllrl
Jan 24 2017 04:37
Shopping List
Dany
@Danylrs
Jan 24 2017 04:38
gotcha, that sucks! lol I had school that wanted to see my github and to my surprise there wasnt any work at all saved so it was kind of a bummer and a bit embarrassing lol. I had to log into my FCC so prove myself. thank you @khaduch
CamperBot
@camperbot
Jan 24 2017 04:38
danylrs sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2346 | @khaduch |http://www.freecodecamp.com/khaduch
Zachary Orona-Calvert
@TheTRUEHoohah
Jan 24 2017 04:38
studlyCapVar is defined and has a value of 10
properCamelCase is defined and has a value of "A String"
titleCaseOver is defined and has a value of 9000
studlyCapVar should use camelCase in both declaration and assignment sections.
properCamelCase should use camelCase in both declaration and assignment sections.
titleCaseOver should use camelCase in both declaration and assignment sections.

// Declarations
var StUdLyCapVaR;
var properCamelCase;
var TitleCaseOver;

// Assignments
STUDLYCAPVAR = 10;
PRoperCAmelCAse = "A String";
tITLEcASEoVER = 9000;

studylCapVar = 10;
properCamelCase = "A String";
titleCaseOver = 9000;

whats wrong
Ken Haduch
@khaduch
Jan 24 2017 04:39
@grantknaver - I saved a fork of your code with my modifications here - there are a couple "debugger;" statements in there maybe I'll comment those out and save it again so it doesn't confuse the issue if you take a look at it... I hope that helps a little?
Manish Giri
@Manish-Giri
Jan 24 2017 04:39
@TheTRUEHoohah your variables are not following camelCase notation
Zachary Orona-Calvert
@TheTRUEHoohah
Jan 24 2017 04:39
@Manish-Giri how do i do that
Manish Giri
@Manish-Giri
Jan 24 2017 04:39
first letter of first word lowercase, then first letter of subsequent words capitalized
@TheTRUEHoohah
like - theTrueHoohah is camelCase
Clara Mae Wells
@run-cmw
Jan 24 2017 04:41
Hi, I have a question about the Basic Algorithm Challenge Factorialize a Number. Although the arguments are returning the correct values, the site isn't recognizing them as passing.
Ken Haduch
@khaduch
Jan 24 2017 04:41
@run-cmw - check to make sure that you don't have a global variable to capture your results... that can mess up the tests because it will accumulate results in between test runs, if you are getting the correct answers... or share your code and people can have a look at it to help.
Clara Mae Wells
@run-cmw
Jan 24 2017 04:43
@khaduch Thanks. I do have a global variable that's returned.
CamperBot
@camperbot
Jan 24 2017 04:43
run-cmw sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2347 | @khaduch |http://www.freecodecamp.com/khaduch
Sean Kelly
@spkellydev
Jan 24 2017 04:44
@vernonkjr thanks so much for the help!
CamperBot
@camperbot
Jan 24 2017 04:44
spkellydev sends brownie points to @vernonkjr :sparkles: :thumbsup: :sparkles:
:cookie: 253 | @vernonkjr |http://www.freecodecamp.com/vernonkjr
Clara Mae Wells
@run-cmw
Jan 24 2017 04:44
var array = [];
var multiply = 1;

function factorialize(num) {
  for (var n = 1; n < num + 1; n++) {
    array.push(n);

  multiply = array.reduce(function(a, b) {
    return a * b;
    });
  } 
  return multiply;
}

factorialize(5);
MarkBales96
@MarkBales96
Jan 24 2017 04:47
Hey, I'm stuck on Make Object Properties Private. I can't seem to figure out what I'm suppose to do, and the instructions aren't making very much sense to me.
var myBike = new Bike();
//private
var gear = ();
//public
myBike.getGear = function(change)
return ;
myBike.setGear = function()
return;
Faique Moqeet
@fikers
Jan 24 2017 04:48
I'm having a hard time with something that I think should be really simple: I have a form on my HTML page that has a submit button. Once the user submits some text on the form, I want to use that text as input and change some text on the HTML page.
How do I capture the results of a form and use it in my JavaScript?
Naresh
@nareshwar
Jan 24 2017 04:48
Hi.. Im working on this problem -> Find the Longest Word in a String

function findLongestWord(str) {
var SplittedArr = str.split(' ');
var longestWord;
var longestWordLength;
for (i = 1; i < SplittedArr.length; i++) {
if (SplittedArr[i].length > SplittedArr[i - 1].length) {
longestWord = SplittedArr[i].length;
}
}
return longestWord;
}

findLongestWord("Google do a barrel roll");

I wrote something like this
let me post a gist
Ken Haduch
@khaduch
Jan 24 2017 04:50
@run-cmw - since you aren't recursively calling your function, just move those variables inside the function body, before your for loop, and try it again.
Clara Mae Wells
@run-cmw
Jan 24 2017 04:51
@khaduch Makes sense. Thanks again, Ken.
CamperBot
@camperbot
Jan 24 2017 04:51
run-cmw sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: run-cmw already gave khaduch points
Naresh
@nareshwar
Jan 24 2017 04:51
The problem is, in "if (SplittedArr[i].length > SplittedArr[i - 1].length)", it assigns the length to longestWord even the length is lesser
How can I solve?
nihar
@nihar93
Jan 24 2017 04:56

Write a switch statement to set answer for the following ranges:
1-3 - "Low"
4-6 - "Mid"
7-9 - "High"
function sequentialSizes(val) {
var answer = "";
// Only change code below this line

switch(val) {
case 1:
case 2:
case 3:

var v="Low";
break;
case 4:
case 5:
case 6:
v="mid";
break;
case 7:
case 8:
case 9:
v= "High";

}
return v;
result = "4 alone";
}

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

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

can someone help me with that code
Syntax error says return statement outside of function
Ken Haduch
@khaduch
Jan 24 2017 05:02
@nihar93 - it looks like you are closing your function early - you should set your answer in the variable answer, which they have declared and which is being returned to the caller. You are making an additional variable that is unneeded.
Reggie
@Reggie01
Jan 24 2017 05:04
@nareshwar You need to compare your longestWord variable to current index in array.
if (SplittedArr[i].length > SplittedArr[i - 1].length) // compares current index to previous index
if (SplittedArr[i].length > longestWord ) // compare to longestWord found
  1. longestWord will need a default value // this can be first index in array or a really low number
  2. Function needs to return a number not a string.
nihar
@nihar93
Jan 24 2017 05:06
Got it Thank you man @khaduch
CamperBot
@camperbot
Jan 24 2017 05:06
nihar93 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2348 | @khaduch |http://www.freecodecamp.com/khaduch
Brian
@BrianCodes33
Jan 24 2017 05:07
function longest(s1, s2) {
  var arrOne = Array.from(s1).sort();
  var arrTwo = Array.from(s2).sort();
  if (arrOne > arrTwo) {
        return arrOne.join('');
    }
    return arrTwo.join('');
}
—> Expected: 'aehrsty', instead got: ‘aeeeehhrrty’
anyone know how to pop off repeated letters?
Reggie
@Reggie01
Jan 24 2017 05:09
@BrianCodes33 what problem are you working on?
Brian
@BrianCodes33
Jan 24 2017 05:09

Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2.

Examples:

a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"

yemicarter
@yemicarter
Jan 24 2017 05:10
Folks in this javascript "profile lookup" exercise, How do i check if a given property is a property of an object??
Brian
@BrianCodes33
Jan 24 2017 05:10
@yemicarter hasOwnProperty
yemicarter
@yemicarter
Jan 24 2017 05:11
@BrianCodes33 then why is this not working ```function lookUpProfile(firstName) {
for (var i = 0; i < contacts.length; i++) {
if (contacts.hasOwnProperty("firstName")) {
alert(contacts[i].firstName);
}
 }```
Edgar Pan
@edgaryp
Jan 24 2017 05:11
Hi why this loop works for array([1, 10]); //[2, 3, 4, 5, 6, 7, 8, 9] but doesn't work for array([2, 10]); //[]
function array(arr) {

  arr.sort();
  var newArr = [];

  for (var i = arr[0] + 1; i < arr[1]; i++ ) {
    newArr.push(i);
  }
  return newArr;
}

array([2, 10]);
yemicarter
@yemicarter
Jan 24 2017 05:12
function lookUpProfile(firstName) {
for (var i = 0; i < contacts.length; i++) {
if (contacts.hasOwnProperty("firstName")) {
alert(contacts[i].firstName);
}
 }
Ken Haduch
@khaduch
Jan 24 2017 05:14
@yemicarter - without giving you too much info - in one place you are using contacts[i].firstName, and in another place you are using contacts.hasOwnProperty("firstName"). First of all, all of the contacts have a firstName. So you don't even need to check that. And contacts is an array, so contacts[i] is the proper thing to do.
jmaher11
@jmaher11
Jan 24 2017 05:14
var a;
var b=7;
var a=var b;
khaduch @khaduch - going to sleep... :sleepy: :sleeping: :zzz: - have a good time coding, everyone!
jmaher11
@jmaher11
Jan 24 2017 05:14
what am I missing here?
Coy Sanders
@coymeetsworld
Jan 24 2017 05:15
@jmaher11 a and b are already defined, so you dont need to use the var keyword when referring to them anymore
remove them from from your 3rd line
yemicarter
@yemicarter
Jan 24 2017 05:16

@khaduch this is the exercise i am trying to solve ```var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

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

 }

}

// Only change code above this line
}

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

jmaher11
@jmaher11
Jan 24 2017 05:16
@coymeetsworld what would I use to refer to them just a or b?
Naresh
@nareshwar
Jan 24 2017 05:16
Thank you @Reggie01 :)
CamperBot
@camperbot
Jan 24 2017 05:16
nareshwar sends brownie points to @reggie01 :sparkles: :thumbsup: :sparkles:
:cookie: 387 | @reggie01 |http://www.freecodecamp.com/reggie01
Coy Sanders
@coymeetsworld
Jan 24 2017 05:17
yep @jmaher11 just its name
Naresh
@nareshwar
Jan 24 2017 05:17
I updated my code, as per your instructions, works like charm.
Coy Sanders
@coymeetsworld
Jan 24 2017 05:17
var is only needed when you are first creating the variable, not necessary when you're referring to the variable after that
John Nunns
@johnnunns
Jan 24 2017 05:18
function countWords(str) {
    str.split(' ')
    .reduce(function(object, word){
        var regex = new Regexp()
    })
}
MarkBales96
@MarkBales96
Jan 24 2017 05:18

Can someone please explain what's wrong with my code? var myBike = new Bike();

var gear = ();

myBike.getGear();
myBike.setGear();

John Nunns
@johnnunns
Jan 24 2017 05:18
Instructions from your teacher:
Write a function called "countWords".

Given a string, "countWords" returns an object where each key is a word in the given string, with its value being how many times that word appeared in th given  string. 

Notes:
* If given an empty string, it should return an empty object.

var output = countWords('ask a bunch get a bunch'); 
console.log(output); // --> {ask: 1, a: 2, bunch: 2, get: 1}

Starter Code : 
function countWords(str) {
  // your code here
}
anyone want to put me in the right direction here
?
or know the Regexp I'm looking for
MarkBales96
@MarkBales96
Jan 24 2017 05:19
It's on Make Object Properties Private.
yemicarter
@yemicarter
Jan 24 2017 05: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
   for (var i= 0; i < contacts.length; i++ ){
     if () {

     }

   }


// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
lookUpProfile("Akira", "likes");
Ken Haduch
@khaduch
Jan 24 2017 05:20
@yemicarter - I came back because I saw you reposted - I'm going to be going offline, but what I was trying to show you here :point_up: January 24, 2017 12:14 AM is that you need to always refer to an object in the array, the array named contacts using an index value, which you are generating in your for loop. So, anywhere within the for loop, always use contacts[i] never use contacts without an [i].
yemicarter
@yemicarter
Jan 24 2017 05:20
This is what i am trying to solve
Ken Haduch
@khaduch
Jan 24 2017 05:22
@yemicarter - yes - start by making sure that you always use contacts[i] and if you are trying to check for a property contacts[i].hasOwnProperty(prop) or contacts[i].hasOwnProperty('propertyName'); - if you make some changes to your code, post them back here and someone will be able to help, because many people have asked for help with this exercise, so many people here will know how to guide you through. Good luck!
khaduch @khaduch - going offline - happy coding everyone!
John Nunns
@johnnunns
Jan 24 2017 05:23
later @khaduch !
MarkBales96
@MarkBales96
Jan 24 2017 05:23
Can anyone lend me a hand, please?
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:24
@johnnunns no regex needed, just string.split() and some other stuff.
Edgar Pan
@edgaryp
Jan 24 2017 05:24

Hi why this loop works for array([1, 10]); //[2, 3, 4, 5, 6, 7, 8, 9] but doesn't work for array([2, 10]); //[]
```
function array(arr) {

arr.sort();
var newArr = [];

for (var i = arr[0] + 1; i < arr1; i++ ) {
newArr.push(i);
}
return newArr;
}

array([2, 10]);
```

yemicarter
@yemicarter
Jan 24 2017 05:24
@khaduch thank you
CamperBot
@camperbot
Jan 24 2017 05:24
yemicarter sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2349 | @khaduch |http://www.freecodecamp.com/khaduch
Dany
@Danylrs
Jan 24 2017 05:25
can anyone better explain why and when do we use the " +=, -=, *=, /= " im confused in this?
John Nunns
@johnnunns
Jan 24 2017 05:25
@not-a-cylon figured regex because I need if there are words that match they need to be grouped
Dany
@Danylrs
Jan 24 2017 05:25
I can accomplish the assignments in FCC but not sure why or when we have to use them
Reggie
@Reggie01
Jan 24 2017 05:25
@BrianCodes33 So the problem is saying you have to find all unique letters then sort them. One approach is to create a new array. Next, combine both of the strings into an array. Then, loop through the newly combined array. While looping through the array, check if the new array has that value, if not push to the new array.
Loop through combinedArr
  ( Does new array not have combinedArr value at current index )  // hint indexOf
  {
    add value to new array
  }
tptynlr
@tptynlr
Jan 24 2017 05:26

function mutation(arr) {
var z=false;

for(var j=0;j<arr1.toLowerCase().length; j++){

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

       if(arr[1].charAt(j)==arr[0].charAt(i)){
         z=true;
        }


   }

}
if(z===true)
return true;

}

mutation(["voodoo", "no"]);

the code is not working for mutation(["voodoo", "no"]) should return false.
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:26
@Danylrs It's just a shorthand. Easier to do longVariableName += 1 than longVariableName = longVariableName + 1
Edgar Pan
@edgaryp
Jan 24 2017 05:27
@Danylrs 1 ++ is equivalent to 1 plus itself
srikanth1212
@srikanth1212
Jan 24 2017 05:27
I am trying to write code for cards counting pgm could you please give an idea about which loop function I have to use...................TIA
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:28
@johnnunns Why not just check each word against what's already contained in the object?
snowcat
@Snowcat8
Jan 24 2017 05:28
@srikanth1212 Switch function
srikanth1212
@srikanth1212
Jan 24 2017 05:29
thank u @Snowcat8
CamperBot
@camperbot
Jan 24 2017 05:29
srikanth1212 sends brownie points to @snowcat8 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for snowcat8
Edgar Pan
@edgaryp
Jan 24 2017 05:29
anybody please
function array(arr) {

  arr.sort();
  var newArr = [];

  for (var i = arr[0] + 1; i < arr[1]; i++ ) {
    newArr.push(i);
  }
  return newArr;
}

array([2, 10]);
John Nunns
@johnnunns
Jan 24 2017 05:29
@not-a-cylon let me know if i'm not following you. But it needs to be dynamic so it can accomodate different objects
MarkBales96
@MarkBales96
Jan 24 2017 05:30

I'm working on Make Object Properties Private, and I can't seem to get my code to work. It keeps on stating SyntaxError: Unexpected Token ) here's my code
var myBike = new Bike();

var gear = ();

myBike.getGear();
myBike.setGear();

Reggie
@Reggie01
Jan 24 2017 05:30
@edgaryp what is the name of the problem your working on?
Darth Skywalker
@adityaparab
Jan 24 2017 05:32
@edgaryp arr.sort(); won't work as you're expecting it. You need to do
arr.sort(function(a,b){
  return a-b;
});
for sorting to work correctly
MarkBales96
@MarkBales96
Jan 24 2017 05:32
I've tried changing the code multiple times already, and nothing that I put in seems to be working.
Darth Skywalker
@adityaparab
Jan 24 2017 05:34
@MarkBales96 : var gear = (); this is syntactically wrong. Get rid of that line
Edgar Pan
@edgaryp
Jan 24 2017 05:34
@Reggie01 array([1, 10]) //[2, 3, 4, 5, 6, 7, 8, 9] but array([2, 10]) \\[]doesn't work.
Darth Skywalker
@adityaparab
Jan 24 2017 05:35
@edgaryp : Yes. when you sort your array simply like arr.sort() it will give you [10,2] for the input of [2,10]
MarkBales96
@MarkBales96
Jan 24 2017 05:38
@adityaparab, that's the code that needs to be private.
Now try it yourself! Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.
Darth Skywalker
@adityaparab
Jan 24 2017 05:39
@MarkBales96 Show your full code
MarkBales96
@MarkBales96
Jan 24 2017 05:39

var Car = function() {
// this is a private variable
var speed = 10;

// these are public methods
this.accelerate = function(change) {
speed += change;
};

this.decelerate = function() {
speed -= 5;
};

this.getSpeed = function() {
return speed;
};
};

var Bike = function() {

// Only change code below this line.

};

var myCar = new Car();

var myBike = new Bike();

var gear = 0;

this.getGear();
this.setGear();

That's the best I can do.
Darth Skywalker
@adityaparab
Jan 24 2017 05:41
@MarkBales96 var gear = 0; should be inside your myBike constructor
like
var Bike = function() {
  // Only change code below this line.
  var gear = 0;
};
then your getGear and setGear should also be inside Bike constructor function.
Reggie
@Reggie01
Jan 24 2017 05:42
@edgaryp sort is not woking as @adityaparab stated. Look at the code example @adityaparab typed for you. Your sort function needs a compare function passed to it.
Darth Skywalker
@adityaparab
Jan 24 2017 05:42
like
var Bike = function() {

  // Only change code below this line.
  var gear = 0;

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

  this.setGear = function(g){
    gear = g;
  };

};
Edgar Pan
@edgaryp
Jan 24 2017 05:44

@Reggie01

  arr.sort(function (a, b){
    return a - b;
  });

I used this code within the function and works, thanks.

CamperBot
@camperbot
Jan 24 2017 05:44
edgaryp sends brownie points to @reggie01 :sparkles: :thumbsup: :sparkles:
:cookie: 388 | @reggie01 |http://www.freecodecamp.com/reggie01
MarkBales96
@MarkBales96
Jan 24 2017 05:45
@adityaparab Thank you, very much! It worked finally.
CamperBot
@camperbot
Jan 24 2017 05:45
markbales96 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:cookie: 883 | @adityaparab |http://www.freecodecamp.com/adityaparab
Reggie
@Reggie01
Jan 24 2017 05:46
@adityaparab thanks for compare function
CamperBot
@camperbot
Jan 24 2017 05:46
reggie01 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:cookie: 884 | @adityaparab |http://www.freecodecamp.com/adityaparab
Dany
@Danylrs
Jan 24 2017 05:51
gotcha, thank you @not-a-cylon
CamperBot
@camperbot
Jan 24 2017 05:51
danylrs sends brownie points to @not-a-cylon :sparkles: :thumbsup: :sparkles:
:cookie: 329 | @not-a-cylon |http://www.freecodecamp.com/not-a-cylon
SBilaal
@SBilaal
Jan 24 2017 05:51
Hello, how do i compare the string given with alphanumeric characters in the check for palindromes task
Ravilesh
@Ravilesh
Jan 24 2017 05:54
can anyone help me on 141
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:54
@SBilaal take a look at str.replace() and how to do regular expressions. That will help you remove the spaces and special characters.
iootbob
@iootbob
Jan 24 2017 05:54
hello, can anybody help me with the "Factorialize a Number" waypoint?
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:55
@Ravilesh what challenge are you on? The 141 are your brownie points :]
iootbob
@iootbob
Jan 24 2017 05:56
can somebody just hint out what I should do first
Ravilesh
@Ravilesh
Jan 24 2017 05:56
141 is the number i am working on
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:57
@iootbob I used a while loop for that one.
Ctiller93
@Ctiller93
Jan 24 2017 05:57
Eyo folks.
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:58
@Ravilesh What's the name of the challenge?
Ravilesh
@Ravilesh
Jan 24 2017 05:58
@not-a-cylon Convert Celsius to Fahrenheit
h1tag
@h1tag
Jan 24 2017 05:58
How do you create html elements using jquery? I found multiple ways on google, not sure which one is right.
iootbob
@iootbob
Jan 24 2017 05:58
ok, I'll try that
Ctiller93
@Ctiller93
Jan 24 2017 05:58
I'm wondering, is there a way to return multiple conditions without using an if statement?
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:58
@Ravilesh could you post your code?
Ctiller93
@Ctiller93
Jan 24 2017 05:59
For instance, if I wanted to return a, b, c, etc etc etc.
Sergey Lukin
@not-a-cylon
Jan 24 2017 05:59
@Ctiller93 why the aversion to if statements? :]
Ravilesh
@Ravilesh
Jan 24 2017 05:59
@not-a-cylon actually I am not being able to understand...so I have no code for now...
im not able to guess what i am missing
Ctiller93
@Ctiller93
Jan 24 2017 06:00
Because I don't want 7 conditions. :P
Oh, six.
I'm working on falsy bouncer and I have a method that works, but I feel it could be way neater.
Ritvars
@RitvarsZ
Jan 24 2017 06:00
@Ctiller93 use a switch instead?
Ctiller93
@Ctiller93
Jan 24 2017 06:01
I considered using a switch as well but it still ends up just about as messy.
Mike
@MNJCMagic
Jan 24 2017 06:01
Has anybody been through the Heap's Algorithm challenge and is willing to try and help unscramble my brain?
No Repeats Please is the name of the challenge specifically
Ctiller93
@Ctiller93
Jan 24 2017 06:03
See, what I wanted to do would have been something like:
return value !== (false, null, 0, "", undefined, NaN)
Reggie
@Reggie01
Jan 24 2017 06:03
@Ctiller93 try thinking about a way to check for all false statements at once. Or figuring out how to check for true in javascript.
Ctiller93
@Ctiller93
Jan 24 2017 06:03
hmm.
Sergey Lukin
@not-a-cylon
Jan 24 2017 06:05
@Ravilesh It's one of the first times they use a function in the code, so maybe that's your confusion.
Basically they're providing you with variables named celcius and fahrenheit. All you have to do is dig up the equation for C to F conversion and substitute the letters for those.
Ctiller93
@Ctiller93
Jan 24 2017 06:05
Gah, why can't the return statement just let me throw multiple things in it. :(
kicks rock
azariahk7
@azariahk7
Jan 24 2017 06:06
Where am i wrong ? please tell function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i=0 ; i< contacts.length ; i++)
{
if(contacts[i] == firstName )
{
if(contacts[i]==prop){
return prop;
}
else{
return "No such property";
}
}
else
{
return "No such contact";
}
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
Ibanda Frederick
@fredo162
Jan 24 2017 06:07
var myStr = "I am a \"double quoted \"string inside\"double quotes\"."; Hi need some help here with exercise escaping literal quotes
Neha
@nehapevekar
Jan 24 2017 06:08

// Initialize these three variables
var a=6;
var b=15;
var c="I am a String!";

// Do not change code below this line

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

whats wrong in my code...its not running
Ctiller93
@Ctiller93
Jan 24 2017 06:10
oh
Reggie
@Reggie01
Jan 24 2017 06:10
@Ctiller93 did you look at the hint doc?
Ctiller93
@Ctiller93
Jan 24 2017 06:10
That was way easier.
Well yeah, my issue was a little different.
I was using the function but what was killing me was that I couldn't neatly put it in a return statement that just said: "Hey, return this thing that isn't any of these things."
aaaaaaaand then I said "whatever" and just put it in an if statement. Turns out if statements like that sort of stuff and it worked.
azariahk7
@azariahk7
Jan 24 2017 06:11
@nehapevekar try c = "I am Neha";
Ctiller93
@Ctiller93
Jan 24 2017 06:11
So yay! Victory!
Reggie
@Reggie01
Jan 24 2017 06:12
@Ctiller93 :thumbsup: glad you figured it out
Coy Sanders
@coymeetsworld
Jan 24 2017 06:13
@nehapevekar I don't think c should have String in it
you concatenate it later in your code
after your code runs c will equal I am a String! String!
Ogundele Olumide
@Lumexralph
Jan 24 2017 06:19
@azariahk7 you're not comparing the firstName property in contacts[i] with the parameter firstName
Ravilesh
@Ravilesh
Jan 24 2017 06:20
@not-a-cylon Thanks Dude.
CamperBot
@camperbot
Jan 24 2017 06:20
ravilesh sends brownie points to @not-a-cylon :sparkles: :thumbsup: :sparkles:
:cookie: 330 | @not-a-cylon |http://www.freecodecamp.com/not-a-cylon
Ogundele Olumide
@Lumexralph
Jan 24 2017 06:20
@azariahk7 and you're to check if prop is a property of contacts[i] in your second nested if
Coy Sanders
@coymeetsworld
Jan 24 2017 06:20
@nehapevekar a and b need to be initialized to different values also. a should be 6 after a = a + 1 is run. if a is 6 then it will equal 7.
Neha
@nehapevekar
Jan 24 2017 06:20
@coymeetsworld got it..ty
Coy Sanders
@coymeetsworld
Jan 24 2017 06:21
ok np
Arpit
@tipra34
Jan 24 2017 06:22
function bouncer(arr) {
  ar = arr.slice(0);
  ar.filter(function(element){return Boolean(element);});
  return ar;
}

bouncer([7, "ate", "", false, 9]);
cant seem to get this to work filter statement working outside the function but not inside it
Ogundele Olumide
@Lumexralph
Jan 24 2017 06:22
@azariahk7 using hasOwnProperty and you return the value of prop in the contacts[i] by doing contacts[i] [prop] if it's true and lastly return no such contact when your loop is done looking through contacts
@tipra34 store the ar you filtered, a new array is returned or you just return it
Long Vu
@longorjames
Jan 24 2017 06:25
Stuck on this Using Objects for Lookups

function phoneticLookup(val) {
var result = "";

// Only change code below this line
result = {
"alpha": "Adams",

 "bravo": "Boston",

"charlie": "Chicago",

"delta": "Denver",

"echo": "Easy",

"foxtrot": "Frank",

};

Ogundele Olumide
@Lumexralph
Jan 24 2017 06:26
@longorjames is result the name of the object from FCC or lookup?
Arpit
@tipra34
Jan 24 2017 06:26
@Lumexralph thankyou.. I thought filter modifies the current array.
CamperBot
@camperbot
Jan 24 2017 06:26
tipra34 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 835 | @lumexralph |http://www.freecodecamp.com/lumexralph
Long Vu
@longorjames
Jan 24 2017 06:26
I'm not quite sure
but i'm not supposed to change it
Shane
@ShanePlus
Jan 24 2017 06:27
myStr should have encoded text with the proper escape sequences and no spacing.
var myStr="FirstLine\n \SecondLine\ \rThirdLine";
Long Vu
@longorjames
Jan 24 2017 06:27
i think it's the object
Ogundele Olumide
@Lumexralph
Jan 24 2017 06:29
@longorjames check
Long Vu
@longorjames
Jan 24 2017 06:30
?
I am uncertain
Ogundele Olumide
@Lumexralph
Jan 24 2017 06:30
@ShanePlus isnthe backslash before and after SecondLine?
@longorjames check it again on FCC
Long Vu
@longorjames
Jan 24 2017 06:31
@Lumexralph I am uncertain how to check or know if it is a object or a lookup
I am going off of the example given

var alpha = {
1:"Z",
2:"Y",
3:"X",
4:"W",
...
24:"C",
25:"B",
26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"

var value = 2;
alpha[value]; // "Y"

ykarslioglu
@ykarslioglu
Jan 24 2017 06:32
Hi there..
Shane
@ShanePlus
Jan 24 2017 06:32
@Lumexralph Yeah, so var myStr="FirstLine\n \SecondLine\ \rThirdLine"; isnt working though
even though i have double backslash before and after 'SecondLine'
Munkhmanlai
@munkhmanlai
Jan 24 2017 06:33
var a=7;
var b = a;
Do not change code above the line
a should have a value of 7
b should have a value of 7
a should be assigned to b with =
anyone?
Long Vu
@longorjames
Jan 24 2017 06:34
@munkhmanlai nothing seems wrong with that
@munkhmanlai none of the things are checkmarked?
Munkhmanlai
@munkhmanlai
Jan 24 2017 06:34
only the first one
Shane
@ShanePlus
Jan 24 2017 06:35
if a=7 and b=a then b=7
L. Tate
@l3v1tat3
Jan 24 2017 06:35
I am also on the same problem as @longorjames My code is over at: https://codepen.io/l3v1tat3/pen/bgRKGX
I thought I was doing the look up table correctly, but apparently not.
Munkhmanlai
@munkhmanlai
Jan 24 2017 06:35
var a=7;
var b = a;
it is correct right?
Long Vu
@longorjames
Jan 24 2017 06:35
yeah
if a is already declared
b should then be declared by a
and since a = 7, so should b
BRlau
@BRlau
Jan 24 2017 06:36
hi how should i solve the word blank excerise
everplay17
@everplay17
Jan 24 2017 06:36
Hey. I have a problem on the primes exercise if someone can help. In console the tests work but on FCC the third test isn't working.
L. Tate
@l3v1tat3
Jan 24 2017 06:36
I've tried the lookup table with and without setting result = "whatever". To no avail.
everplay17
@everplay17
Jan 24 2017 06:37
Am I allowed to post code for the algorithms challenges here?
BRlau
@BRlau
Jan 24 2017 06:37

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

// Your code above this line
return result;
}

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

i am stuck here T.T
everplay17
@everplay17
Jan 24 2017 06:38
@BRlau add random stuff between all of the args
Markus Kiili
@Masd925
Jan 24 2017 06:38
@BRlau Use function parameters myNoun, myAdjective, myVerb, myAdverb that hold the passed words. Concat those parameters and some spaces and perhaps some in between words to make a long sentence.
everplay17
@everplay17
Jan 24 2017 06:38
concatenate "stuff here" + myNoun + " more stuff" blah blah blah

function sumPrimes(num) {
var sum = 0;

for (var i = 2; i <= num; i++) {
var matches = 0;

for (var j = 2; j <= i; j++) {
  if (i % j === 0) {
    matches++;
  }
}

if (matches == 1) {
  sum += i;
}

}

return sum;
}

sumPrimes(10);

sumPrimes(977) should return 73156.
in console, it returns 73156.
but when i run tests it's showing that test did not work.
Shane
@ShanePlus
Jan 24 2017 06:39

Assign the following three lines of text into the single variable myStr using escape sequences.

FirstLine
\SecondLine\
ThirdLine

var myStr= "FirstLine\n \SecondLine\ \rThirdLine";
Is that not correct?
BRlau
@BRlau
Jan 24 2017 06:39
thanks
:D
Markus Kiili
@Masd925
Jan 24 2017 06:40
@everplay17 Slow enough algorithm might not pass. Your algorithm seems to be brute force.
everplay17
@everplay17
Jan 24 2017 06:40
@ShanePlus you need \
ugh filter
you need two \s for one \
Shane
@ShanePlus
Jan 24 2017 06:40
Yes I have that
everplay17
@everplay17
Jan 24 2017 06:40
thanks @Masd925 i'll think of a better way
CamperBot
@camperbot
Jan 24 2017 06:40