These are chat archives for FreeCodeCamp/HelpJavaScript

12th
Mar 2017
Joseph
@revisualize
Mar 12 2017 00:00
@HeebieGeeBee It's one of the well known coding bootcamps.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:00
@revisualize just an online one?
Gulsvi
@gulsvi
Mar 12 2017 00:00
@GrannyCamper Function arguments are separated by commas
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:01
@SkyCoder01 Im still lost, I put a comma and it didnt function
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:01
@revisualize you said you were doing some prep or summin earlier does that mean youre gong to be goingto a live bootcamp?
Joseph
@revisualize
Mar 12 2017 00:02
@HeebieGeeBee Ha ha .. No. I'm not paying for this shit.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:02
@revisualize was gonna say
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:02
functionWithArgs(7, 9);
its still not functioning
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:02
@GrannyCamper do you understand what it means by arguments?
Gulsvi
@gulsvi
Mar 12 2017 00:03

@GrannyCamper What happens when you run this function?

function functionWithArgs(a, b){

console.log(1 + 2);
}

??

Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:03
So far I thought so for arguments are a b
Gulsvi
@gulsvi
Mar 12 2017 00:03
You will get 3 no matter what pass you into that function

console.log(1 + 2);
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:04
yep Im clear there Sky
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:04
@GrannyCamper those are the parameters of the function
Gulsvi
@gulsvi
Mar 12 2017 00:04
So now, you need to substitute a and b for the values you want to add
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:04
Should I create a new argument or what
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:04
the arguments are what you pass into he function when you call the function
Gulsvi
@gulsvi
Mar 12 2017 00:05
@HeebieGeeBee Go ahead and help with this one. Seems like you're on it...
Can get confusing when multiple people all trying to help at once
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:05
sorry i didnt mean to interfere i just wanted to know that she understood what the arguments were
Gulsvi
@gulsvi
Mar 12 2017 00:05
No need to apologize
We all want to help :)
Joseph
@revisualize
Mar 12 2017 00:06
I think I'm going to watch some youtube.
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:07
and now I passed the argument which I assume is (a + b)
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:09
if we take this example....
function example(param1) {    // this is  a function written with one parameter called param1
console.log(param1);         // all this function will do is console log param1 to the console
}
but this function does nothing until its called and we do that by....
example("hello");  // this is calling the function with an argument of "hello" so that means the function example will run and "hello" will get logged to he console
@GrannyCamper
so in the challenge its asking you to write the function that has two parameters a and b, and its wants you to output their sum
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:11
@HeebieGeeBee Hey bro!
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:11
@Lumexralph yo
@GrannyCamper so that when that function is called with two agruments such as 9 and 7 the function will take those to arguments add them together and output the result
@Lumexralph hows it going?
@GrannyCamper does that make sense?
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:13
Im all ears
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:13
@GrannyCamper so how would you write such a function?
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:13
what doesnt make sense to me is that I called those arguments and yet I get an error
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:14
@GrannyCamper what does your code look like?
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:15
@HeebieGeeBee very well, thanks... just woke up, you?
CamperBot
@camperbot
Mar 12 2017 00:15
lumexralph sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1022 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:15
function example(param1, param2){console.log(1+2) Wait a sec I send you the code
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:15
@Lumexralph just woke?
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:15

// Example
function ourFunctionWithArgs(a, b) {
console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5

// Only change code below this line.

function functionWithArgs(a, b){

console.log(1 + 2);
}
functionWithArgs(7, 9);

HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:15
@GrannyCamper right so what does you function your trying to call do at the moment?
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:16
@HeebieGeeBee yeah, was working, took a nap but overslept :smile:
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:16
@Lumexralph ahh ok cool
toddylane
@toddylane
Mar 12 2017 00:16
anyone have a free few minutes to help with a javascript lesson. im stuck on lesson 172.
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:16
When I call the argument I get an error
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:16
@HeebieGeeBee how's your day been?
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:16
functionWithArgs(7,9) should output 16
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:16
@toddylane sure
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:17
@GrannyCamper yes thats becuase your function hasnt been written properly
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:17
How do I write it properly
because
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:17
@GrannyCamper look at the function youre trying to call, can you see what its doing at the moment?
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:17
Its giving me errors
toddylane
@toddylane
Mar 12 2017 00:17
this is the lesson im stuc
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:18
ignore the errors for now @GrannyCamper just look at the function and try and see whats purpose is at the moment
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:18
@toddylane what have you tried?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:18
function functionWithArgs(a, b){
console.log(1 + 2);
}
this is the function
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:19
Yep
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:19
@GrannyCamper whats its purpose at the moment
Anthony
@ar94952
Mar 12 2017 00:19
sometimes the answers are a lot simpler than it sounds
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:19
I need an argument I assume
toddylane
@toddylane
Mar 12 2017 00:19
@Lumexralph im stuck at the return line where it says return item;...i know thats not right but i cant figure out how to get the correct result
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:19
if i call functionWithArgs(); whats going to happen
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:19
@ar94952 yeah
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:20
@GrannyCamper ignore that for now just try and understand what this function is doing at the moment
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:20
@toddylane your shift method removed the first element from arr, that's what your function should return
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:20
Well this argument is gonna give me 3 on the screen
The one you wrote so far
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:21
yes, but not the argument the function
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:21
ok
Hopper Kremer
@hopperkremer
Mar 12 2017 00:21
Hi guys, I'm stuck trying to change between temperature units on the weather API challenge.
https://codepen.io/hopperkremer/pen/PpWZyO
Lines 9 thru 17 are supposed to work.
I hope my comments are helpful : )
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:21
yes thats becuase its only purpose is to console.log(1+2)
@GrannyCamper
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:21
yep
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:22
now how would you change its purpose to instead of console logging 1+2
you want to console log the parameters of the function
@GrannyCamper or just one of the parameters for now
the parameters of the function being a and b
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:23
console.log (7 + 9), apparently I need a comma as an argument which is then I should call the function
toddylane
@toddylane
Mar 12 2017 00:23
@Lumexralph i thought so at first, but i couldnt figure the correct syntax to right it. i tried 'return arr[0]' but it came back as an error
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:23
no we dont want to hard code values
@GrannyCamper
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:23
yep a b are parameters of the function
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:23
@GrannyCamper we want to write a function that just uses that parameters
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:23
but then I need arguments
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:23
@toddylane how about now?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:24
the arguments arent needed for writing the function @GrannyCamper
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:24
ok what is then needed
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:24
we want to write a function that just uses the parameters,
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:24
and that should be enough
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:25
becuase parameters are like representative of the arguments that will get passed in later on when the function is called
@GrannyCamper so if we right a function thats purpose is to console.log(a + b);
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:25
so now I want to call the function, how do I call it
yep I get that
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:26
that means when ever we call a function with arguments it wont matter what the arguments are the function will always add them together correctly
toddylane
@toddylane
Mar 12 2017 00:26
@Lumexralph return arr[0]; doesnt give me the removed number, just the remaining first number in the array
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:27
@toddylane use shift
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:27
@GrannyCamper so can you write the function that will add the two parameters together?
and output it to console
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:28
that should be in the console.log(1 + 3)
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:28
no remember we want to use the parameters of the function
so we want to add a and b
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:28
but parameter does not have arguments yet
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:29
the parameters are representative of arguments
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:29
I thought they were representatives of the function
toddylane
@toddylane
Mar 12 2017 00:29
@Lumexralph you can see my code right? is everything correct besides the return line?
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:29
not seen your code @toddylane
toddylane
@toddylane
Mar 12 2017 00:30
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:30
function example(param1) {   
console.log(param1);        
}

example("hello"); // this is when the function is called and it outputs "hello" to the console
remember this example
@GrannyCamper
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:31
can you paste the code here?
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:31
yep
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:31
the bottom line is where we call the function "hello" is the argument
so in the function we see the param1 represents the argument
Dorothy Wegmüller-Ngudle
@GrannyCamper
Mar 12 2017 00:32
hello cannot be a function, or where is it declared as a function
ok I see it
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:33
its not a function its an argument we're passing into the function when we call it
toddylane
@toddylane
Mar 12 2017 00:33
@Lumexralph function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
return arr[0]; // Change this line
}
@Lumexralph i need to return the removed element
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:34
@toddylane shift() is holding the first element removed from arr you need to return that
toddylane
@toddylane
Mar 12 2017 00:34
yes but when i try to return shift it just tells me it is undefined
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:35
@toddylane return arr.shift()
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:36
@GrannyCamper when we write a function, its just declaring it and defining it, that function doesnt actually do anything until we call that function
toddylane
@toddylane
Mar 12 2017 00:37
@Lumexralph that made it go from 3 out 4 things wrong to all 4. i dont know why this wont work.
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:37
@toddylane show your code
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:38
and when we call the function with arguments, for example example("hello") its like saying hey function called example do your purpose with this string i give you @GrannyCamper
and then the function will go "ok so, 'hello' is my first parameter, what do i do with my first parameter?, oh ok i have to console.log my first parameter, here you go 'console.log("hello")". @GrannyCamper
toddylane
@toddylane
Mar 12 2017 00:40
@Lumexralph
function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
return arr.shift(); // Change this line
}
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:41
if that makes sense
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:41
@toddylane you're shifting twice.... remove this line to shift once arr.shift()
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:42
maybe im just rambling at this point
toddylane
@toddylane
Mar 12 2017 00:42
@Lumexralph HAH omg thank you, that was driving me insane
CamperBot
@camperbot
Mar 12 2017 00:42
toddylane sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1296 | @lumexralph |http://www.freecodecamp.com/lumexralph
M.Forest
@wheelsofsteel
Mar 12 2017 00:42
Hey all! How would you guys shorten this function?

    nNN=a=> {
      for(var i = 0; i < a.length; i += 2) {
        if(a[i] * 11 !== a[i+1]){
          return false;
        }
      }
      return true;
    };
    nNN([22,2,11,1,3,33])
Sorry, I forgot to explain the idea. It should check that it follows a pattern like: 1, 11, 2, 22, 6, 66 etc. multiples of eleven n pairs :)
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:44
@wheelsofsteel use .sort()
oh and muliply
M.Forest
@wheelsofsteel
Mar 12 2017 00:44
@HeebieGeeBee Sort to equate to true or false?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:45
@wheelsofsteel wait what does it have to do?
M.Forest
@wheelsofsteel
Mar 12 2017 00:45
@HeebieGeeBee nNN([22,2,11,1,3,33]) -> False, nNN([1,11,2,22]) -> True
@HeebieGeeBee one oneone, two twotwo, five fivefive
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:47
@wheelsofsteel does your code work?
M.Forest
@wheelsofsteel
Mar 12 2017 00:47
@HeebieGeeBee Yeah, I'm asking how would you shorten it
;D
@HeebieGeeBee Why?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:48
sorry youre incrimenting by two and the return true is out the loop
M.Forest
@wheelsofsteel
Mar 12 2017 00:48
Yeah ;)
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:48
its 2am
M.Forest
@wheelsofsteel
Mar 12 2017 00:48
haha no worries
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 00:49
@wheelsofsteel why do you need to shorten it?
M.Forest
@wheelsofsteel
Mar 12 2017 00:49
A coding challenge, they want it under 36 characters, I really don't see how that's possible haha
Cory Bowles
@cbconsulting
Mar 12 2017 00:53

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

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

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

If any body can help me out further explain the working of this one much would be appreciated
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:53
@truepalyer6 use celsius parameter with the formula and assign it to fahrenheit
Cory Bowles
@cbconsulting
Mar 12 2017 00:54
@Lumexralph can we get on a chat basis
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:54
@truepalyer6 sure
Cory Bowles
@cbconsulting
Mar 12 2017 00:55
@Lumexralph how would you like to move forward
Liana Haque
@baruma
Mar 12 2017 00:56
@truepalyer6 I'm literally on the same problem lol
also, hi all
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:56
@truepalyer6 i don't understand your question?
@baruma what have you tried
Liana Haque
@baruma
Mar 12 2017 00:56
@Lumexralph here, let me post what i've got

function convertToF(celsius) {
var fahrenheit;

farenheit = celsius * 9/5 + 32;
return fahrenheit;

}

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

Ogundele Olumide
@Lumexralph
Mar 12 2017 00:57
@baruma you have a typo there
@baruma farenheit = celsius * 9/5 + 32; .......... fahrenheit
Liana Haque
@baruma
Mar 12 2017 00:57
ahhhh i see
thanks for catching that , I thought I was losing it :)
Ogundele Olumide
@Lumexralph
Mar 12 2017 00:58
@baruma :smile:
Andrew Shieh
@andrewlikes
Mar 12 2017 01:01
function chunkArrayInGroups(arr, size) {
  //push divided arrays into newArr
  var newArr = [];
  var i = 0;

  while (i < arr.length) {
    newArr.push(arr.slice(i, size + i));
    i += size;
  }





  return newArr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Hey all, just wrote this code from scratch. It works but i'm wondering if I approached it the best possible way..
Uros Tadic
@urketadic
Mar 12 2017 01:05
Hey, does anyone know how i can make it so when an image/div is clicked, a screen pops up with all the information. So not a new page, just a new screen on the same page, and you can press X to exit etc. Is there a plugin or something already existing?
Benjamin Hike
@BenJess
Mar 12 2017 01:06
can anyone help out with "Stand in Line"?
Andrew Shieh
@andrewlikes
Mar 12 2017 01:07
@BenJess I can give it a shot, what you got so far?
Benjamin Hike
@BenJess
Mar 12 2017 01:08

@andrewlikes
function nextInLine(arr, item) {
// Your code here
arr.push(4);
arr.unshift(1);

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

Andrew Shieh
@andrewlikes
Mar 12 2017 01:08
what's the instructions?
Ogundele Olumide
@Lumexralph
Mar 12 2017 01:09
@BenJess push item to arr
Benjamin Hike
@BenJess
Mar 12 2017 01:09
@andrewlikes Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Ogundele Olumide
@Lumexralph
Mar 12 2017 01:09
@BenJess and you need to use shift to remove the first element in the arr , don't forget to return it
Andrew Shieh
@andrewlikes
Mar 12 2017 01:09
also .shift gets rid of the 1st number, .unshift puts a number to the front
M.Forest
@wheelsofsteel
Mar 12 2017 01:10
@andrewlikes I did this:
  var newArray = [];
  for(var i = 0; i < arr.length; i += size) {
      newArray.push(arr.slice(i, i + size));
  }
  return newArray;
Abhijeet Singh
@abhijeetps
Mar 12 2017 01:10
Hey guys, check out my Pomodoro Clock!
Suggestions and changes are warmly welcomed. :smile:
http://codepen.io/aps120797/full/mWmbxq
Andrew Shieh
@andrewlikes
Mar 12 2017 01:11
@wheelsofsteel hm that does look cleaner. i'm more comfortable doing while loops versus for loops right now
Benjamin Hike
@BenJess
Mar 12 2017 01:12
sorry guys, it's just not clicking
M.Forest
@wheelsofsteel
Mar 12 2017 01:12
@andrewlikes While loops are great for when you want to keep doing an action for a certain amount of time. But for iterating over arrays then a for loop is a lot more convenient :). What you did was fine though
Andrew Shieh
@andrewlikes
Mar 12 2017 01:14
@wheelsofsteel thx! I see what you mean, can while loops utilize if/else statements like for loops can?
CamperBot
@camperbot
Mar 12 2017 01:14
andrewlikes sends brownie points to @wheelsofsteel :sparkles: :thumbsup: :sparkles:
:cookie: 299 | @wheelsofsteel |http://www.freecodecamp.com/wheelsofsteel
Hopper Kremer
@hopperkremer
Mar 12 2017 01:14
Hi guys, I'm stuck trying to change between temperature units on the weather API challenge.
https://codepen.io/hopperkremer/pen/PpWZyO
Lines 9 thru 17 are supposed to work.
I hope my comments are helpful, any help is appreciated : )
Ogundele Olumide
@Lumexralph
Mar 12 2017 01:15
@BenJess
1. using push method,    push item parameter to arr
2. using shift method,  remove the first element in arr by doing  arr.shift(), but remember to return it
Cory Bowles
@cbconsulting
Mar 12 2017 01:16
@Lumexralph Thank you for the help.
CamperBot
@camperbot
Mar 12 2017 01:16
truepalyer6 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1297 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Mar 12 2017 01:16
@truepalyer6 :+1:
Benjamin Hike
@BenJess
Mar 12 2017 01:17
i must need some sleep or something
M.Forest
@wheelsofsteel
Mar 12 2017 01:17
@andrewlikes Sure, why not? A while loop does the same thing except you don't have to specify so much. A for loop is specifically for interating over data while a while loop can be used for different purposes (and are less common.) For example, if you are waiting for something to become false
@andrewlikes Hopefully that makes sense
Benjamin Hike
@BenJess
Mar 12 2017 01:19
@Lumexralph I understand the methods, i'm lost on how to apply them
Andrew Shieh
@andrewlikes
Mar 12 2017 01:19
@wheelsofsteel I think I understand, I guess while loops don't look as scary as for loops which is why i'm more compelled to use them over for loops lol
achudoz
@achudoz
Mar 12 2017 01:19
Hi, I'm doing the Make a Person Challenge and While writing the methods into the person-constructor function, I have a problem that my setSomethingName methods change the names when creating the object at first, while I would need them to only change those names when called. I haven't found much info on it unfortunately. Here is the code:
var Person = function(firstAndLast) {
  var nameArr = firstAndLast.split(" ");
  this.getFirstName = function() {
   return nameArr[0];
  };
  this.getLastName = function() {
   return nameArr[1];
  };
  this.getFullName = function() {
   return (nameArr[0] + " " + nameArr[1]);
  };
  //Below lies the problem
  this.setFirstName = function(n) {
   nameArr[0] = n;
  };

};

var bob = new Person('Bob Ross');
bob.setFirstName("Haskell");
Andrew Shieh
@andrewlikes
Mar 12 2017 01:19
I haven't gotten into any situations that I would need a for loop instead of a while loop yet
M.Forest
@wheelsofsteel
Mar 12 2017 01:20
@andrewlikes Imagine a game and you want the game to continue until the user makes a mistake. You could do while(userIsAlive) { user decisions} and in the user decisions then they might select something which would trigger "userIsAlive = false" then it would break
Ogundele Olumide
@Lumexralph
Mar 12 2017 01:20
@BenJess maybe you sleep .... but you used push in your initial code
M.Forest
@wheelsofsteel
Mar 12 2017 01:20
@andrewlikes There aren't any specific situations where you can't use a while loop instead of a for loop, it's just a lot less convenient hehe
@achudoz return ;)
@achudoz return nameArr[0] = n;
Benjamin Hike
@BenJess
Mar 12 2017 01:23
@Lumexralph any additional help would be appreciated. still completely lost
M.Forest
@wheelsofsteel
Mar 12 2017 01:23
@achudoz or you'll get undefined. It's in a function (method) remember so it has to return data unless you're only going to use it inside the function
Ogundele Olumide
@Lumexralph
Mar 12 2017 01:24
@BenJess arr.push(item)
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:24
@achudoz you dont return in a setter
@wheelsofsteel
achudoz
@achudoz
Mar 12 2017 01:24
@wheelsofsteel I don't think that is the problem. The setFirstName works properly in that it actually changes the name. The problem is, that I don't want it to change the name at first, but only after setFirstName(something)
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:25
@achudoz all the function will run when the new object gets created
M.Forest
@wheelsofsteel
Mar 12 2017 01:25
Yeah, completely ignore what I just said actually hahaha, sorry. It's 2:25 here
achudoz
@achudoz
Mar 12 2017 01:25
@HeebieGeeBee yeah that's what is happening. I just don't know how to prevent it from happening
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:26
@achudoz you cant prevent
dont need to
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:26
would someone be kind enough to help me figure out how to acces "H" in
var contacts = [ { f: "A" } , { f: "H" } , { f: "S" } , { f: "K" } ];
Joseph
@revisualize
Mar 12 2017 01:26
@yassbetch I can.
Benjamin Hike
@BenJess
Mar 12 2017 01:26
@Lumexralph so arr is adding what to item?
Joseph
@revisualize
Mar 12 2017 01:26
@yassbetch Seeing as I wrote it.
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:27
@revisualize lol Thanks
CamperBot
@camperbot
Mar 12 2017 01:27
yassbetch sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3486 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 12 2017 01:27
@yassbetch Look at the structure (shape) of the data.
@yassbetch I asked you before a question.
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:27
so i would think it would be something close to contacts.f1;
Joseph
@revisualize
Mar 12 2017 01:27
Let's say we have an array:
var contacts = [ "A" , "H" , "S" , "K" ];
How do you access "H"?
Conner
@ConnerMal
Mar 12 2017 01:27
var myStr = "<a href='http://www.example.com\' target=\"_blank\">Link</a>";
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:27
contacts[1]
Joseph
@revisualize
Mar 12 2017 01:28
@yassbetch So, when you access contacts[1] You're accessing the element in that array index.
Conner
@ConnerMal
Mar 12 2017 01:28
trying to get rid of all backslashes
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:28
@revisualize right
achudoz
@achudoz
Mar 12 2017 01:28
@HeebieGeeBee so how can I create a setFirstName changes the first name when called? This is what I have to satisfy:
"bob.getFullName() should return "Haskell Ross" after bob.setFirstName("Haskell")"
Joseph
@revisualize
Mar 12 2017 01:28

@yassbetch Now... If you have
var contacts = [ { f: "A" } , { f: "H" } , { f: "S" } , { f: "K" } ];
When you access

contacts[1];

You're getting the data from that element that is an object. { f: "H" }

@yassbetch Then you just need to combine that with object access.
@yassbetch To access the "f" property value you just have to drill further.
@yassbetch So, first you access contacts[1] then you access .f and you combine the two to be contacts[1].f or you can do the same with contacts[1]["f"]
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:30
{f:"H"} is a property inside an object. so in order to access "f" I would have to do something like contacts1.f)
I think i got it!
Joseph
@revisualize
Mar 12 2017 01:30
@yassbetch Yes.
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:31
@revisualize Yaaaaaaaaas
Joseph
@revisualize
Mar 12 2017 01:31
@yassbetch SOOO if you notice something.
@yassbetch With Profile Lookup ... the data structure is the same.
@yassbetch I just shorted the property and values to 1 letter.
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:31
@revisualize ah. let me give it another shot
@revisualize appreciate you being patient with me
Joseph
@revisualize
Mar 12 2017 01:32
@yassbetch With that challenge you need to understand that you're working with an ARRAY. Where the array elements are all objects.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:33
@achudoz what have you got? orry
@revisualize how was youtubeing?
M.Forest
@wheelsofsteel
Mar 12 2017 01:34
@BAchu19
var Person = function(first, last) {
  first = first,
  last = last;
};

bob = new Person('bob', 'ross');
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:35
@revisualize not sure how to beging to answer this question
Benjamin Hike
@BenJess
Mar 12 2017 01:35
@Lumexralph got it. thanks!
CamperBot
@camperbot
Mar 12 2017 01:35
benjess sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1298 | @lumexralph |http://www.freecodecamp.com/lumexralph
M.Forest
@wheelsofsteel
Mar 12 2017 01:36
sorry, this.first, this.last*
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:37
@revisualize I know I need a for loop but not sure how to go about using it
in this scenario
M.Forest
@wheelsofsteel
Mar 12 2017 01:37
@achudoz

var Person = function(first, last) {
  this.first = first,
  this.last = last;
};

bob = new Person('bob', 'ross');
bob.first = 'Haskall';
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:38
@wheelsofsteel he cant do that for that challenge
Marc Droz
@b1tc0de
Mar 12 2017 01:40
what is the correct way to do...
M.Forest
@wheelsofsteel
Mar 12 2017 01:40
Ah, forget it then
Marc Droz
@b1tc0de
Mar 12 2017 01:40

    return Math.floor(year / 100) +1
achudoz
@achudoz
Mar 12 2017 01:40

@HeebieGeeBee i have to have an object that works with these methods and has exactly 6 object keys.

getFirstName() 
getLastName() 
getFullName() 
setFirstName(first) 
setLastName(last) 
setFullName(firstAndLast)

The set methods have to change what the get methods return, but may only change it when implemented. That means that at first, for a person "Bob Ross" the getFirstName(); should return Bob, and when setFirstName("Haskell") is called, the next time the test calls getFirstName, it should return Haskell. This is my code now:


var Person = function(firstAndLast) {
  var nameArr = firstAndLast.split(" ");
  this.getFirstName = function() {
   return nameArr[0];
  };
  this.getLastName = function() {
   return nameArr[1];
  };
  this.getFullName = function() {
   return (nameArr[0] + " " + nameArr[1]);
  };
  //Below lies the problem
  this.setFirstName = function(n) {
   nameArr[0] = n;
  };

};

var bob = new Person('Bob Ross');
bob.setFirstName("Haskell");
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:40
@revisualize this is what I have so far
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0; i < contacts.length; i++) {
   console.log(contacts[i]);
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
achudoz
@achudoz
Mar 12 2017 01:41
@wheelsofsteel yeah, just as @HeebieGeeBee says, they make it much more complicated in this challenge
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:42
@achudoz try having a variable thats the full name, and then work on that
@achudoz whats not working with your code at the moment?
achudoz
@achudoz
Mar 12 2017 01:44
@HeebieGeeBee well I am working with Array ["first", "last"], which is what you say I guess, but that isn't working. I somehow have to delay the setSomethingName methods so they would not be implemented when the object is created.
Marc Droz
@b1tc0de
Mar 12 2017 01:44
what is the correct way to add 1 to the result of Math.floor?
   return  Math.floor(year / 100) +1
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:44
@achudoz you dont have to do that
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:45

can someone walk through this problem with me? We have an array of objects representing different people in our contacts lists.

A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

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

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

If prop does not correspond to any valid properties then return "No such property"
so far I have

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

// Change these values to test your function
lookUpProfile("Akira", "likes");
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:46
@achudoz how do you know its not working at the moment?
Jameel Matin
@cutiepatootiebear
Mar 12 2017 01:46
I am unsure how to do this part: The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
achudoz
@achudoz
Mar 12 2017 01:47
@HeebieGeeBee how so? The way I have it now, it works well, but thanks to the setFirstName..... Wait.... it seems it just started to work.
CamperBot
@camperbot
Mar 12 2017 01:47
achudoz sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1023 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
achudoz
@achudoz
Mar 12 2017 01:47
wth
:D
@HeebieGeeBee it was returning "haskel ross" immediately before and never returned "bob ross", but now it seems to work. I know it because of the tests that are performed
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:49
@achudoz oh ok well yeah wait till youve written the whole function before seeing it it dosnt pass all the test
Andrew Shieh
@andrewlikes
Mar 12 2017 01:51
function mutation(arr) {

  //Need to make all elements lowercase
  var target = arr[0].split('');
  var test = arr[1].split('');


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

    //if letters in test do not match target, return false
    if (target[i] !== test[i]) {
      return false;
    }
    return true;
  }

}

mutation(["hello", "hey"]);
I know using .toLowerCase is supposed to make the string lowercase, but I don't know where to put it.
Also my if else statement seems to have a bug in it.
Luis Felipe López G.
@luishendrix92
Mar 12 2017 01:52
if (target[i] !== test[i]) {
      return false;
    }
return true;
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:52
@andrewlikes that wont work how you have it setup at the moment, try using index of
Luis Felipe López G.
@luishendrix92
Mar 12 2017 01:52
your function will return either true or false after the first iteration no matter what
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:53
@andrewlikes and you can chain tolowercase to your split method
Andrew Shieh
@andrewlikes
Mar 12 2017 01:53
oh right
toLowerCase didn't work when I tried attaching it to the arr[0] or arr[1]
says it wasn't a function
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:54
@andrewlikes how did you do it?
achudoz
@achudoz
Mar 12 2017 01:54

@HeebieGeeBee well the problem was, that some of the tests that were passing before the setFirstName method was written, suddenly stopped being passed, so I knew something was wrong and I just figured out what was wrong and why it works now. I left this:

bob.setFirstName("Haskell");

method call used for my testing at the bottom, so the test always implemented the method before running other tests. Such a silly mistake and none of us saw it. Thank you!

CamperBot
@camperbot
Mar 12 2017 01:54
achudoz sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:warning: achudoz already gave heebiegeebee points
Andrew Shieh
@andrewlikes
Mar 12 2017 01:54
var target = arr[0].split('').toLowerCase();
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:54
@achudoz ok cool
@andrewlikes oh sorry you youre splitting every word into letters, add it before
try arr[0].toLowerCase().split("")
Andrew Shieh
@andrewlikes
Mar 12 2017 01:56
@HeebieGeeBee I swear I did that too and it didn't work, but after you suggested it, it works now lol
@HeebieGeeBee thx!
CamperBot
@camperbot
Mar 12 2017 01:56
andrewlikes sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1024 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Andrew Shieh
@andrewlikes
Mar 12 2017 01:56
@luishendrix92 and thx for the reminder
CamperBot
@camperbot
Mar 12 2017 01:56
andrewlikes sends brownie points to @luishendrix92 :sparkles: :thumbsup: :sparkles:
:star2: 1433 | @luishendrix92 |http://www.freecodecamp.com/luishendrix92
achudoz
@achudoz
Mar 12 2017 01:56
@andrewlikes It's important to remember, that some methods only work with strings, and others only with arrays
Andrew Shieh
@andrewlikes
Mar 12 2017 01:57
do you have some examples?
Joseph
@revisualize
Mar 12 2017 01:57
Meh.
function isPrime(num) {
   if (num < 2 || num % 2 === 0 || num % 3 === 0 || num % 5 === 0 || num % 7 === 0) {
      return false;
   } // the code above just short cuts a majority of values hitting the for loop.

   for (var i = 4; i < primes.length; i++) {
        if (i % num === 0) {
           return false;
        }
   }
   return true;
}
Andrew Shieh
@andrewlikes
Mar 12 2017 01:57
I do get confused when things work on some things and not on others
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:58
@revisualize whats up?
Joseph
@revisualize
Mar 12 2017 01:58
Just trying to sum these primes.
@HeebieGeeBee These more advanced math challenges are difficult for me.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 01:59
@revisualize yeah i dont llike the math ones either
achudoz
@achudoz
Mar 12 2017 01:59
@andrewlikes always google the method. something like: .tolowercase javascript one of the first results will be mdn and it will liste the method as String.toLowerCase(), from which you know it is a string method
Andrew Shieh
@andrewlikes
Mar 12 2017 02:00
ahh that's what it means, that's very helpful, thx @achudoz
CamperBot
@camperbot
Mar 12 2017 02:00
andrewlikes sends brownie points to @achudoz :sparkles: :thumbsup: :sparkles:
:cookie: 310 | @achudoz |http://www.freecodecamp.com/achudoz
achudoz
@achudoz
Mar 12 2017 02:01
@andrewlikes You're welcome. I know, right! Now it seems obvious, but I had my deal of frustration before the aha moment too :D
Andrew Shieh
@andrewlikes
Mar 12 2017 02:02
yeah I jumped into JavaScript so fast that I put Array and String in the same category at one point lol
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:03
@revisualize im confused by your function
Craig Warren
@stream8media
Mar 12 2017 02:10
Hi everyone, looking for some help with the Profile Lookup challenge, before I loose all of my hair from pulling it out. Array of several objects, need to write function that accepts two params one being a value of a object property and other a property in the object. Function needs to A..check if value exists in object && if object has the property - if both true return value of property
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:11
   for (var i = 2; i <=num; i++) {
        if (i % num === 0) {
               if(i === num) {
                       return true;
               }
        }
   }
Manish Giri
@Manish-Giri
Mar 12 2017 02:12
@stream8media have you tried some code?
Eric Long
@ejlong90
Mar 12 2017 02:13
Thanks @Rafase282 for your help with Checkpoint: Word Blanks
CamperBot
@camperbot
Mar 12 2017 02:13
ejlong90 sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star2: 1497 | @rafase282 |http://www.freecodecamp.com/rafase282
Craig Warren
@stream8media
Mar 12 2017 02:13
oh heck yes, several times..
achudoz
@achudoz
Mar 12 2017 02:14
@stream8media why don't you post what you have here and you shall be helped
Pagnito
@Pagnito
Mar 12 2017 02:16
ok so i solved the problem, but i was trying to have it alert instead of return in case the first if statement didnt work and instead it just ignores the whole code and goes strait to alert

function lookUpProfile(firstName, prop){

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

}
alert( "No such contact");
}
// Change these values to test your function
lookUpProfile("Sherlock", "number");

i tried it like this too and nop

function lookUpProfile(firstName, prop){

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

}
lookUpProfile("Akira", "number");

Manish Giri
@Manish-Giri
Mar 12 2017 02:17
@Pagnito does Sherlock exist?
Pagnito
@Pagnito
Mar 12 2017 02:17
yes it does
Manish Giri
@Manish-Giri
Mar 12 2017 02:17
@Pagnito post the URL, click "run tests" first
Craig Warren
@stream8media
Mar 12 2017 02:18
this is what i came up with for first part of problem

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[i].hasOwnProperty(contacts[i].firstName) && contacts[i].hasOwnProperty(prop)){
return contacts[prop][i];
}
}

// Only change code above this line
}

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

Alexander Køpke
@alexanderkopke
Mar 12 2017 02:18
does holmes work?
Pagnito
@Pagnito
Mar 12 2017 02:18
the code works if i use return "No such contact"
but not with alert("No such contact")
its really irritating
Craig Warren
@stream8media
Mar 12 2017 02:19
lol yes it is..this could be an all nighter
Pagnito
@Pagnito
Mar 12 2017 02:19
lol forreal
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:19
don't use alert. it is not what is asked for you
Jor
@joreyesl
Mar 12 2017 02:19
@Pagnito but you are supposed to to return it, not alert it
Pagnito
@Pagnito
Mar 12 2017 02:19
yea i get that
but im trying to be more than just following the book
cuz when we write our own code we wont be following directions
so im tryin to understand why alert is reacting so diffirent
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:20
use console.log(variable here); then press f12 to see output to debug code
Craig Warren
@stream8media
Mar 12 2017 02:20
ok..keep it simple follow the instructions return not alert..problem is challenging enough
Manish Giri
@Manish-Giri
Mar 12 2017 02:21
@Pagnito if you don't have a return, the function keeps executing, which is why you get the repeated alerts..
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:21
@Pagnito if you dont use return your loop will just continue to loop
Craig Warren
@stream8media
Mar 12 2017 02:21
can anyone help that has suceeded in this challenge
Jor
@joreyesl
Mar 12 2017 02:21
@Pagnito return ends the function execution, but if you only alert, then the function continues, so you see all the alerts.
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:21
yes
Manish Giri
@Manish-Giri
Mar 12 2017 02:21
@stream8media I can give you some pseudocode, if it helps..
Craig Warren
@stream8media
Mar 12 2017 02:22
yes anything at this point thank you Manish
Pagnito
@Pagnito
Mar 12 2017 02:22
aaaaah sweet thank you!!
@joreyesl thank you
CamperBot
@camperbot
Mar 12 2017 02:22
pagnito sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 587 | @joreyesl |http://www.freecodecamp.com/joreyesl
Pagnito
@Pagnito
Mar 12 2017 02:22
@HeebieGeeBee thank you
CamperBot
@camperbot
Mar 12 2017 02:22
pagnito sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1025 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Pagnito
@Pagnito
Mar 12 2017 02:22
@Manish-Giri thank you
CamperBot
@camperbot
Mar 12 2017 02:22
pagnito sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4706 | @manish-giri |http://www.freecodecamp.com/manish-giri
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:22
@Pagnito also your no such contacts return should be outside the loop
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:23
if loo doesn't catch you need default outside loop to return 'No such property' or whatever is said
Manish Giri
@Manish-Giri
Mar 12 2017 02:23
@stream8media before that, a few things in your code - return contacts[prop][i];
Craig Warren
@stream8media
Mar 12 2017 02:23
ManishGirl did you send the pseudo code?
yeh?
Pagnito
@Pagnito
Mar 12 2017 02:23
@HeebieGeeBee why outside the loop?
Manish Giri
@Manish-Giri
Mar 12 2017 02:23
contacts is an array of objects, when you are loop through the array, you have each element at the index i, so the current object is at contacts[i]
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:24
not yet
Joseph
@revisualize
Mar 12 2017 02:24
I don't understand why my code thinks 121 is a prime.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:24
@Pagnito because you need to look through all the contacts before you know there isnt a match
Manish Giri
@Manish-Giri
Mar 12 2017 02:24
now, the property prop of the object at contacts[i] can be accessed via contacts[i][prop]
you have it backwards
Craig Warren
@stream8media
Mar 12 2017 02:24
yes i understand that Manish
Manish Giri
@Manish-Giri
Mar 12 2017 02:24
@stream8media
Jor
@joreyesl
Mar 12 2017 02:24
@Pagnito if you want to know what is being returned, you can keep the returns and add an alert or log right before each return so you can see when something gets returned. That way the logic remains the same. Also you can use http://www.pythontutor.com/visualize.html#mode=edit to step through the code and see each step.
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:24
121 is not prime
Joseph
@revisualize
Mar 12 2017 02:25
No shit.
Pagnito
@Pagnito
Mar 12 2017 02:25
@joreyesl thanks
CamperBot
@camperbot
Mar 12 2017 02:25
pagnito sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:warning: pagnito already gave joreyesl points
Manish Giri
@Manish-Giri
Mar 12 2017 02:25
@stream8media anyway, here's some pseudocode
//loop through contacts array 
 if firstName is a match 
   a. if property found - return it's value
   b. else return no prop found
//outside the loop, return no contacts found
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:25
you need to change your code so it doesn't think this
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:25
@revisualize whats your code now?
lol @alexanderkopke cant argue with that
Craig Warren
@stream8media
Mar 12 2017 02:26
cheers Manish i will take a look at problem again
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:26
8)
Joseph
@revisualize
Mar 12 2017 02:26
I got my code backwards!
HA!
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:27
omg I is so hungry I needs food now
Joseph
@revisualize
Mar 12 2017 02:27
I solved it!
Manish Giri
@Manish-Giri
Mar 12 2017 02:27
@alexanderkopke :fries:
Joseph
@revisualize
Mar 12 2017 02:28
I SOLVED IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:28
thx @Manish-Giri
CamperBot
@camperbot
Mar 12 2017 02:28
alexanderkopke sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4708 | @manish-giri |http://www.freecodecamp.com/manish-giri
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:28
awesome.. glad we could help @revisualize
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:28
i just had some tuna, i can already feel the mercury rotting my brain
Manish Giri
@Manish-Giri
Mar 12 2017 02:28
I had pasta
Joseph
@revisualize
Mar 12 2017 02:28
Motherf'ing ... if (num % i === 0) vs if (i % num === 0)
Manish Giri
@Manish-Giri
Mar 12 2017 02:28
alfredo
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:28
nice
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:28
mercury can bee good. like in queen
Joseph
@revisualize
Mar 12 2017 02:29
@alexanderkopke You know I just want to take the time to thank your obvious commentary about my obvious statement when I knew that 121 wasn't prime.
CamperBot
@camperbot
Mar 12 2017 02:29
revisualize sends brownie points to @alexanderkopke :sparkles: :thumbsup: :sparkles:
:star2: 1193 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:29
not when it gets into you blood stream
just like mercury from queen
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:29
@revisualize no problem :)
Joseph
@revisualize
Mar 12 2017 02:29
Obviously.
Now, I need to refactor it more.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:31
@revisualize just think about it next time, if your code makes something happen you dont want to happen, make your code not do what you dotn want to happen
Joseph
@revisualize
Mar 12 2017 02:31
@HeebieGeeBee I know right.
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:31
try the karaoke version of bohemian rhapsody and you'll know how great their music was/is
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:32
i dont dispute the greatness of queen music
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:32
true
@revisualize I underestimated you. My apologies
Joseph
@revisualize
Mar 12 2017 02:33
@alexanderkopke Puscifer is one of my favorite bands.
Damn, I love this video.
Alexander Køpke
@alexanderkopke
Mar 12 2017 02:35
good stuff for sure
zixster
@zixster
Mar 12 2017 02:41

I'm on the "Convert Celsius to Fahrenheit" lesson and this code


function convertToF(celsius) {
  var fahrenheit;
  // Only change code below this line
  var celcius = 5;
  fahrenheit = celcius*(9/5)+32;

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

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

returns "41," which is correct. but the same code without my declared 5 returns "null"

function convertToF(celsius) {
  var fahrenheit;
  // Only change code below this line
  var celcius = 5;
  fahrenheit = celcius*(9/5)+32;

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

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

and I can't see why. it should be easier without my declared 5.

HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:42
@zixster get rid of the celcius variable and just use the celsius parameter
AKS
@amitkumarsarangi
Mar 12 2017 02:42
@zixster you don't have to define the var celcius again
Joseph
@revisualize
Mar 12 2017 02:43
@zixster remove var celcius = 5;
@zixster spell celcius correctly. ... celsius
zixster
@zixster
Mar 12 2017 02:44
@revisualize haha! right, there's an "s" in there :) thanks!
CamperBot
@camperbot
Mar 12 2017 02:44
zixster sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3487 | @revisualize |http://www.freecodecamp.com/revisualize
Ken Aguilar
@piq9117
Mar 12 2017 02:45
you could simplify that function
const convertToF = celsius =>
  celsius * 9/5 + 32
Roxroy
@roxroy
Mar 12 2017 02:49
@zixster , you should remove var celcius = 5;, as it will wipe out the value that is pass in for celcius;
you will get the same answer every time, if you do not remove it
Pagnito
@Pagnito
Mar 12 2017 02:50
I figured out how to break the loop and use the alert at the same time!!

function lookUpProfile(firstName, prop){

for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === firstName) {
if (contacts[x].hasOwnProperty(prop)) {
alert(contacts[x][prop]);
} else {
alert( "No such property");
}
} return "No such contact" + alert("No such Contact biiish");
}

}
lookUpProfile("kira", "number");

glad thats over...
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:51
@Pagnito that wont pass the challenge
Pagnito
@Pagnito
Mar 12 2017 02:51
i didnt do it for the challange
i did this one for me
i passed the challange with the return
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:51
but your function isnt even working properly
Pagnito
@Pagnito
Mar 12 2017 02:52
but i wanted it to work for me in codepen with some kind of actualy output that i can see
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:53
function test() {
alert("this is an alert")
}
test();
can do that if you just wanna see an alert
Pagnito
@Pagnito
Mar 12 2017 02:54
i didnt do it to see a random alert
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:55
ok fair enough
Pagnito
@Pagnito
Mar 12 2017 02:55
i wanted it to output actual info that would be useful if this was a real profile look up
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:56
break will break out of a loop without a return
Pagnito
@Pagnito
Mar 12 2017 02:56
oh shit nice to know, thanks
@HeebieGeeBee thanks
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:57
no problem
Craig Warren
@stream8media
Mar 12 2017 02:57
@JLuboff What the heck is a backtick.. is it a backslash \
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 02:58
@stream8media press the key to the left of your 1 button
Roxroy
@roxroy
Mar 12 2017 02:58
@stream8media , it is this character ` or shift ~ (tilda)
Craig Warren
@stream8media
Mar 12 2017 03:01
Big ole thank you to Pagnito, really appreciate you help :-)
Got it thank you to eveyrone who has helped
Jones Tee
@JonesTee
Mar 12 2017 03:04
Hi guys
:smile:
Pagnito
@Pagnito
Mar 12 2017 03:04
@stream8media np
Ben Carp
@carpben
Mar 12 2017 03:09
Hi, Please take a look at this pen http://codepen.io/bencarp/full/dvWXgq/ . I'm really not sure what is going on. The debugger doesn't run, the sumPrimes(15) doesn't seem to run, and when I run sumPrimes(15) from the console I get an error I don't understand: "Uncaught ReferenceError: sumPrimes is not defined
at <anonymous>:1:1" any suggestions?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:11
@carpben it is working
Roxroy
@roxroy
Mar 12 2017 03:12
@carpben, I am not seeing any error, it get a 3's for the output
Ben Carp
@carpben
Mar 12 2017 03:12
@HeebieGeeBee try to run sumPrimes(anyNumber) from the console.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:13
@carpben you have to write the function in the console
to be able to runa function from the console
Ben Carp
@carpben
Mar 12 2017 03:13
Oh. I didn't know that. Can't I enter the function from the console without writing it?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:14
not a custom one
Ben Carp
@carpben
Mar 12 2017 03:14
so it's different from Python .
Custom one?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:14
type this into the console
Ben Carp
@carpben
Mar 12 2017 03:15
blob
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:15
thats whats available to you in the console
no im just saying thats whats available to you in the console
Ben Carp
@carpben
Mar 12 2017 03:16
ok. I understand
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:16
until you write a new function in the console
Joseph
@revisualize
Mar 12 2017 03:16
la la la la la
Syed Khalid
@syed87
Mar 12 2017 03:16
Hi, I'm haveing trouble with passing my code for the mutations algorithm, could someone take a look and see what I'm doing wrong. It seems to be working on codepen.
Joseph
@revisualize
Mar 12 2017 03:17
How do I benchmark my code?
Syed Khalid
@syed87
Mar 12 2017 03:17

function mutation(arr) {

  var sliced = arr.shift();
  var newArr = arr.join("").split("");

  var collection = [];

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

    var a = newArr.shift();
    var b = sliced.indexOf(a);

    collection.push(b);

  }

  collection.join("");

  var test = collection.indexOf(-1);


    if (test < 0) {
      console.log(true);
    } else {
      console.log(false);
    }
}

mutation(["hello", "hey"]);
I belive the issue is with the for loop, where I say i=newArr.length;
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:18
@syed87 many things
Ben Carp
@carpben
Mar 12 2017 03:18
@HeebieGeeBee - see line 25 sumPrimes(15) I would expect the return to be printed to the console. I'm wrong right? Only if it has console.log?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:19
@carpben yes you'll need to console log
@syed87 thats one yeah, but theres many things wrong with the code
Joseph
@revisualize
Mar 12 2017 03:20
@carpben I JUST solved that challenge.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:20
@syed87 have you got an idea of what you want to do?
any plan or anything?
Syed Khalid
@syed87
Mar 12 2017 03:21
@HeebieGeeBee I have done this because if I say i<=newArr.length; it doesn't cycle through all the array, how can I get it to cycle though the whole array. Other than this the code seems to work fine.
the code is supposed to return true if the letters in "hey" can be found in "hello" and false if not
Oh!
I think I know why
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:24
i = newArr.length isnt a conditional for a for loop @syed87
youre just re assigning the value of i
b = sliced.indexOf(a); this will just be either a -1 or a positive number
Syed Khalid
@syed87
Mar 12 2017 03:26
@HeebieGeeBee yes I did this because the for loop would not do the same number of loops as the length of newArr. But I can see now this is because I am shifting the first element of newArr within the loop.
@HeebieGeeBee I know how to correct this issue now and I'm sure this will pass however what other issues did you see with the code. seems fine apart from this...
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:28
@syed87 why are you just console logging the true and false?
Syed Khalid
@syed87
Mar 12 2017 03:29
@HeebieGeeBee for some reason codepen doesn't work when I use return so I use console.log in place of that. Just forgot to switch it back to return.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:30
why is everyone working in codepen all of a sudden?
@syed87 well anyways if you get it to work cool, but could do with some refactoring
Jor
@joreyesl
Mar 12 2017 03:33
@syed87 you can use https://repl.it/languages/javascript for a better js environment.
Ben Carp
@carpben
Mar 12 2017 03:39
@revisualize HiJuseph. I solved it as well. I'm actually quite proud of my solution. http://codepen.io/bencarp/pen/dvWXgq. U can send me yours as well.
Joseph
@revisualize
Mar 12 2017 03:40
@carpben I just posted mine.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:40
@revisualize nice
Jason Luboff
@JLuboff
Mar 12 2017 03:40
Man @HeebieGeeBee you're still awake?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:40
@JLuboff just about
Jason Luboff
@JLuboff
Mar 12 2017 03:41
I guess you did say you have weird sleep habits the other day
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:41
yup
Pagnito
@Pagnito
Mar 12 2017 03:43
can someone explain to me the logic and mechanics behind this Math.floor(Math.random() * (max - min + 1)) + min
Math.floor(Math.random() * (max - min + 1)) + min
Joseph
@revisualize
Mar 12 2017 03:43
Is it a full moon tonight?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:44
@Pagnito what do you need explaining about it?
Jason Luboff
@JLuboff
Mar 12 2017 03:44
Maybe @revisualize
Joseph
@revisualize
Mar 12 2017 03:44
@JLuboff March 11
Waxing Gibbous
Illumination: 99%
Tomorrow night is a full moon.
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:45
a waxing gibbous
new hipster gin cocktail
Jason Luboff
@JLuboff
Mar 12 2017 03:45
Heh. I was just outside walking and the moon did look pretty full
Joseph
@revisualize
Mar 12 2017 03:46
@JLuboff 99%
Jason Luboff
@JLuboff
Mar 12 2017 03:46
Yes in fact it looked exactly 99% full
Joseph
@revisualize
Mar 12 2017 03:46
LOL.
I want to figure out how to make my algorithm faster.
Pagnito
@Pagnito
Mar 12 2017 03:48
@HeebieGeeBee i dont understand the point of +1 and then + min outside the paranthesis
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:49
@Pagnito what does math floor do?
Pagnito
@Pagnito
Mar 12 2017 03:49
@HeebieGeeBee rounds down the number right?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:49
@Pagnito yes
and math random?
Pagnito
@Pagnito
Mar 12 2017 03:50
gives me a random number between 0 and 1
or decimal i guess
Jeanne
@Jeanne126
Mar 12 2017 03:50
guys, what is wrong with these codes
function nextInLine(arr, item) {
// Your code here
newArr=arr.push(item);
var first=newArr.shift();
return first; // Change this line
}
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:51
so if math max was 10 and math min was 5 @Pagnito
Joseph
@revisualize
Mar 12 2017 03:51
@Jeanne126 You don't understand what .push() returns
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:51
what would 5 * 0.01 give you?
Joseph
@revisualize
Mar 12 2017 03:51
@Jeanne126 .push() doesn't make newArr an array.
Pagnito
@Pagnito
Mar 12 2017 03:51
.05
@HeebieGeeBee .05
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:52
so thats not a number above the min number
so you need to add the min number afterwards
Jeanne
@Jeanne126
Mar 12 2017 03:53
ok, what does that mean @revisualize
Joseph
@revisualize
Mar 12 2017 03:53
@Jeanne126 Let me explain.

@Jeanne126 Question:

function getName() { return "Happy Feet"; }
var name = getName();
console.log(name);

What do you think is output to the console when you log the variable name?
Why do you think that is?
@Jeanne126

Pagnito
@Pagnito
Mar 12 2017 03:53
@HeebieGeeBee k h/o lemme soak that in
Roxroy
@roxroy
Mar 12 2017 03:53
@Jeanne126 , you cannot assign the result of push to a variable. It will automatically update the array that you are adding items to.
Jeanne
@Jeanne126
Mar 12 2017 03:54
@revisualize 'Happy Feet'?
Joseph
@revisualize
Mar 12 2017 03:54
@Jeanne126 Okay. The important question is .. WHY?
Jeanne
@Jeanne126
Mar 12 2017 03:55
@you define a variable that points to the functions returns
Joseph
@revisualize
Mar 12 2017 03:55
@Jeanne126 Great!
@Jeanne126 So, The push() method adds one or more elements to the end of an array and returns the new length of the array.
james umali
@indefinite0212
Mar 12 2017 03:55
hi, can anyone help me with the challenge : Reverse a String
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 03:56
@Pagnito now the plus 1, becuase math random will never give an exact 1
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 03:56

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];
      return product;
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Plz help me to figure out whats wrong in my code
Joseph
@revisualize
Mar 12 2017 03:56
@Jeanne126 If you notice .push() doesn't actually return the new array. It returns the new .length of the array after the element is added..
Roxroy
@roxroy
Mar 12 2017 03:56
@indefinite0212 , what issue are you having?
Jeanne
@Jeanne126
Mar 12 2017 03:56
@revisualize so its the same array
Joseph
@revisualize
Mar 12 2017 03:57
@Jeanne126 with how your code is.. newArr becomes a number that is the new length of arr after the element is added.
Jeanne
@Jeanne126
Mar 12 2017 03:57
alright
Pagnito
@Pagnito
Mar 12 2017 03:58
@HeebieGeeBee but isnt the max - min = 10 and having math.random() * 10 already give u a number abve 1
Joseph
@revisualize
Mar 12 2017 03:59
@Jeanne126 So, with method calls. like .push() you don't actually have to do anything with the returned value.
Roxroy
@roxroy
Mar 12 2017 03:59
@MrityunjaiMishra , the product calculation will not go to the end because you a return just after while it is trying to do the sum.
@MrityunjaiMishra, remove the first return product and keep the second one.
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 03:59
ohk
Jeanne
@Jeanne126
Mar 12 2017 03:59
@revisualize thank u .
CamperBot
@camperbot
Mar 12 2017 03:59
jeanne126 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3489 | @revisualize |http://www.freecodecamp.com/revisualize
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 03:59
got it
thnx @roxroy
CamperBot
@camperbot
Mar 12 2017 03:59
mrityunjaimishra sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 381 | @roxroy |http://www.freecodecamp.com/roxroy
Jeanne
@Jeanne126
Mar 12 2017 03:59
@revisualize problems solved
Joseph
@revisualize
Mar 12 2017 04:00
@Jeanne126 Does it make sense?
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 04:01
@Pagnito no but if you 5 x 0.99 its going to give you 4.95
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 04:01
but still it is giving i am getting this error
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 04:01
which will get rounded down to 4
Pagnito
@Pagnito
Mar 12 2017 04:01
@HeebieGeeBee aah ok ok got that part
HeebieGeeBee
@HeebieGeeBee
Mar 12 2017 04:01
so you have to add the one otherwise you will never get a whole number that can be the max number
Pagnito
@Pagnito
Mar 12 2017 04:02
i see i see
Jeanne
@Jeanne126
Mar 12 2017 04:03
@revisualize yeah
Joseph
@revisualize
Mar 12 2017 04:03
@Jeanne126 You know you didn't need to create a new variable for the return either.
@Jeanne126 The shift() method removes the first element from an array and returns that element.
You can just return the returned element from the method call.
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 04:03
type error cannot read propert 'length' of undefined
this is the erro i am getting @roxroy
Jamal Uddin
@jamal-pb95
Mar 12 2017 04:03
how can I solve 168(Stand in Line)
Joseph
@revisualize
Mar 12 2017 04:04

@jamal-pb95 Gist by revisualize / FreeCodeCamp - Stand in Line.js

// How do you add a number (item) to the end of an array (arr)? What does this method return?
// How do you remove the first element from an array (arr)? What does this method return?

You're supposed to:
Write a function nextInLine which has two parameters
an array (arr) and a number (item).
That part has been done for you here:

function nextInLine(arr, item) { }

Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Here's an example of this:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

You can use the fName and uName parameters just like a variable inside of your function.

You just need to add a number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr).
But, there is another part of this challenge. You need to know What the methods that do those two things return.

Pagnito
@Pagnito
Mar 12 2017 04:07
@HeebieGeeBee appreciate ur help once again thanks
CamperBot
@camperbot
Mar 12 2017 04:07
pagnito sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1026 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Jeanne
@Jeanne126
Mar 12 2017 04:08
@revisualize I see, it is important to tell what result the 'method' returns
sramdeo
@sramdeo
Mar 12 2017 04:08
@MrityunjaiMishra in the second for loop, the variable is 'i' but should be 'j'
@MrityunjaiMishra for the last part of the loop it should be j++
Joseph
@revisualize
Mar 12 2017 04:08
@Jeanne126 You should look it up.
james umali
@indefinite0212
Mar 12 2017 04:10
how can I reverse a string?
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 04:11
thnx @sramdeo
CamperBot
@camperbot
Mar 12 2017 04:11
mrityunjaimishra sends brownie points to @sramdeo :sparkles: :thumbsup: :sparkles:
:cookie: 215 | @sramdeo |http://www.freecodecamp.com/sramdeo
Joseph
@revisualize
Mar 12 2017 04:11
@indefinite0212 You can't. You can convert a string into an array and reverse an array. Then you can convert the array back into a string.
james umali
@indefinite0212
Mar 12 2017 04:12
but how can i convert strings into array?
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 04:15
can anyone tell me what is the coding behind send button iof contact form
of*
Joseph
@revisualize
Mar 12 2017 04:16
@MrityunjaiMishra Depends on the contact form
@MrityunjaiMishra Is the contact form just updating a file? Is it updating an Excel document? Is it submitting the data to a database? Is it actually having the server send an email?
My contact form actually sends an email.
abhishek-sinha3453
@abhishek-sinha3453
Mar 12 2017 04:34

function largestOfFour(arr) {
var largest=0,j;
var barr=[];
for(var i=0;i<=arr.length-1;i++)
for(j=0;j<=arr[i].length;j++)
if(largest<arr[i][j])
largest=arr[i][j];
barr=Array.from(arr[i]);

return barr;
}

i am finding largest numbers in array
could one please point out my mistake

Seth
@sethdcd
Mar 12 2017 04:35

hello, i'm working on the twitch tv API and having some difficulties with display data from the different users.
this is my codepen -> https://codepen.io/sethdcd/pen/oZZYLz?editors=1010

you'll notice that when you run the app it only ends up displaying one <li> tag even though I have a console.log and it ends up showing all the different users. how can i get this to iterate through and actually display all the info?
click the button in order to run it :)

jacob
@bjh2012
Mar 12 2017 04:35
hello, all. I'm stuck on the stand in line challenge in the basic JavaScript section
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
I'm not sure what number "add the number to the end of the array" refers to.
Andrew Shieh
@andrewlikes
Mar 12 2017 04:40
function destroyer(arr) {


var test = []; // test = [2, 3];
var newArr = [];
var target = arguments[0]; //target = [1, 2, 3, 1, 2, 3]

  test.push(arguments[1]);
  test.push(arguments[2]);

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

  }

 return newArr;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Seek and Destroy Challenge. This is what I have so far. I turned the 2nd and 3rd element into an array in hopes it would make it easier for me. However i'm stuck and im not sure if i'm going in the right direction or not..
@bjh2012 you should be pushing the item into the end of the array first
then remove using .shift
and assign the removed array to a variable
jacob
@bjh2012
Mar 12 2017 04:44
return arr.push(6); works, but i'm not sure what to do after that
Andrew Shieh
@andrewlikes
Mar 12 2017 04:45
@bjh2012 you can't push a number because the item can change depending on the input
so just push item
Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 04:48

@andrewlikes To make things easier, try using:

var newArr = Array.prototype.slice.call(arguments);

It should convert arguments into arrays.

jacob
@bjh2012
Mar 12 2017 04:49
@andrewlikes return arr.push(item); works, but i'm not sure where to go from ther
Jamal Uddin
@jamal-pb95
Mar 12 2017 04:49
how can I solve : Comparisons with the Logical Or Operator(179)
Johnny
@jtan3
Mar 12 2017 05:03
@jamal-pb95 what do you need help with?
Joseph
@revisualize
Mar 12 2017 05:09
@hakimi1999 [...arguments]
Simon
@smnshulgan
Mar 12 2017 05:10
can i use .replace() on a variable
Dharshan2004
@Dharshan2004
Mar 12 2017 05:11

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

can you helpme with this
Joseph
@revisualize
Mar 12 2017 05:11

@Dharshan2004 Gist by revisualize / FreeCodeCamp - Stand in Line.js

// How do you add a number (item) to the end of an array (arr)? What does this method return?
// How do you remove the first element from an array (arr)? What does this method return?

You're supposed to:
Write a function nextInLine which has two parameters
an array (arr) and a number (item).
That part has been done for you here:

function nextInLine(arr, item) { }

Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Here's an example of this:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

You can use the fName and uName parameters just like a variable inside of your function.

You just need to add a number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr).
But, there is another part of this challenge. You need to know What the methods that do those two things return.

Simon
@smnshulgan
Mar 12 2017 05:13
what method do I use to turn , into spaces
.replace()?
Dharshan2004
@Dharshan2004
Mar 12 2017 05:14
I dont get it can you help me
@revisualize
Joseph
@revisualize
Mar 12 2017 05:15
@Dharshan2004 i did.
@Dharshan2004 How do you add a number (item) to the end of an array (arr)?
Dharshan2004
@Dharshan2004
Mar 12 2017 05:16
idk
that's the problem
@revisualize
pls
Joseph
@revisualize
Mar 12 2017 05:16
@Dharshan2004 You should solve that problem.
Dharshan2004
@Dharshan2004
Mar 12 2017 05:16
how
Joseph
@revisualize
Mar 12 2017 05:16
about @Dharshan2004
CamperBot
@camperbot
Mar 12 2017 05:16
:warning: no user found for dharshan2004
Dharshan2004
@Dharshan2004
Mar 12 2017 05:16
can give another example
Joseph
@revisualize
Mar 12 2017 05:16

@Dharshan2004
Manipulate Arrays With push()

Manipulate Arrays With pop()

Manipulate Arrays With shift()

Manipulate Arrays With unshift()

@Dharshan2004 You should re-do those lessons.
UponATime
@UponATime
Mar 12 2017 05:17
Hey folks o/ Hope everyone is doing good! Got a question for those of you already having a job in web dev, I'm currently really struggling with intermediate algorithm scripting and was wondering how often do you get to use this knowledge in your everyday work? Is it THAT common?
Joseph
@revisualize
Mar 12 2017 05:18
@UponATime I don't think so. But, I'm not really a web developer. I think it is more learning how to problem solve.
@UponATime I have 1 Intermed Algo to solve: Smallest Common Multiple Incomplete   * .. Then I'm done with Intermed Algo's
badalsaibo
@heyDante
Mar 12 2017 05:19
@UponATime Algorithm is used by us everyday.
Joseph
@revisualize
Mar 12 2017 05:19
@heyDante But, are the Algorithms that you learn in the Intermediate Challenges used every day?
UponATime
@UponATime
Mar 12 2017 05:20
@revisualize Ah, I'm stuck on this one too actually!
Joseph
@revisualize
Mar 12 2017 05:20
@heyDante Do you have to Sum All Numbers in a Range ... every day?
badalsaibo
@heyDante
Mar 12 2017 05:20
@revisualize That was more of a non-technical view.
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 05:20
hi joseph i want to get to know what my coustomer's message is and his data as well so i can contact him so in that case what should i do @revisualize
badalsaibo
@heyDante
Mar 12 2017 05:21
What we think and how we think is kind of an Algorithm
Joseph
@revisualize
Mar 12 2017 05:21
@MrityunjaiMishra What?
Andrew Shieh
@andrewlikes
Mar 12 2017 05:21
@hakimi1999 thx for the suggestion
CamperBot
@camperbot
Mar 12 2017 05:21
andrewlikes sends brownie points to @hakimi1999 :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @hakimi1999 |http://www.freecodecamp.com/hakimi1999
Andrew Shieh
@andrewlikes
Mar 12 2017 05:21
I don't really understand what var newArr = Array.prototype.slice.call(arguments); means though
the prototype part
seems to defy everything I learned so far
UponATime
@UponATime
Mar 12 2017 05:22
@heyDante I really should have listened more in math classes when I was a kid ahah, knew that would be coming to haunt me some day, thanks
CamperBot
@camperbot
Mar 12 2017 05:22
uponatime sends brownie points to @heydante :sparkles: :thumbsup: :sparkles:
:cookie: 563 | @heydante |http://www.freecodecamp.com/heydante
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 05:22
i want to store the data in excel sheet so i can refer to it @revisualize
Joseph
@revisualize
Mar 12 2017 05:23
@MrityunjaiMishra I'm sorry, what are you talking about?
Andrew Shieh
@andrewlikes
Mar 12 2017 05:23
@revisualize ohhh so arguments are never really considered arrays, interesting, thx!
CamperBot
@camperbot
Mar 12 2017 05:23
andrewlikes sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3490 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 12 2017 05:23
@MrityunjaiMishra What?
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 05:23
about contact form send button
coding behind it
Pagnito
@Pagnito
Mar 12 2017 05:24
how come i dont have to use the plus sign for the inverted
/\S/g;
Joseph
@revisualize
Mar 12 2017 05:24
@MrityunjaiMishra That was hours ago.
@MrityunjaiMishra You need to google.
@MrityunjaiMishra I can't help you with that issue.
MrityunjaiMishra
@MrityunjaiMishra
Mar 12 2017 05:24
ohk thnx @revisualize
CamperBot
@camperbot
Mar 12 2017 05:24
mrityunjaimishra sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3491 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 12 2017 05:26
@andrewlikes arguments is an object.
Ayush Bahuguna
@relentless-coder
Mar 12 2017 05:26

@relentless-coder
is the following configuration of .babelrc file correct

{
  "presets": ["es2015", {"modules": false}]
}

I want to use es2015 but don't want it to transform my modules because for starters I don't have any and it is transforming my this references to undefined

Bigyan Karki
@bigyankarki
Mar 12 2017 05:27
anyone here joining chingu march cohort?
Pjdaze
@Pjdaze
Mar 12 2017 05:40
hi people .. does anyone remember find the longest word on a str... one solution would be creating a variable and set it to 0 and then for loop and if str[i].length > variable , variable = str[i]
Jim
@JLOSS1
Mar 12 2017 05:40
Hey anyone got a second? I'm on 'Understand String Immutability'
Pjdaze
@Pjdaze
Mar 12 2017 05:40
can somebody explain why does that work???
since str[i] is always bigger than 0;
@revisualize whats up bro love ur solutions!!
Joseph
@revisualize
Mar 12 2017 05:43
Cheater.
Jim
@JLOSS1
Mar 12 2017 05:44
I'm not understanding JS logic. If var myStr = "Jello World"; why is myStr[0] = "hello world"; the correct answer if declaring a variable is defining/?
I thought brackets find the first letter? if its myStr[0]
Ben Carp
@carpben
Mar 12 2017 05:46
Hi, I enjoyed the SmallesCommonMultiple challenge, but it doesn't seem to be an intermeidate challenge as it says. Can u please take a look and provide your opinion on my solution approach.
Pjdaze
@Pjdaze
Mar 12 2017 05:46
not really
Jim
@JLOSS1
Mar 12 2017 05:46
anyone?
Pjdaze
@Pjdaze
Mar 12 2017 05:47
sometimes i have a crappy long solution and u got a bunch of solutions per exersice real nice
Johnny vo
@jphivo
Mar 12 2017 05:48
Can someone help me with "finding a remainder in JavaScript"? they are telling me that my Value of remainder should be 2 and I should use the % operator. I'm confused...
Jim
@JLOSS1
Mar 12 2017 05:49
@jphivo post your code really quick, I just did that not long ago
Johnny vo
@jphivo
Mar 12 2017 05:50
I'm confused, so I only got as far as: var remainder;
@JLOSS1 not sure what to do next
Jim
@JLOSS1
Mar 12 2017 05:52
@jphivo So that one the % only finds the remainder of the division of the 2 numbers "11" and "3"
Pjdaze
@Pjdaze
Mar 12 2017 05:52

``
1

2
function findLongestWord(str) {
3
var long = 0
4
str = str.split(' ')
5
for(var i = 0; i < str.length; i++){
6

7
if(str[i].length > long){
8

9
long = str[i].length
10

11
}
12

13
}
14
return long
15
}
16

17
findLongestWord("The quick brown fox jumped over the lazy dog");
18

``

Joseph
@revisualize
Mar 12 2017 05:53
@Pjdaze Can you delete that post and try again?
Pjdaze
@Pjdaze
Mar 12 2017 05:53
how do u make it dark
``?
Joseph
@revisualize
Mar 12 2017 05:53
@Pjdaze Step 1 . Delete post. Step 2. I'll show you.
Jim
@JLOSS1
Mar 12 2017 05:54
three of those @Pjdaze
Joseph
@revisualize
Mar 12 2017 05:54

@Pjdaze
If you are posting code that is large, Please use Gist - https://gist.github.com/ then please paste the link here.
...
How to do code block format: ..... PLEASE try with a small block of code before you try to make a bigger one.
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code
```js [SHIFT+ENTER]
// your code here
``` [CTRL+ENTER or CMD+ENTER to send]
Please do not confuse `s with 's.
Also note that the ```s need to each be on their own lines
The ` key can usually be found on most keyboards up next to the 1 key.
If you hit SHIFT+` it will give you the ~.
Example:
```
code
```
...
Output:

var code = undefined;

...
You can also do inline code formatting:
A string of text with a `variable` or `other bit of code`.
Output:
A string of text with a variable or other bit of code.

@jphivo
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;

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
Just like in my examples above you use the % operator just like any other math operator (+, -, *, /)

Pjdaze
@Pjdaze
Mar 12 2017 05:55
im on an iphone at work hidding in the batchroom so im sorry idk how to delete the post
Joseph
@revisualize
Mar 12 2017 05:56
@Pjdaze By the way. I tend to keep all of my previous solutions on my FreeCodeCamp profile. So, usually at the bottom will be my first solution with a refactor above it. Then another refactor above that.
@Pjdaze I want to include my learning process.
Jim
@JLOSS1
Mar 12 2017 05:56
@Pjdaze ON YOUR IPHONE!!!! hahahah omg dude! How the hell are you doing this on such a small screen!?!?!
Pjdaze
@Pjdaze
Mar 12 2017 05:57
@revisualize i know i like ur solutions helps with knowing how longer code can be simplified love it
Johnny vo
@jphivo
Mar 12 2017 05:57
@JLOSS1 I still don't understand. Can you show me an example of this 11 divided by 3 using the @JLOSS1 remainder % operator?
Manish Giri
@Manish-Giri
Mar 12 2017 05:58
@jphivo how would you add 4 and 5 in JS?
Pjdaze
@Pjdaze
Mar 12 2017 05:58
yes is a bitch on the iphone keyboard but i need to since is hard for me to learn .. at home i work on my projects and at work i practice js as much as i can lol @JLOSS1
the cool thing is that freecodecamp works perfect on a phone
Suraj Regmi
@Suraj1127
Mar 12 2017 05:59
Guys, I tried to change the background color of body randomly using this code of jQuery but didn't work. What may be the reason?
$("body").css("background-color", "rgb(Math.floor(1 + (Math.random())255),Math.floor(1 + (Math.random())255),Math.floor(1 + (Math.random())*255))");
Johnny vo
@jphivo
Mar 12 2017 05:59
@Manish-Giri 4 + 5? I'm sorry, this part(JavaScript) challenge is really tough for me. m=nothing makes sense. lol
Manish Giri
@Manish-Giri
Mar 12 2017 05:59
@jphivo yes, so var result = 4 + 5;
what do you think result now stores?
Jim
@JLOSS1
Mar 12 2017 06:00
@jphivo no no no technically not dividing. just finding the remainder of the quotient. so instead of the output being the integer with a remainder, just input a division problem with the percent where the / is supposed to go.
Jason Luboff
@JLuboff
Mar 12 2017 06:00
@Suraj1127 you need to generate the random numbers outside of your css function
Pjdaze
@Pjdaze
Mar 12 2017 06:00

```function findLongestWord(str) {
var long = 0
str = str.split(' ')
for(var i = 0; i < str.length; i++){

if(str[i].length > long){

  long = str[i].length

}

}
return long
}

findLongestWord("The quick brown fox jumped over the lazy dog"); ```

Jim
@JLOSS1
Mar 12 2017 06:00
@Pjdaze I gotcha.
Pjdaze
@Pjdaze
Mar 12 2017 06:01
can someone tell me why this works ? since str[i].length is always bigger than long
Jim
@JLOSS1
Mar 12 2017 06:02
@jphivo you're not putting a division problem into the computer per se. you are only telling the computer to find the remainder of the division problem.
Johnny vo
@jphivo
Mar 12 2017 06:02
@Manish-Giri I'm not sure. The most obvious answer for me is 9.
Suraj Regmi
@Suraj1127
Mar 12 2017 06:02
I did generate and put them into array variable, array and tried to access them through rgb(array[0], array[1], array[2]) but still didn't work. @Pjdaze
Johnny vo
@jphivo
Mar 12 2017 06:03
@JLOSS1 so, do I write it like this: var remainder; 11 % 3;?
Jim
@JLOSS1
Mar 12 2017 06:03
@jphivo lol try it out brotha!
Manish Giri
@Manish-Giri
Mar 12 2017 06:03
@jphivo yes, so let's break it down
var result = 4 + 5;
The right hand side of this equation is an expression, which results in the sum 9, which then gets assigned to the variable result on the left.
Jason Luboff
@JLuboff
Mar 12 2017 06:03
@Suraj1127 ya but you can have it inside the quotes, you're turning all of that into a string
badalsaibo
@heyDante
Mar 12 2017 06:03
@Pjdaze ;
Manish Giri
@Manish-Giri
Mar 12 2017 06:03
similarly, in the challenge, the right hand side of the expression will be 11 % 3
Suraj Regmi
@Suraj1127
Mar 12 2017 06:04
How could i do that? @JLuboff
Jim
@JLOSS1
Mar 12 2017 06:04
@jphivo remove the ; after remainder. youre declaring "remainder" as a variable so you need an =
Johnny vo
@jphivo
Mar 12 2017 06:05
@JLOSS1 so I just tried: var remainder = 11 % 3;
Suraj Regmi
@Suraj1127
Mar 12 2017 06:05

I did this:

@JLuboff

var suraj = [Math.floor(1 + (Math.random())255), Math.floor(1 + (Math.random())255), Math.floor(1 + (Math.random())*255)];
$("button").click(function() {
$("body").css("background-color", "rgb(array[0], array1, array2)");
});
Johnny vo
@jphivo
Mar 12 2017 06:05
didn't work because it's telling a remainder is undefined
Suraj Regmi
@Suraj1127
Mar 12 2017 06:06
var suraj = [Math.floor(1 + (Math.random())255), Math.floor(1 + (Math.random())255), Math.floor(1 + (Math.random())*255)];
$("button").click(function() {
$("body").css("background-color", "rgb(array[0], array[1], array[2])");
});
Jason Luboff
@JLuboff
Mar 12 2017 06:07
@Suraj1127 "rgb(" +variable + "," + variable ......+ ")"
Jim
@JLOSS1
Mar 12 2017 06:07
@jphivo it literally should be var remainder = 11 % 3;
Johnny vo
@jphivo
Mar 12 2017 06:08
@JLOSS1 @Manish-Giri ok ok ok, I understand now. lol. I was spelling "remainder" wrong. thank you for y'all help and patience.
CamperBot
@camperbot
Mar 12 2017 06:08
jphivo sends brownie points to @jloss1 and @manish-giri :sparkles: :thumbsup: :sparkles:
:cookie: 155 | @jloss1 |http://www.freecodecamp.com/jloss1
:star2: 4710 | @manish-giri |http://www.freecodecamp.com/manish-giri
Joseph
@revisualize
Mar 12 2017 06:08

@jphivo 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;

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
Just like in my examples above you use the % operator just like any other math operator (+, -, *, /)

Jim
@JLOSS1
Mar 12 2017 06:08
@jphivo No problem dude!
Zafeer Khan
@ZafeerKhan
Mar 12 2017 06:10
i am having trouble with profile look up in the java script section
can someone help me out
Manish Giri
@Manish-Giri
Mar 12 2017 06:11
@ZafeerKhan post your code..
Zafeer Khan
@ZafeerKhan
Mar 12 2017 06:12

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

// Only change code above this line
}

is there an easier way to post it
i cant seem to post images
Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 06:13

@ZafeerKhan You can use

"```"

<Your Code here>
"```"
(without quotes)

Then, your text will change into code format

Zafeer Khan
@ZafeerKhan
Mar 12 2017 06:14
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i][0] == firstName) {
      console.log("test");
      for(var j = 1; j < contacts[i].length; j++) {
        if (contacts[i][j] == prop) {
          return contacts[prop];
        }
        else {
          return "No such property";
        }
      }
    }
    else {
      return "No such contact";
    }
  }

// Only change code above this line
}
Manish Giri
@Manish-Giri
Mar 12 2017 06:14
@ZafeerKhan contacts is an array of objects, not an array of arrays..
Joseph
@revisualize
Mar 12 2017 06:22

@ZafeerKhan Gist by revisualize / FreeCodeCamp - Profile Lookup.js

We have an array of objects representing different people in our contacts lists.
Example: var contacts = [ { ... } , { ... } , { ... } , { ... } ];

Nazar
@IsaakNazar
Mar 12 2017 06:22
Hey guys! why function fun = 3, instead there should be 2 right (i<3)?
function fun() {
  var i, j; 
  for (i = 0; i < 3; i++) {

   }
console.log(i);
  }
fun();
Joseph
@revisualize
Mar 12 2017 06:22

@ZafeerKhan

for ( ..... ) {
    if (evaluation) {
        return "truth";
    } else {
        return "lies";
    }
 }

This exact loop.. Does not loop. Because as we know:
The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.

Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 06:23
@IsaakNazar Because i is repeated 3 times
Andrew Shieh
@andrewlikes
Mar 12 2017 06:24
function destroyer(arr) {


return arr;


}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
can someone explain why arr returns [1, 2, 3, 1, 2, 3] and not [1, 2, 3, 1, 2, 3], 2, 3 ? is it because 2 & 3 is not actually part of arr ?
I read it as 3 elements, 1st being an array, and the other 2 being number elements
Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 06:25
@andrewlikes It's an argument, not an array
Nazar
@IsaakNazar
Mar 12 2017 06:25
@hakimi1999 ok :+1:
Andrew Shieh
@andrewlikes
Mar 12 2017 06:26
if that's the case, how is it possible to have entered the other arguments, 2 and 3?>
Jason Luboff
@JLuboff
Mar 12 2017 06:26
They're arguments. A function can have multiple arguments but not have multiple parameters that pass the value. Therefore you need to use arguments to access them
Andrew Shieh
@andrewlikes
Mar 12 2017 06:27
so the other 2 arguments, 2 & 3, will not be passed through unless called?
I need to look up difference between parameters and arguments, they seemed the same to me so I just called everything arguments
Jason Luboff
@JLuboff
Mar 12 2017 06:28
They're still passed in but inaccessible without using arguments (see the documentation)
Suraj Regmi
@Suraj1127
Mar 12 2017 06:29
@JLuboff Thank you it worked.
CamperBot
@camperbot
Mar 12 2017 06:29
suraj1127 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1109 | @jluboff |http://www.freecodecamp.com/jluboff
Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 06:29

@andrewlikes Yes.

You can convert it into an array, though

patrickfrank
@patrickfrank1
Mar 12 2017 06:29

hello everyone, can somebody find my mistake?

function destroyer(arr) {
  // Remove all the values
  var i = 1;
  var args = Array.from(arguments);
  var tmp = arr;
  var drop = function(val,a){
    return val != a;
  };
  while(i<args.length){
    tmp = tmp.filter(drop,args[i]);
    i++;
  }
  return tmp;
}

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

the function drop does not seem to work, it works if i replace args[i] with a certain value, but it does not work for iteration...

Andrew Shieh
@andrewlikes
Mar 12 2017 06:31
I see, so the only reason why [1,2,3,1,2,3] was returned is because it was the 1st element in line
Suraj Regmi
@Suraj1127
Mar 12 2017 06:31
@JLuboff
I should understand that while using variables inside css property value in jquery, I should do " + "variable" + ", right?
Because otherwise, that would treat the property value variables as string.

I want to change the background color of the body each time the user clicks on the button. Once user clicks it changes but afterwards it does not change until I reload the page. Why is that problem?

My code is:
$(document).ready(function() {
var array = [Math.floor(1 + (Math.random())255), Math.floor(1 + (Math.random())255), Math.floor(1 + (Math.random())*255)];
$("button").click(function() {
$("body").css("background-color", "rgb(" + array[0] + ", " + array[1] + ", " + array[2] + ")");
});
});

Jason Luboff
@JLuboff
Mar 12 2017 06:35
@Suraj1127 just in general anytime you put quotes around something it changes it to a string. A variable will not be seen
Suraj Regmi
@Suraj1127
Mar 12 2017 06:40
Now, I am clear. :)
Craig Warren
@stream8media
Mar 12 2017 06:41
I finally figured out, thank you to all who offered help, appreciated
Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 06:44

To make things easier, @patrickfrank1 , you can use Array.indexOf()instead of for loop.

Array.indexOf() can be used to check the element inside of array one-by-one.

Ben Carp
@carpben
Mar 12 2017 06:51
Hi, I solved the SmallesCommonMultiple and it was great. However I was surprised by the complexity and length it took me. If possible please take a look at the code, and let me know if there are simpler methods I could be using. THANKS. http://codepen.io/bencarp/pen/dvWXgq
Jor
@joreyesl
Mar 12 2017 06:53
@carpben for js you can use https://repl.it/languages/javascript to run and share code,
cwxr
@cwxr
Mar 12 2017 07:01

hi can anyone pls advise me thx..

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

Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Manish Giri
@Manish-Giri
Mar 12 2017 07:02
@cwxr nextInLine is the name of the function.
cwxr
@cwxr
Mar 12 2017 07:03
should i be using: ourArray.shift();?
Ronald Johnson
@ronnieg1988
Mar 12 2017 07:07

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 cant figure this one out says 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).
Conor Hinchee
@captnstarburst
Mar 12 2017 07:07
@cwxr that could work! Maybe check out .push too
patrickfrank
@patrickfrank1
Mar 12 2017 07:10
@hakimi1999 is there no way to use the Array.filter() function? Sure with Array.indexOf() i could get around it, but would be a bit more tideous right?!
Conor Hinchee
@captnstarburst
Mar 12 2017 07:12
@ronnieg1988 looks like your building a string using the passed in variables
Jor
@joreyesl
Mar 12 2017 07:12
@patrickfrank1 you can use .filter() alongside .indexOf(). .indexOf() will make your .filter function much more simple.
cwxr
@cwxr
Mar 12 2017 07:13
@ronnieg1988 This code worked for me:
result = "I love it when my beloved " + myNoun + " was " + myAdjective + " and " + myVerb + " very " + myAdverb + ".";
Ronald Johnson
@ronnieg1988
Mar 12 2017 07:14
oh lol i think i was making it more complicated then it actually was
Conor Hinchee
@captnstarburst
Mar 12 2017 07:15
Yeah it threw me off for a hot second too
Ronald Johnson
@ronnieg1988
Mar 12 2017 07:17
myNoun="xxx";
myAdjective="xxx";
myVerb="xxx";
myAdverb="xxx";
result= myNoun + myAdjective + my Verb + myAdverb;
was trying this and it returned what i typed but wouldnt work lol
@cwxr thank you
CamperBot
@camperbot
Mar 12 2017 07:17
ronnieg1988 sends brownie points to @cwxr :sparkles: :thumbsup: :sparkles:
:warning: @cwxr's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 07:20
@patrickfrank1 Why not use Array.indexOf() inside Array.filter()?
Joseph
@revisualize
Mar 12 2017 07:23
@cwxr You do realize giving away answers doesn't actually help people learn?
Andrew Shieh
@andrewlikes
Mar 12 2017 07:24
function getIndexToIns(arr, num) {

  //place num into arr
  arr.push(num);
  arr.sort();

  return arr.indexOf(num);
}

getIndexToIns([2, 5, 10], 15);
Where do I belong challenge. So far this code is working for some of the examples, however I need it to be sorted into numerical order rather than unicode. I read up on it but I can't come up with a clear code for it.
Joseph
@revisualize
Mar 12 2017 07:24
@andrewlikes how does the default .sort() work?
Andrew Shieh
@andrewlikes
Mar 12 2017 07:25
by unicode standards
Joseph
@revisualize
Mar 12 2017 07:25
@andrewlikes What?
Andrew Shieh
@andrewlikes
Mar 12 2017 07:26
Unicode Character set
Joseph
@revisualize
Mar 12 2017 07:27
@andrewlikes Okay.
@andrewlikes Clearly you're smarter than I am.
@andrewlikes Good luck figuring that one out.
Because I had to apply a function to my sort
Andrew Shieh
@andrewlikes
Mar 12 2017 07:28
lol I was just answering your question to the best of my knowledge
The function that I used is on that page.
Andrew Shieh
@andrewlikes
Mar 12 2017 07:29
and yes I tried applying a function as well, but I didn't know how to chain the index part
  return arr.sort(function(a, b) {
    return a - b;
Joseph
@revisualize
Mar 12 2017 07:30
@andrewlikes You don't
@andrewlikes You don't return the sort. You need to return the indexOf
@andrewlikes If you want to use complete method chaining you have to use .concat() instead of .push()
But, you still need to apply a function to your .sort().
You can .sort().indexOf()
That's what I did.
Andrew Shieh
@andrewlikes
Mar 12 2017 07:36
oops lol
function getIndexToIns(arr, num) {

  //place num into arr
  arr.push(num);
  arr.sort(function(a, b) {
    return a - b;
  });
  return arr.indexOf(num);
}

getIndexToIns([2, 5, 10], 15);
there we go
@revisualize thx
CamperBot
@camperbot
Mar 12 2017 07:36
andrewlikes sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3492 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 12 2017 07:36
Again. you can chain the indexOf(). to the .sort()
Andrew Shieh
@andrewlikes
Mar 12 2017 07:37
still getting the hang of functions within functions
Joseph
@revisualize
Mar 12 2017 07:37
Lambda functions.
Andrew Shieh
@andrewlikes
Mar 12 2017 07:37
let me try
oh cool, thats much cleaner
Joseph
@revisualize
Mar 12 2017 07:40
@andrewlikes And you can use .concat() instead of .push() and turn it into a one liner
Enar Mariinsky
@Mariinsky
Mar 12 2017 07:48

function reverseString(str) {
var splitted = str.split("");
var reversed = splitted.reverse();
var joined = reversed.join("");
return joined;
}

reverseString("hello");

anyone could give me feedback on this?
Jor
@joreyesl
Mar 12 2017 07:49
@Mariinsky the logic is there, but you can just chain them
Enar Mariinsky
@Mariinsky
Mar 12 2017 07:50
@joreyesl yeah exactly my thoughts. Could you give me example how to chain? Not sure about the syntax rules
@joreyesl Found the solution on mdn. thanks for the help!
CamperBot
@camperbot
Mar 12 2017 07:53
mariinsky sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 588 | @joreyesl |http://www.freecodecamp.com/joreyesl
Enar Mariinsky
@Mariinsky
Mar 12 2017 07:53
var reversed = str.split("").revese().join("");
Jor
@joreyesl
Mar 12 2017 07:56

@Mariinsky ok good, i was typing something up, but +1 for looking up the docs yourself!
Also another tip, you can just return the expression instead of having to assign it to a variable.
Ex:

function add(num1,num2) {
  var sum = num1+num2;
  return sum;
}

just return the expression.

function add(num1,num2) {
  return num1+num2;
}
Enar Mariinsky
@Mariinsky
Mar 12 2017 07:57
@joreyesl Thank you for a great tip! this cleans up the code even more.
CamperBot
@camperbot
Mar 12 2017 07:57
mariinsky sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:warning: mariinsky already gave joreyesl points
patrickfrank
@patrickfrank1
Mar 12 2017 08:05
@hakimi1999 @joreyesl thanks i got it now; but my solution seems to be unnecessary complex, i think there must be an easier way...
function destroyer(arr) {
  // Remove all the values
  var i = 1;
  var args = Array.from(arguments);
  var tmp = arr;
  while(i<args.length){
    idx = tmp.indexOf(args[i]);
    while(idx!=-1){
      tmp = tmp.filter(function(val){return tmp.indexOf(val)!=idx;});
      idx = idx = tmp.indexOf(args[i]);
    }
    i++;
  }
  return tmp;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
CamperBot
@camperbot
Mar 12 2017 08:05
patrickfrank1 sends brownie points to @hakimi1999 and @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 277 | @hakimi1999 |http://www.freecodecamp.com/hakimi1999
:cookie: 589 | @joreyesl |http://www.freecodecamp.com/joreyesl
Muhammad Hakimi Shahrul Azmi
@hakimi1999
Mar 12 2017 08:07
You're welcome, @patrickfrank1 :smile:
Joseph
@revisualize
Mar 12 2017 08:07
@patrickfrank1 There is.
@patrickfrank1 But, done is better than perfect.
Markus Kiili
@Masd925
Mar 12 2017 08:10
@patrickfrank1 For better solutions, post in https://gitter.im/FreeCodeCamp/CodeReview
patrickfrank
@patrickfrank1
Mar 12 2017 08:12
thanks everyone!
ArhaanAhmad
@ArhaanAhmad
Mar 12 2017 08:22
what am i doing wrong here

//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[i][1].hasOwnProperty(firstname)){

  return cantacts[i].prop;
}
else{
  return "No such property";
}

}

// Only change code above this line
}

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

This is from challenge 216
Joseph
@revisualize
Mar 12 2017 08:29
@ArhaanAhmad Re: return cantacts[i].prop;
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];
@ArhaanAhmad Re: contacts[i][1].hasOwnProperty(firstname))
For this lesson that will never be true. Because contacts[i][1] doesn't exist.
@ArhaanAhmad Re: contacts.length() ... Not correct syntax.