These are chat archives for FreeCodeCamp/HelpJavaScript

29th
Jan 2017
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 00:00
@flyblackbox ... u are just calling the <p> element in the DOM ... and adding a listening event to it . that when there is a click event run this callback function
Tyler Moeller
@TylerMoeller
Jan 29 2017 00:01
@flyblackbox Is your starting color black? If so, change the last one to blue or something. The code runs fast, probably too fast for you to see red.
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 00:02
@flyblackbox ... it's also best practice to keep your script away from your markup
xemexpress
@xemexpress
Jan 29 2017 00:11
Hi guys, I am doing Falsy Bouncer.
https://www.freecodecamp.com/challenges/falsy-bouncer
Should I really pass the value to a Boolean object for testing? Or there is another way out?
Jor
@joreyesl
Jan 29 2017 00:14
@xemexpress of course there are multiple ways out, thats just the most concise.
Cindy Xiong
@cindyx123
Jan 29 2017 00:15
@Lumexralph are you on?
David Morales
@davmor94
Jan 29 2017 00:22
Hey guys, how can I use a JSON file thats on my local computer on Codepen? Like how do I upload it?
ekiriano
@ekiriano
Jan 29 2017 00:22
hello ,please do someone know if it is possible to reset a algorithm challenge without been on the actual page of the challenge , because when i go to the 'sum all prime algo' it keeps freezing without me actualy running my code
xemexpress
@xemexpress
Jan 29 2017 00:24
@joreyesl creating an object is the most concise? Why not directly put the target into if(condition) for test?
Jor
@joreyesl
Jan 29 2017 00:27
@xemexpress whats your code?
Basanth Narra
@narraboss
Jan 29 2017 00:27
hello friends i am here to learn the coding like the real time i am about to grad by next may by that time i must be prepared for the job and crack the interview. thank you friends
xemexpress
@xemexpress
Jan 29 2017 00:29
@narraboss welcome:)

@joreyesl I've passed it~

function bouncer(arr) {
// Don't show a false ID to this bouncer.
arr = arr.filter(function(val) {
if(val) {
return true;
}
}
);
return arr;
}

David Morales
@davmor94
Jan 29 2017 00:30
Anyone working on the Weather challenge? I'd like to work with someone :D
Louis Girifalco
@flyblackbox
Jan 29 2017 00:30
@joreyesl I am using JSFiddle and trying to get it to ruin. The text just turns green and then stays green upon further clicks
Run*
xemexpress
@xemexpress
Jan 29 2017 00:31
actually when do we need to create a new boolean object?
it seems a bit redundant? (coz we can tell true from false by if statement) Am I wrong?
Jor
@joreyesl
Jan 29 2017 00:33
@flyblackbox can you link the JS fiddle?
@xemexpress .filter takes a function. You were not creating a boolean object. You were passing in Boolean as a function. Rather than defining your own anonymous function that returns true/false, you can just passed in the Boolean function making it more concise.
Juwdohr
@Juwdohr
Jan 29 2017 00:42
has any one used the datatype declarations? Could of been spelled dataType?
Hello911
@Hello911
Jan 29 2017 00:45
var string=[["t","w","o"],["t","e","a"]];
console.log(string.length());
Computer says there is no such function as string.length(); why?
Stephen James
@sjames1958gm
Jan 29 2017 00:46
@Hello911 string is an array - but length is a property not a function
nathanthai
@nathanthai
Jan 29 2017 00:47
test
Tyler Moeller
@TylerMoeller
Jan 29 2017 00:47
@flyblackbox It works fine, it just goes too fast. You'd need to slow it down to see the color changes. http://jsfiddle.net/ub890kg1/4/
Hello911
@Hello911
Jan 29 2017 00:48
@sjames1958gm What does that mean? I am dumb. Could you plz explain?
Louis Girifalco
@flyblackbox
Jan 29 2017 00:48
@TylerMoeller I want it to change each time I click it, not all at once
Stephen James
@sjames1958gm
Jan 29 2017 00:48
@Hello911 it is string.length - not string.length()
Hello911
@Hello911
Jan 29 2017 00:48
OHHHH.
Oh myyy
Thanks @sjames1958gm
CamperBot
@camperbot
Jan 29 2017 00:49
hello911 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5589 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Tyler Moeller
@TylerMoeller
Jan 29 2017 00:51
@flyblackbox Ahh, then use an array of colors, and make textState the index for that array:
<p id="text" onClick="myFunction()">word</p>
<script>
  var textState = 0;
    var colors = ['green', 'red', 'black'];

  function myFunction() {
      document.getElementById('text').style.cssText = 'color: ' + colors[textState];
      textState += 1;
    }
</script>
nathanthai
@nathanthai
Jan 29 2017 00:51
Can anyone explain what exactly the madlibs challenge is asking for? I don't see why my code won't work
```

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

  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
Moisés Man
@moigithub
Jan 29 2017 00:52
@nathanthai u not using myAdverb parameter
u should use all 4 parameters
nathanthai
@nathanthai
Jan 29 2017 00:52
like, I don't know if I am supposed to make a sentence or what
the directions aren't really clear
xemexpress
@xemexpress
Jan 29 2017 00:52
@joreyesl Thank you!
CamperBot
@camperbot
Jan 29 2017 00:52
xemexpress sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 391 | @joreyesl |http://www.freecodecamp.com/joreyesl
Stephen James
@sjames1958gm
Jan 29 2017 00:53
@nathanthai YOu are close just use myAdverb as well.
xemexpress
@xemexpress
Jan 29 2017 00:53
I put it this way
arr = arr.filter(function(val){
return Boolean(val);
});
please correct me if i misused it. thanks
john94
@lpy1994
Jan 29 2017 00:53
hello guys
I am kind of stuck at a FCC js challenge called “ Missing letters”.
nathanthai
@nathanthai
Jan 29 2017 00:54
lol, thanks @moigithub & @sjames1958gm
CamperBot
@camperbot
Jan 29 2017 00:54
nathanthai sends brownie points to @moigithub and @sjames1958gm :sparkles: :thumbsup: :sparkles:
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 00:54
@lpy1994 .. ok
CamperBot
@camperbot
Jan 29 2017 00:54
:star2: 2623 | @moigithub |http://www.freecodecamp.com/moigithub
:star2: 5590 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
john94
@lpy1994
Jan 29 2017 00:54
please allow me send the code

```function fearNotLetter(str) {
var strSpl = str.split("");
var arr1 = [];
var arr2 =[];

for(var i = 0; i < strSpl.length; i++){
arr1.push(str.charCodeAt(i));
}

for(var x = arr1[0]; x <= arr1[arr1.length - 1]; x++){
arr2.push(x);
}

for(var y = 0; y < arr2.length; y++)
if(arr1.indexOf(arr2[y]) > -1){
return "undefined";
} else {
return String.fromCharcode(arr2[y]);
}

}

fearNotLetter("abce");

function fearNotLetter(str) {
 var strSpl = str.split("");
  var arr1 = [];
  var arr2 =[];

  for(var i = 0; i < strSpl.length; i++){
      arr1.push(str.charCodeAt(i));
  }

  for(var x = arr1[0]; x <= arr1[arr1.length - 1]; x++){
    arr2.push(x);
  }

  for(var y = 0; y < arr2.length; y++)
   if(arr1.indexOf(arr2[y]) > -1){
     return "undefined";
   } else {
     return String.fromCharcode(arr2[y]);
   }



}

fearNotLetter("abce");
Stephen James
@sjames1958gm
Jan 29 2017 00:55
@xemexpress You can reduce this to arr.filter(Boolean);
because Boolean is a function which is what filter expects.
john94
@lpy1994
Jan 29 2017 00:55
it supposed to show the missing letter, in this case. it should return “d”;
xemexpress
@xemexpress
Jan 29 2017 00:56
@sjames1958gm wooo, thanks A LOT!
CamperBot
@camperbot
Jan 29 2017 00:56
xemexpress sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5591 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
john94
@lpy1994
Jan 29 2017 01:02
anybody???
jamesjd54
@jamesjd54
Jan 29 2017 01:05

im trying to do the title case challenge, ive gotten this far but am obviously missing the second part of every word. should I start over or could you guys refer me to a few things i could sneak in there to keep the rest of the words?

function titleCase(str) {
var lString=str.toLowerCase();
var lArray=lString.split(" ");
for (var i=0;i<lArray.length;i++){
lArray[i]=lArray[i][0].toUpperCase();
}
var cStr=lArray.join(" ");
return cStr;
}

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

john94
@lpy1994
Jan 29 2017 01:07
@jamesjd54 try to use replace method.
and then return array with join method.
Stephen James
@sjames1958gm
Jan 29 2017 01:11
@jamesjd54 YOu have to add back in the last part of the string.
john94
@lpy1994
Jan 29 2017 01:12
@sjames1958gm help me please
Stephen James
@sjames1958gm
Jan 29 2017 01:12
@lpy1994 YOur code is overly complex - you really only need one loop - or two if you use that arr1
@lpy1994 set a variable to the charCodeAt(0) and then increment that variable until it doesn't match the current character or the loop ends
ShiveringCode
@ShiveringCode
Jan 29 2017 01:14
blob
blob
john94
@lpy1994
Jan 29 2017 01:14
@sjames1958gm are you a web developer ??
ShiveringCode
@ShiveringCode
Jan 29 2017 01:14
oops
stuck on that challenge, not sure what the instructions are asking me to do, or what numbers to use
Juwdohr
@Juwdohr
Jan 29 2017 01:16
@ShiveringCode create an algorithim to change the temp from F to C.
Anh Nguyen
@tiremon112
Jan 29 2017 01:16
use the formular they provide to convert it
Amit Patel
@AmitP88
Jan 29 2017 01:17
hey guys, I'm trying to setup my containers to create a dynamic menu for a restaurant website and I need a little help.
here are my container variables
menuContainer.png
Joseph
@revisualize
Jan 29 2017 01:19
@ShiveringCode It's asking you to do math with a variable.
Amit Patel
@AmitP88
Jan 29 2017 01:19
what i'm trying to do in the picture is place the 3 variables indicated in red in the HTMLdishInfoContainer variable where %data% is. my question is, how do I replace the %data% in the HTMLdishInfoContainer variable with multple variables?
ShiveringCode
@ShiveringCode
Jan 29 2017 01:21
so something like var sum = 10 + 10;?
xemexpress
@xemexpress
Jan 29 2017 01:23

hey guys, I am doing "Seek and Destroy"
https://www.freecodecamp.com/challenges/seek-and-destroy
What's wrong with my code? It doesn't get the answer.

Here is my code:
function destroyer(arr) {
var target = arr.filter(function(val){
for (var i = 1; i < arguments.length; i++) {
return val != arguments[i];
}
});
return target;
}

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

Spyrantis Theodoros
@thodorisanta
Jan 29 2017 01:25
I have to calculate the Smallest Common Multiple beetween the given numbers. How am i suppose to uproach this?

function smallestCommons(arr) {
  var x = Math.max(arr[0],arr[1]);
  var z = Math.min(arr[0],arr[1]);

  for(var i=0;i<x;i++){
    arr[i] = i+1;
  }


  return arr;
}


smallestCommons([1,5]);
Jor
@joreyesl
Jan 29 2017 01:25
@ShiveringCode you're summing 2 literal numbers. In that challenge they are passing in a value as an argument and you need to use the function parameter to convert it.
ex: lets say I was converting from celcius to kelvin instead, then I would do var kelvin = celsius + 273.15
Sean Kelly
@spkellydev
Jan 29 2017 01:26
Sup everyone
could someone help me understand this ternary operator for a FizzBuzz game?
for(i=1;i<=20;i++) {
console.log(((i%3)?(i%5)?i:'Buzz':(i%5)?'Fizz':'FizzBuzz'));
};
David Amanze
@GodKingShogun
Jan 29 2017 01:27
can someone tell me if my code looks right. i am on the weather project. i want to filter my api so it only returns the key main
$.getJSON("http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metrics&APPID=6b5216c389dc27fe53457d96bc7aae93", function(json) {
    json=json.filter(function(key){
      return (key==="main");
Joseph
@revisualize
Jan 29 2017 01:29
@spkellydev Do you know what the ternary operator is?
Sean Kelly
@spkellydev
Jan 29 2017 01:30
Yea, I get how I could use it in this case:
i%3 ===0:"true string":"false string"
but I don't understand stacking the ?'s
whoops
? instead of the first :
i%3 ===0?"true string":"false string"
Jor
@joreyesl
Jan 29 2017 01:31
@xemexpress your loop returns on the first iteration always. try enclosing the return statement with an if statement. if(val === arguments[i]) {return false;} then after the loop just have a return true;
Joseph
@revisualize
Jan 29 2017 01:31
@spkellydev Great.
@spkellydev So, it is just a ternary operator with a ternary operator inside of it.
Sean Kelly
@spkellydev
Jan 29 2017 01:32
oh
Moisés Man
@moigithub
Jan 29 2017 01:32
@GodKingShogun FIRST thing u need to know.. is , function(json) { <-- WHAT datatype contain that json variable
that will let u know.. what kind of methods u can use to handle that data...
array methods (like filter)
or object methods
or string methods.. etc
Joseph
@revisualize
Jan 29 2017 01:33
@spkellydev The true is a ternary operator ... and the false is another ternary operator
David Amanze
@GodKingShogun
Jan 29 2017 01:33
@moigithub idk. it wasn't explained properly in the lesson :worried:
Moisés Man
@moigithub
Jan 29 2017 01:34
@GodKingShogun $.getJSON("http://api.openweathermap.org/data/2.5........... <-- thats an URL.. u can open any url on ur web.browser
and INSPECT the data
Sean Kelly
@spkellydev
Jan 29 2017 01:34
I just don't understand why it evaluates the Fizz before the Buzz,
console.log(((i%3)?(i%5)?i:'Buzz':(i%5)?'Fizz':'FizzBuzz'));
David Amanze
@GodKingShogun
Jan 29 2017 01:34
@moigithub im following
Moisés Man
@moigithub
Jan 29 2017 01:34
@GodKingShogun or use console.log(json) and check on devtools
Sean Kelly
@spkellydev
Jan 29 2017 01:35
does the Buzz:(i%5) become the second evaluation before Fizzbuzz because it has the conditional attached
David Amanze
@GodKingShogun
Jan 29 2017 01:36
@moigithub the url goes to a multidimensional object
Ayobami
@purpose50
Jan 29 2017 01:36

Hi guys, can someone please tell me why this code is not working..it is nont passsing the last test..
Sum all the prime numbers up to and including the provided number.

A prime number is defined as a number greater than one and having only two divisors, one and itself. For example, 2 is a prime number because it's only divisible by one and two.

The provided number may not be a prime.

sumPrimes(10) should return a number.
sumPrimes(10) should return 17.
sumPrimes(977) should return 73156.

function sumPrimes(num) {
  var prime = [];
  for(i = 2; i <= num; i++) {
    if(i == 2 || i == 3 || i == 5 || i == 7) {
      prime.push(i);
    }else {
        if(i % 2 === 0 || i % 3 === 0 || i % 4 === 0 || i % 5 === 0 || i % 7 === 0) {
          continue;
        }else {
          prime.push(i);
        }

    }//end else
  }//end for
  num = prime.reduce(function(prev, curr) {
    return prev + curr;
  }, 0); 

  return num;
}

sumPrimes(977);
Moisés Man
@moigithub
Jan 29 2017 01:36
ok.. IF its an object.. then u can NOT use filter on it @GodKingShogun cuz filter is an array method
Sean Kelly
@spkellydev
Jan 29 2017 01:37
@purpose50 did you try rewriting the else into an else if first
might clean it up a bit
Hello911
@Hello911
Jan 29 2017 01:39

function titleCase(str) {

  var string=str.split(" ");

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

}

  return string;
}

titleCase("I'M A liTtle tEa pot");
Why is the function returning a array of words, unchanged from the string? How should I make the toLowerCase() method work?
Moisés Man
@moigithub
Jan 29 2017 01:39
@GodKingShogun thats an object with a lot of properties/nested object inside...
https://i.gyazo.com/16e77c0c7fc81c96f33740c47ea1af2e.png
David Amanze
@GodKingShogun
Jan 29 2017 01:40
@moigithub that makes a lot of sense. thanks. so i would have to use bracket notation to access the temp
CamperBot
@camperbot
Jan 29 2017 01:40
godkingshogun sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 2625 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Jan 29 2017 01:40
@GodKingShogun if u recall this exercise.. it might help https://www.freecodecamp.com/challenges/accessing-nested-objects
Natalia Ramos
@NataliaRamos
Jan 29 2017 01:42
Escape the string will not accept my answer. var myStr = 'FirstLine\n\\SecondLine\\\rThirdline'; The test I am not passing is myStr should have encoded text with the proper escape sequences and no spacing.
Ayobami
@purpose50
Jan 29 2017 01:42
@spkellydev i don't understand what you just said
Hello911
@Hello911
Jan 29 2017 01:42
I GOT IT NOW
Moisés Man
@moigithub
Jan 29 2017 01:42
@NataliaRamos line with uppercase L on third
Natalia Ramos
@NataliaRamos
Jan 29 2017 01:43
Thanks @moigithub
CamperBot
@camperbot
Jan 29 2017 01:43
nataliaramos sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 2626 | @moigithub |http://www.freecodecamp.com/moigithub
David Amanze
@GodKingShogun
Jan 29 2017 01:45
@moigithub would this be more appropiate
 $.getJSON("http://ip-api.com/json",function(){
  $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metrics&APPID=6b5216c389dc27fe53457d96bc7aae93", function(json) {
    json=json.main.temp;
    });
    });
Ogundele Olumide
@Lumexralph
Jan 29 2017 01:49
@purpose50 one way you can do that is to check if any number less than that number can divide through the number except one, if any then it's not prime but if no number then it's prime
David Amanze
@GodKingShogun
Jan 29 2017 01:52
@moigithub still there
after looking at it i think it would be more appropriate if i return there so it would go like this
  $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metrics&APPID=6b5216c389dc27fe53457d96bc7aae93", function(json) {
    return json.main.temp;
    });
    });
Juwdohr
@Juwdohr
Jan 29 2017 01:54
has anyone ever used dataType to declare a Data Type?
David Amanze
@GodKingShogun
Jan 29 2017 01:54
@Juwdohr everyone is on lunch break :smile:
xemexpress
@xemexpress
Jan 29 2017 01:59
@joreyesl what do you mean by returns on the first iteration? var i gets increment each time each time?
@joreyesl it still doesn't work.. why?
for (var i = 1; i < arguments.length; i++) {
if (val === arguments[i]) {
return false;
}
return true;
}
David Amanze
@GodKingShogun
Jan 29 2017 02:03
@xemexpress what are you supposed to be doing
xemexpress
@xemexpress
Jan 29 2017 02:05
@GodKingShogun Hi, I am doing "Seek and Destroy"

Now my code is:

function destroyer(arr) {
var target = arr.filter(function(val){
for (var i = 1; i < arguments.length; i++) {
if (val === arguments[i]) {
return false;
}
return true;
}
});
return target;
}

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

But it doesn't work

Aj Broman
@Bromana
Jan 29 2017 02:06
can someone give me a hand with passing the local/global scope portion of javascript?
no matter what I do, I just can't continue to the next lesson.. maybe I'm doing something wrong
David Amanze
@GodKingShogun
Jan 29 2017 02:07
@Bromana post what you have so far
Aj Broman
@Bromana
Jan 29 2017 02:07

function myLocalScope() {
'use strict';
var myVar = 20;

console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

// Now remove the console log line to pass the test

xemexpress
@xemexpress
Jan 29 2017 02:08
@GodKingShogun do you have any idea?
Aj Broman
@Bromana
Jan 29 2017 02:08
I've tried everything X_X
Maybe I'm just missing something basic here I'm not really sure, I've declared the variable local to the function, then I followed instructions to remove the console.log line
xemexpress
@xemexpress
Jan 29 2017 02:09
@Bromana which part you don't understand then?
Aj Broman
@Bromana
Jan 29 2017 02:10
Nothing, I totally understand this lesson, I just can't continue on to the next because it's saying I'm wrong
But I don't see where lol
Ogundele Olumide
@Lumexralph
Jan 29 2017 02:10
@Bromana try reloading your page
Aj Broman
@Bromana
Jan 29 2017 02:10
I did a few times, and reset the code too
Ogundele Olumide
@Lumexralph
Jan 29 2017 02:11
@Bromana removed all the console. log statements?
Aj Broman
@Bromana
Jan 29 2017 02:11
yep
welp
Did it again and it worked that time
That was like 6 times w the same code ~_~ </3
Ogundele Olumide
@Lumexralph
Jan 29 2017 02:12
@Bromana it worked now, right?
Aj Broman
@Bromana
Jan 29 2017 02:12
Yeah, worked that time. Maybe cause my wifi is being buggy IDK that was weird
mitron6
@mitron6
Jan 29 2017 02:15
@Bromana probably not your wifi. The version that I saw had two console.log statements. Only supposed to have one inside the function.
Aj Broman
@Bromana
Jan 29 2017 02:15
No yeah that was the default code they gave me, I just wanted to include all of it when I pasted it in here
I had both of them removed on my end.
anyway I appreciate it
That would've bugged me forever x)
Colin Bell
@Sacs
Jan 29 2017 02:20
@xemexpress to be honest it looks like you have the filter and the for mixed up, I'd want to filter the array for one argument, then the next suggesting my filter is within a for loop. Does that make sense?
David Amanze
@GodKingShogun
Jan 29 2017 02:21
@Sacs are you good with apis :smile:
api's
Jor
@joreyesl
Jan 29 2017 02:22
@xemexpress still now working? I missed 1 thing, arguments inside your loop refers to the arguments of the anonymous function. In this case we want the arguments object of the function. To get around that, we need to assign arguments to var so that we can use it inside our nested function.
function destroyer(arr) {
 var args = arguments;
 var target = arr.filter(function(val){
 for (var i = 1; i < args.length; i++) {
  if (val === args[i]) {
   return false;
  }
  return true;
}
});
return target;
}
David Amanze
@GodKingShogun
Jan 29 2017 02:24
@joreyesl lol you just disappeared
can you take a look at my code thus far
$.getJSON("http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metrics&APPID=6b5216c389dc27fe53457d96bc7aae93", function(json) {
    return json.main.temp;
    });
    });
Colin Bell
@Sacs
Jan 29 2017 02:26
is "metrics" the right units? Not "metric"
Ken Aguilar
@piq9117
Jan 29 2017 02:26
@GodKingShogun having trouble with your code above?
David Amanze
@GodKingShogun
Jan 29 2017 02:26
@piq9117 im asking to see if it is correct
Ken Aguilar
@piq9117
Jan 29 2017 02:26
do you wanna be programmtic with your lattitude and longitude?
David Amanze
@GodKingShogun
Jan 29 2017 02:27
@piq9117 ?
Jor
@joreyesl
Jan 29 2017 02:27
@GodKingShogun srry, i gtg, but someone else here can probably help better than I can. Also you can go to that link and see what the json returns. In this case I got an error saying city not found.
http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metrics&APPID=6b5216c389dc27fe53457d96bc7aae93
Ken Aguilar
@piq9117
Jan 29 2017 02:29
lat={lat}
is lat inside the curly brace a variable ur trying to pass in?
David Amanze
@GodKingShogun
Jan 29 2017 02:29
@joreyesl thats because lon and lat are params. i have another api above that to determine the lon and lat
Ken Aguilar
@piq9117
Jan 29 2017 02:29
you should look into template strings
David Amanze
@GodKingShogun
Jan 29 2017 02:29
this is the whole thing
  $.getJSON("http://ip-api.com/json",function(){
  $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metrics&APPID=6b5216c389dc27fe53457d96bc7aae93", function(json) {
    return json.main.temp;
    });
    });
Juwdohr
@Juwdohr
Jan 29 2017 02:30
Has anyone used datatype to declare a type for the next object in an array
David Amanze
@GodKingShogun
Jan 29 2017 02:31
@piq9117 is my code correct
Ayush Bahuguna
@relentless-coder
Jan 29 2017 02:32
@GodKingShogun I'm afraid not because lat and lon are variables, so you can't really put them inside the ""
also, use https
Ken Aguilar
@piq9117
Jan 29 2017 02:32
it doesnt look like it.. are you trying to access the openweather api? what else are you trying to do with that function?
David Amanze
@GodKingShogun
Jan 29 2017 02:33
@relentless-coder thats how the weather app api had it
Ken Aguilar
@piq9117
Jan 29 2017 02:34
const hello = 'hello';
const greeting = `{hello} everybody`; // using back ticks
// 'hello everybody'
David Amanze
@GodKingShogun
Jan 29 2017 02:34
@piq9117 all i want to do is get the temp in Celsius and display it on my page and then i will want to be able to click the temp and change it to fahrenheit
Ken Aguilar
@piq9117
Jan 29 2017 02:35
okay lets figure it out one step at a time..
Ayush Bahuguna
@relentless-coder
Jan 29 2017 02:36
@GodKingShogun how are you getting values for {lat} and {lon}?
Ken Aguilar
@piq9117
Jan 29 2017 02:36
so what you wanna do is access that api end point and see if returns something
David Amanze
@GodKingShogun
Jan 29 2017 02:37
@relentless-coder from the api above it. someone confirmed that it would work
Ken Aguilar
@piq9117
Jan 29 2017 02:37
try using that end point and paste in your browser
David Amanze
@GodKingShogun
Jan 29 2017 02:37
@relentless-coder the api above gets the lat and lon and applies it to the open weather api to get the weather and such
Ken Aguilar
@piq9117
Jan 29 2017 02:38
you will see that will not return anything because it will need the lattitude and longitude
Ayush Bahuguna
@relentless-coder
Jan 29 2017 02:38
@GodKingShogun no but, how are you retrieving the values? You haven't passed any parameters to the callback function after the ip-api call.
David Amanze
@GodKingShogun
Jan 29 2017 02:38
@piq9117 i thought it would. how do i fix it
Ken Aguilar
@piq9117
Jan 29 2017 02:39
try going to the openweather api and just put in a city
let me try it
Ayush Bahuguna
@relentless-coder
Jan 29 2017 02:39
@GodKingShogun to the first callback function pass in the data that you receive from ip-api, and then extract lat and lon from that data and use it for open weather
David Amanze
@GodKingShogun
Jan 29 2017 02:40
@relentless-coder :worried: and how do i do that
Ayush Bahuguna
@relentless-coder
Jan 29 2017 02:41
$.getJSON("http://ip-api.com/json",function(data){
  var lat = data.lat //just an example
 var lon = data.lon //just an example
  $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metrics&APPID=6b5216c389dc27fe53457d96bc7aae93", function(json) {
    return json.main.temp;
    });
    });
you passed 'json' parameter to the second api call. Do you know why you did that?
David Amanze
@GodKingShogun
Jan 29 2017 02:42
@relentless-coder so i get that you are using dot notation to access the lat and lon but what does data mean
@relentless-coder i didn't do that. that is how open weather had the api.
Ayush Bahuguna
@relentless-coder
Jan 29 2017 02:43
@GodKingShogun data is parameter, and it can have any name, but it refers to the data that you receive from ip-api call
@GodKingShogun see that's wrong. Don't want to sound rude, but how much do you know about AJAX and API calls?
I'd say that you should look up a little bit on AJAX. won't take more than an hour. Search "the net ninja" on youtube, he has good content on AJAX. :)
David Amanze
@GodKingShogun
Jan 29 2017 02:45
@relentless-coder barely. there were three lessons on it and they were vague about it. i know why lat and lon are in the open weather api. depending on the value, that is where the temperature will be taken
temperature and other data but i only need temperature
jds61403
@jds61403
Jan 29 2017 02:46
I cannot pass the "Understanding Uninitialized Variables" challenge, can anyone help. What's wrong with my code? Thanks in advance!

// Initialize these three variables
var a = 5;
var b = 10;
var c = "i am a";

// Do not change code below this line

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

David Amanze
@GodKingShogun
Jan 29 2017 02:46
what are you suppose to do @jds61403
jds61403
@jds61403
Jan 29 2017 02:47
Initialize the three variables a, b, and c with 5, 10, and "I am a" respectively so that they will not be undefined.
@GodKingShogun Initialize the three variables a, b, and c with 5, 10, and "I am a" respectively so that they will not be undefined.
David Amanze
@GodKingShogun
Jan 29 2017 02:47
@jds61403 make sure i is capitalized
jds61403
@jds61403
Jan 29 2017 02:48
@GodKingShogun That worked lol. Thanks so much!
CamperBot
@camperbot
Jan 29 2017 02:48
jds61403 sends brownie points to @godkingshogun :sparkles: :thumbsup: :sparkles:
:cookie: 77 | @godkingshogun |http://www.freecodecamp.com/godkingshogun
Ayush Bahuguna
@relentless-coder
Jan 29 2017 02:49
@GodKingShogun then you should definitely take some time out to learn AJAX because it's an important part of web development. once you'd understand it then API calls would be eazy peezy
David Amanze
@GodKingShogun
Jan 29 2017 02:50
@jds61403 :+1:
@relentless-coder okay will check it out :smile:
Ayobami
@purpose50
Jan 29 2017 02:59

Hi guys i have been stuck with this please help, what is wrong with my code..the last test is not passing
Sum all the prime numbers up to and including the provided number.

A prime number is defined as a number greater than one and having only two divisors, one and itself. For example, 2 is a prime number because it's only divisible by one and two.

The provided number may not be a prime.

sumPrimes(10) should return a number.
sumPrimes(10) should return 17.
sumPrimes(977) should return 73156.

function sumPrimes(num) {
  var prime = [];
  for(i = 2; i <= num; i++) {
    if(i == 2 || i == 3 || i == 5 || i == 7) {
      prime.push(i);
    }else {
        if(i % 2 === 0 || i % 3 === 0 || i % 4 === 0 || i % 5 === 0 || i % 7 === 0) {
          continue;
        }else {
          prime.push(i);
        }

    }//end else
  }//end for
  num = prime.reduce(function(prev, curr) {
    return prev + curr;
  }, 0); 

  return num;
}

sumPrimes(977);

Hi guys i have been stuck with this please help, what is wrong with my code..the last test is not passing
Sum all the prime numbers up to and including the provided number.

A prime number is defined as a number greater than one and having only two divisors, one and itself. For example, 2 is a prime number because it's only divisible by one and two.

The provided number may not be a prime.

sumPrimes(10) should return a number.
sumPrimes(10) should return 17.
sumPrimes(977) should return 73156.

function sumPrimes(num) {
  var prime = [];
  for(i = 2; i <= num; i++) {
    if(i == 2 || i == 3 || i == 5 || i == 7) {
      prime.push(i);
    }else {
        if(i % 2 === 0 || i % 3 === 0 || i % 4 === 0 || i % 5 === 0 || i % 7 === 0) {
          continue;
        }else {
          prime.push(i);
        }

    }//end else
  }//end for
  num = prime.reduce(function(prev, curr) {
    return prev + curr;
  }, 0); 

  return num;
}

sumPrimes(977);
RobsonPhoenix
@RobsonPhoenix
Jan 29 2017 03:03
function largestOfFour(arr) {

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

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Why is this only returning the first array? I can't get it...
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:04
@RobsonPhoenix ... that what return does
it will iterate once and stop
RobsonPhoenix
@RobsonPhoenix
Jan 29 2017 03:04
Humm
Ow... thanks!
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:05
but u are all most there
RobsonPhoenix
@RobsonPhoenix
Jan 29 2017 03:05
@mindsworth Thank you... now I think I got it
CamperBot
@camperbot
Jan 29 2017 03:05
robsonphoenix sends brownie points to @mindsworth :sparkles: :thumbsup: :sparkles:
:cookie: 249 | @mindsworth |http://www.freecodecamp.com/mindsworth
Matthew
@mtphil
Jan 29 2017 03:05
is there any way anyone knows to use ES6 in the Algorithim Challenges ? i’m returning to my previous solutions and trying to update them into ES6 for practice but it’s returning warning/errors
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:06
@RobsonPhoenix ... if u need more help let me know ok
RobsonPhoenix
@RobsonPhoenix
Jan 29 2017 03:07
Ok, thanks ^^
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:07
@RobsonPhoenix .. ok
Matthew
@mtphil
Jan 29 2017 03:07
NVM, it seems to be working now…strange.
Aj Broman
@Bromana
Jan 29 2017 03:16
Jw, how much do you guys work through a day? I sit here for like 10 hours sometimes but I feel like I don't retain S:
Brian
@BrianCodes33
Jan 29 2017 03:16
anyone mind helping me w/ a simple algorithm
Ayush Bahuguna
@relentless-coder
Jan 29 2017 03:25
@BrianCodes33 you just ask it away. don't wait for permission :)
Aaditya Chitnis
@hawkthegamer
Jan 29 2017 03:27
hello everybody. i am confused as to what we have to do in the testing objects for properties of Java. can someone please help me?
is anybody there?
Brian
@BrianCodes33
Jan 29 2017 03:29

Write a function which returns the number of digits in any number with more than 21 digits. If the function is passed a string or a number with 21 or fewer digits it should return "wrong input".

function getNumberLength(n){
  if (n.length >= 21) {
  return n.length;
} 
  return 'wrong input';
}
Test Results:Expected: 28, instead got: 'wrong input'
✔ Test Passed: Value == 'wrong input’

anyone know why this first test won’t work?

Dylan Hsiao
@greedylan
Jan 29 2017 03:34

if I have two arrays

var arr1 = [1, 2, 3];
var arr2 = [5, 2, 1, 4];

how do I delete items 1 and 2 respectively in both arrays considered they are duplicated?

var arr1 = [3];
var arr2 = [5, 4];
Joseph
@revisualize
Jan 29 2017 03:35
Hey.
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:37
@revisualize ... any idea .... chunkArrayInGroups
Joseph
@revisualize
Jan 29 2017 03:41
@mindsworth Write out the problem on paper
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:41
@mindsworth ... ok
then what?
Joseph
@revisualize
Jan 29 2017 03:43
Start writing code.
What do you mean then what?
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:44
give me insight
Joseph
@revisualize
Jan 29 2017 03:44
Dude.
@mindsworth What do you want from me?
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:44
have being trying to figure it out
Joseph
@revisualize
Jan 29 2017 03:44
What do you have?
I can't help you if you can't help yourself.
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:45
good
Joseph
@revisualize
Jan 29 2017 03:45
If you ask an arbitrary contrived question.. You'll get an arbitrary and contrived answer.
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 03:46
i want to loop through the array
and use the iteration to slice it and push into an empty declared array
what do u think?
@revisualize ... am waiting
Joseph
@revisualize
Jan 29 2017 03:56
I think...
"Talk is cheap. Show me the code." - Linus Torvalds, (2000-08-25).
Brian
@BrianCodes33
Jan 29 2017 04:02
@mindsworth just start writing code and console logging stuff.
Ken Haduch
@khaduch
Jan 29 2017 04:03
@BrianCodes33 - I don't think that you can take .length of a number - are the values that are being passed to your function integer values ( as opposed to string values?)
Brian
@BrianCodes33
Jan 29 2017 04:03
yes int values @khaduch
Ken Haduch
@khaduch
Jan 29 2017 04:06
@BrianCodes33 - so, I don't think that you can take .length of a number. You can try to convert it to a string value? Then you should be able to .length it?
Brian
@BrianCodes33
Jan 29 2017 04:07
i just did that
function getNumberLength(n){
  var conversion = n.toString();
  if (conversion.length >= 21) {
  return conversion.length;
} 
  return 'wrong input';
}
Ken Haduch
@khaduch
Jan 29 2017 04:12
@BrianCodes33 - hmmmm - it is getting represented as a float number, at least when I run in the debugger. I put this really long numeric value 100010001000100010001000100010001000 and after .toString() it shows up as 1.000100010001e+35
@BrianCodes33 - so it's probably running into the MAXINT value that can be represented? I don't know what you do once you get beyond that?
Brian
@BrianCodes33
Jan 29 2017 04:14
it just wants me to return the length
Ken Haduch
@khaduch
Jan 29 2017 04:16
@BrianCodes33 - but if you cannot actually process an integer with more than about 16 digits, then you won't be able to handle it. http://www.2ality.com/2012/07/large-integers.html - check this article, it is describing what I'm seeing. It says that you have to use string values, and that would mean that it would have to be a string only - you cannot represent a really huge integer straight away?
Brian
@BrianCodes33
Jan 29 2017 04:22
i am using string values
Minoy
@minoy
Jan 29 2017 04:23

Hello! I am a bit stuck with the 'Falsy Bouncer' algorithm challenge. Following is the current code:

function bouncer(arr) {

  for (var i = 0; i < arr.length;i++){
    if (Boolean(arr[i]) === false){
      arr.splice(arr.indexOf(arr[i]),1);
    } 
    }  
 return arr;
  }


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

I am not able to understand why only one iteration is happening in the for loop. Any idea?
Current output is [7, "ate", false, 9]

Ken Haduch
@khaduch
Jan 29 2017 04:24
@BrianCodes33 - then what you have should work, no? Maybe I'm slightly confused.
Ogundele Olumide
@Lumexralph
Jan 29 2017 04:25
@minoy why don't you try filter?
@cindyx123 i am now
@mindsworth okay, safe trip
Minoy
@minoy
Jan 29 2017 04:26
@Lumexralph Hi Ogundele, Yes I intend to do that after I solve this version of the code. I do realise that the challenge expects us to use array.filter().
Ogundele Olumide
@Lumexralph
Jan 29 2017 04:26
@minoy okay
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 04:27
thanks
Ogundele Olumide
@Lumexralph
Jan 29 2017 04:27
@minoy why don't you splice at i ?
@minoy this arr.indexOf(arr[i]) is same as iteration i cos it's the index of the element in the array
Minoy
@minoy
Jan 29 2017 04:31
@Lumexralph Yes, you are right. That does simplify the code. But the output is still the same. Only one iteration happening.
Ken Haduch
@khaduch
Jan 29 2017 04:34
@BrianCodes33 - this is exactly the problem we are talking about - any number that is larger than a certain value will be displayed with exponential notation. - my first guess, after reaading their description, is that you would have to recognize that - converting the number to a string you would see that it contains a value such as 1.000100010001e+35 This means 35 decimal places, so you might just be able to count the number of digits to the left of the decimal point, and then add the count of those digits with the value of the exponent? I can't think of any other way that it is going to work?
Minoy
@minoy
Jan 29 2017 04:35
@Lumexralph Ok, got it!
Ogundele Olumide
@Lumexralph
Jan 29 2017 04:36
@minoy when you splice the array, it reduces the length of the array and that updates arr length
Ken Haduch
@khaduch
Jan 29 2017 04:36
@BrianCodes33 - for example, the value they show 7005623021525000000000000000 is converted to the floating point representation 7.005623021525e+27 - so it is 1 whole number digit and 27 decimal places, therefore the length is 28.
Ogundele Olumide
@Lumexralph
Jan 29 2017 04:37
@minoy so that approach needs some lil logic if you insist on trying that method
Minoy
@minoy
Jan 29 2017 04:37
@Lumexralph Yes, I figured it out :)
@Lumexralph Now, I will try to solve using array.filter()
@Lumexralph Thanks for your help!
CamperBot
@camperbot
Jan 29 2017 04:38
minoy sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 886 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Jan 29 2017 04:47
@minoy :smile:
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 04:52
@Lumexralph /smile/ thanks
CamperBot
@camperbot
Jan 29 2017 04:52
mindsworth sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 887 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Jan 29 2017 04:52
@mindsworth :smile:
:clap:
checkmate-bitch
@checkmate-bitch
Jan 29 2017 05:00
function pairElement(str) {
  var arr = [];
  str = str.split("").forEach(function(item){
      if(item === "G") arr.push(["G","C"]);
        else if(item === "C") arr.push(["C","G"]);
        else if(item === "A") arr.push(["A","T"]);
        else arr.push(["T","C"]);
 });
 console.log(arr);  
 return arr;
}
Can someone please help me. I'm stuck on DNA pair strand intermediate problem where we get a string and have to return a 2-D array. I can't see what I'm doing wrong.
Ogundele Olumide
@Lumexralph
Jan 29 2017 05:02
@checkmate-bitch what error are you getting?
checkmate-bitch
@checkmate-bitch
Jan 29 2017 05:03
@Lumexralph there's no error. Just says the answer is wrong for some reason.
Ogundele Olumide
@Lumexralph
Jan 29 2017 05:03
@checkmate-bitch what test did it fail?
checkmate-bitch
@checkmate-bitch
Jan 29 2017 05:04
@Lumexralph All :( . IDK what the problem is. It's giving me the answer in the console. And returning a 2-d array
Ogundele Olumide
@Lumexralph
Jan 29 2017 05:06
@checkmate-bitch what is your function to output?
what are the instructions?
checkmate-bitch
@checkmate-bitch
Jan 29 2017 05:09
@Lumexralph for the function call pairElement("GCG");
For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]]
And if it's "A" then return ["A", "T"]
if "T" return ["T", "A"]
@Lumexralph problem solved man. Sorry. Inserting the wrong pair. My bad
Ogundele Olumide
@Lumexralph
Jan 29 2017 05:13
@checkmate-bitch okay, cool you got it cos it looked okay
Joseph
@revisualize
Jan 29 2017 05:35
This :poop: is :skull:
agesmith52
@agesmith52
Jan 29 2017 05:43
can someone give me a hand with an exercise?
Manish Giri
@Manish-Giri
Jan 29 2017 05:44
@agesmith52 which one
agesmith52
@agesmith52
Jan 29 2017 05:44
stand in line
Joseph
@revisualize
Jan 29 2017 05:44
@agesmith52 What you got?
Manish Giri
@Manish-Giri
Jan 29 2017 05:44
@agesmith52 what's the problem?
agesmith52
@agesmith52
Jan 29 2017 05:44
just what is given im just confused
Joseph
@revisualize
Jan 29 2017 05:45
@agesmith52 It shouldn't be.
@agesmith52 Look.
@agesmith52 Stand In Line is a great lesson.
@agesmith52 You really need to look past the extra shit
@agesmith52 And just focus on the problem at hand.
@agesmith52 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) { }
That is done.
agesmith52
@agesmith52
Jan 29 2017 05:46
yeah
Joseph
@revisualize
Jan 29 2017 05:46
Now you need to remember the array is arr
The number is item
Both of those are parameters.
agesmith52
@agesmith52
Jan 29 2017 05:47
yup
Joseph
@revisualize
Jan 29 2017 05:47
@agesmith52 and Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).
@agesmith52 So then it is simple.
@agesmith52 How do you add a number to the end of the array?
iootbob
@iootbob
Jan 29 2017 05:48
hello can anybody help me in 'returning largest numbers in arrays'?
agesmith52
@agesmith52
Jan 29 2017 05:48
is it .appendTo()?
Joseph
@revisualize
Jan 29 2017 05:48
@agesmith52 No.
agesmith52
@agesmith52
Jan 29 2017 05:48
.push
?
Joseph
@revisualize
Jan 29 2017 05:48
There you go.
agesmith52
@agesmith52
Jan 29 2017 05:49
aha
Joseph
@revisualize
Jan 29 2017 05:49
@agesmith52 But, really HOW.. You need to be specific.
@agesmith52 Do you see how the problem becomes a lot easier when you cut the extra shit out?
agesmith52
@agesmith52
Jan 29 2017 05:50
pushing item to the end of the array
Joseph
@revisualize
Jan 29 2017 05:50
@agesmith52 Exactly.
@agesmith52 But, that's not the code.. You need to code it up.
agesmith52
@agesmith52
Jan 29 2017 05:52
item = arr.push('item');
?
Joseph
@revisualize
Jan 29 2017 05:52
@agesmith52 Quotes define strings.
Why overwrite the parameter item?
agesmith52
@agesmith52
Jan 29 2017 05:53
i have to return item though
Joseph
@revisualize
Jan 29 2017 05:53
@agesmith52 No.. NO you don't
@agesmith52 You have to CHANGE that LINE
agesmith52
@agesmith52
Jan 29 2017 05:54
im confused
Joseph
@revisualize
Jan 29 2017 05:54
@agesmith52 You have to return the element that was removed from the array (arr)
@agesmith52 How/Why? You are in control of the code 100%
You don't HAVE to return item; You can erase that line and write something else.
And you should.
agesmith52
@agesmith52
Jan 29 2017 05:56
return arr instead?
Joseph
@revisualize
Jan 29 2017 05:56
@agesmith52 NO.
Chase
@Athabasco
Jan 29 2017 05:56
Joseph
@revisualize
Jan 29 2017 05:56
Read the directions.
@agesmith52 You need to do something else. after you push the number (as a variable) to the end of the array.
Lợi Nguyễn Văn
@warcraft034
Jan 29 2017 05:56
How should I do to remove all non-alphanumeric characters in a tring
string
Joseph
@revisualize
Jan 29 2017 05:56
@warcraft034 By keeping all alphanumeric characters

@agesmith52 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?

The push() method adds one or more elements to the end of an array and returns the new length of the array.

The pop() method removes the last element from an array and returns that element.

The shift() method removes the first element from an array and returns that element.

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

....
Anyhow.
I'm at a bar.
I need to get my to the pool table.
:v:
Lợi Nguyễn Văn
@warcraft034
Jan 29 2017 05:58
I want to use String.prototype.replace()
Manish Giri
@Manish-Giri
Jan 29 2017 05:58
@agesmith52 there are just two steps really - add a number to the end of the array using .push(), then remove and return the first element with .shift().
heroiczero
@heroiczero
Jan 29 2017 05:59
@warcraft034 use regexp
Lợi Nguyễn Văn
@warcraft034
Jan 29 2017 06:01
oh
agesmith52
@agesmith52
Jan 29 2017 06:06
whats wrong with this
testArr = arr.push(item);
testArr = arr.shift();
return testArr;
jcllevado-gc
@jcllevado-gc
Jan 29 2017 06:09
@agesmith52 i think you don't need to do testArr = arr.push(item); because it doesn't return anything
you can just write it like arr.push(item);
arr.push(item);
testArr = arr.shift();
return testArr;
agesmith52
@agesmith52
Jan 29 2017 06:11
didnt work
same results
jcllevado-gc
@jcllevado-gc
Jan 29 2017 06:12
what output do you want to get? I want to see your array too.. and the item your pushing
agesmith52
@agesmith52
Jan 29 2017 06:13
var testArr = [1,2,3,4,5];
is the array
Chase
@Athabasco
Jan 29 2017 06:14
@agesmith52 Firstly, do you know what a queue is? Answer this before trying to make one.
agesmith52
@agesmith52
Jan 29 2017 06:14
yeah its like an ordered list of things to do
iootbob
@iootbob
Jan 29 2017 06:17
'''test'''
CamperBot
@camperbot
Jan 29 2017 06:17
:bulb: to format code use backticks! ``` more info
iootbob
@iootbob
Jan 29 2017 06:17
test
can somebody help me with the "return largest numbers in arrays"?
jcllevado-gc
@jcllevado-gc
Jan 29 2017 06:18
I see! so you want to output the first element like queue does..
arr.reverse();
arr.pop();
iootbob
@iootbob
Jan 29 2017 06:19
function largestOfFour(arr) {
  var highestNum;
  var storedArr;

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

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

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
jcllevado-gc
@jcllevado-gc
Jan 29 2017 06:19
it's stack in nature but when it is reverse then it behave like queue
arr.push(item);
arr.reverse();
testArr = arr.pop();
return testArr;
idk if that well work
just a hunch
iootbob
@iootbob
Jan 29 2017 06:22
I'm tryng to iterate through the sub arrays and pop() each one.
which I've each sored from lowest to highest
jcllevado-gc
@jcllevado-gc
Jan 29 2017 06:23
let i = 0;
while(i < arr.length){
arr.reverse();
arr.pop();
arr.reverse();
i++;
}
try that
oopz.. I guest that didn't work either
iootbob
@iootbob
Jan 29 2017 06:25
hehe yep..
Ghulam Shabir
@ghulamshabir
Jan 29 2017 06:37
@iootbob pop shrinks the array, you can just use arr.length in while loop condition when array becomes empty it's length will be zero which is a falsy and loop will stop then
wade
@wadejnu
Jan 29 2017 06:39

// Setup
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
]
},
1245: {
artist: "Robert Palmer",
tracks: [ ]
},
5439: {
album: "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function update(id, prop, value) {
if(value !==''&& prop !='tracks')
collectionCopy[id][prop].push(value);
//else if(value !==''&&prop == 'tracks')collectionCopy[id][prop].push(value);
//else if(value === '') delete collectionCopy[id][prop];
return collectionCopy;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");

why the "push" cant work?
Jor
@joreyesl
Jan 29 2017 06:41
@iootbob after you sort the array, you should pop the last one, otherwise you are setting a[i] to the sorted array.
for(i = 0; i < arr.length; i++){
     arr[i] = arr[i].sort(function(a,b){return a-b;}).pop();
  }
iootbob
@iootbob
Jan 29 2017 06:43
oh I see, I misplaced where the pop() was supposed to be.
Niels3030
@niels3030
Jan 29 2017 06:44
w/ Multi-Dimensional arrays, do I use Zero-based indexing, Right to Left?
Jor
@joreyesl
Jan 29 2017 06:44
@niels3030 yes all arrays start at index 0, left to right I belive tho.
Ghulam Shabir
@ghulamshabir
Jan 29 2017 06:44
@niels3030 yeah always zero based unless you want to skip first element
Niels3030
@niels3030
Jan 29 2017 06:45
@joreyesl @ghulamshabir Thank you!!! just needed to reaffirm my suspicions.
CamperBot
@camperbot
Jan 29 2017 06:45
niels3030 sends brownie points to @joreyesl and @ghulamshabir :sparkles: :thumbsup: :sparkles:
:cookie: 392 | @joreyesl |http://www.freecodecamp.com/joreyesl
:star2: 1763 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
Ghulam Shabir
@ghulamshabir
Jan 29 2017 06:45
@niels3030 but for multi dim arrays will need multiple indices to get values from subarrays
iootbob
@iootbob
Jan 29 2017 06:46
since I couldn't find a way with pop() earlier I tried sorting through the arrays from highest to lowest and returning the 0 index of each array.
Jor
@joreyesl
Jan 29 2017 06:46
@iootbob that works too :thumbsup:
Niels3030
@niels3030
Jan 29 2017 06:47
multiple indexes to get value from sub-arrays....Thank you, I like to at least try and 'Fully comprehend what I'm working on. @ghulamshabir
Ghulam Shabir
@ghulamshabir
Jan 29 2017 06:49
@niels3030
yeah for example arr = [[1,2], [3, 4]], you will need two loops to iterate over it, then arr[i][j] will get you values from subarrays
Niels3030
@niels3030
Jan 29 2017 06:51
@ghulamshabir Thank you! your very helpful & that totally makes sense pal! thx
CamperBot
@camperbot
Jan 29 2017 06:51
niels3030 sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:warning: niels3030 already gave ghulamshabir points
Ghulam Shabir
@ghulamshabir
Jan 29 2017 06:52
@niels3030 you are welcome :smile:
Niels3030
@niels3030
Jan 29 2017 06:53
@ghulamshabir I read somewhere 'Engineers try to understand the problem, and 'Developers sometime's find solution and try to understand later. I want to think like an 'Engineer as much as I can....
Ghulam Shabir
@ghulamshabir
Jan 29 2017 06:57
@niels3030 yeah should be an Engineer atleast in basics. when things become complex later then practicing will be the key
Niels3030
@niels3030
Jan 29 2017 06:58
@ghulamshabir Couldn't have said it better...
Aymen Bareche
@aym3nb
Jan 29 2017 07:24
hey guys, i'm on rot13 challange, my code works with every letter except E,B,C it doesn't decode them, anyone who faced the same problem?
rot13("SERR PBQR PNZC");
result : FEEE CBDE CAMC
Ghulam Shabir
@ghulamshabir
Jan 29 2017 07:31
@aym3nb your code ?
Aymen Bareche
@aym3nb
Jan 29 2017 07:33
@ghulamshabir function rot13(str) {
var decoded="";
for(var i=0; i<str.length; i++){ if( (str.charCodeAt(i)-13>=65 &&str.charCodeAt(i)-13<=90) || (str.charCodeAt(i)-13>=97 &&str.charCodeAt(i)-13<=122)){
decoded+=String.fromCharCode(str.charCodeAt(i)-13);
}else{
decoded+=str[i];
}
}
return decoded;
}
Ghulam Shabir
@ghulamshabir
Jan 29 2017 07:34
@aym3nb you should not subtract 13 in if conditions
Aymen Bareche
@aym3nb
Jan 29 2017 07:35
@ghulamshabir no it's okay, i tried without it n still the same result
Ghulam Shabir
@ghulamshabir
Jan 29 2017 07:39
@aym3nb the idea is to check for characters A-M and N-Z in if conditions then swap them so A-M becomes N-Z and vice versa, keep the characters beyond those characters the same
Robert Purcea
@RobertPurcea
Jan 29 2017 07:41
How do you do multiple inheritance in javascript
?
Aymen Bareche
@aym3nb
Jan 29 2017 07:42
@ghulamshabir aaaah just from A-M and N-Z
@ghulamshabir thanks man you are the best (y)
CamperBot
@camperbot
Jan 29 2017 07:42
aym3nb sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1764 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
Ghulam Shabir
@ghulamshabir
Jan 29 2017 07:45
@aym3nb :+1:
BHASKAR KANDARI
@hackbook001
Jan 29 2017 07:48
Problem in Stand in Line

function nextInLine(arr, item) {
// Your code here
var nextInline = item;
testArr.push(nextInline);
testArr.shift();
console.log(testArr);
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));

nextInLine([2], 1) should return 2

nextInLine([5,6,7,8,9], 1) should return 5

Tyler Moeller
@TylerMoeller
Jan 29 2017 07:49
@Robertb4 Whoa, you're moving right along with your learning :)
Have you learned about proxy objects yet? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
Ghulam Shabir
@ghulamshabir
Jan 29 2017 07:50
@hackbook001 you should use arr instead of testArr, push item not nextInline
Robert Purcea
@RobertPurcea
Jan 29 2017 07:50
I've heard of them, but I haven't learned about them yet
BHASKAR KANDARI
@hackbook001
Jan 29 2017 07:53
@ghulamshabir error
Ghulam Shabir
@ghulamshabir
Jan 29 2017 07:54
post the code
Robert Purcea
@RobertPurcea
Jan 29 2017 07:59
class Walker {
    walk() {
        console.log("I am walking");
    }
}
class Runner {
    run() {
        console.log("I am running");
    }
}

// Make a class that inherits only the run and walk functions
Let's say I want to make another custom class that has ONLY the walk and run functions. How do I do this using es6 classes?(no copying, I want them to be inherited)
@TylerMoeller
BHASKAR KANDARI
@hackbook001
Jan 29 2017 08:00

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

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

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

Ghulam Shabir
@ghulamshabir
Jan 29 2017 08:02
@hackbook001 var nextInline = item; is not needed, just push item and shift returns the removed element you should return that not just item
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:02
@hackbook001 you can check this out
function nextInLine(arr, item) {
// Your code here
var nextInline = item;
arr.push(nextInline);
arr.reverse();
item = arr.pop();
arr.reverse();
console.log(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));
nextInLine([2], 1); //should return 2
nextInLine([5,6,7,8,9], 1); //should return 5
improvisation on queue like operation
idk if that will work but you can try it dev console
Ghulam Shabir
@ghulamshabir
Jan 29 2017 08:06
@jcllevado-gc why reverse ? just for removing first element ? you should use .shift instead of that reverse and pop thingy
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:06
yeah shift will remove the first element but it doesn't output the removed element
it's just that javascript have an easy way of doing stack and stack is a reverse operation of queue
Ghulam Shabir
@ghulamshabir
Jan 29 2017 08:07
@jcllevado-gc item = arr.pop(); can be done for .shift as well like this item = arr.shift()
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:08
i see.. i haven't thought of that..
that's nice @ghulamshabir
@ghulamshabir thanks
CamperBot
@camperbot
Jan 29 2017 08:08
jcllevado-gc sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1765 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:09
updated *
unction nextInLine(arr, item) {
// Your code here
var nextInline = item;
arr.push(nextInline);
item = arr.shift();
console.log(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));
nextInLine([2], 1); //should return 2
nextInLine([5,6,7,8,9], 1); //should return 5
Ghulam Shabir
@ghulamshabir
Jan 29 2017 08:10
@jcllevado-gc if you run your version of reverse and pop and this version with .shift in benchmarking website you will see the difference in run time of them
BHASKAR KANDARI
@hackbook001
Jan 29 2017 08:10
syntax error
unction :p
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:10
yeah.. I can see that
sorry @hackbook001 hehe
BHASKAR KANDARI
@hackbook001
Jan 29 2017 08:10
not working
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:11
Before: [1,2,3,4,5]
1
undefined
After: [2,3,4,5,6]
2
5
that is what i get..
Ghulam Shabir
@ghulamshabir
Jan 29 2017 08:13

@hackbook001

arr.push(item);
item = arr.shift();
return item

or simply

arr.push(item);
return arr.shift();
BHASKAR KANDARI
@hackbook001
Jan 29 2017 08:13
ok
thanks @ghulamshabir and @jcllevado-gc
CamperBot
@camperbot
Jan 29 2017 08:14
hackbook001 sends brownie points to @ghulamshabir and @jcllevado-gc :sparkles: :thumbsup: :sparkles:
:cookie: 102 | @jcllevado-gc |http://www.freecodecamp.com/jcllevado-gc
:star2: 1766 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 08:15
hey guys i need help
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
i want access the "maps and assign it to the variable gloveBoxContents. tried this but is not working.\
var gloveBoxContents = "myStorage.car.inside["glove box"]";
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:21
@snaps23 remove "" on var gloveBoxContents
var gloveBoxContents = myStorage.car.inside["glove box"];
Pablo Arcia
@freakaziod210
Jan 29 2017 08:21
Hello, I have some code challenges that a friend gave me and I just want some guidance. I think I know how to do them but I want someone to bounce my ideas off of so that I can figure it out. Can anyone help me?
Manish Giri
@Manish-Giri
Jan 29 2017 08:21
@freakaziod210 sup
Pablo Arcia
@freakaziod210
Jan 29 2017 08:21
Hey
What I need to do is make some text display as a > symbol as you type it
jcllevado-gc
@jcllevado-gc
Jan 29 2017 08:22

@snaps23
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
var gloveBoxContents = myStorage.car.inside["glove box"];

console.log(gloveBoxContents);

Pablo Arcia
@freakaziod210
Jan 29 2017 08:22
I have a video if that doesn’t make sense
Manish Giri
@Manish-Giri
Jan 29 2017 08:24
where at
Pablo Arcia
@freakaziod210
Jan 29 2017 08:32
Can anyone help me?
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 08:39
it worked, thanks @jcllevado-gc
CamperBot
@camperbot
Jan 29 2017 08:39
snaps23 sends brownie points to @jcllevado-gc :sparkles: :thumbsup: :sparkles:
:cookie: 103 | @jcllevado-gc |http://www.freecodecamp.com/jcllevado-gc
sorry, brb
ronald
@ronstarcool
Jan 29 2017 09:08
back
anyone idea's?
kaustubh
@kausgit
Jan 29 2017 09:08
in counting cards challenge...i used below code....but not working

var count = 0;

function cc(card) {
// Only change code below this line
if(card==2||card==3||card==4||card==5||card==6)
count++;
else if(card==10 || card=='J'||card=='Q'||card=='K'||card=='A')
count--;

if(count>0)
console.log(count+" Bet");
else console.log(count+" Hold");
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Oh ignore i got this
Ming
@MingHill
Jan 29 2017 09:18
im confused how to convert Celsius to fahrenheit
Niels3030
@niels3030
Jan 29 2017 09:19
@MingHill got you brosif
Ming
@MingHill
Jan 29 2017 09:19
thanks
I just learned about operators and stuff but im confused how to use them

function convertToF(celsius) {
var fahrenheit;
farenheit *= 5/9;
farenhit += 32;

// Only change code below this line

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

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

Niels3030
@niels3030
Jan 29 2017 09:20
fahrenheit = celsius;
fahrenheit *= 9/5
fahrenheit += 32; @MingHill
Ming
@MingHill
Jan 29 2017 09:21
alright thanks ill try that i just didnt put the fahrenheit = celsius part
Niels3030
@niels3030
Jan 29 2017 09:21
and leave (30) in the input field. @MingHill
that one was hard for me too, the instructions were a little vague. @MingHill
Ming
@MingHill
Jan 29 2017 09:22
thanks
Niels3030
@niels3030
Jan 29 2017 09:23
did it work? @MingHill
ronald
@ronstarcool
Jan 29 2017 09:23
maybe i should redo the oop stuff
Ming
@MingHill
Jan 29 2017 09:24
it says that the celcius is not defined
Vantrav
@vantrav
Jan 29 2017 09:24
help pasting code
CamperBot
@camperbot
Jan 29 2017 09:24
no wiki entry for: pasting code
Vantrav
@vantrav
Jan 29 2017 09:25
help code
CamperBot
@camperbot
Jan 29 2017 09:25
no wiki entry for: code
Vantrav
@vantrav
Jan 29 2017 09:25
code here
Ming
@MingHill
Jan 29 2017 09:27
i got the first answer to work for me but i dont know whats wrong with he rest
Niels3030
@niels3030
Jan 29 2017 09:28

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

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

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

@MingHill do it just like that.....
Ming
@MingHill
Jan 29 2017 09:29
this was my code

function convertToF(celsius) {
var fahrenheit;

// Only change code below this line
fahrenheit = celcius;
fahrenheit *= 5/9;
fahrenheit += 32;

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

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

Niels3030
@niels3030
Jan 29 2017 09:29
@MingHill *= 9/5 like that
Ming
@MingHill
Jan 29 2017 09:30
oh i just had them switched
thanks a lot for helping me
Niels3030
@niels3030
Jan 29 2017 09:30
@MingHill exactly,,,,,, no prob!!!! that one was hard thank's to the explanation!
CamperBot
@camperbot
Jan 29 2017 09:30
niels3030 sends brownie points to @minghill :sparkles: :thumbsup: :sparkles:
:cookie: 86 | @minghill |http://www.freecodecamp.com/minghill
Niels3030
@niels3030
Jan 29 2017 09:31
@MingHill ha, it gave you the brownie points. lol
Ming
@MingHill
Jan 29 2017 09:31
what are brownie points?
ronald
@ronstarcool
Jan 29 2017 09:32
like karma
islamic
@Rashid123mehmood
Jan 29 2017 09:32
any body help me
Niels3030
@niels3030
Jan 29 2017 09:32
its when you tell someone thank you, and they add up, make you more powerful? makes people think your cool. lol
islamic
@Rashid123mehmood
Jan 29 2017 09:32
how to use ++ operator?
Ming
@MingHill
Jan 29 2017 09:33
oh lol
i think you used it as like
var a;
a ++;
and that just adds one
ronald
@ronstarcool
Jan 29 2017 09:34
a++
no space
Niels3030
@niels3030
Jan 29 2017 09:34
@Rashid123mehmood exactly choose a var such as y = ++
islamic
@Rashid123mehmood
Jan 29 2017 09:36

var myVar = 87;

myVar =++87+1; it is right or not

if not then how?
Niels3030
@niels3030
Jan 29 2017 09:36
@Rashid123mehmood no, its much easier
islamic
@Rashid123mehmood
Jan 29 2017 09:37
@niels3030 then tell me
Niels3030
@niels3030
Jan 29 2017 09:37
choose an actual math variable like y = ++yourVar;
@Rashid123mehmood simple as that.....
ronald
@ronstarcool
Jan 29 2017 09:38
go to console. type: var a = 1 (and press enter)
then type: a++
youll see
islamic
@Rashid123mehmood
Jan 29 2017 09:38
@niels3030 hy dude i don't understand how plz explain
Dennis
@pleabargain
Jan 29 2017 09:39
re: Generate Random Whole Numbers with JavaScript / it works on FCC but when I try to get the same code work on codepen it throws an undefined error: http://codepen.io/pleabargain/pen/YNEMBW?editors=0010 ... WHY?
Niels3030
@niels3030
Jan 29 2017 09:40
@Rashid123mehmood ok.. so first of all read it Right to left, that means 87 IS your variable, right? myVar = 87;
ronald
@ronstarcool
Jan 29 2017 09:40
where is the error @dennis
islamic
@Rashid123mehmood
Jan 29 2017 09:40
@niels3030 yes
Dennis
@pleabargain
Jan 29 2017 09:40
@ronstarcool you talking to me?
ronald
@ronstarcool
Jan 29 2017 09:41
ow, i see
yes Dennis
i see the problem
look at ur code
ur not putting in the result of the function, but the function itself
islamic
@Rashid123mehmood
Jan 29 2017 09:41
@niels3030 i read then now
ronald
@ronstarcool
Jan 29 2017 09:41
how do you get the result of the function?
Niels3030
@niels3030
Jan 29 2017 09:41
@Rashid123mehmood so now use an actual 'math variable, like 'y' = yourVar
Dennis
@pleabargain
Jan 29 2017 09:42
the console displays correct value but my document.write does not...
islamic
@Rashid123mehmood
Jan 29 2017 09:42
then now @niels3030
ronald
@ronstarcool
Jan 29 2017 09:42
type in ur console this: var h = function(){}
Niels3030
@niels3030
Jan 29 2017 09:42
@ronstarcool y = ++ yourVar;
ronald
@ronstarcool
Jan 29 2017 09:43
then type: h
h will return the function, as you had given it
do you see it?
Dennis
@pleabargain
Jan 29 2017 09:43
going to test now...
ronald
@ronstarcool
Jan 29 2017 09:43
but you dont want the function. you want the result óf the function. to do that, you call the function: you add the braces ()
islamic
@Rashid123mehmood
Jan 29 2017 09:43
@niels3030 thanks bro it's too easy thank alot of thanks
CamperBot
@camperbot
Jan 29 2017 09:43
rashid123mehmood sends brownie points to @niels3030 :sparkles: :thumbsup: :sparkles:
:cookie: 166 | @niels3030 |http://www.freecodecamp.com/niels3030
Dennis
@pleabargain
Jan 29 2017 09:44
CamperBot
@camperbot
Jan 29 2017 09:44
pleabargain sends brownie points to @ronstarcool :sparkles: :thumbsup: :sparkles:
:cookie: 359 | @ronstarcool |http://www.freecodecamp.com/ronstarcool
Niels3030
@niels3030
Jan 29 2017 09:44
@Rashid123mehmood I do that all the time! with JS you really have to pay attention to details
Dennis
@pleabargain
Jan 29 2017 09:45
@Rashid123mehmood I do that all the time! with JS you really have to pay attention to details can't say that often enough...
:)
ronald
@ronstarcool
Jan 29 2017 09:46
@pleabargain haha, np. you didnt have to name ur function 'h'. it was merly a test example to run in the console. but, it works :)
Dennis
@pleabargain
Jan 29 2017 09:46
@ronstarcool :) whatever works, right? :)
ronald
@ronstarcool
Jan 29 2017 09:46
document.write("The value is : " + randomWholeNum() + "<br/>");
@pleabargain to remove that work around
Dennis
@pleabargain
Jan 29 2017 09:47
it's just toy code..trying to to figure out how stuff works
Niels3030
@niels3030
Jan 29 2017 09:47
time for a smoke....
Dennis
@pleabargain
Jan 29 2017 09:47
@niels3030 don't do it... we want you to stick around a lot longer :)
@ronstarcool added your suggestion: http://codepen.io/pleabargain/pen/YNEMBW?editors=0010 Thanks again!
CamperBot
@camperbot
Jan 29 2017 09:48
pleabargain sends brownie points to @ronstarcool :sparkles: :thumbsup: :sparkles:
:warning: pleabargain already gave ronstarcool points
ronald
@ronstarcool
Jan 29 2017 09:49
awesome
ill get fat
Niels3030
@niels3030
Jan 29 2017 09:56
@pleabargain no worries, i've come along way.... taking bupropion, and it takes away the cravings so i don't smoke as much any more.. less and less
its 3am, I think i've put in about 7-8hrs of coding today... the time flies though...
time to crash with netflix, laters
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:00
Use Conditional Logic with If Statements

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

Problem :
trueOrFalse(true) should return "Yes, that was true"

trueOrFalse(false) should return "No, that was false"

Dennis
@pleabargain
Jan 29 2017 10:01
@niels3030 have a good one!
@hackbook001 please use for your code
three ` on the front and ` at the back
it makes the code easier to read
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:02
:(

'
// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

Isak La Fleur Engdahl
@isaklafleur
Jan 29 2017 10:02
Hello all! I have a problem. Cant remove the null element in the array in the exercise "Falsy Bouncer". Any one who know how to solve this?

function bouncer(arr) {
// Don't show a false ID to this bouncer.
var arrayNoFalsy = [];

for (var i=0; i < arr.length; i++) {
if (arr[i] === false || arr[i] === 0 || arr[i] === "" || arr[i] === undefined || arr[i] === null) {
console.log(arrayNoFalsy);
} else {
arrayNoFalsy.push(arr[i]);
}
}
return arrayNoFalsy;
}
//console.log(arrayNoFalsy);

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

Dennis
@pleabargain
Jan 29 2017 10:02
three `
back ticks NOT apostrophe
it's the ~ key / top left usually...
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:05
:/
Help me
CamperBot
@camperbot
Jan 29 2017 10:10
no wiki entry for: me
Joseph
@revisualize
Jan 29 2017 10:12
Hey!
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:12

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

ronald
@ronstarcool
Jan 29 2017 10:13
@isaklafleur you did remove NaN ?
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:13
@camperbot help

trueOrFalse(true) should return "Yes, that was true"

trueOrFalse(false) should return "No, that was false"

Joseph
@revisualize
Jan 29 2017 10:14
@hackbook001 Your text needs to be EXACT!
@hackbook001 It's not EXACT
islamic
@Rashid123mehmood
Jan 29 2017 10:16

@niels3030 Convert the assignments for a, b, and c to use the += operator.

help me

how to Convert the assignments for a, b, and c to use the += operator.
ronald
@ronstarcool
Jan 29 2017 10:18
@isaklafleur hows going? i cant fix it now myself.. :(
oh, fixed it
redoz94
@redoz94
Jan 29 2017 10:20
The jump from Object Oriented and Functional Programming to basic algorithm scripting seems a bit difficult. is there any advice on how to brush up stuff you should already know, before starting this set of challenges?
Johnny
@JohnnyBizzel
Jan 29 2017 10:21
@redoz94 You could watch some videos or look at W3Schools JS if you are not happy.
Dennis
@pleabargain
Jan 29 2017 10:22
@redoz94 I agree with @JohnnyBizzel ... sometimes it helps to pull back a little back to get some theory and then jump back in for coding... it's a mix/balance (IMHO)
Joseph
@revisualize
Jan 29 2017 10:23
@isaklafleur Why are you trying to recreate something that is built into JS?
ronald
@ronstarcool
Jan 29 2017 10:23
@isaklafleur are you logging ur results?
Isak La Fleur Engdahl
@isaklafleur
Jan 29 2017 10:24
@ronstarcool The output is: [7, "ate", 9, null, 9]
Joseph
@revisualize
Jan 29 2017 10:24

www.pythontutor.com/javascript.html <<<--- USE THIS TO VISUALIZE YOUR CODE EXECUTION.

ronald
@ronstarcool
Jan 29 2017 10:25
Number.isNaN(value)
redoz94
@redoz94
Jan 29 2017 10:25
@revisualize sweeeet was looking for something like that
@revisualize thanks
CamperBot
@camperbot
Jan 29 2017 10:25
redoz94 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3139 | @revisualize |http://www.freecodecamp.com/revisualize
redoz94
@redoz94
Jan 29 2017 10:26
@JohnnyBizzel any particular videos i should be looking at?
badalsaibo
@heyDante
Jan 29 2017 10:28
//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

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

  else {
    return "No such property";
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
What's wrong with this code?
Lesson: Profile Lookup
Joseph
@revisualize
Jan 29 2017 10:28
@heyDante You don't know the shape of your data.
adlad269
@adlad269
Jan 29 2017 10:28

hi guys. I need some help. I am trying toModify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=1; i < multiplyAll; i*multiplyAll)
// Only change code above this line
return product;
}

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

there is my code what am i doing wrong?

Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:28

Help with this, i'm realy stuck.
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr. here is my code
function multiplyAll(arr) {
var product = 1;

for(var i= 0; i<multiplyAll.length; i++){
for(var j= 0; j< multiplyAll[i].length; j++){
product * multiplyAll[i][j];
}
}

return product;
}

multiplyAll([1,[3,]]);

CamperBot
@camperbot
Jan 29 2017 10:28
no wiki entry for: with this im realy stuck modify function multiplyall so that it multiplies the product variable by each number in the sub-arrays of arr here is my code
badalsaibo
@heyDante
Jan 29 2017 10:29
@revisualize I didn't get you?
Joseph
@revisualize
Jan 29 2017 10:29
@heyDante What do you mean .. You don't get me...
@heyDante What is the shape of contacts?
badalsaibo
@heyDante
Jan 29 2017 10:29
@heyDante You don't know the shape of your data.
Joseph
@revisualize
Jan 29 2017 10:30
@heyDante What is the shape of your data?
badalsaibo
@heyDante
Jan 29 2017 10:30
Explain me
CamperBot
@camperbot
Jan 29 2017 10:30

:point_right: readme [wiki]

Depecrated Wiki!

This repo serves as an archive for the wiki and a place to report issues for our current wiki located in our forum!

Our open source community's Wiki focuses on answering your questions about learning to code and getting a coding job. We also cover in detail our:

  • Curriculum
  • Other Programming Languages
  • Local Group Communities
  • Nonprofit Projects and much more

:pencil: read more about readme on the FCC Wiki

adlad269
@adlad269
Jan 29 2017 10:31
hi guys. I need some help. I am trying toModify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=1; i < multiplyAll; i*multiplyAll)
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
there is my code what am i doing wrong?
Joseph
@revisualize
Jan 29 2017 10:31
@heyDante We have an array of objects representing different people in our contacts lists.
Example: var contacts = [ { ... } , { ... } , { ... } , { ... } ];
Darth Skywalker
@adityaparab
Jan 29 2017 10:31
function lookUpProfile(firstName, prop){
// Only change code below this line
  var contact = contacts.find(c => c.firstName === firstName);

  return contact ? contact.hasOwnProperty(prop) ? contact[prop] : 'No such property' : 'No such contact';
// Only change code above this line
}
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:31
@adlad269 then we all stuck at the same place.
adlad269
@adlad269
Jan 29 2017 10:31
ok
Darth Skywalker
@adityaparab
Jan 29 2017 10:31
ooops! wrong group
badalsaibo
@heyDante
Jan 29 2017 10:32
@revisualize Yes I got you.
adlad269
@adlad269
Jan 29 2017 10:33
anyone?
Joseph
@revisualize
Jan 29 2017 10:34
@adlad269
redoz94
@redoz94
Jan 29 2017 10:34
Thanks @Rafase282 for your help with Algorithm: Reverse a String
CamperBot
@camperbot
Jan 29 2017 10:34
redoz94 sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star2: 1453 | @rafase282 |http://www.freecodecamp.com/rafase282
Joseph
@revisualize
Jan 29 2017 10:35

Parameters are like variables that represent the values that get passed into your function from the function call.
https://cs.wellesley.edu/~cs110/lectures/L16/images/function-anatomy.png
Notice how the variables level and score in the function definition addScore are called parameters.
However, when we invoke the function like in:
addScore(3, 10) or addScore(6, 20)
the values are called arguments. Here is an important lesson:
You define a function with parameters, you call a function with arguments.

Another 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.

Yet another example code:

function addThree (num) {
    var result;
    result = num + 3;
    return result;
}

You can see how the parameter is used like a variable inside of the function.
And you can do mathematical operations to the parameter and assign the value to the variable result.

Other important things to remember:
* A function can have zero parameters. You still have to use the parentheses to define it.
* A function might have no return statements. In this case we say that the function returns undefined.

From knowing that please note that technically, calling parameters variables isn't correct. Parameters are part of the function declaration and when the function is called, an execution context is formed and there parameters are variables that hold the passed arguments.

adlad269
@adlad269
Jan 29 2017 10:35
thank you @revisualize I need some help. I am trying toModify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=1; i < multiplyAll; i*multiplyAll)
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
there is my code what am i doing wrong?
CamperBot
@camperbot
Jan 29 2017 10:35
adlad269 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3140 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jan 29 2017 10:35
@adlad269 You're not writing your for loop correctly.
@adlad269 Nor are you using the parameter correctly.
@adlad269 Your function is returning product
@adlad269 Maybe you should be modifying that before you return it.
adlad269
@adlad269
Jan 29 2017 10:36
thanks
Joseph
@revisualize
Jan 29 2017 10:36
:zzz: ... :sailboat: ... :zzz: ... :sailboat: :sunrise: ... :zzz: ... :sailboat: :tropical_fish: :sunrise: ... :zzz: ... :sailboat: :tropical_fish: :dolphin: :whale2: :sunrise: ... :zzz: l
:v:
adlad269
@adlad269
Jan 29 2017 10:38
@revisualize how is my for loop wrong exactly? i dont understand
Johnny
@JohnnyBizzel
Jan 29 2017 10:38
@redoz94 No, just look on YouTube. You will find a channel that suits you.
Aleksander Gębicki
@Takumar
Jan 29 2017 10:39
@adlad269 multiplyAll is name of your function, you cannot multiply by name
What do you expect this: i*multiplyAll do?
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:40

any help

Help with this, i'm realy stuck.
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr. here is my code
function multiplyAll(arr) {
var product = 1;

for(var i= 0; i<multiplyAll.length; i++){
for(var j= 0; j< multiplyAll[i].length; j++){
product * multiplyAll[i][j];
}
}

return product;
}

multiplyAll([[1],[3,]]);
any help

Aleksander Gębicki
@Takumar
Jan 29 2017 10:41
@adlad269 usually loop looks differently:
for (initial value of your index; end condition of loop;  incrementation of index) {
  // you do something inside your loop
}
adlad269
@adlad269
Jan 29 2017 10:41
ok thanks @Takumar
CamperBot
@camperbot
Jan 29 2017 10:41
adlad269 sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star2: 3472 | @takumar |http://www.freecodecamp.com/takumar
Aleksander Gębicki
@Takumar
Jan 29 2017 10:41
@snaps23 you should check length of your array not function!
Johnny
@JohnnyBizzel
Jan 29 2017 10:41
@snaps23 product * multiplyAll[i][j]; :x: product *= multiplyAll[i][j];
APURV SINGH
@apurvvv
Jan 29 2017 10:42
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var j=[];
  for(var i=0;i<arr.length;i++){
    var t=filter((arr[i]));
      j[i]=t;
    }
  return j;
}
function filter(value) {
  if(Boolean(value)===true) {
    return value;
  }
}
bouncer([7, "ate", "", false, 9]);
output is [7, "ate", "null","null",9]. please find error in the logic
Aleksander Gębicki
@Takumar
Jan 29 2017 10:42
@snaps23
for(var i= 0; i<arr.length; i++){
@JohnnyBizzel not exactly: product *= arr[i][j];
adlad269
@adlad269
Jan 29 2017 10:42
iis this right @Takumar for (var i=1; i < arr; i*arr);
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:43
@revisualize ?
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:43
@Takumar ok
Aleksander Gębicki
@Takumar
Jan 29 2017 10:43
@adlad269 you have three things:
var i  = 1;  // this is good
i < arr;   // this is not so good, because you check if number is less than array, but you should check if it is less than number of elements of array
\\ so better would be:
i < arr.length;
Johnny
@JohnnyBizzel
Jan 29 2017 10:44
@Takumar :smile: I mis-read the fact he is using recursion :exclamation:
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:44
@JohnnyBizzel great. work on that
adlad269
@adlad269
Jan 29 2017 10:44
ok thanks.
Aleksander Gębicki
@Takumar
Jan 29 2017 10:44
@JohnnyBizzel yes, but I don't think he tried to use recursion :-(
Johnny
@JohnnyBizzel
Jan 29 2017 10:45
;)
Chigoziem Nwaiwu
@mindsworth
Jan 29 2017 10:45
:fire:
Aleksander Gębicki
@Takumar
Jan 29 2017 10:45
@adlad269 the last element of your loop is changing value of index, if you don't change it it never ends
i*arr is not correct
maybe simple i++ is better?
adlad269
@adlad269
Jan 29 2017 10:46
is it arr*arr.length
sunny
@sunny7899
Jan 29 2017 10:46
hlo guys
adlad269
@adlad269
Jan 29 2017 10:46
i mean i*arr.length
sunny
@sunny7899
Jan 29 2017 10:46
i need some help
magiqfoxx
@magiqfoxx
Jan 29 2017 10:47

Hello :)
'function titleCase(str) {
str = str.split(" ");

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

str[i][0] = str[i][0].toUpperCase();

}
return str;
}

titleCase("I'm a little tea pot");'
Could anyone please explain why this is "TypeError: Cannot assign to read only property '0' of string 'I'm'"?

APURV SINGH
@apurvvv
Jan 29 2017 10:47
@Takumar help with my code above
badalsaibo
@heyDante
Jan 29 2017 10:47
function lookUpProfile(firstName, prop){
// Only change code below this line

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

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

        else {
          return "No such property";
        }

      // Only change code above this line
      }
}
@revisualize
sunny
@sunny7899
Jan 29 2017 10:47
in the word blanks game
Aleksander Gębicki
@Takumar
Jan 29 2017 10:47
@adlad269 when you write i * 2 it doesn't change value of i !
when you write i = i*2 it assigns value of i multiplied by 2 to the i variable
adlad269
@adlad269
Jan 29 2017 10:48
ohh I see
voxgranular
@voxgranular
Jan 29 2017 10:48
@apurvvv I believe there is a much more simple way of doing this - the key is to use filter() as a method on the arr and return whatever that returns
Aleksander Gębicki
@Takumar
Jan 29 2017 10:48
@adlad269 so the correct code would be:
for (i = 1; i <arr.length; i=i+1) { } or for(i=1; i< arr.length; i++) {}
because i++ adds 1 to the value of i variable and stores result in the variable
sunny
@sunny7899
Jan 29 2017 10:49

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");
help me in this i don't understand what to do

adlad269
@adlad269
Jan 29 2017 10:50
ok thanks but im tying to multiply will that code do that?
Aleksander Gębicki
@Takumar
Jan 29 2017 10:50
@sunny7899 you have to use parameters myNoun, myAdjective and rest to create sentence and store this sentence in result variable
@sunny7899 Remember that in sentence you have blank spaces between words, you have to add them
Vantrav
@vantrav
Jan 29 2017 10:50
Hello @Takumar
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:51
modified this product *= multiplyAll[i][j];
sunny
@sunny7899
Jan 29 2017 10:51
ok
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:51
stil not working
adlad269
@adlad269
Jan 29 2017 10:51
@Takumar would this multiply for (var i=1; i < arr.length; i=i*arr.length);
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:51

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "Yes, That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

Aleksander Gębicki
@Takumar
Jan 29 2017 10:52
@snaps23 multiplyAll is name of your function, use your array instead:
product *= arr[i][j] because you need to take every element from your array and multiply it by rest of elements
badalsaibo
@heyDante
Jan 29 2017 10:52
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

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

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

        else {
          return "No such property";
        }

      // Only change code above this line
      }
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Help!
lesson: Profile Lookup
Aleksander Gębicki
@Takumar
Jan 29 2017 10:52
@adlad269 I think you have to read about loops what they are meant for.
loop is only for creating sequence of elements:
1,2,3,4..... 15
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:52
help me
CamperBot
@camperbot
Jan 29 2017 10:52

:point_right: readme [wiki]

Depecrated Wiki!

This repo serves as an archive for the wiki and a place to report issues for our current wiki located in our forum!

Our open source community's Wiki focuses on answering your questions about learning to code and getting a coding job. We also cover in detail our:

  • Curriculum
  • Other Programming Languages
  • Local Group Communities
  • Nonprofit Projects and much more

:pencil: read more about readme on the FCC Wiki

BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:53

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "Yes, That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 10:53

@Takumar a bit confused here is my code now function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for(var i= 0; i<multiplyAll.length; i++){
for(var j= 0; j< multiplyAll[i].length; j++){
product *= multiplyAll[i][j];
}
}
// Only change code above this line
return product;
}

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

adlad269
@adlad269
Jan 29 2017 10:54
ok @Takumar but it is saying Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:54
???????????????????????????????????????/
tsjohns9
@tsjohns9
Jan 29 2017 10:54
Can anyone help me on how to put my code into this message box so it looks like it does when i type it?
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:55
No one can help me
Aleksander Gębicki
@Takumar
Jan 29 2017 10:56
@adlad269 you have 2 dimensional array, so you need two loop (two indices) to point to element of such array.
e.g. var arr = [ [1,7], [8,4]],
arr[0,0] have value 1 right?
so you have to multiply 1 * 7 * 8 * 4
it means arr[0,0] * arr[0,1] * arr[1,0] * arr[1,1]
BHASKAR KANDARI
@hackbook001
Jan 29 2017 10:56

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "Yes, That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "Yes, That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

// Only change code below this line.

// Only change code below this line.
var result = "Yes, That was ";
return result += wasThatTrue;

// Only change code above this line.

}

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

adlad269
@adlad269
Jan 29 2017 10:56
ok thanks @Takumar
CamperBot
@camperbot
Jan 29 2017 10:56
:warning: adlad269 already gave takumar points
adlad269 sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
Aleksander Gębicki
@Takumar
Jan 29 2017 10:57
@adlad269 so you have to multiply 1 * 7 * 8 * 4
it means arr[0,0] * arr[0,1] * arr[1,0] * arr[1,1]
@snaps23 please read my explanation for @adlad269
you have to multiply elements of your arr array!
@snaps23 product *= arr[i][j]; and please correct your loops!
Hi @vantrav
@hackbook001 I don't know what you are trying to do. Which challenge is it? (give me title) and please use backticks to format your code
Aleksander Gębicki
@Takumar
Jan 29 2017 11:02
@hackbook001 https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
It is easier to read large blocks of code
@tsjohns9 please read the link I gave: https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
You use three backticks before and after your code
it looks like that:
```
your code
```
your code
krishnauppalapati
@krishnauppalapati
Jan 29 2017 11:08
Concatenating Strings with the Plus Equals Operator
need help in this lesson
Aleksander Gębicki
@Takumar
Jan 29 2017 11:09
@heyDante you cannot say "No such contact" before you check every contact in your contacts array. So you can return such message only outside your loop!
Yakubu El-Rufai Mahatma
@snaps23
Jan 29 2017 11:11
@Takumar my problem was with the loop. rectified that prob. thank you
CamperBot
@camperbot
Jan 29 2017 11:11
snaps23 sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star2: 3474 | @takumar |http://www.freecodecamp.com/takumar
Pieter Stokkink
@forkerino
Jan 29 2017 11:11
Hello room!
Aleksander Gębicki
@Takumar
Jan 29 2017 11:11
@snaps23 good job :thumbsup: :-)
Hi @forkerino (I'm responding in name of whole room :-) )
Pieter Stokkink
@forkerino
Jan 29 2017 11:14
@Takumar :wave:
@krishnauppalapati What is the problem you encounter
?
badalsaibo
@heyDante
Jan 29 2017 11:15
@Takumar but the loop is going on for every individual array right?
Idowu Wasiu
@Hoxtygen
Jan 29 2017 11:17
And when trying to use the backtick (~) switch from chat mode to compose mode. It's better that way
Aleksander Gębicki
@Takumar
Jan 29 2017 11:18
@heyDante yes, you have to specify row and column of your array,
so you need two loops one will be iterating over rows and second for columns
ronald
@ronstarcool
Jan 29 2017 11:19
hey, can anyone help me on this one?
this is my code, but ofc, its not good:
var Person = function(fulln) {
  this.setFirstName = function(fn){
    this.firstName = fn;
  };
  this.setLastName = function(ln){
    this.lastName = ln;
  };
  this.setFullName = function(fulln){
    this.firstName = fulln.split(' ')[0];
    this.lastName = fulln.split(' ')[1];
  };
  this.getFullName = function(){
    return this.firstName + ' ' + this.lastName;
  };
  this.getFirstName = function(){
    return this.firstName;
  };
  this.getLastName = function(){
    return this.lastName;
  };
};
Aleksander Gębicki
@Takumar
Jan 29 2017 11:19
@heyDante or rather one loop will choose elements of main array: arr[i] and second index will choose elements of that array: arr[i][j]
badalsaibo
@heyDante
Jan 29 2017 11:20
What should I rectify in my code then?
Pieter Stokkink
@forkerino
Jan 29 2017 11:21
@ronstarcool One hint: outside of your getters and setters you need to have one or more variables to store the name. Don't use this for them, otherwise it will not be hidden from the outside world as you want to.
ronald
@ronstarcool
Jan 29 2017 11:22
but i cant have more then 6 props on the object
Ujwal Kadariya
@kadariyaujwal
Jan 29 2017 11:28
Hello guys...I need help with the chunky monkey challenge..Thanks in advance . https://www.freecodecamp.com/challenges/chunky-monkey
Pieter Stokkink
@forkerino
Jan 29 2017 11:28
@ronstarcool if you don't put this before it, it won't count.
@kadariyaujwal show what you have written, so we can help you.
Phokgedi
@Peekaymaja
Jan 29 2017 11:29
Selecting from many options with Switch Statements using switch and case statements help

Instructions

Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - "delta"

Here are some helpful links:

Switch Statement
Pieter Stokkink
@forkerino
Jan 29 2017 11:29
@Peekaymaja Have you written any code already?
Phokgedi
@Peekaymaja
Jan 29 2017 11:29

```function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch(answer){
case val === 1: return ("alpha");

case val === 2: return ("beta");

case val === 3: return ("gamma");

case val === 4: return ("delta");

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

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

@forkerino yes
Pieter Stokkink
@forkerino
Jan 29 2017 11:30
I see
Phokgedi
@Peekaymaja
Jan 29 2017 11:30
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(answer){
    case val === 1: return ("alpha");

    case val === 2: return ("beta");

    case val === 3: return ("gamma");

    case val === 4: return ("delta");

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

// Change this value to test
caseInSwitch(1);
Pieter Stokkink
@forkerino
Jan 29 2017 11:30
@Peekaymaja A few things.
Phokgedi
@Peekaymaja
Jan 29 2017 11:30
@forkerino whats the problem with my code
Pieter Stokkink
@forkerino
Jan 29 2017 11:30
the thing you want to switch on isn't answer, because answer at that point will always be "".
You want to switch on the value that is passed in.
Phokgedi
@Peekaymaja
Jan 29 2017 11:31
val
Pieter Stokkink
@forkerino
Jan 29 2017 11:31
The cases then only need the value on which to execute that code, so you can put it like: case 1: etc.
Phokgedi
@Peekaymaja
Jan 29 2017 11:32
case 1: return what?
Pieter Stokkink
@forkerino
Jan 29 2017 11:33
If you do those changes, the code will work as is required, but the exercise actually implies that inside your case statements, you assign the answer to the answer variable, break the switch and then afterwards return the answer.
btw if you return a string, you don't need to put ( ) around it.
Phokgedi
@Peekaymaja
Jan 29 2017 11:34
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(val){
    case 1: return ("alpha");

    case 2: return ("beta");

    case 3: return ("gamma");

    case 4: return ("delta");

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

// Change this value to test
caseInSwitch(1);
Pieter Stokkink
@forkerino
Jan 29 2017 11:35
Any errors?
Phokgedi
@Peekaymaja
Jan 29 2017 11:35
nop. it says you should have at least 3 break statements
Vijith Nair
@wizelmagnifico
Jan 29 2017 11:36

var array = [1, 12, 21, 2];

// Only change code below this line.

array.sort();

can somebody help me with this?
i have to sort it from largest to smallest
Pieter Stokkink
@forkerino
Jan 29 2017 11:38

@Peekaymaja yeah, that's why I said before that

the exercise actually implies that inside your case statements, you assign the answer to the answer variable, break the switch and then afterwards return the answer.

Phokgedi
@Peekaymaja
Jan 29 2017 11:39
i dont even understand what i did. What i don't understand is
how does it return answer and answer was never used in my block
Pieter Stokkink
@forkerino
Jan 29 2017 11:40

@wizelmagnifico inside the sort(), you need to write a function that sorts, as sort defaults to alphabetic sorting (which makes 12 come before 2). So:

array.sort(function(a,b){
   // sort there.
});

check the sort docs to see what this function should look like.

Phokgedi
@Peekaymaja
Jan 29 2017 11:41
or because answer equal empty string. therefore when i return a string it goes inside that string if val match the string?
Pieter Stokkink
@forkerino
Jan 29 2017 11:41
@Peekaymaja Well, it doesn't return the variable answer, because for all valid inputs, it will return something before it reaches that line.
Dhavalkumar Prajapati
@adhavalboy
Jan 29 2017 11:41
function lookUpProfile(firstName, prop){
// Only change code below this line
  if(firstName==contacts.firstName)
    return contacts.prop;
  else
    return "No such property";
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
how to do this ?? where i am wrong?
Jamil Akhtar
@frontender007
Jan 29 2017 11:41
Hello World
CamperBot
@camperbot
Jan 29 2017 11:41

welcome to FreeCodeCamp @frontender007!

Pieter Stokkink
@forkerino
Jan 29 2017 11:41

Try to refactor your cases like so:

case 1: 
  answer = "what the answer is for this case";
  break;

@Peekaymaja

Phokgedi
@Peekaymaja
Jan 29 2017 11:42
@forkerino can you write me the correct code ?ill try to understand it
Jamil Akhtar
@frontender007
Jan 29 2017 11:42
can anybody help me please?
I'm at "Arguments Optional" challenge
Phokgedi
@Peekaymaja
Jan 29 2017 11:43
@forkerino i see let me try this
Jamil Akhtar
@frontender007
Jan 29 2017 11:43
addTogether(2)(3) returning 6 rather 5
Vijith Nair
@wizelmagnifico
Jan 29 2017 11:43

var array = [1, 12, 21, 2];

// Only change code below this line.

array.sort(function(a,b){

});

Pieter Stokkink
@forkerino
Jan 29 2017 11:43
@adhavalboy You will need to go over all the contacts somehow (looping might be good). Also you need to use bracket notation in case of using a variable to access a certain property. Dot notation will convert the variable to a string containing the variable name.
Vijith Nair
@wizelmagnifico
Jan 29 2017 11:43
what is wrong?
Pieter Stokkink
@forkerino
Jan 29 2017 11:43
@wizelmagnifico there is nothing inside your function.
Dhavalkumar Prajapati
@adhavalboy
Jan 29 2017 11:44
@forkerino thanks , this will me
CamperBot
@camperbot
Jan 29 2017 11:44
adhavalboy sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 733 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jan 29 2017 11:44
@frontender007 show your code!
Jamil Akhtar
@frontender007
Jan 29 2017 11:44
@wizelmagnifico return the difference of a and b
Dhavalkumar Prajapati
@adhavalboy
Jan 29 2017 11:44
@frontender007 return a-b;
Phokgedi
@Peekaymaja
Jan 29 2017 11:44
@forkerino Thank you
CamperBot
@camperbot
Jan 29 2017 11:44
peekaymaja sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 734 | @forkerino |http://www.freecodecamp.com/forkerino
Jamil Akhtar
@frontender007
Jan 29 2017 11:44
@adhavalboy extactly
Phokgedi
@Peekaymaja
Jan 29 2017 11:44

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(val){
    case 1: answer = "alpha";
      break;

    case 2: answer = "beta";
      break;

    case 3: answer = "gamma";
      break;

    case 4: answer = "delta";
      break;

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

// Change this value to test
caseInSwitch(1);
Pieter Stokkink
@forkerino
Jan 29 2017 11:44
@Peekaymaja :+1: do you understand how it works?
Phokgedi
@Peekaymaja
Jan 29 2017 11:45
absolutely
Pieter Stokkink
@forkerino
Jan 29 2017 11:45
technically, the last break isn't necessary, because the switch ends immediately after.
@Peekaymaja
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:45
@wizelmagnifico return a-b
Jamil Akhtar
@frontender007
Jan 29 2017 11:46
function addTogether() {
  if ( arguments.length === 2 ) {
    if ( isNaN(arguments[0]) || isNaN(arguments[1]) ) {
      return undefined;
    }
    else {
      return arguments[0] + arguments[1];
    }
  }

  function add3( num ) {
    return arguments[0] + num;
  }

  return add3;
}

addTogether(2)(3);
@forkerino
here is my code
Phokgedi
@Peekaymaja
Jan 29 2017 11:46
when val = 1 answer = string alpha.. then caseInSwitch will return what ever is equal to the variable answer when ever theres an input
@forkerino this is frustrating...
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:47
@frontender007 do you understand how closure works?
Jamil Akhtar
@frontender007
Jan 29 2017 11:47
got a bit of idea but not fully
may be you can explain?
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:48
@frontender007 closure is when a function returns an object that's aware of the environment it was declared
Pieter Stokkink
@forkerino
Jan 29 2017 11:48
@Peekaymaja yes, it will assign a value to answer and at the end return this.
Dhavalkumar Prajapati
@adhavalboy
Jan 29 2017 11:48
@Peekaymaja add default in last
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:49
@frontender007 the object can be a function too
Jamil Akhtar
@frontender007
Jan 29 2017 11:50
@Lumexralph so what is closure is my code ?
Robert Purcea
@RobertPurcea
Jan 29 2017 11:50
How do I export the whole file, insted of just a function? Is there a simple way to do it?
In es6 with import, no library
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:50
@frontender007 your code doesn't have closure in it
Jamil Akhtar
@frontender007
Jan 29 2017 11:51
I guess it does as the inner function being returned ? isn't ?
asafofer
@asafofer
Jan 29 2017 11:52
can someone help me with the smallest common multiple
?
cloudsere
@cloudsere
Jan 29 2017 11:52
ah!I have the same question now...
Jamil Akhtar
@frontender007
Jan 29 2017 11:53
@asafofer have you tried anything yet ?
cloudsere
@cloudsere
Jan 29 2017 11:53
屏幕快照 2017-01-29 下午7.52.53.png
This is my solution ,worked fine with [1,5], but cannot work with [1,8] or [1,9]…etc , can anyone help me ??
Jamil Akhtar
@frontender007
Jan 29 2017 11:54
first you need to have an array within the range of arguments
then you need to have variable to start dividing the numbers in the array to see if all of them divisible by that variable equally
if not just keep incrementing the variable until you find that common multiple
a while loop will do
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:56
@frontender007
function sub(a) {
      return function(b) {
            return a + b;
       }
}
var c = sub(6);    //sub(6)(7)
c(7)   // will give 13
Jamil Akhtar
@frontender007
Jan 29 2017 11:56
but be sure to have a termination condition otherwise you will crash your browser
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:57
@frontender007 that's a closure for you
Jamil Akhtar
@frontender007
Jan 29 2017 11:57
@Lumexralph I'm doing kinda same thing by using arguments[0]
if it is not right then how ?
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:58
@frontender007 addTogether will always have one parameter
Jamil Akhtar
@frontender007
Jan 29 2017 11:59
return a + b gives error that a is not defined
Ogundele Olumide
@Lumexralph
Jan 29 2017 11:59
@frontender007 using arguments object to capture the (2)(3) won't work they're in different parenthesis
Jamil Akhtar
@frontender007
Jan 29 2017 11:59
?
Ogundele Olumide
@Lumexralph
Jan 29 2017 12:00
@frontender007 depends on how you call the function
foahchon
@foahchon
Jan 29 2017 12:00
@frontender007 Also, note that the addTogether function should return another function
Ujwal Kadariya
@kadariyaujwal
Jan 29 2017 12:01
Hello guys..please help me with chunky monkey algorithm or maybe give some instructions
Ogundele Olumide
@Lumexralph
Jan 29 2017 12:01
@frontender007
function sub(a) {
      return function(b) {
            return a + b;
       }
}
var c = sub(6)(7);    //sub(6)(7)
console.log(c);
that's how you call that kind of closure, the initial way i told you or this way
foahchon
@foahchon
Jan 29 2017 12:04
Key concept: calling sub(6) alone from from the above snippet will return a function; i.e. if you were to just type var c = sub(6);, c would point to function, which you could then invoke thusly: c(7);
cloudsere
@cloudsere
Jan 29 2017 12:04
@frontender007 Thank you very much for your help , there’s a strange thing that I changed my browser from Chrome to Safari, and the same code worked!…?
CamperBot
@camperbot
Jan 29 2017 12:04
cloudsere sends brownie points to @frontender007 :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @frontender007 |http://www.freecodecamp.com/frontender007
Jamil Akhtar
@frontender007
Jan 29 2017 12:08
@Lumexral