These are chat archives for FreeCodeCamp/HelpJavaScript

17th
May 2017
David Amanze
@GodKingShogun
May 17 2017 00:01
i'll just stick to bootstrap because flex is not doing it for me :cry:
but i want to use what all the cool kids are using :cry:
Moisés Man
@moigithub
May 17 2017 00:19
@L-e-i-f starting result with true.. and changin to false on the if block should work
grfraser
@grfraser
May 17 2017 00:21
anyone able to help me connect my weather api to my ip api?
i can get the location but getting the variables for the ip seem to be out of scope or something
David Amanze
@GodKingShogun
May 17 2017 00:23
making a page look good on desktop and mobile is more challenging than i thought lol
grfraser
@grfraser
May 17 2017 00:23
check out the JS , i need to connect the location to create a url to retrieve json data from
i am new to apis as well
David Amanze
@GodKingShogun
May 17 2017 00:27
@grfraser you have to store your weather location in a global variable so you can pass that on to your second get request
Stephen James
@sjames1958gm
May 17 2017 00:28
@grfraser You'll want to move your $.get into the callback from ip.info.
Also, you need http:// on the front of your openweather URL - and openweather only supports http: so you will need to
connect to codepen over http:
grfraser
@grfraser
May 17 2017 00:29
@GodKingShogun how can i make i global?
David Amanze
@GodKingShogun
May 17 2017 00:30
@grfraser create your variable right after the document ready opening brackets
grfraser
@grfraser
May 17 2017 00:30
@sjames1958gm my open weather site i have open says https but the json is http. odd.
@sjames1958gm which$get? the weather $get? is there a better site that uses https?
Pierofgonzalez
@Pierofgonzalez
May 17 2017 00:31

if i have an array of objects :
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
}, and some mores objects.

the question is if i evaluate if akira exist how can i ask for another key of akira.
im sorry if it isn't easy to understand.

grfraser
@grfraser
May 17 2017 00:31
@GodKingShogun let me try that. i just figured since they didnt exist yet it wouldnt work
Manish Giri
@Manish-Giri
May 17 2017 00:33

@Pierofgonzalez

the question is if i evaluate if akira exist how can i ask for another key of akira.

what does this mean?

grfraser
@grfraser
May 17 2017 00:34
@GodKingShogun @sjames1958gm bc the ip is https and openweather is http, they wont work together true?
i cant be on both http and https codepen
they all need to be one or the other right?
Johnny Meza
@XLpacman805
May 17 2017 00:35
I think http can access https:// but not the reverse
Pierofgonzalez
@Pierofgonzalez
May 17 2017 00:35
@Manish-Giri when i find that "firstname"="akira" how can i ask if another key exist of that same object.
grfraser
@grfraser
May 17 2017 00:36
why cant they all be the same :worried: ( @XLpacman805 lol
that makes sense though
Johnny Meza
@XLpacman805
May 17 2017 00:36
CORS policy. I used Darksky API which uses an https api.
grfraser
@grfraser
May 17 2017 00:37
why would openweather by https but their json is http?
@XLpacman805 and the dark sky json is https?
i like stickin to https
Johnny Meza
@XLpacman805
May 17 2017 00:37
so they could get your location probably. You can try just adding the 's' to the http
yup
grfraser
@grfraser
May 17 2017 00:37
legit thank you!
how bad is my js?
Manish Giri
@Manish-Giri
May 17 2017 00:38
@Pierofgonzalez you can use .hasOwnProperty() for that..
Johnny Meza
@XLpacman805
May 17 2017 00:40
@grfraser not bad, It's readable.
also Darksky is free. The homepage makes it seem like it's not but it is. You get like 10,000 requests per day
Pierofgonzalez
@Pierofgonzalez
May 17 2017 00:42
@Manish-Giri thanks
CamperBot
@camperbot
May 17 2017 00:42
pierofgonzalez sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5552 | @manish-giri |http://www.freecodecamp.com/manish-giri
Masaki
@masaki1223
May 17 2017 00:43
Morning guys!

function myReplace(str, before, after) {
   var newStr=str.split(' ');
  newStr.splice(newStr.indexOf(before),1, after);

  return newStr.join().replace(/,/g,' ');
}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
I don't know how to preserve the case of the original word.. Any help?
grfraser
@grfraser
May 17 2017 00:44
@XLpacman805 okay let me try that and get back to you! thanks!
CamperBot
@camperbot
May 17 2017 00:44
grfraser sends brownie points to @xlpacman805 :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @xlpacman805 |http://www.freecodecamp.com/xlpacman805
HeebieGeeBee
@HeebieGeeBee
May 17 2017 00:48
@masaki1223 you need to compare if the first letter of the world to be replaced is the same as that letter .toUpperCase()
3gimpfingers
@3gimpfingers
May 17 2017 00:50
@Manish-Giri Pierofgonzalez's question is on the same problem you helped me with earlier.
Julio Legrec
@juliolegrec
May 17 2017 00:52
How to accomplish this "After nextInLine(testArr, 10), testArr[4] should be 10" in Stand in Line Challenge?
aRtoo
@artoodeeto
May 17 2017 00:53

hey guys. OMG! i just want to share. ive solved another algorithm problem on fcc. after 1hr i finally solved it. im so happy like theres a butterflies on my stomach right now. im not dumb after all. i know you can do this problem like 5sec but i usually do it on paper first so i can see it better. heres the code. im so happy. :))))))


function factorialize(num) {

  var numb3= 1;
  for(var i=1; i <=num; i++){

    var result = numb3 *i;
    var numb2 =result;
     numb3 = numb2;

     console.log(result);



  }


  return numb3;
}

factorialize(10);

sorry for long message. love you guys.

LoserNoOne
@LoserNoOne
May 17 2017 00:54
Hey
HeebieGeeBee
@HeebieGeeBee
May 17 2017 00:54
@artoodeeto well done, now you can remove all those empty lines to make your code look prettier :)
Joseph
@revisualize
May 17 2017 00:55
Hi
HeebieGeeBee
@HeebieGeeBee
May 17 2017 00:55
Hi
aRtoo
@artoodeeto
May 17 2017 00:55
@HeebieGeeBee yea. i forgot! hahaha. thank you man. love this group
CamperBot
@camperbot
May 17 2017 00:55
artoodeeto sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1654 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
LoserNoOne
@LoserNoOne
May 17 2017 00:55
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var a = [false,0,null,"",undefined,NaN];
return arr.filter(function(val){
if(val===null) return false;
return a.indexOf(val)<0;
});
}
I want to ask why this function cannot filter null in the input array.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 00:55
@artoodeeto also maybe try refactoring your algorithm, theres some unneccessary stuff there
aRtoo
@artoodeeto
May 17 2017 00:56
yea. i feel like there's unnecessary stuff but ill figure it out
HeebieGeeBee
@HeebieGeeBee
May 17 2017 00:57
you can just do something like numb3 *= i
@artoodeeto
aRtoo
@artoodeeto
May 17 2017 01:00
@HeebieGeeBee fkkkkk. i tried that before but without initializing numb3.
@HeebieGeeBee shit. i knew it i could solve this with 2lines of code
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:03
//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


// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
CamperBot
@camperbot
May 17 2017 01:03
:bulb: to format code use backticks! ``` more info
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:03
Anybody know where to start for the above code?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:04
@LoserNoOne it does
@AlanMcDowell888 i would start with loop through the contacts
LoserNoOne
@LoserNoOne
May 17 2017 01:05
@HeebieGeeBee But the answer shows that the code did not filter null ...... Maybe there is something different about null?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:06
but that function will filter null from an array
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var a = [false,0,null,"",undefined,NaN];
return arr.filter(function(val){
if(val===null) return false;
return a.indexOf(val)<0;
});
}

bouncer([1, null]) // [1]
@LoserNoOne
grfraser
@grfraser
May 17 2017 01:06
@XLpacman805
XMLHttpRequest cannot load https://api.darksky.net/forecast/9777900652193e30cbb835dace68f235/32.8685,-96.4031. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.
makes no sense
Johnny Meza
@XLpacman805
May 17 2017 01:08
Are you using JSONP?
LoserNoOne
@LoserNoOne
May 17 2017 01:10
@HeebieGeeBee I tried [null,0] and passed but failed when I try array like [false, null, 0, NaN, undefined, ""]
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:11
@LoserNoOne youre left with NaN
LoserNoOne
@LoserNoOne
May 17 2017 01:12
what does that mean ?
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:12
@HeebieGeeBee thanks
CamperBot
@camperbot
May 17 2017 01:12
alanmcdowell888 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1655 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:12
it means that NaN === NaN is false
LoserNoOne
@LoserNoOne
May 17 2017 01:13
oh, how can I change that to filter NaN
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:14
well theres a few ways
isNaN is one i guess
Masaki
@masaki1223
May 17 2017 01:14

function myReplace(str, before, after) {
   var newStr=str.split(' ');

  if(before[0] === before[0].toUpperCase()){
    newStr.splice(newStr.indexOf(before),1, after[0].toUpperCase() + after.replace(after[0],''));
  }
  else{
  newStr.splice(newStr.indexOf(before),1, after);
  }
  return newStr.join().replace(/,/g,' ');

}

myReplace("He is Sleeping on the couch", "Sleeping", "jumping");
This code worked, but it doesn't look pretty.
Can you make 'after.replace(after[0],''));' prettier?
abraham anak agung
@padunk
May 17 2017 01:15
@LoserNoOne are you trying to filter Boolean?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:15
but NaN is just a falsy value
you just want to filter out all falsy values
and filter evaluates all its callback function returns to either falsy or truthy
LoserNoOne
@LoserNoOne
May 17 2017 01:15
I found this method and it works (typeof x === 'number' && isNaN(x))
@HeebieGeeBee So how to simply filter out all falsy values?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:17
just return that value in the filter callback and let the filter function evaluate whether its a truthy value or a falsy value
Na-Ya
@Na-Ya
May 17 2017 01:17
Hey everyone I am working on the mutations algorithm challenge and can't seem to get the last test to pass
any tips?
Screen Shot 2017-05-16 at 9.16.08 PM.png
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:18
@masaki1223 theres no need for tat replace at the end
Anurag Lahon
@anuraglahon16
May 17 2017 01:18
@Na-Ya remove the split

function sumAll(arr) {
let s;
for(var i=math.min(arr);i<=math.max(arr);i++)
{
s+=i;
}
return s;
}

sumAll([1, 4]);

What wrong here?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:19
@Na-Ya change your if statement return around
Na-Ya
@Na-Ya
May 17 2017 01:19
hmm
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:19
and only return true outside the loop
@anuraglahon16 Math.min cant evaluate an array
neither can Math.max
Mohamed Derhalli
@derhallim
May 17 2017 01:21
@HeebieGeeBee do u sleep? :O
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:21
occasionally
Mohamed Derhalli
@derhallim
May 17 2017 01:21
:joy:
when ur bored
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:21
when i feel like it
Mohamed Derhalli
@derhallim
May 17 2017 01:21
haha
Na-Ya
@Na-Ya
May 17 2017 01:21
@HeebieGeeBee thanks, that actually solved it but I am a bit unsure why
CamperBot
@camperbot
May 17 2017 01:21
na-ya sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1656 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
abraham anak agung
@padunk
May 17 2017 01:21
:) i already sleep 7 hours and he is still here
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:21
@Na-Ya returns will stop a functions operation
Mohamed Derhalli
@derhallim
May 17 2017 01:22
@padunk yea i know
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:22
so youre only going to do one iteration of your loop
DistinctWolf
@DistinctWolf
May 17 2017 01:22

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  var string=str.match(/^[A-Za-z]+$/);
  var result=[];
  for(var i=0;i<string.length;i++){
    if(string[i]===string[i].toUpperCase()&&i!==0){
      result.push('-'+string[i].toLowerCase());
    }else{
      result.push(string[i].toLowerCase());
    }
  }
  return result.join('');
}

spinalCase('This Is Spinal Tap');
what is wrong with this please help
Na-Ya
@Na-Ya
May 17 2017 01:22
@HeebieGeeBee Oh that makes total sense
Johnny Meza
@XLpacman805
May 17 2017 01:23

@grfraser Here's how I made my JSONP requests.

    //get Weather Data
    $.getJSON("https://api.darksky.net/forecast/f702ce4da532b8f82436498dd1f72e03/"+lat+","+long+"?callback=?", function(response){
   // Please don't abuse my API key. 
   console.log(response);

This website helped me understand CORS and JSONP https://www.sitepoint.com/jsonp-examples/

Vamp
@the-vampiire
May 17 2017 01:25
does anyone know if there is another way to donate to FCC besides paypal?
abraham anak agung
@padunk
May 17 2017 01:26
@FlashHero why this var string=str.match(/^[A-Za-z]+$/); this will return null
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:26
@the-vampiire yeah you send a cheque to heebiegeebee France
Vamp
@the-vampiire
May 17 2017 01:26
hah
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:26
i'll make sure they'll get it
Vamp
@the-vampiire
May 17 2017 01:26
well round here in murica all we have are checks
will those do?
:wink:
DistinctWolf
@DistinctWolf
May 17 2017 01:27
@padunk I don't know regular expressions, I'm trying to just return letters how do i do that please help
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:27
yeah but better if you leave them blank @the-vampiire
Anurag Lahon
@anuraglahon16
May 17 2017 01:28
@HeebieGeeBee ohh lets try somethng else
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:28
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
  var i =0;
  while (i<contacts.length) {
    return contacts[i].firstName[i].likes[i];
  }






// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Vamp
@the-vampiire
May 17 2017 01:28
no problem, you’re welcome to take the 6 dollars I have to my name lol
abraham anak agung
@padunk
May 17 2017 01:28
check here for regex https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions and test your regex here regex101.com @flashhero
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:28
@HeebieGeeBee is that it?
LoserNoOne
@LoserNoOne
May 17 2017 01:28
@HeebieGeeBee thanks a lot
CamperBot
@camperbot
May 17 2017 01:28
losernoone sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1657 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:28
I mean am I close?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:28
@AlanMcDowell888 please dont include all the contacts, just the function when you paste
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:28
function lookUpProfile(firstName, prop){ // Only change code below this line var i =0; while (i<contacts.length) { return contacts[i].firstName[i].likes[i]; }
Vamp
@the-vampiire
May 17 2017 01:28
@AlanMcDowell888 just this part
function lookUpProfile(firstName, prop){
// Only change code below this line
  var i =0;
  while (i<contacts.length) {
    return contacts[i].firstName[i].likes[i];
  }
// Only change code above this line
}
HeebieGeeBee
@HeebieGeeBee
May 17 2017 01:28
@AlanMcDowell888 not really
AlanMcDowell888
@AlanMcDowell888
May 17 2017 01:29
yikes
Vamp
@the-vampiire
May 17 2017 01:29
that code wont work though. where is @Lumexralph
@AlanMcDowell888 you need to consider what the problem is asking you. also I will give you a hint you may not have discovered yet. when a return statement is reached in a for / while / do while loop the loop will exit at that point
meaning even if this were an acceptable approach to the problem it would break after the first iteration (i = 0) as soon as it hit that return statement
DistinctWolf
@DistinctWolf
May 17 2017 01:31
@padunk thank you for the reference but i'm not trying to learn regular expression right now so can you just tell me what the answer is
CamperBot
@camperbot
May 17 2017 01:31
flashhero sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @padunk |http://www.freecodecamp.com/padunk
Vamp
@the-vampiire
May 17 2017 01:31
@FlashHero why dont you want to learn it?
very useful skill to have, you don’t need to be an expert but at least learn the basics of it. the basics will get you up and running with your particular expression in under an hour
here are some of my notes. they are not complete nor do they use the correct technical terminology but it may be a helpful guide while you are learning...
essentially you have 2 “types” of formats to play with:
( ) group - anything in this has to be matched exactly as seen in the group
[ ] range - a match can be found for any character within this “range” of characters. you can also put an actual dash separated range in here for digits, 0-9, or lower alpha, a-z, upper alpha, A-Z

and 2 types of quantifiers placed beside a char, or outside a group or range:
? - match 0 or 1 time, placed next to a character in /char?/ format or outside a group / range to specify for that group range (char)? [char-char]?
{} - match {x} times exactly, match {x, y} x to y times exactly, match {x, } x to infinite times

the OR pipe
| - used in groups to specify that either match within that group is acceptable. just like || for javascript you can have multiple of these in a group 

the ^ start and $ finish markers
^ - starts with, this character, group, range
$ - ends here (exactly match up to this point)
@FlashHero and here is a short read (http://eloquentjavascript.net/09_regexp.html) that can get you started. combine this with a few practice expressions on www.regex101.com and you will have your expression functioning in under an hour
you will be hard pressed to find anyone in here who will give you answers when you preface your request with “i dont care about learning”. this is a learning environment, not a pool for cheating and shortcuts. there is no rush to completing challenges, the purpose is to learn.
DistinctWolf
@DistinctWolf
May 17 2017 01:36
@the-vampiire thank you man, I have noticed that a lot of things can be done using regular expressions but i never really learned it but i think I should start learning and implementing on my exercises to get better
CamperBot
@camperbot
May 17 2017 01:36
flashhero sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 394 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
May 17 2017 01:36
take it from me
I neglected regex and always tried to work around it wit inefficient code
then i got to the advanced algorithms telephone problem and forced myself to sit down and learn it
DistinctWolf
@DistinctWolf
May 17 2017 01:37
@the-vampiire how long did it take you
Vamp
@the-vampiire
May 17 2017 01:37
what would have been a disgusting nest of ifs and elses turned into a one line solution by the power of regex. everything i learned came from that website, the notes i wrote and shared with you, and regex101 practice
i am by no means an expert. i think I have a reasonable understanding of it, the basics. and it took me an afternoon but I like to be thorough.
regex is like its own language. it looks daunting and alien but if you take the time to learn the basics it becoems much more approachable, and learning the nuances / advanced techniques will actually make sense vs copying some regex and trying to hack it down into something useful for your particular code
JHnnis
@JHnnis
May 17 2017 01:39
function golfScore(par, strokes) {
  // Only change code below this line
  if (strokes = 1, par = 4) {
    return "Hole-in-one!";
  }
whats wrong with my code :worried:
Vamp
@the-vampiire
May 17 2017 01:39
@JHnnis = is an assignment operator
== is a non-strict comparison operator
=== is a strict comparison operator
DistinctWolf
@DistinctWolf
May 17 2017 01:40
@the-vampiire thank you again, I'll definitively try to learn regular expressions
CamperBot
@camperbot
May 17 2017 01:40
flashhero sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:warning: flashhero already gave the-vampiire points
CyberBrick
@CyberBrick
May 17 2017 01:40
the if is one condition not two
Dan Skelly
@dskell88
May 17 2017 01:40
Hey guys,
anyone here have general knowledge of OOP using Javascript? I'm stuck on one of the challenges.
Vamp
@the-vampiire
May 17 2017 01:40
you can not place an assignment in an if statement, you need to use a comparison operator
CyberBrick
@CyberBrick
May 17 2017 01:40
@JHnnis
JHnnis
@JHnnis
May 17 2017 01:40
ah thanks @the-vampiire but can I use more then one var?
CamperBot
@camperbot
May 17 2017 01:40
jhnnis sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 395 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
May 17 2017 01:41
if you want to combine multiple comparisons in an if statement you must use the and (&&) or the or ( || ) operators to separate the conditions
for example
JHnnis
@JHnnis
May 17 2017 01:41
ah I remember :smile:
Vamp
@the-vampiire
May 17 2017 01:43
var x = 5 // this ASSIGNS ( = ) the value of 5 to the variable x
var y = “5" // same, STRING “5”  to y

x == y // true, because the string’s value (assigned to y)  is the same as the integer 5 (assigned to x) 
// this is a non-strict comparison meaning that the values are the same but the TYPES may or may not be

x === y // false, because while the values are the same the TYPES are not
// this is a strict comparison meaning the value AND the type must be equal
in almost all cases unless you have specific reason not to ALWAYS use === the strict comparison operator
Dan Skelly
@dskell88
May 17 2017 01:44

var Bike = function() {

var gear = 0;

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

// Only change code below this line.

};

var myBike = new Bike(3);
myBike.getGear(3);
myBike.setGear(3);

Stephen James
@sjames1958gm
May 17 2017 01:44
@dskell88 Which challenge?
Dan Skelly
@dskell88
May 17 2017 01:44
there's the source code
Vamp
@the-vampiire
May 17 2017 01:44

@dskell88 when posting code do it in the following format

```js
new line
paste code here
new line

```
Stephen James
@sjames1958gm
May 17 2017 01:44
@dskell88 setGear by its name should assign a value to gear -
You cannot have parameters named gear or the functions have no access
to the var gear = 0; value
Vamp
@the-vampiire
May 17 2017 01:44
var Bike = function() {

  var gear = 0;

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

  // Only change code below this line.

};


var myBike = new Bike(3);
myBike.getGear(3);
myBike.setGear(3);
@JHnnis scroll up to view what I wrote about comparison operators if you need a refresher
Dan Skelly
@dskell88
May 17 2017 01:45
okay, i'll continue on the challenge there. Thanks, @the-vampiire
CamperBot
@camperbot
May 17 2017 01:45
dskell88 sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 396 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
sanu921
@sanu921
May 17 2017 01:46
hey guys i cant refresh my page to the default code script
any help is appreciated
Vamp
@the-vampiire
May 17 2017 01:50
@sjames1958gm I disagree
Stephen James
@sjames1958gm
May 17 2017 01:50
@the-vampiire With what?
Vamp
@the-vampiire
May 17 2017 01:50
@sjames1958gm while his getter function cant have a parameter passed his setter has no issue having the same parameter as the object function
ill pm you i dont want to spoil the solution for him
Stephen James
@sjames1958gm
May 17 2017 01:56
@sanu921 reset is not working?
CyberBrick
@CyberBrick
May 17 2017 01:59
Hello All
Stephen James
@sjames1958gm
May 17 2017 02:00
@CyberBrick :wave:
CyberBrick
@CyberBrick
May 17 2017 02:01
I'm having some issues with the case challenge. Some pointers would e appreciated.

Here is my code,--function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val){
case 1:
console.log("alpha");
break;

case 2:
  console.log("beta");
  break;
case 3:
  console.log("gamma");
  break;

case 4:
 console.log("delta");
  break;

}

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

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

My error is saying, caseInSwitch(1) should have a value of "alpha" , etc through all cases
Should I be using return statements instead?
Dovydas Stirpeika
@Giveback007
May 17 2017 02:08
Hey there, I think I am done with the functionality of my javascript calculator could you take a look?
https://codepen.io/giveback007/pen/Njzevz?editors=1010
abraham anak agung
@padunk
May 17 2017 02:11
@Giveback007 wow, i'm still coding it. your decimal value is too long
Dovydas Stirpeika
@Giveback007
May 17 2017 02:12
@padunk what do you mean?
abraham anak agung
@padunk
May 17 2017 02:13
i am trying 10/6 and the value is out of the screen
Brittany Heller
@b-marie
May 17 2017 02:13
Hey guys, does anyone have any insight into why this algorithm code isn't working?

function palindrome(str) {
var string = str.toLowerCase();
var k = string.length;
for(var i = 0; i == k; i ++) {
for(var j = k - 1; j === 0; j--) {
if(str[i] === str[j]) {
return true;
} else {
return false;
}
}

}
}

Dovydas Stirpeika
@Giveback007
May 17 2017 02:14
oh, thank you for catching that @padunk
CamperBot
@camperbot
May 17 2017 02:14
giveback007 sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 319 | @padunk |http://www.freecodecamp.com/padunk
abraham anak agung
@padunk
May 17 2017 02:15
@Giveback007 no prob. it looks cool man!
Dovydas Stirpeika
@Giveback007
May 17 2017 02:15
@padunk it doesn't take long to do the calculator, just try using flex box, I did the design in 3 hours
abraham anak agung
@padunk
May 17 2017 02:16
i didn't know about flexbox yet, but i am trying to make it in react, :) still learning react though
Dovydas Stirpeika
@Giveback007
May 17 2017 02:16
I was thinking of switching up the colors, but I am thankful for the for the compliment!
@padunk why are you trying to do it in react? For this project I decided I wouldn't use any frameworks or libraries, I was surprised how few lines it took to do each thing.
Greg Lawrence
@Chewieez
May 17 2017 02:17
Hi all, I'm working on the Using Objects for Lookups question and I'm stuck. Any tips on why my code isn't working?
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookUp = {
    alpha: "Adams",
    bravo: "Boston",
    charlie: "Chicago",
    delta: "Denver",
    echo: "Easy",
    foxtrot: "Frank",
  };

  lookUp.val;

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

// Change this value to test
phoneticLookup("charlie");
Dovydas Stirpeika
@Giveback007
May 17 2017 02:19
@padunk idk if you are not done with the design of it look at this video https://www.youtube.com/watch?v=k32voqQhODc&t=611s. Flex box is amazing, I wish I knew about it sooner
Greg Lawrence
@Chewieez
May 17 2017 02:19

Sorry, I meant to have this in the code

lookUp[val];

but it also doesn't work with that line at the end.

Claudio Restifo
@Marmiz
May 17 2017 02:20

@b-marie this loop will never iterate:

for(var i = 0; i == k; i ++)

Since you're telling " starting from i as 0, as long as it's equal to k, loop". But it isn't equal to k.
Do you see the flaws?

Dovydas Stirpeika
@Giveback007
May 17 2017 02:20
@Chewieez on which asignment is it?
Brittany Heller
@b-marie
May 17 2017 02:20
@Marmiz Ahh yeah, that makes sense! Thank you for catching that
CamperBot
@camperbot
May 17 2017 02:20
b-marie sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 866 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
May 17 2017 02:21
@b-marie anyway remember that in the palindrome challenge it's asking you to remove all non alphanumeric values from the string as well
Cazhen
@Cazhen
May 17 2017 02:21

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

// Only change code below this line

amke b=7?
Brittany Heller
@b-marie
May 17 2017 02:22
@Marmiz hmmm…. okay, I will try to use that too.. Thanks!
CamperBot
@camperbot
May 17 2017 02:22
b-marie sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:warning: b-marie already gave marmiz points
Dovydas Stirpeika
@Giveback007
May 17 2017 02:22
@Chewieez you actualy did everything right except at your return statement
Greg Lawrence
@Chewieez
May 17 2017 02:22
@Giveback007 I think I may have gotten it.
Cazhen
@Cazhen
May 17 2017 02:22
var a=7;
Greg Lawrence
@Chewieez
May 17 2017 02:22

@Giveback007 I just changed my last line to this

var result = lookUp[val];

and it said that worked

Is that correct?
Claudio Restifo
@Marmiz
May 17 2017 02:23
@Chewieez you're returning result, that never get reassigned so you are returning an empty string
With your correction, makes sense
Greg Lawrence
@Chewieez
May 17 2017 02:23
@Marmiz Thanks, see my comment right above yours. Did I get it right
CamperBot
@camperbot
May 17 2017 02:23
chewieez sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 867 | @marmiz |http://www.freecodecamp.com/marmiz
Greg Lawrence
@Chewieez
May 17 2017 02:23
@Marmiz thanks!
CamperBot
@camperbot
May 17 2017 02:23
chewieez sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:warning: chewieez already gave marmiz points
Dovydas Stirpeika
@Giveback007
May 17 2017 02:23
yes, it is. you can even do
return lookUp[val];
its an https site?
Greg Lawrence
@Chewieez
May 17 2017 02:24
Why is that return = ""; line included at the very top? It threw me off
grfraser
@grfraser
May 17 2017 02:24
XMLHttpRequest cannot load https://api.darksky.net/forecast/9777900652193e30cbb835dace68f235/32.8685,-96.4031. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
Claudio Restifo
@Marmiz
May 17 2017 02:24
@Chewieez for setting up the test :)
Greg Lawrence
@Chewieez
May 17 2017 02:24
@Giveback007 yes, but that line is under the "Only change code above this line" comment, so thus, somewhat cheating. :)
Dovydas Stirpeika
@Giveback007
May 17 2017 02:25
@Chewieez :)
Greg Lawrence
@Chewieez
May 17 2017 02:25
@Marmiz But it's useless up at the top right, since the value is left empty.
@Giveback007 or is that normal operating proc?
sorrry wrong tag
grfraser
@grfraser
May 17 2017 02:25
@XLpacman805
Dovydas Stirpeika
@Giveback007
May 17 2017 02:26
ok, time for me to go to sleep, have a good night
Claudio Restifo
@Marmiz
May 17 2017 02:26
@Chewieez not for when we write the tests :)
You can write the same function for yourself differently. But since we have to test it on a variety of people, a more "standard" approach is needed.
And that comes with the cost of initializing the same variables for everyone
Greg Lawrence
@Chewieez
May 17 2017 02:26
Thanks for your help @Giveback007 !
CamperBot
@camperbot
May 17 2017 02:26
chewieez sends brownie points to @giveback007 :sparkles: :thumbsup: :sparkles:
:cookie: 302 | @giveback007 |http://www.freecodecamp.com/giveback007
Greg Lawrence
@Chewieez
May 17 2017 02:27
@Marmiz ok. I just meant is it normal to define a var at the beginning and leave it blank like that? Outside of the test environment?
Claudio Restifo
@Marmiz
May 17 2017 02:28
@Chewieez yep. Lots of time you'll write functions and initialize var that you'll use later in the code.
Having them all at the top of the scope increase the readability
(that does not mean writing global varaibles)
Greg Lawrence
@Chewieez
May 17 2017 02:28
@Marmiz alright, thanks
CamperBot
@camperbot
May 17 2017 02:28
chewieez sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:warning: chewieez already gave marmiz points
Arthur Ryan Ballon
@ryanart
May 17 2017 02:30
can someone help with these? a should have a value of 7
b should have a value of 7
a should be assigned to b with =
Dan Skelly
@dskell88
May 17 2017 02:30
hmm, I'm still not getting this challenge.
Johnny Meza
@XLpacman805
May 17 2017 02:30
@gfraser999 A callback function needs to be specified in the query. Look at the code I posted earlier.
Dan Skelly
@dskell88
May 17 2017 02:30
Can anyone help me with the "make Object Properties Private" challenge? It's the OOP javascript section
Wisdom Peters
@blackcytographer
May 17 2017 02:30
good day world pls i am having a problem with my codes doesnt seem to know what the problem is. some help will be greatly appreciated.

function testElse(val) {
var result = "";
// Only change code below this line

if (val > 5 && val <= 5) {
result = "Bigger than 5";
}
else {
result = "5 or Smaller";
}

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

// Change this value to test
testElse(4);

Hannah A M
@hmolette
May 17 2017 02:32
Hey everybody, how's it going
?
I have completed the JS tasks but I am currently reviewing it for my projects
Dan Skelly
@dskell88
May 17 2017 02:33

I'm supposed to have two public methods: getGear and setGear. myBike.getGear() should 4 after calling myBike.setGear(4):

var Bike = function() {

var gear = 0;

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

};

// Only change code below this line.

};

var myCar = new Car();

var myBike = new Bike();
myBike.setGear(4);
myBike.setGear(3);

Claudio Restifo
@Marmiz
May 17 2017 02:33
@grfraser have you tried making it a JSONP request instead of a JSON?
Dan Skelly
@dskell88
May 17 2017 02:33
why is it not returning 4? BTW, ignore myBike.setGear(3)
Hannah A M
@hmolette
May 17 2017 02:33
I wanted to gain a better understanding about the practical usage of compound assignments....when would I need to use this in programming? is there a practical example?
Claudio Restifo
@Marmiz
May 17 2017 02:35

@blackcytographer
here:

if (val > 5 && val <= 5)

you're telling if val is bigger than 5 and is smaller or equal to 5...
Which basically means every integer :)

Wisdom Peters
@blackcytographer
May 17 2017 02:37
@Marmiz i dont get is it wrong? or right?
Claudio Restifo
@Marmiz
May 17 2017 02:38
@dskell88 because setGear does not accept any value and just return the gear:
this.setGear = function(){
return gear;
};
@blackcytographer what do you think? Do you think is correct sayng:
 *if val is bigger, euqual or smaller than 5
  ** tell me that the value is smaller than 5
Wisdom Peters
@blackcytographer
May 17 2017 02:39
@Marmiz ok thanks for the scolding and correction
CamperBot
@camperbot
May 17 2017 02:39
blackcytographer sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 868 | @marmiz |http://www.freecodecamp.com/marmiz
Wisdom Peters
@blackcytographer
May 17 2017 02:40
@Marmiz i will look into it mr Restifo
Claudio Restifo
@Marmiz
May 17 2017 02:40
@blackcytographer probably makes more sense telling:
if val is bigger than 5
** tell me is bigger than 5
otherwise tell me is smaller than 5
Juan Pablo Jaramillo
@JuanP97
May 17 2017 02:51

Hello, I'm super stuck in the Seek and Destroy. I was wondering if someone could give me some clues? Here's my code so far


function destroyer(arr) {
  // Remove all the values

  return arr.filter(function DeleteXValues(val, index){
    return arr[0] == arguments[2];
  });

}

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

I know the filter function return is wrong.

Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 02:54
@JuanP97 i think that you can do like this, trying to understand each line that you are coding (1) The first line will turn the arguments variable into a full array instead of the limited array it currently is.
Joseph
@revisualize
May 17 2017 02:54
@JuanP97 So... arguments is a universal function object.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 02:54
its ok on your code? lets start to understand what is going on
Joseph
@revisualize
May 17 2017 02:55
@JuanP97 Each function has its OWN arguments object.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 02:55
@JuanP97 like this?
function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1;
  });
}
Joseph
@revisualize
May 17 2017 02:56
@JuanP97 So, the function inside of your .filter() has its own arguments object.
Juan Pablo Jaramillo
@JuanP97
May 17 2017 02:56
@revisualize Should I declare in function ('here') ?
or there's no need to declare them
Joseph
@revisualize
May 17 2017 02:58
@JuanP97 Should I declare in function ('here') ? ... I have no idea what this means.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 02:59
@revisualize use the arr.filter() to filter out the elements that are on the array and keep the ones that are not.
Joseph
@revisualize
May 17 2017 02:59
@Leonardo-demeloweb What?
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 02:59
@revisualize The first line will turn the arguments variable into a full array instead of the limited array it currently is.
Next I remove the first argument since I don't need, since I only want the other arguments passed besides the first which is the array we are going to compare against.
Then use the filter() to filter out the elements that are on the array and keep the ones that are not.
Juan Pablo Jaramillo
@JuanP97
May 17 2017 03:00
@revisualize I was trying to say if I should say the function is receiving those arguments like this
function example (arr, index) {
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:00
@revisualize You need to work with arguments as if it was a regular array. The best way is to convert it into one.
Joseph
@revisualize
May 17 2017 03:00
@JuanP97 Your function should have parameters.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:01
@revisualize You need to filter, this also means you need to create a callback function, one that checks if the element is on the indexOf()
Joseph
@revisualize
May 17 2017 03:01
@Leonardo-demeloweb Tell me more.
Juan Pablo Jaramillo
@JuanP97
May 17 2017 03:02
@Leonardo-demeloweb Thank's Leonardo for the explanation.
@revisualize How will you work without Arrays on this occasion?
CamperBot
@camperbot
May 17 2017 03:02
juanp97 sends brownie points to @leonardo-demeloweb and @revisualize :sparkles: :thumbsup: :sparkles:
:cookie: 218 | @leonardo-demeloweb |http://www.freecodecamp.com/leonardo-demeloweb
:star2: 3979 | @revisualize |http://www.freecodecamp.com/revisualize
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:02
@revisualize To convert arguments into an array use this code var args = Array.prototype.slice.call(arguments);
@JuanP97
Joseph
@revisualize
May 17 2017 03:02
@Leonardo-demeloweb Yeah? How does that work?
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:03
@revisualize will turn the arguments variable into a full array instead of the limited array it currently is.
@JuanP97
Joseph
@revisualize
May 17 2017 03:03
@Leonardo-demeloweb No way. You sure?
Xi
@yuman959
May 17 2017 03:03
Hi friends, I got stuck on Twitch API validating non-existant user - comster404. This user doesn’t exist, but when I call the api: https://wind-bow.gomix.me/twitch-api/streams/comster404?callback=?, the console-network doen’t show any error message in the object data returned under Preview and the status is simply null like when it’s offline. How should I parse the returned data for this non-existant user? https://codepen.io/yuman959/pen/wdXMgj Thank you so much!!!
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:03
can i show you my code to represent this? @revisualize i am sure man
Joseph
@revisualize
May 17 2017 03:03
@Leonardo-demeloweb Interesting.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:04
@revisualize
function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1;
  });
}
abraham anak agung
@padunk
May 17 2017 03:04
@Giveback007 thank you for the flexbox youtube, it is super easy yeah. definitely going to try it. so is flexbox need bootstrap?
CamperBot
@camperbot
May 17 2017 03:04
padunk sends brownie points to @giveback007 :sparkles: :thumbsup: :sparkles:
:cookie: 303 | @giveback007 |http://www.freecodecamp.com/giveback007
Gabe Rotberg
@grotberg
May 17 2017 03:04
@yuman959 you can use a different api route to get that info : https://wind-bow.glitch.me/twitch-api/users/comster404?callback=?
Juan Pablo Jaramillo
@JuanP97
May 17 2017 03:04
@Leonardo-demeloweb Leonardo why did you put slice.call(arguments . When you were creating the array?
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:04
@revisualize why not?
Joseph
@revisualize
May 17 2017 03:05

@Leonardo-demeloweb

function destroyer(arr) { 
    // get the values after our initial array, these will be removed.
    // the .slice 1. removes arguments[0] from the new Array
    // arguments[0] is arr and we don't want to remove arr elements.
    var removeThese = Array.prototype.slice.call(arguments, 1);

    // Filter through our array, remove our unwanted values
    // this basically iterates through "arr" and challenges them against
    // our filter function
    return arr.filter(function (v) { 
        // if remove_these does not contain value
        if (removeThese.indexOf(v) === -1) { 
            // return true, since we will be letting this value stay in "arr"
            return true;
        }
    });
}

... I then refactored the code to this:


function destroyer(arr) { 
    var remove = Array.prototype.slice.call(arguments, 1);
    return arr.filter(v => remove.indexOf(v) === -1);
}

... Then I refactored the code to this:

function destroyer(arr) { 
    var remove = Array.from(arguments).slice(1);
    return arr.filter(v => !remove.includes(v));
}

And.. here's another solution as well....

function destroyer(arr) {
  return arr.filter(function(val) {
         return Array.prototype.indexOf.call(this,val,1)===-1;
  } , arguments);
}
....
@Leonardo-demeloweb :O
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:06
@revisualize and?
Joseph
@revisualize
May 17 2017 03:06
@Leonardo-demeloweb I honestly have no idea why you told me all of that stuff. I don't need help with the challenge.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:07
function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1;
  });
}
why is it wrong?
Joseph
@revisualize
May 17 2017 03:07
I'm here to help people.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:07
we have alway some thing to learn
Joseph
@revisualize
May 17 2017 03:07
Did I say something was wrong with your solution?
I'm really confused right now.
What the fuck is going on? Did I miss something?
I'm just here to offer help to people trying to learn JavaScript.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:08
@revisualize Why are yiou overeacting? I am just trying to help as well and have conversations about
Joseph
@revisualize
May 17 2017 03:08
I don't know what is happening.
h1tag
@h1tag
May 17 2017 03:08
@yuman959 just show some message that the channel is deleted or doesn't exist
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:08
@revisualize just think on your own reaction
Joseph
@revisualize
May 17 2017 03:09
@Leonardo-demeloweb Did you mis-tag me in a bunch of posts that should have been directed @JuanP97
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:09
we was tsalking about the same thing
Joseph
@revisualize
May 17 2017 03:09
I'm really confused right now. I'm just going to walk the hell away.
:v:
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:09
because both of you are talking about something that every body can express them selfs
Ademola Adegbuyi
@ooade
May 17 2017 03:10
@revisualize :smile:
Xi
@yuman959
May 17 2017 03:11
@grotberg great this api actually show me the error message under Preview. But somehow I want to print the message value (User \"comster404\" is unavailable) to html and it doesn’t do anything. Do you see any issue with my code? https://codepen.io/yuman959/pen/wdXMgj
Gabe Rotberg
@grotberg
May 17 2017 03:12
@yuman959 I'll take a look/
Xi
@yuman959
May 17 2017 03:12
Awesme!!!
Arthur Ryan Ballon
@ryanart
May 17 2017 03:12
help... myVar should equal 88
myVar = myVar should be changed
Use the ++ operator
Do not change code above the line
Juan Pablo Jaramillo
@JuanP97
May 17 2017 03:13
@Leonardo-demeloweb Leonardo can I ask why are you calling arguments in your code. ?
Gabe Rotberg
@grotberg
May 17 2017 03:14
@yuman959 i think you might need to resave your pen? I think I'm seeing an older version
Xi
@yuman959
May 17 2017 03:14
ok
one sec
saved
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:15
@JuanP97 here is the syntax of the array.splice() array.splice(start, deleteCount[, item1[, item2[, ...]]])
This method changes array's content by removing existing elements and/or adding new elements.
Xi
@yuman959
May 17 2017 03:16
@grotberg
Gabe Rotberg
@grotberg
May 17 2017 03:16
@yuman959 Oh, I see. $("h3comster404")
@yuman959 need a # in there to reference the ID of that element
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:17
@JuanP97 This problem is a bit tricky because you have to familiarize yourself with Arguments
Xi
@yuman959
May 17 2017 03:17
OHHHH!!! @grotberg thanks a million!!!
CamperBot
@camperbot
May 17 2017 03:17
yuman959 sends brownie points to @grotberg :sparkles: :thumbsup: :sparkles:
:cookie: 379 | @grotberg |http://www.freecodecamp.com/grotberg
Xi
@yuman959
May 17 2017 03:17
It’s tricky
Gabe Rotberg
@grotberg
May 17 2017 03:17
@yuman959 :+1:
@yuman959 yeah, hard to remember all those .s and #s sometimes
Netrunner21
@Netrunner21
May 17 2017 03:17
I had never thought in depth about the difference between slice() and splice(). Thanks @Leonardo-demeloweb
CamperBot
@camperbot
May 17 2017 03:17
netrunner21 sends brownie points to @leonardo-demeloweb :sparkles: :thumbsup: :sparkles:
:cookie: 219 | @leonardo-demeloweb |http://www.freecodecamp.com/leonardo-demeloweb
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:18
@JuanP97 You need to work with arguments as if it was a regular array. The best way is to convert it into one.
Juan Pablo Jaramillo
@JuanP97
May 17 2017 03:18
@Leonardo-demeloweb Thanks Leonardo. I'll research more about arguments, perhaps that will help me understand the problem
CamperBot
@camperbot
May 17 2017 03:18
juanp97 sends brownie points to @leonardo-demeloweb :sparkles: :thumbsup: :sparkles:
:warning: juanp97 already gave leonardo-demeloweb points
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:19
@Netrunner21 perhaps a understood wrong, sorry
@Netrunner21 perhaps I understood wrong, sorry
Netrunner21
@Netrunner21
May 17 2017 03:19
@Leonardo-demeloweb I just popped in and saw you talk about splice, and realised I had confused the two, you didn't do anything wrong.
Leonardo de Melo
@Leonardo-demeloweb
May 17 2017 03:20
@Netrunner21 it is ok, no problem
thanks
quanmap612
@quanmap612
May 17 2017 03:24
can anyone help me with Regular Expressions: Reuse Patterns Using Capture Groups?
here is my code so far....
let repeatNum = "42 42 42";
let reRegex = /(\d+\s)\1/; // Change this line
let result = reRegex.test(repeatNum);
Netrunner21
@Netrunner21
May 17 2017 03:25
@quanmap612 sure
quanmap612
@quanmap612
May 17 2017 03:25
thank you
Netrunner21
@Netrunner21
May 17 2017 03:26
which section is this in?
I'm not finding it by that name
quanmap612
@quanmap612
May 17 2017 03:26
it is on beta freecode camp
regular expression
the third one from the bottom
Netrunner21
@Netrunner21
May 17 2017 03:27
then I haven't done it, but I'll be more than welcome to look at it if you link it to me
quanmap612
@quanmap612
May 17 2017 03:27
I am new here, so how do I link it?
Netrunner21
@Netrunner21
May 17 2017 03:28
just post the url here
Netrunner21
@Netrunner21
May 17 2017 03:29
give me a minute to digest it lol
quanmap612
@quanmap612
May 17 2017 03:32
oh ok thank you
abraham anak agung
@padunk
May 17 2017 03:33
@quanmap612 you could test you regex in https://regex101.com
quanmap612
@quanmap612
May 17 2017 03:36
@padunk thank you
CamperBot
@camperbot
May 17 2017 03:36
quanmap612 sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 320 | @padunk |http://www.freecodecamp.com/padunk
Daniel Zeff
@Diesirae9
May 17 2017 03:37
Hey Guys, how do i post code so it looks nice. For you guys?
Netrunner21
@Netrunner21
May 17 2017 03:37
backticks ```
below the esc button
1) three backticks
2) shift+enter
3) paste code in hole
4) CMD+ENTER
Daniel Zeff
@Diesirae9
May 17 2017 03:39
function titleCase(str) {
 var words = str.split(" ");
  for (i=0;i < words.length; i++) {
    return str[i].charAt(0).toUpperCase() + str.slice(1);
  }


}
titleCase("i'm a little tea pot");
oooo that's fancy!
Might I ask where I have goofed :)
Netrunner21
@Netrunner21
May 17 2017 03:40
@quanmap612 did you get it figured out?
quanmap612
@quanmap612
May 17 2017 03:41
I am still in the process of testing
Daniel Zeff
@Diesirae9
May 17 2017 03:43
Any one wanting to help a lost soul? :)
Netrunner21
@Netrunner21
May 17 2017 03:43
@Diesirae9 I solved it a few weeks ago, but mine is very long, so I'm not sure I can help
@Diesirae9 My code works, but I think there is an easier way to do it.
Daniel Zeff
@Diesirae9
May 17 2017 03:43
I see
Netrunner21
@Netrunner21
May 17 2017 03:44
@Diesirae9 I figured out an easier way I think working one of the algoritms, I'd have to go back and check
Daniel Zeff
@Diesirae9
May 17 2017 03:44
I feel like I am on the right track...
I have turned the string into an array, and then have a for loop running the array.
abraham anak agung
@padunk
May 17 2017 03:45
@Diesirae9 if you have return, the function will stop and exit
so basically your function stop at i=0
Daniel Zeff
@Diesirae9
May 17 2017 03:46
Ahhh
so I need a variable that exists for the loop?
Christopher McCormack
@cmccormack
May 17 2017 03:47
@Diesirae9 you're also iterating over an array of words but you're string build is creating a string with a capital letter then the rest of the entire original string. You'll want to build multiple strings then combine them into a new sentence
Netrunner21
@Netrunner21
May 17 2017 03:47
@Diesirae9 you may need to lowercase everything before you begin because some of the test cases have odd capitalization.
Daniel Zeff
@Diesirae9
May 17 2017 03:49
Thank you guys much more too it than I was thinking.. back to it :)
@padunk @cmccormack @Netrunner21 Thank you cookies for all!
CamperBot
@camperbot
May 17 2017 03:50
diesirae9 sends brownie points to @padunk and @cmccormack and @netrunner21 :sparkles: :thumbsup: :sparkles:
:cookie: 294 | @netrunner21 |http://www.freecodecamp.com/netrunner21
:cookie: 321 | @padunk |http://www.freecodecamp.com/padunk
:cookie: 583 | @cmccormack |http://www.freecodecamp.com/cmccormack
abraham anak agung
@padunk
May 17 2017 03:51
@Diesirae9 there is a difference between .split("") and .split(" ") in this case i think it is easier to use regex and replace :)
David Amanze
@GodKingShogun
May 17 2017 03:54
check out my website :smile:
Netrunner21
@Netrunner21
May 17 2017 03:57
facts abouit kevin hart lol
@GodKingShogun looks good man
Rafael Shono
@JUCKA23
May 17 2017 04:13

What is wrong with my code ?
It is the thirde exercise from basic algorithm
var resultado = [];
var fatorial=[];
var valor = 0;

function factorialize(num) {
var retornar =0;
var guardar =0;
fatorial.push(guardar);
while(guardar<=num){

 resultado.push(guardar);
guardar++;

}
resultado.shift();
resultado.reduce(function(a,b){
return a*b;
});

}
factorialize(5);

Ogundele Olumide
@Lumexralph
May 17 2017 04:15
@JUCKA23 you don't need an array, you can simply use a loop and if you understand recursion, you can use that too
Richard Manzoli
@richmanzoli
May 17 2017 04:17
i need help! i have a question -> Change the 0.0 so that quotient will equal to 2.2.
and a code -> var quotient = 0.0 / 2.0; // Fix this line
Ogundele Olumide
@Lumexralph
May 17 2017 04:18
@richmanzoli multiply 2.2 with 2.0
Rafael Shono
@JUCKA23
May 17 2017 04:18
thank you @Lumexralph , but there is anayway to make what I did work, or will not work at all ?
CamperBot
@camperbot
May 17 2017 04:18
jucka23 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1766 | @lumexralph |http://www.freecodecamp.com/lumexralph
Richard Manzoli
@richmanzoli
May 17 2017 04:18
i have this rules -> The variable quotient should equal 2.2, You should use the / operator to divide 4.4 by 2, The quotient variable should only be assigned once
Ogundele Olumide
@Lumexralph
May 17 2017 04:20
@JUCKA23
return resultado.reduce(function(a,b){
return a*b;
});
Richard Manzoli
@richmanzoli
May 17 2017 04:20
i make this var quotient = 4.4 / 2;
Ogundele Olumide
@Lumexralph
May 17 2017 04:20
@JUCKA23 you're not returning the value accumulated from the reduced array
Richard Manzoli
@richmanzoli
May 17 2017 04:20
but break this rule The quotient variable should only be assigned once
Ogundele Olumide
@Lumexralph
May 17 2017 04:22
show your code
Vicky Lai
@vickylai
May 17 2017 04:22

Steamroller:

function steamrollArray(arr) {
    var flat = arr.reduce(function(prev,curr){
      return prev.concat(curr);
    }, []);
  console.log('flat: ',flat)
}

Gives this: flat: [ 1, 2, 3, [ [ 4 ] ] ]

How can I address the next level of nested arrays?

Ogundele Olumide
@Lumexralph
May 17 2017 04:23
@vickylaiio you need to look for a way to check if the value you have is an array then you reduce it
Rafael Shono
@JUCKA23
May 17 2017 04:24
@Lumexralph ok tanks for the help
Vicky Lai
@vickylai
May 17 2017 04:24
@Lumexralph I can use Array.isArray, but what I mean is more.. how can I implement that without going into if statements?
Joseph
@revisualize
May 17 2017 04:26
Hi.
Markus Ivancsics
@ivancsicsmarkus
May 17 2017 04:28
@revisualize Hi
Marlon
@borgatajunky
May 17 2017 04:45

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
product *= arr[i][j];
}
}
// Only change code above this line
return product;
}

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

Hello all. Even though I came to the correct conclusion for this problem I am confused as to why I only needed 2 for loops when there are 3 arrays. Any clarification on this would be helpful and much appreciated. I have a feeling Im going to regret asking this question but I dont want to move on until its sunk in. Gratitude

Ogundele Olumide
@Lumexralph
May 17 2017 04:47
@borgatajunky you have 2-dimensional array [ [ ... ], [......], [.......] ] an array in another array
@borgatajunky the 3 arrays are in an array, can you see the structure ?
Marlon
@borgatajunky
May 17 2017 04:48
I'm trying.
Ogundele Olumide
@Lumexralph
May 17 2017 04:49
@borgatajunky take a loot at this [ [......] ] what's that?
Marlon
@borgatajunky
May 17 2017 04:49
an array nested in an array
Ogundele Olumide
@Lumexralph
May 17 2017 04:50
@borgatajunky cool, it's 2 - dimensional
@borgatajunky how about this [ [ [.......] ] ]
Marlon
@borgatajunky
May 17 2017 04:51
an array nested in an array nested in another array
Ogundele Olumide
@Lumexralph
May 17 2017 04:51
@borgatajunky cool, 3 -dimensional
Marlon
@borgatajunky
May 17 2017 04:52
the last one (3 dimensional) would need 3 for loops?
Richard Kreidi
@bedouintravels
May 17 2017 04:52

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

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

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

Ogundele Olumide
@Lumexralph
May 17 2017 04:52
@borgatajunky now what is this [ [ ... ], [......], [.......] ] ?
Richard Kreidi
@bedouintravels
May 17 2017 04:52
sorry, the code gets the required result but FCC doesn't allow it
Marlon
@borgatajunky
May 17 2017 04:52
2 dimensional?
Ogundele Olumide
@Lumexralph
May 17 2017 04:53
@borgatajunky yes, you'll need to 3 loops for the 3-dimensional sub-array elements
@borgatajunky so how many time do you need to loop 2-dimensional array to get it's sub-array elements?
Marlon
@borgatajunky
May 17 2017 04:54
twice
Claudio Restifo
@Marmiz
May 17 2017 04:54

Hello, someone is willing to land me a hand on React-Router 4?
I'm trying to implement a simple Auth. The logic is all there and is working besides the redirect after login/logout.
In react-router v3 I would simply:

// the server reply that the user is authenticated:

 this.context.router.replace('/dashboard');

same goes for the logout. In the route.js I would deautenticate the user and redirect where needed:

path: '/logout',
      onEnter: (nextState, replace) => {
        Auth.deauthenticateUser();


        replace('/HomePage');

Now I'm facing lots of struggle to import the same logic in the new v4 without the need of a store like Redux.connect().
At first I thought that for logging in would be enough to:

// the server reply that the user is authenticated:

        <Redirect to="/dashboard"/>

But it's not doing anything :/
Any advice?
thanks <3

Ogundele Olumide
@Lumexralph
May 17 2017 04:54
@borgatajunky that's why you had to loop twice
Marlon
@borgatajunky
May 17 2017 04:55
ty so much. I feel much more comfortable moving on. Im still going to research this further though. appreciated.
Quentin Butler
@quentin1431
May 17 2017 04:56
@bedouintravels Hi, you can remove the return "Change Me"; it's not gonna do anything. Also add brackets around the par part as such: if (strokes <= (par -2))
Richard Kreidi
@bedouintravels
May 17 2017 04:58
hi @quentin1431 it's lighting up green for most of the examples except for golfScore(4, 1) and golfScore(1, 1). So it has something to do with the first if statement I believe.
Long Nguyen
@longnt80
May 17 2017 05:00
Just finished the "No Repeat Please" challenge using Heap's algorithm, but I still can't figure out how Heap's algorithm works :worried:
Quentin Butler
@quentin1431
May 17 2017 05:03
@bedouintravels Oh, it should only be == and not ===
Richard Kreidi
@bedouintravels
May 17 2017 05:03
@quentin1431 I've tried that as well but it won't accept it ???
Listener23
@Listener23
May 17 2017 05:05
I need help with this
Quentin Butler
@quentin1431
May 17 2017 05:05
@bedouintravels
This is mine and works perfectly.
function golfScore(par, strokes) {
  // Only change code below this line
  if(strokes == 1) {
    return "Hole-in-one!";
  }
  else if(strokes <= (par - 2)) {
    return "Eagle";
  }
  else if(strokes <= (par - 1)) {
    return "Birdie";
  }
  else if(strokes == par) {
    return "Par";
  }
  else if(strokes == (par + 1)) {
    return "Bogey";
  }
  else if(strokes == (par + 2)) {
    return "Double Bogey";
  }
  else if(strokes >= (par + 3)) {
    return "Go Home!";
  }    
  // Only change code above this line
}
@bedouintravels Can you compare your to mine and see something different?
@bedouintravels Can it be just the ! missing, such as in "Hole-in-one!" ?
quanmap612
@quanmap612
May 17 2017 05:08
can anyone explain regular expressions capturing groups?
let repeatStr = "regex regex";
let repeatRegex = /(\w+)\s\1/;
repeatRegex.test(repeatStr); // Returns true
repeatStr.match(repeatRegex); // Returns ["regex regex", "regex"]
I don't understand "\1" do
Richard Kreidi
@bedouintravels
May 17 2017 05:09
@quentin1431 omg, it was the !
thank you for your help
CamperBot
@camperbot
May 17 2017 05:09
bedouintravels sends brownie points to @quentin1431 :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @quentin1431 |http://www.freecodecamp.com/quentin1431
Quentin Butler
@quentin1431
May 17 2017 05:09
@bedouintravels LOL, no problem.
harshdalal442
@harshdalal442
May 17 2017 05:15
Hi, can anyone help inside Counting Cards problem in freecodecamp.
Liam Powley
@Web-dev-liam
May 17 2017 05:15
Help please says sort isn't a function
arr3.sort(function(a,b){
return a - b;
});
harshdalal442
@harshdalal442
May 17 2017 05:16

var count = 0;
var times = 0;
function cc(card) {
// Only change code below this line
if(card == 2 || card == 3 || card == 4 || card == 5 || card == 6)
count++;
if(card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A')
count--;
times++;
if(times == 5)
{
var answer = "";
answer += count;
if(count < 0)
answer+= " Hold";
else
answer+= " Bet";
return answer;
}
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);

Ogundele Olumide
@Lumexralph
May 17 2017 05:16
@Web-dev-liam what's data type of arr3 ?
@harshdalal442 firstly, FCC used just one global variable count, var times should be in the function
harshdalal442
@harshdalal442
May 17 2017 05:18
@Lumexralph Then it wont ever reach to 5, and wont display the message.
Ogundele Olumide
@Lumexralph
May 17 2017 05:19
@harshdalal442 why do you need times ?
Long Nguyen
@longnt80
May 17 2017 05:19
@quanmap612
here's an example:
/[a]\w[a]/g
in this case you want to match any words with letter a on each side right?
you can use capturing group to not have to repeat typing the [a] like this:
/([a])\w\1/g
harshdalal442
@harshdalal442
May 17 2017 05:19
Because it says after 5 cards are read, then only display the message
I dont understand how to implement that without using another global variable.
Ogundele Olumide
@Lumexralph
May 17 2017 05:21
@harshdalal442 the card parameter holds the card values, FCC calls the function 5 times during its tests, don't worry about that
@harshdalal442 just implement your function
@harshdalal442 removing whatever times is doing in your code, just check count return count + appropriate string based on whether it's positive or negative
harshdalal442
@harshdalal442
May 17 2017 05:22
@Lumexralph Thanks a lot :+1:
CamperBot
@camperbot
May 17 2017 05:22
harshdalal442 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1767 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
May 17 2017 05:23
@harshdalal442 :+1:
Markus Kiili
@Masd925
May 17 2017 05:24
@Lumexralph Morning.
Ogundele Olumide
@Lumexralph
May 17 2017 05:24
@Masd925 Hey Bro!
@Masd925 slept well?
Markus Kiili
@Masd925
May 17 2017 05:25
@Lumexralph Yeah. How about you?
Ogundele Olumide
@Lumexralph
May 17 2017 05:25
@Masd925 did too, working on asteroids arcade game ...since I woke up
zxyango
@zxyango
May 17 2017 05:26
The results are correct, why not pass?
Ogundele Olumide
@Lumexralph
May 17 2017 05:26
@zxyango post the code here
Markus Kiili
@Masd925
May 17 2017 05:26
@zxyango Are you using a global variable there?
zxyango
@zxyango
May 17 2017 05:26
yes
Quentin Butler
@quentin1431
May 17 2017 05:26
@zxyango Passes just fine by me. Maybe refresh browser.
Markus Kiili
@Masd925
May 17 2017 05:26
@zxyango It will mess up FCC tests most likely.
zxyango
@zxyango
May 17 2017 05:26
I use a global variable
Ogundele Olumide
@Lumexralph
May 17 2017 05:27
@zxyango FCC doesn't like globals
zxyango
@zxyango
May 17 2017 05:27
I understand
Ogundele Olumide
@Lumexralph
May 17 2017 05:27
@zxyango i think it doesn't reset globals which might affect the result
Markus Kiili
@Masd925
May 17 2017 05:27
@zxyango You can change the logic, or make a wrapper function around the variable and the function.
zxyango
@zxyango
May 17 2017 05:28
@Lumexralph @Masd925 ok,thank you!
CamperBot
@camperbot
May 17 2017 05:28
zxyango sends brownie points to @lumexralph and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1768 | @lumexralph |http://www.freecodecamp.com/lumexralph
:star2: 4086 | @masd925 |http://www.freecodecamp.com/masd925
zxyango
@zxyango
May 17 2017 05:28
i try a new method
Kelechi Chinaka
@ke1echi
May 17 2017 05:29
greetings @Lumexralph
Ogundele Olumide
@Lumexralph
May 17 2017 05:30
@kelechichinaka Good morning bro
Kelechi Chinaka
@ke1echi
May 17 2017 05:31
quick one ```
var a = 123;
a.toString();
gives me 123 @Lumexralph
Ogundele Olumide
@Lumexralph
May 17 2017 05:32
@kelechichinaka okay....
what's the question?
Markus Kiili
@Masd925
May 17 2017 05:32
@kelechichinaka '123' actually
Kelechi Chinaka
@ke1echi
May 17 2017 05:32
want "123" @Lumexralph
Ogundele Olumide
@Lumexralph
May 17 2017 05:32
@Masd925 :smirk:
Markus Kiili
@Masd925
May 17 2017 05:33
@kelechichinaka That gives you a string.
Ogundele Olumide
@Lumexralph
May 17 2017 05:33
@kelechichinaka it's a string
@kelechichinaka check it use typeof
Kelechi Chinaka
@ke1echi
May 17 2017 05:34
no, it returns 123 @Lumexralph @Masd925
Long Nguyen
@longnt80
May 17 2017 05:34
@kelechichinaka
var a = 123;
a.toString();
console.log(typeof a); // string
Ogundele Olumide
@Lumexralph
May 17 2017 05:34
@kelechichinaka no doubt it's 123 on the console, check the data type if it's a number or a string
Markus Kiili
@Masd925
May 17 2017 05:34
@kelechichinaka It returns a string. Different consoles just show strings differently.
@kelechichinaka What the console shows doesn't matter.
Long Nguyen
@longnt80
May 17 2017 05:35
@kelechichinaka in the console the string may be shown as 123
Kelechi Chinaka
@ke1echi
May 17 2017 05:35
shows 123 in console @Lumexralph @Masd925 @longnt80
Long Nguyen
@longnt80
May 17 2017 05:36
@kelechichinaka the console cannot show it as "123"
Ogundele Olumide
@Lumexralph
May 17 2017 05:36
@kelechichinaka use typeof to check as @longnt80 previously illustrated
Kelechi Chinaka
@ke1echi
May 17 2017 05:37
typeof returns number @Lumexralph @Masd925 @longnt80
Ogundele Olumide
@Lumexralph
May 17 2017 05:38

@kelechichinaka

var a = 123;
let b = a.toString();
console.log(typeof b); // string

run that in the console you're using

Markus Kiili
@Masd925
May 17 2017 05:38
@kelechichinaka What the value is matters. Not how it is shown on the console.
Long Nguyen
@longnt80
May 17 2017 05:40
@kelechichinaka sorry:
var a = 123;
a.toString();
console.log(typeof a.toString());
@kelechichinaka it returns a string but it doesn't change a
Kelechi Chinaka
@ke1echi
May 17 2017 05:42
i like the idea @Lumexralph
i want it to return a string @longnt80
thanks guys...fixed @longnt80 @Lumexralph @Masd925
CamperBot
@camperbot
May 17 2017 05:42
:cookie: 269 | @longnt80 |http://www.freecodecamp.com/longnt80
:star2: 1769 | @lumexralph |http://www.freecodecamp.com/lumexralph
:star2: 4087 | @masd925 |http://www.freecodecamp.com/masd925
kelechichinaka sends brownie points to @longnt80 and @lumexralph and @masd925 :sparkles: :thumbsup: :sparkles:
Long Nguyen
@longnt80
May 17 2017 05:43
@kelechichinaka
var a = 123;
a = a.toString();
console.log(typeof a);
Quentin Butler
@quentin1431
May 17 2017 05:43

Can someone please show me how. I am trying below code:

function checkCashRegister(price, cash) {
  var result = [];
  var change = (cash - price).toFixed(2);

  var arr = [];
  arr.push("QUARTER");
  arr.push(change);
  result.push(arr);

  return result;
}

checkCashRegister(19.50, 20.00);

Result is: [["QUARTER","0.50"]]
I need result to be: [["QUARTER",0.50]]

Anurag Lahon
@anuraglahon16
May 17 2017 05:44
Given an array of one's and zero's convert the equivalent binary value to an integer. how to do these?
Markus Kiili
@Masd925
May 17 2017 05:44
@quentin1431 For rounding a number, you can use Number(num.toFixed(n))
Sourav Borah
@Souravborah
May 17 2017 05:45
what is your probelm? @anuraglahon16
Anurag Lahon
@anuraglahon16
May 17 2017 05:45
@Souravborah how to solve these problem
Quentin Butler
@quentin1431
May 17 2017 05:45
@Masd925 But then it drop the zero at the end I end up with 0.5 instead of 0.50
Markus Kiili
@Masd925
May 17 2017 05:46
@quentin1431 That is the same number. How it is shown doesn't matter.
Long Nguyen
@longnt80
May 17 2017 05:46
@anuraglahon16 use parseInt(str, 2) to convert binary to integer
Quentin Butler
@quentin1431
May 17 2017 05:46
@Masd925 It does matter else the test of FCC does not pass.
Markus Kiili
@Masd925
May 17 2017 05:47
@quentin1431 If the numbers are correct it will pass regardless of how the numbers are shown. The error is elsewhere.
Anurag Lahon
@anuraglahon16
May 17 2017 05:47
@longnt80 oh lets try
Quentin Butler
@quentin1431
May 17 2017 05:49
@Masd925 Okay thanks, let me complete everything first and then see what the result is.
CamperBot
@camperbot
May 17 2017 05:49
quentin1431 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4088 | @masd925 |http://www.freecodecamp.com/masd925
Maximus
@maximusfi
May 17 2017 05:59
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
{Can anyone walk me thru this, it doesn't make sense to me.
Andrea
@sailortaco
May 17 2017 06:01

'''
// Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line

var lookup = {

"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank",

};

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

// Change this value to test
phoneticLookup("charlie");

CamperBot
@camperbot
May 17 2017 06:01
:bulb: to format code use backticks! ``` more info
Andrea
@sailortaco
May 17 2017 06:01
Hi guys need help
Maximus
@maximusfi
May 17 2017 06:02
What do you need help with ?
Ogundele Olumide
@Lumexralph
May 17 2017 06:02
@maximusfi you need 2 array methods, what array method will you use to add a value to the end of an array?
Andrea
@sailortaco
May 17 2017 06:02

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

  // Only change code below this line

  var lookup =  {

    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank",

  };

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

// Change this value to test
phoneticLookup("charlie");
Ogundele Olumide
@Lumexralph
May 17 2017 06:03
@sailortaco you need to use the val parameter of your function to access the value of the property name held by the parameter amd assign it to result
Andrea
@sailortaco
May 17 2017 06:04
@Lumexralph I'm not sure how to incorporate "val" into my object
Ogundele Olumide
@Lumexralph
May 17 2017 06:05
@sailortaco just as you use a variable to access an object using bracket notation
Maximus
@maximusfi
May 17 2017 06:06
An array is created [1,2,3,4,5] correct ? @Lumexralph
Ogundele Olumide
@Lumexralph
May 17 2017 06:07
@maximusfi you need to use push method
@maximusfi push item into arr
Andrea
@sailortaco
May 17 2017 06:08
@Lumexralph i was under the impression that you could only change the code between the comments...
Long Nguyen
@longnt80
May 17 2017 06:09
@sailortaco you can reassign result between the comment
Ogundele Olumide
@Lumexralph
May 17 2017 06:09
@sailortaco it's still within just assign it to result before
Andrea
@sailortaco
May 17 2017 06:12
OH thanks guys! I got it down
:)
Anurag Lahon
@anuraglahon16
May 17 2017 06:15
What does this mean ?const binaryArrayToNumber = arr => {
Marlon
@borgatajunky
May 17 2017 06:15

//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){
var i = 0;
while (i < contacts.length) {
if(contacts[i].firstName === firstName && contacts[i].hasOwnProperty === contacts[i].prop) {
return contacts[i][prop];
}else if (contacts[i].firstName !== firstName) {
return "No such contact";
}else if (contacts[i].property !== prop) {
return "No such property";
}
i++;

}
// Only change code below this line

// Only change code above this line
}

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

help lol
Long Nguyen
@longnt80
May 17 2017 06:17
@anuraglahon16
const binaryArrayToNumber = arr => {
create a constant binaryArrayToNumber
assign a function with parameter arr to that constant
Anurag Lahon
@anuraglahon16
May 17 2017 06:17
@longnt80 how we write this in simple code
function binaryArrayToNumber(arr) {same?
Long Nguyen
@longnt80
May 17 2017 06:18
@anuraglahon16 it is the simple code
the complex code would be:
const binaryArrayToNumber = function(arr){...

function binaryArrayToNumber(arr) {same?

yes

Marlon
@borgatajunky
May 17 2017 06:20
function lookUpProfile(firstName, prop){
var i = 0;
while (i < contacts.length) {
if(contacts[i].firstName === firstName && contacts[i].hasOwnProperty === prop) {
return contacts[i][prop];
}else if (contacts[i].firstName !== firstName) {
return "No such contact";
}else if (contacts[i].property !== prop) {
return "No such property";
}
i++;}
Anurag Lahon
@anuraglahon16
May 17 2017 06:20
@longnt80 thnx
CamperBot
@camperbot
May 17 2017 06:20
anuraglahon16 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @longnt80 |http://www.freecodecamp.com/longnt80
chintan7135
@chintan7135
May 17 2017 06:20

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("cat", "little", "hit", "slowly");

whats the solution ?
what it says?
Long Nguyen
@longnt80
May 17 2017 06:21
@anuraglahon16 actually function binaryArrayToNumber(arr) {... is the same as var binaryArrayToNumber = function(arr) {...
Anurag Lahon
@anuraglahon16
May 17 2017 06:22
@longnt80 oh
Markus Kiili
@Masd925
May 17 2017 06:22
@longnt80 It is not the same, but the differences are small.
Long Nguyen
@longnt80
May 17 2017 06:25
@Masd925 with function binaryArrayToNumber(arr) {... can you declare binaryArrayToNumber as a const?
Markus Kiili
@Masd925
May 17 2017 06:26
@longnt80 I believe that you can reassign to the function name. So it is not a constant.
Anurag Lahon
@anuraglahon16
May 17 2017 06:27
@longnt80 okk lets see
Marlon
@borgatajunky
May 17 2017 06:27

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

// Only change code below this line

function lookUpProfile(firstName, prop){
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 if (contacts[i].property !== prop) {
return "No such property";
}
}
// Only change code above this line
}

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

Long Nguyen
@longnt80
May 17 2017 06:27
@Masd925 I meant can you reassign it as a const?
Dakota Woods
@Dakoa
May 17 2017 06:28
Hey could anyone help ne with the Longest Word challenge? My code returns the first word of a string instead of the longest word and I don't know why. Here's my code:
function findLongestWord(str) {
str = str.split(" ");
var longestWord = [0];
for (var i = 0;i<str.length; i++){ if (str[i].length > longestWord){
longestWord = str[i];
}
}
return longestWord;
}
   findLongestWord("The quick brown fox jumped over the lazy dog");
Markus Kiili
@Masd925
May 17 2017 06:29
@longnt80 Don't know. Differences between those two ways are hoisting (declaration is hoisted), name property (declared function has a name property) and use inside control structures (declaration cannot be used inside control structures if/try/while/for etc).
lagasi
@lagasi
May 17 2017 06:36
@Dakoa str[i].length > longestWord.length
Luke Sallmen
@LukeSallmen
May 17 2017 06:36
@Dakoa Yeah, I was going to say the same thing, the problem is the comparison
now, I'm on the same challenge, any help on mine?

function findLongestWord(str) {
  var splitStringArr = str.split(' ');
  for (var i; i < splitStringArr.length; i++) {
  var longestWordSoFar;
  if (splitStringArr[i].length > longestWordSoFar.length) {
    longestWordSoFar = splitStringArr[i];
  }
 if (i == splitStringArr.length) {return longestWordSoFar.length;}
  }
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Dakota Woods
@Dakoa
May 17 2017 06:36
@lagasi Thank you very much
CamperBot
@camperbot
May 17 2017 06:36
:cookie: 81 | @lagasi |http://www.freecodecamp.com/lagasi
dakoa sends brownie points to @lagasi :sparkles: :thumbsup: :sparkles:
Luke Sallmen
@LukeSallmen
May 17 2017 06:39
@Dakoa lol what did I do wrong? Mine doesn't return anything
lagasi
@lagasi
May 17 2017 06:39
@LukeSallmen var longestWordsoFar should be above your first loop otherwise, it resets at every interval
Luke Sallmen
@LukeSallmen
May 17 2017 06:40
@lagasi AHHHH. That makes a lot of sense lmao - longestWordSoFar is undefined (I think?) or set to '' - so naturally that's what is returned
@lagasi Thank you.
CamperBot
@camperbot
May 17 2017 06:40
lukesallmen sends brownie points to @lagasi :sparkles: :thumbsup: :sparkles:
:cookie: 82 | @lagasi |http://www.freecodecamp.com/lagasi
lagasi
@lagasi
May 17 2017 06:40
@LukeSallmen Also, you need to initialize your loop var i ... for (var i=0; i < splitStringArr.length; i++)
Luke Sallmen
@LukeSallmen
May 17 2017 06:43
@lagasi Hmm, right. I moved the var declaration above the loop and initialized i to =, but I'm getting a Type Error thrown
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:43
@Masd925 yo
Markus Kiili
@Masd925
May 17 2017 06:43
@HeebieGeeBee Hi.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:44
@Masd925 hows things?
Suraj Yadav
@981suraj
May 17 2017 06:44
Hello, I am stuck at "Testing Objects for Properties"
Long Nguyen
@longnt80
May 17 2017 06:45
@981suraj copy your code
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:45
@Masd925 how are you on OOP?
Markus Kiili
@Masd925
May 17 2017 06:46
@HeebieGeeBee I know java, so I have some knowledge there.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:46
@Masd925 im doing a little work on this arkanoid clone
if you have a look you see all those read squares which youre meant to hit with the ball
Luke Sallmen
@LukeSallmen
May 17 2017 06:47

function findLongestWord(str) {
  var splitStringArr = str.split(' ');
  var longestWordSoFar;
  for (var i = 0; i < splitStringArr.length; i++) {
  if (splitStringArr[i].length > longestWordSoFar.length) {
    longestWordSoFar = splitStringArr[i];
  }

  }
  return longestWordSoFar.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
I'm getting a type error thrown - " Cannot read property length of undefined"
lagasi
@lagasi
May 17 2017 06:48
@LukeSallmen var longestWordSoFar = ""
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:48
function tiles() {
    let x = 0; let y = 70;    let width = 50;    let height = 25; let color = "red";
    for(var i = 0; i < 11; i++) {
        tilesArr.push(new HitSquare(x, y, width, height, color));
        x += width;
    }
}
this is a function im using to generate them at the moment
@Masd925
Nazar
@nazarpelekh
May 17 2017 06:48
Hi everybody))
Luke Sallmen
@LukeSallmen
May 17 2017 06:48
@lagasi bleh, I can't declare it as empty - I must declare it as a string?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:49
but im trying to think if theres way i could use like a sort of map made out of arrays and numbers to generate them
for each level
Nazar
@nazarpelekh
May 17 2017 06:49
I have problem with it
lagasi
@lagasi
May 17 2017 06:50
@LukeSallmen length doesn't exist on undefined variables
Luke Sallmen
@LukeSallmen
May 17 2017 06:50
@lagasi Ah. Kudos
Suraj Yadav
@981suraj
May 17 2017 06:50
@longnt80 can you give me with checkObj function please
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:51
so i would make a two dimensional array like
let level map = [
[1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,0,0,0,0,1,1,1]
]
Long Nguyen
@longnt80
May 17 2017 06:51
@981suraj
which one?
Suraj Yadav
@981suraj
May 17 2017 06:52
How to get true or false return of a function?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:52
so whenever theres a one it will make 1 hit square and where ever theres a 0 it wouldnt
Nazar
@nazarpelekh
May 17 2017 06:52
I will be grateful for the help
Long Nguyen
@longnt80
May 17 2017 06:52
@981suraj can you give the link or copy your code in here
Markus Kiili
@Masd925
May 17 2017 06:53
@HeebieGeeBee Yes. That seems logical if that is the level information you need.
Suraj Yadav
@981suraj
May 17 2017 06:53
I havent. It doesnt work
Long Nguyen
@longnt80
May 17 2017 06:53
@nazarpelekh create a variable inside a function will make it private
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:53
but i cant think of a way i should use that array in function to generate them @Masd925
Markus Kiili
@Masd925
May 17 2017 06:55
@HeebieGeeBee Seems like a reduce or forEach job because you don't generate HitSquares for those zeros?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:55
yes but there still needs to be an empty space
lagasi
@lagasi
May 17 2017 06:56
@nazarpelekh you have a infinite loop cause by the calling getGear inside setGear and setGear inside getGear; also, your variable should be gear
Dakota Woods
@Dakoa
May 17 2017 06:57
Hey yall I'm back with another issue.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:57
hmm actually i think i might have thought of something
Markus Kiili
@Masd925
May 17 2017 06:57
@HeebieGeeBee There could be a function that does the mapping and has some variable that you increment?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:57
yes thats what i was just thinking
the variable could still incriment on each loop, the square just doesnt have to be drawn if its a 0
Dakota Woods
@Dakoa
May 17 2017 06:57
I know that I need to join the strings, but I need help understanding why this code isn't title casing my input string. Here's the code:
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:57
or generated
Dakota Woods
@Dakoa
May 17 2017 06:57

function titleCase(str) {
str=str.toLowerCase().split(" ");
for (var i = 0; i<str.length; i++){
var titleCaseStr = []; titleCaseStr.push(str[i].charAt(0).toUpperCase());

}
return str;
}

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

It returns str.split("")
*str.split(" ")
HeebieGeeBee
@HeebieGeeBee
May 17 2017 06:58
@Masd925 i'll try something for a bit
Masaki
@masaki1223
May 17 2017 06:59
var newArr=[];
var vowels=['a','i','u','e','o'];
//var newStr='';
function translatePigLatin(str) {

  for(var i=0; i<vowels.length; i++){
     if(str[0].indexOf(vowels[i])>=0){
      return str + 'way';
    } else if(str[0].indexOf(vowels[i])<0 && str[1].indexOf(vowels[i])<0){
      return str.substr(2) + str.substr(0,2) +'ay';
    } else{
      return str.substr(1) +str.substr(0,1) + 'ay';
    }

  }
}

translatePigLatin('eight');
I don't know why the first if is not working for 'eight'.
eight should be converted into 'eightway', but its converted to 'ghteiay'.
Please help me....
Dakota Woods
@Dakoa
May 17 2017 07:01
Y
Sorry, didn't mean to type that
Alexandre Conrady
@Aberoom
May 17 2017 07:10
@masaki1223 I think your first condition is testing the letter 'a' first, which doesnt exist in eight.
@masaki1223 I'm guessing you want to test all the letters, store the values of the indexes, and then check if any of the indexes are >= 0
Blauelf
@Blauelf
May 17 2017 07:14
Oh, vowels in the same order as in Japanese alphabet "aiueo"/あいうえお :)
Ogundele Olumide
@Lumexralph
May 17 2017 07:15
@HeebieGeeBee Bro!
Markus Kiili
@Masd925
May 17 2017 07:16
@Blauelf Finnish language has one word that has 7 adjacent vowels.
youUnion619
@youUnion619
May 17 2017 07:17
can anyone help with this code, i didn't understand the min and max part: Math.floor(Math.random() * (max - min + 1)) + min
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:18
@Lumexralph yo
@Masd925 ive managed something
with the mapping
lagasi
@lagasi
May 17 2017 07:20
@youUnion619 What are you trying to achieve?
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:20
function tiles() {
    let x = 0; let y = 70; let width = 50; let height = 25;
    for(let i = 0; i < levelMap.length; i++) {
        for(let j = 0; j < levelMap[i].length; j++) {
            if(levelMap[i][j] > 0) {
                tilesArr.push(new HitSquare(x,y,width,height,tileColors[levelMap[i][j]]));
            }    
            x += 50;
        }
        x = 0;
        y += 25;    
    }
}
did it like this
Alexandre Conrady
@Aberoom
May 17 2017 07:20
@youUnion619 lets work from the end. +min gets your range of numbers to at least the minimum of the range. Max-min +1 is the actual absolute range of values you are targeting, aka if max = 10 and min = 5, you want values from 5 to 10. The +1 part works with the Math.random(), to force values to really be within the range and not drop below.
@youUnion619 Just a guess, someone will correct me if I'm wrong :D
youUnion619
@youUnion619
May 17 2017 07:22
oh ok thanks @Aberoom :D
CamperBot
@camperbot
May 17 2017 07:22
youunion619 sends brownie points to @aberoom :sparkles: :thumbsup: :sparkles:
:cookie: 349 | @aberoom |http://www.freecodecamp.com/aberoom
Markus Kiili
@Masd925
May 17 2017 07:22
@HeebieGeeBee ok.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:22
@Masd925 any ideas to make it more efficient or anything?
or just better ways to do it in general
Blauelf
@Blauelf
May 17 2017 07:23
@Masd925 I fear we Germans only have words with 7 adjacent consonants (probably composed words then). Found a composed one with 7 instantly: "Schiffsschraube"
Markus Kiili
@Masd925
May 17 2017 07:24
@HeebieGeeBee Not really. You could use iterators too and for clarity you could split that into several functions.
@Blauelf Hääyöaie means something you plan to do on a wedding night. So an important word too.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:24
fair enough
Blauelf
@Blauelf
May 17 2017 07:25
@Masd925 Sounds pretty specialised.
Claudio Restifo
@Marmiz
May 17 2017 07:25

@Masd925

Hääyöaie means something you plan to do on a wedding night.

You actually need planning for that? I thought the plan is already written in stone since the beginning of time

:P :P :P
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:26

@Masd925 also in the constructors i have hit detection functions like

    this.edges = (_paddleX, _paddleY, _paddleWidth)=> {
            // left wall bounds detection
            if(this.x < 5) {this.speedX = 3;}
            // right wall bounds detection 
            if(this.x > 495) {this.speedX = -3;}
            // ceiling bounds detection 
            if(this.y < 5){ this.speedY = 3;}
            // paddle hit detection 
            if(this.x > _paddleX && this.x < _paddleX + _paddleWidth && this.y >= _paddleY - this.width/2) {
                this.speedY = -3;
                if(this.x > _paddleX + _paddleWidth/2) {this.speedX = 3;}
                if(this.x < _paddleX + _paddleWidth/2) {this.speedX = -3;}
            }
        }

is this something should be made a prototype

njordomir
@njordomir
May 17 2017 07:26
@Blauelf As someone who spoke German as a child and English as an adult, I really do prefer the German language. It can be so much more descriptive at times. :P
Markus Kiili
@Masd925
May 17 2017 07:27
@Marmiz Yes. Many people consider having children their greatest life achievement. Built-in feature imo.
Blauelf
@Blauelf
May 17 2017 07:27
@njordomir It's also much longer. i18n is a pain for apps developed in English and tranlated to German or French.

My code example
var Bike = function() {

// Only change code below this line.
this.setGear = function(a){
var getGear = a;
};
this.getGear = function(a){
var setGear = a;
};
};

var myCar = new Car();

var myBike = new Bike();

Alexandre Conrady
@Aberoom
May 17 2017 07:29
@nazarpelekh getgear and setgear are mixed up. Also what is the goal of the getgear function?
Nazar
@nazarpelekh
May 17 2017 07:30
@Aberoom myBike.getGear() should return 3 after calling myBike.setGear(3)
Blauelf
@Blauelf
May 17 2017 07:30
@nazarpelekh You should have a local variable in Bike function (like speed in Car), which you use in getGear and setGear.
Zerne
@Zerne
May 17 2017 07:30
@sailortaco Have you finished it yet?
Claudio Restifo
@Marmiz
May 17 2017 07:30
@Masd925 :laughing: :laughing: :laughing:
Blauelf
@Blauelf
May 17 2017 07:30
@nazarpelekh getGear should then return this variable's value, while setGear should update it to a new value.
Alexandre Conrady
@Aberoom
May 17 2017 07:30
@nazarpelekh yup, literally. How does that translate to code?
Nazar
@nazarpelekh
May 17 2017 07:31

@Blauelf I also try this code

var Bike = function() {

// Only change code below this line.
var getGear, setGear;
this.setGear = function(a){
getGear = a;
};
this.getGear = function(a){
setGear = a;
};
};

var myCar = new Car();

var myBike = new Bike();

Alexandre Conrady
@Aberoom
May 17 2017 07:32
@nazarpelekh you might want to make a variable called gear as well by the way ;)
Blauelf
@Blauelf
May 17 2017 07:32
@nazarpelekh Look at how Car works. It should be very similar, though you have a setGear function instead of the two manipulating speed. getGear and getSpeed should be pretty similar.
Nazar
@nazarpelekh
May 17 2017 07:38

@Blauelf
I still don't understand why it doesn't work...
var Bike = function() {

// Only change code below this line.
var getGear, setGear;
this.setGear = function(a){
getGear += a;
};
this.getGear = function(a){
setGear += a;
};
};

Blauelf
@Blauelf
May 17 2017 07:38
@nazarpelekh That does not look at all like Car.
Long Nguyen
@longnt80
May 17 2017 07:39
@nazarpelekh you have to create variable gear
Alexandre Conrady
@Aberoom
May 17 2017 07:42
@nazarpelekh like @longnt80 and I have said, make a variable called gear. How is setGear going to change this variable? What is getGear going to return? That's it.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:50
anyone got any ideas if im making a class in javascript, whether i should make a protoype for the functions
or just have all the functions for the instances kept within the construtor
Blauelf
@Blauelf
May 17 2017 07:53
Totally depends on your use case. If the method uses properties only, prototype looks best. If it uses a shared variable (like getGear and setGear in the example above), it obviously needs a scope for each instance.
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:54
class HitSquare {
    constructor(_x, _y, _width, _height, _color) {
        //hit square variables
        this.x = _x;
        this.y = _y;
        this.width = _width;
        this.height = _height;
        this.color = _color;
        this.strength = 1;
    }
}
HitSquare.prototype.show = function() {
    fill(this.color);
    rect(this.x, this.y, this.width, this.height, 5, 5, 5, 5);
}

HitSquare.prototype.hit = function(_ball) {
    return (_ball.x > this.x && _ball.x < this.x + this.width && _ball.y > this.y && _ball.y < this.y + this.height)
}
so if i have something like this?
Nazar
@nazarpelekh
May 17 2017 07:55

@Aberoom sorry, but I try, and it doesn't work

var Bike = function() {

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

this.setGear = function(a){
gear += a;
};

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

noelachica
@noelachica
May 17 2017 07:56
I have a problem with an exercise, I do not understand what to do
HeebieGeeBee
@HeebieGeeBee
May 17 2017 07:56
@nazarpelekh you need to just assign the variable in set gear, not +=
Alexandre Conrady
@Aberoom
May 17 2017 07:56
@nazarpelekh You're a lot closer. Changing gears on a bike isn't like changing speed, setGear should just execute gear = a;
Victor Popescu
@VicPopescu
May 17 2017 07:56
@noelachica tell us how can we help you
noelachica
@noelachica
May 17 2017 07:56
Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable.

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

// Only change code below this line
switch(val) {
case "alpha":
result = "Adams";
break;
case "bravo":
result = "Boston";
break;
case "charlie":
result = "Chicago";
break;
case "delta":
result = "Denver";
break;
case "echo":
result = "Easy";
break;
case "foxtrot":
result = "Frank";

}

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

// Change this value to test
phoneticLookup("charlie");

Alexandre Conrady
@Aberoom
May 17 2017 07:57
@noelachica post your code with ``` above and below your code.
noelachica
@noelachica
May 17 2017 07:58
double? "

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

// Only change code below this line
switch(val) {
case "alpha":
result = "Adams";
break;
case "bravo":
result = "Boston";
break;
case "charlie":
result = "Chicago";
break;
case "delta":
result = "Denver";
break;
case "echo":
result = "Easy";
break;
case "foxtrot":
result = "Frank";

case "":
  result = undefined;

}

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

// Change this value to test
phoneticLookup("charlie");

phoneticLookup('delta');
"

lagasi
@lagasi
May 17 2017 08:00
@noelachica var lookup = { "alpha": "Adams", "bravo": "Boston" ... }
noelachica
@noelachica
May 17 2017 08:00
Is an object without more!
.<
lagasi
@lagasi
May 17 2017 08:04
@noelachica What do you mean?
Alexandre Conrady
@Aberoom
May 17 2017 08:04
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  switch(val) {
    case "alpha": 
      result = "Adams";
      break;
    case "bravo": 
      result = "Boston";
      break;
    case "charlie": 
      result = "Chicago";
      break;
    case "delta": 
      result = "Denver";
      break;
    case "echo": 
      result = "Easy";
      break;
    case "foxtrot": 
      result = "Frank";

    case "":
      result = undefined;

  }

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

// Change this value to test
phoneticLookup("charlie");

phoneticLookup('delta');
@noelachica like that, with the backticks (on the same key as ~, to the left of 1 on the EN keyboard)
@nazarpelekh did it work?
noelachica
@noelachica
May 17 2017 08:07
single quotes ¿¿
Has worked what you said victor, I appreciate it
Alexandre Conrady
@Aberoom
May 17 2017 08:12
@noelachica no, backticks, like a downwards accent. This ```, not ´´´ or ''' or """. its somewhere on your keyboard.
CamperBot
@camperbot
May 17 2017 08:12
:bulb: to format code use backticks! ``` more info
Nazar
@nazarpelekh
May 17 2017 08:12
thanks, all works)
@nazarpelekh :+1:
KeiMogodi
@KeiMogodi
May 17 2017 08:16
hi there guys, im stuck on the "Storing values with the assignment operator" challenge. im not too sure how to assign the contents of a to variable b
Alexandre Conrady
@Aberoom
May 17 2017 08:17
@KeiMogodi well, what is your first instinct? The fastest solution that you can think of?
aceroAD
@aceroAD
May 17 2017 08:19

hi, im in the algorithms part in the one wich asks you to return an array with the higuer number of each sub-array but iterating through both it only gives me the highest numbers of the first 2 sub arrays

this is the code im using:

function largestOfFour(arr) {
var contArr = [];
for (var i = 0; i < arr.length; i++){
for (var j = 0; j < arr[i].length; j++){
if (contArr <= arr[i][j]){
contArr[i] = arr[i][j];
}
// else contArr[i] = contArr[i];
}
}
return contArr;
}

KeiMogodi
@KeiMogodi
May 17 2017 08:20
@Aberoom the challenge shows an example code of " myVar = 5;
noelachica
@noelachica
May 17 2017 08:20
thanx

```function checkObj(checkProp) {
// Your Code Here

return "Change Me!";
}´´´

KeiMogodi
@KeiMogodi
May 17 2017 08:21
myNum = myVar; @Aberoom , so i tried to type "myNum = a; nyNum = myVar;
Alexandre Conrady
@Aberoom
May 17 2017 08:21

@KeiMogodi ok you have

var a = 2;
var b = 0;

what can you change there, so that no matter what a equals, b will always be equal to a?

KeiMogodi
@KeiMogodi
May 17 2017 08:22
id probably say var b = a;
Alexandre Conrady
@Aberoom
May 17 2017 08:22
@KeiMogodi yup that's it
noelachica
@noelachica
May 17 2017 08:23

```function checkObj(checkProp) {
// Your Code Here

return "Change Me!";```
}

KeiMogodi
@KeiMogodi
May 17 2017 08:23
@Aberoom thanks dude
CamperBot
@camperbot
May 17 2017 08:23
keimogodi sends brownie points to @aberoom :sparkles: :thumbsup: :sparkles:
noelachica
@noelachica
May 17 2017 08:23
I do not get haha
CamperBot
@camperbot
May 17 2017 08:23
:cookie: 350 | @aberoom |http://www.freecodecamp.com/aberoom
Alexandre Conrady
@Aberoom
May 17 2017 08:23
@noelachica the backticks need to be above and below, on new lines.
noelachica
@noelachica
May 17 2017 08:24
<paste code here>

`function checkObj(checkProp) {
// Your Code Here

return "Change Me!";

``` function checkObj(checkProp) {
// Your Code Here

return "Change Me!";
}´´´

Alexandre Conrady
@Aberoom
May 17 2017 08:25
@noelachica on new lines above and below.
Blauelf
@Blauelf
May 17 2017 08:25
@noelachica Backticks both times, and they need their own line (Shift+Return for line break in chat mode)
noelachica
@noelachica
May 17 2017 08:26

`function checkObj(checkProp) {
// Your Code Here

return "Change Me!";

´

function checkObj(checkProp) {
// Your Code Here

return "Change Me!";
}

var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
Victor Popescu
@VicPopescu
May 17 2017 08:27
@noelachica use ``` on single lines before and after your code if you want to format it
Blauelf
@Blauelf
May 17 2017 08:27
Backticks. And code blocks need triple backticks, on their own line, like
```js Shift+Return for line break
var answer = 42;
```
=>
var answer = 42;
noelachica
@noelachica
May 17 2017 08:29
But I have to put the 3 lines, paste the code and then put line jump (Shift + Return)?
Alexandre Conrady
@Aberoom
May 17 2017 08:29
@noelachica you want a line of backticks, shift+return for new line, paste your code, shift+return for new line, 3 backticks.
Victor Popescu
@VicPopescu
May 17 2017 08:29
This message was deleted
noelachica
@noelachica
May 17 2017 08:30
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};
oleeeeee
Victor Popescu
@VicPopescu
May 17 2017 08:30
@noelachica gj
Alexandre Conrady
@Aberoom
May 17 2017 08:30
@noelachica :clap:
noelachica
@noelachica
May 17 2017 08:30
A miracle of god
Blauelf
@Blauelf
May 17 2017 08:30
@VicPopescu I don't have Enter on my notebook's keyboard (no numpad, not even emulated one)
noelachica
@noelachica
May 17 2017 08:31
thx :D
Victor Popescu
@VicPopescu
May 17 2017 08:31
@Blauelf lol why?
@Blauelf ah enter = return
Listener23
@Listener23
May 17 2017 08:31
Hi, I need help with this one
Blauelf
@Blauelf
May 17 2017 08:32
@VicPopescu Just did not fit on keyboard for 14" notebook. Return is part of the alphabetic keyboard, Enter is part of numpad. They originate in different devices (enter => enter data, return => carriage return)
Victor Popescu
@VicPopescu
May 17 2017 08:33
@Blauelf yea you are right, but normal laptops got 2 enters, meaning 1 numpad enter and the return
Blauelf
@Blauelf
May 17 2017 08:34
Different make/break codes. I once bought an USB numpad, which had an "Enter" key, but that had "Return" codes :(
Joseph Joe
@JoeTinnySpace
May 17 2017 08:35

Excuse me

need help!
blob

Blauelf
@Blauelf
May 17 2017 08:35
Joseph Joe
@JoeTinnySpace
May 17 2017 08:36
@Blauelf

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (str.length > num){
    if (num<=3){
      return str.slice(0, -(str.length-num) ) + "...";
    }

    else {
      return str.slice(0, -(str.length-num)-3) + "...";
    }
  }

}

truncateString("A-tisket a-tasket A green and yellow basket",6);
I was showing you the use cases ! btw
Blauelf
@Blauelf
May 17 2017 08:37
@JoeTinnySpace Why this - in second argument to slice? Wouldn't str.slice(0, num) be same as str.slice(0, -(str.length-num) )?
@JoeTinnySpace Problem is what happens if str does not need truncation. You should have a third return statement for that one.
Joseph Joe
@JoeTinnySpace
May 17 2017 08:40
@Blauelf

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var trunc= "";
  if (str.length > num){
    if (num<=3){
      trunc = str.slice(0, num ) + "...";
    }

    else {
      trunc = str.slice(0, num-3) + "...";
    }
  }
  return trunc;
}

truncateString("A-tisket a-tasket A green and yellow basket",6);
Blauelf
@Blauelf
May 17 2017 08:40
@JoeTinnySpace Try var trunc = str;
Joseph Joe
@JoeTinnySpace
May 17 2017 08:40
4 outof 6 cases are satisfied,
Blauelf
@Blauelf
May 17 2017 08:41
You should return str if it does not need any truncation.
Joseph Joe
@JoeTinnySpace
May 17 2017 08:41
bingo , that worked

@Blauelf


function truncateString(str, num) {
  // Clear out that junk in your trunk
  var trunc= str;
  if (str.length > num){
    if (num<=3){
      return trunc.slice(0, num ) + "...";
    }

    else {
      return  trunc.slice(0, num-3) + "...";
    }
  }
  return trunc;
}

truncateString("A-tisket a-tasket A green and yellow basket",6);

:fire: :clap: :smile:

oh and @Blauelf thanks
CamperBot
@camperbot
May 17 2017 08:43
joetinnyspace sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4165 | @blauelf |http://www.freecodecamp.com/blauelf
Dakota Woods
@Dakoa
May 17 2017 08:53
If I have an array
Whoops, if I have an array arr=["this","that"]; what is the index lf the first t?
I'm having a problem iterating through the first letters in an array of words
Sulaiman
@suli-g
May 17 2017 08:54
arr[0][0];
Dakota Woods
@Dakoa
May 17 2017 08:54
@Sulmain
Thank you
Joseph Joe
@JoeTinnySpace
May 17 2017 08:55
@Dakoa you sent the brownies to deep space bro :smile:
Dakota Woods
@Dakoa
May 17 2017 08:59
Ah shit
@suli-g thank you!
CamperBot
@camperbot
May 17 2017 08:59
dakoa sends brownie points to @suli-g :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @suli-g |http://www.freecodecamp.com/suli-g
Dakota Woods
@Dakoa
May 17 2017 09:00
str = str.join(" ");
Why isn't this working?
Here's the context:

function titleCase(str) {

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

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

Blauelf
@Blauelf
May 17 2017 09:03
@Dakoa You cannot join a string. I would do join and return after the loop. And do not assign to str in the loop. Maybe assign to str[i], but not str
Dakota Woods
@Dakoa
May 17 2017 09:06

function titleCase(str) {

var titleCaseStr = []; str=str.toLowerCase().split(" ");
for (var i = 0; i<str.length; i++){
str = str[i][0].toUpperCase();

}
return str;
}

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

i tried taking the join out and instead of capitalizing the first letters, it returns the first letter, capitalized
rxi16
@rxi16
May 17 2017 09:07
My code works, but does anyone know if I can make it simpler?

function reverseString(str) {
str.split(str);
var a = str.split(nostring);
var arev = a.reverse();
var ajoin = arev.join(nostring);
return ajoin;
}

var nostring = '';

reverseString("hello");

Dakota Woods
@Dakoa
May 17 2017 09:10
Str.split("").reverse().join("");
rxi16
@rxi16
May 17 2017 09:12
@Dakoa wow, that is remarkable. That looks more advanced than what I learned so far. I just started
Dariusz Sikorski
@dariuszsikorski
May 17 2017 09:13

I have widget storage like:

widgets: {
  '8ds7fh4': {...},
  'fg8grdr': {...},
  'xgfd85f': {...},
  'dfg945n': {...}
}

The order of widgets is extremely important, since they render on website in that order. How can i append/prepend new object in exact position, for example before 'xgfd85f'?

Blauelf
@Blauelf
May 17 2017 09:14
They might be ordered alphabetically
Dan Couper
@DanCouper
May 17 2017 09:15
You can't if it's an object like that, objects aren't ordered
Dariusz Sikorski
@dariuszsikorski
May 17 2017 09:15
i want to avoid changing the order of id's on any modern browser
that sounds bad :(
so I'd have to use plain arrays instead?
Blauelf
@Blauelf
May 17 2017 09:15
@Dakoa If you assign to str[i], you're replacing the whole word. You might want to append the rest of the word to your uppercased first letter first.
Dan Couper
@DanCouper
May 17 2017 09:16
add something that specifies the order, an id of some kind
Dariusz Sikorski
@dariuszsikorski
May 17 2017 09:17
@DanCouper i get your point
Blauelf
@Blauelf
May 17 2017 09:17
@dariuszsikorski Arrays have order. Object properties instead in some cases are listed alphabetically, in other cases are listed by order of creation, with some browsers treating deletion and recreation of a property as if it had never left the object, and others considering it a new property then.
Vicky Lai
@vickylai
May 17 2017 09:18
This is really confounding me.

I have this:


function steamrollArray(arr) {
      if (Array.isArray(arr)) {
      arr.reduce(function(done,curr){
        console.log(curr);
      return done.concat(steamrollArray(curr));
      }, []);
      }
}

console.log(steamrollArray([1, [2], [3, [[4]]]]));

And I can see from console.log that it does reach the 'unwrapped' array items, but I can't get it to actually put them into done.

Stephen James
@sjames1958gm
May 17 2017 09:20
@vickylaiio What if Array.isArray is false?
Blauelf
@Blauelf
May 17 2017 09:21
@vickylaiio You might need a few more return statements in steamrollArray. You currently have one only in your anonymous function expression, while your main function never returns anything.
Stephen James
@sjames1958gm
May 17 2017 09:21
@vickylaiio The result of your reduce is not use either
Steefkee
@Steefkee
May 17 2017 09:21
Assign the contents of a to variable b. how?
Dariusz Sikorski
@dariuszsikorski
May 17 2017 09:22
@Blauelf thx or explaination. Seems i have to rewrite my widget tree. I work on something simmilar to react.js component tree, but with drag & drop functionality on real website, quite an abstract thing.
CamperBot
@camperbot
May 17 2017 09:22
dariuszsikorski sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4166 | @blauelf |http://www.freecodecamp.com/blauelf
Stephen James
@sjames1958gm
May 17 2017 09:22
@Steefkee The assignee, here b is always on the left of the =
Victor Popescu
@VicPopescu
May 17 2017 09:22
@Steefkee
var a = 1;
var b = a; //b takes 'a' value and store it
Steefkee
@Steefkee
May 17 2017 09:23
@sjames1958gm thanks!
CamperBot
@camperbot
May 17 2017 09:23
steefkee sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7344 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Steefkee
@Steefkee
May 17 2017 09:23
@VicPopescu Thanks!
Stephen James
@sjames1958gm
May 17 2017 09:23
@Steefkee :+1:
CamperBot
@camperbot
May 17 2017 09:23
steefkee sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 380 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
Dakota Woods
@Dakoa
May 17 2017 09:25
@Blauelf That sounds about right. My idea was to splice the first letter off of each string in the array, then concat the capitalized version in order. I don't know I'd go about concatenating them without adding them to the end instead, though. Could you point me in the right direction?
Abhishek Tiwari
@fillopfy
May 17 2017 09:26
can anyone tell me how should I proceed in this challenge:Reverse a String
Dan Couper
@DanCouper
May 17 2017 09:27
@dariuszsikorski ideally you want two data structures: one which holds your widgets, (which can be the object you have there), and one which just has those IDs in the specific order you want. You use the second one for ordering, and it has to be iterable (like an array), and it needs to allow insertion at a specific index.
Blauelf
@Blauelf
May 17 2017 09:27
@Dakoa Strings are immutable, so no splicing, but you can use substring, substr, or slice, and concatenate the two things.
Stephen James
@sjames1958gm
May 17 2017 09:28
@fillopfy Consider that arrays have a reverse function and you can convert strings to/from arrays
Dakota Woods
@Dakoa
May 17 2017 09:28
@Blauelf Okay, I'll try that out
Dan Couper
@DanCouper
May 17 2017 09:29
@dariuszsikorski Then the first one, it doesn't matter about order, it's just a way you can look up your widgets based on the ID
Vicky Lai
@vickylai
May 17 2017 09:30
@sjames1958gm @Blauelf This is me not getting it... https://codepen.io/vickylaiio/pen/RVMwmj?editors=0012#
I don't think it's structured right
Stephen James
@sjames1958gm
May 17 2017 09:30
@vickylaiio If you Array.isArray is false then just push the value to the end of done. Just return the result of reduce.
@vickylaiio When you recurse you usually have a base case where you stop recursing, that is Array.isArray is false here.
Blauelf
@Blauelf
May 17 2017 09:33
@vickylaiio If you use reduce, then use the result of reduce, like
  if (Array.isArray(arr)) {
    return arr.reduce(function(done,curr){
      return done.concat(steamrollArray(curr));
    }, []);
  } else {
Stephen James
@sjames1958gm
May 17 2017 09:35
If it isn't an array just return arr which is your terminal value
Blauelf
@Blauelf
May 17 2017 09:37

Just thinking... isn't

    return arr.reduce(function(done,curr){
      return done.concat(steamrollArray(curr));
    }, []);

effectively the same as

    return Array.prototype.concat.apply([], arr);

?

Joasch Seidenberg
@joshysiddy
May 17 2017 09:37
How to assign a to b at task 121?
Dan Couper
@DanCouper
May 17 2017 09:37
@dariuszsikorski you can use an array of IDs, and then use splice to insert at a specific point (a bit ungainly from an API point of view as they don't carry positional info, but there isn't really anything else in JS that allows what you want without writing your own tree-like data structure)
Vicky Lai
@vickylai
May 17 2017 09:38
@sjames1958gm @Blauelf Yes. I understand now. Thank you for your help!
CamperBot
@camperbot
May 17 2017 09:38
vickylaiio sends brownie points to @sjames1958gm and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 7345 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 4167 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
May 17 2017 09:39

@joshysiddy The number is meaningless, it's number of your brownie points.

And the variable to assign to is always on the left of = assignment operator, while on the right side there's an expression (for example another variable) that's evaluated, and determines the value to assign.

Stephen James
@sjames1958gm
May 17 2017 09:41
@Blauelf The second one wouldn't unpack multiple levels
Blauelf
@Blauelf
May 17 2017 09:42

@sjames1958gm Then

    return Array.prototype.concat.apply([], arr.map(steamrollArray));

:)

Stephen James
@sjames1958gm
May 17 2017 09:42
@Blauelf Yes, I was thinking that map was needed :+1:
Blauelf
@Blauelf
May 17 2017 09:43
That was what I thought, but forgot map somewhere.
Joasch Seidenberg
@joshysiddy
May 17 2017 09:43
@Blauelf I still don't understand, how a should be assigned to b with =
Blauelf
@Blauelf
May 17 2017 09:43
"Assign to b" means b =
Joasch Seidenberg
@joshysiddy
May 17 2017 09:46
that doesn't work
Keon Samuel
@keonsam
May 17 2017 09:48
b = a;
minhmoc710
@minhmoc710
May 17 2017 09:53
Hi, I am trying to finish the "Caesars Cipher" chanllenge but I got a problem! Here's my code
Blauelf
@Blauelf
May 17 2017 09:53
@joshysiddy The variable to assign to goes to the left, while the value to assign goes to the right of assignment operator =. b = a; would evaluate a, and assign its value to b.
minhmoc710
@minhmoc710
May 17 2017 09:53
function rot13(str) { // LBH QVQ VG!
  var newString = [];
  for (var i = 0; i < str.length; i++){
    if (str.search(/[A-Z]/) !== -1 && str.charCodeAt(i) >= 78){
      newString[i] = String.fromCharCode(str.charCodeAt(i)- 13);
    } else if (str.search(/[A-Z]/) !== -1 && str.charCodeAt(i) < 78){
      newString[i] = String.fromCharCode(90 - 13 + str.charCodeAt(i) -65 + 1); 
    } 
    else {
      newString[i] = str[i];
    }
  }
  return newString.join('');
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
it should return "FREE CODE CAMP" but for some reason it returns "FREE-CODE-CAMP"
Blauelf
@Blauelf
May 17 2017 09:54
@minhmoc710 Strange use for regular expression. Did you mean like if (/[A-Z]/.test(str[i]) && str.charCodeAt(i)...?
I don't think str.search(/[A-Z]/) !== -1 will ever be false.
Joasch Seidenberg
@joshysiddy
May 17 2017 09:55
@Blauelf Thanks, I tried this before, somehow it didn't work. Perhaps I did something wrong.
CamperBot
@camperbot
May 17 2017 09:55
joshysiddy sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4168 | @blauelf |http://www.freecodecamp.com/blauelf
minhmoc710
@minhmoc710
May 17 2017 09:55
why? @Blauelf
Nivas Reddy Donthireddy L
@iamnivas
May 17 2017 09:56
HI
I have a problem working with javascript ....I am struck somewhere in WordBlancks in free code camp..
Any one could help me out
minhmoc710
@minhmoc710
May 17 2017 09:57
the space " " is not anything beetween A-Z @Blauelf
Nish795
@Nish795
May 17 2017 09:57
Hi can someone please help me I'm stuck on Profile lookup
Blauelf
@Blauelf
May 17 2017 09:57
@minhmoc710 You never restrict the search to this specific letter. Maybe str.charAt(i).search(/[A-Z]/) !== -1 would work, too.
Stephen James
@sjames1958gm
May 17 2017 09:57
@minhmoc710 Actually string search will return -1 if not found, but you search the entire string. But I would suggest
str[i].search(/[A-M]/) !== -1
then you don't need >= 78 test
also you need to only search the one character
Blauelf
@Blauelf
May 17 2017 09:58
@sjames1958gm You forgot the []? Or did they get eaten by gitter?
Nish795
@Nish795
May 17 2017 09:58

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

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

CamperBot
@camperbot
May 17 2017 09:58
:bulb: to format code use backticks! ``` more info
KirillGalkin
@KirillGalkin
May 17 2017 09:58
hey, could anybody help?
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

}

// Test your code by modifying these values
checkObj("gift");
Stephen James
@sjames1958gm
May 17 2017 09:58
@KirillGalkin when you have a variable you must use []
Blauelf
@Blauelf
May 17 2017 09:58
Yeah, /[A-M]/.test(str[i]) is probably more efficient.
Nish795
@Nish795
May 17 2017 09:59

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

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

Stephen James
@sjames1958gm
May 17 2017 09:59
@Nish795 You cannot return no such contact until you check all the contacts - your code is quitting if the first one isn't a match
Blauelf
@Blauelf
May 17 2017 09:59
@Nish795 = is assignment operator, == and === are used for comparison
minhmoc710
@minhmoc710
May 17 2017 09:59
ok, I'l try @Blauelf
Stephen James
@sjames1958gm
May 17 2017 10:00
@iamnivas You need to put string literals between the words in the variables
@Blauelf Thet got eaten by my rush to type :)
Nish795
@Nish795
May 17 2017 10:03
@sjames1958gm @Blauelf I have updated my code but it still doesn't work
```function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < lookUpProfile.length; i++){
if (contacts[i].firstName == firstName) {
if (contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}
else{
return "No such property";
}
}
}
else {
return "No such contact";
Blauelf
@Blauelf
May 17 2017 10:04
@Nish795 No else before "No such contact"
Nish795
@Nish795
May 17 2017 10:04
so should I write an if statment
?
Blauelf
@Blauelf
May 17 2017 10:04
No.
Nish795
@Nish795
May 17 2017 10:05
Please can you explain what I should do and what I am doing wrong
John Charnock
@johnnycharnock
May 17 2017 10:07
Hi guys I'm stuck on 'Nesting For Loops' this is my solution so far, but it only returns 1:

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

  for (var i = 0; i < arr[i]; i++) {
  for (var j = 0; j < arr[i].length ; j++) {
      console.log([i][j]);
      product = 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,7]]);
Anyone completed it yet?
Keon Samuel
@keonsam
May 17 2017 10:10
no
no one
Markus Kiili
@Masd925
May 17 2017 10:10
@johnnycharnock You need to use the function parameter arr, not the function name multiplyAll.
Matt Flynn
@flynnwebdev
May 17 2017 10:10
@johnnycharnock Shouldn't it be i < arr[i].length?
Nish795
@Nish795
May 17 2017 10:10
@johnnycharnock your first for loop should have i < arr.length
Matt Flynn
@flynnwebdev
May 17 2017 10:11
What Nish said
Just arr.length
Stephen James
@sjames1958gm
May 17 2017 10:12
@Nish795 IF your loop always returns when firstName matches - then if the loop reaches end of contacts.
The code "knows" that there was no such contact
CraZy biRd
@Preeetrockz
May 17 2017 10:12
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (val){
    case 1:
      answer "alpha"; 
  break;
    case 2:   
  return "beta";  
 break;
   case 3:
   answer "gamma";
   break;
    case 4:
   answer "delta";

    } 
}

// Change this value to test
caseInSwitch(1);
Instructions
Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - "delta"
getting error !!
Keon Samuel
@keonsam
May 17 2017 10:12
answer =
need a return statement too.
Matt Flynn
@flynnwebdev
May 17 2017 10:13
or just return
return "alpha"
return "gamma"
Just like beta
CraZy biRd
@Preeetrockz
May 17 2017 10:13
okay lemme try
Matt Flynn
@flynnwebdev
May 17 2017 10:14
There's no need for a variable
Keon Samuel
@keonsam
May 17 2017 10:14
I think you have to use answer for that challenge.
Matt Flynn
@flynnwebdev
May 17 2017 10:14
Why? It makes no sense to have the variable, it's not needed. The value isn't going to be used later in the function, it's just returned
Nish795
@Nish795
May 17 2017 10:14
@sjames1958gm so how should I return the "no such contact"
Matt Flynn
@flynnwebdev
May 17 2017 10:15
default:
Keon Samuel
@keonsam
May 17 2017 10:15
because the challange provided the varibale.
Stephen James
@sjames1958gm
May 17 2017 10:15
@Nish795 After the loop just return "No such contact";
CraZy biRd
@Preeetrockz
May 17 2017 10:15
Gotcha :)
@flynnwebdev thanks :)
CamperBot
@camperbot
May 17 2017 10:15
preeetrockz sends brownie points to @flynnwebdev :sparkles: :thumbsup: :sparkles:
:cookie: 8 | @flynnwebdev |http://www.freecodecamp.com/flynnwebdev
Matt Flynn
@flynnwebdev
May 17 2017 10:15
Fine, but just because a var is provided doesn't mean you must use it
Stephen James
@sjames1958gm
May 17 2017 10:16
@Preeetrockz you deleted these lines - it is best for these challenges not to change code when the comments say not to
  // Only change code above this line  
  return answer;
Matt Flynn
@flynnwebdev
May 17 2017 10:16
Ah well, that's different then!
CraZy biRd
@Preeetrockz
May 17 2017 10:16
@sjames1958gm yea and i don't need this line to run :)
Keon Samuel
@keonsam
May 17 2017 10:16
well thanks pro I didn't know that.
CraZy biRd
@Preeetrockz
May 17 2017 10:17
it's work without that lines @sjames1958gm
Dariusz Sikorski
@dariuszsikorski
May 17 2017 10:19
@DanCouper i exactly have the structure you described. "Flat" storage of widgets descibed with ID's and "tree" structure based on "slots" - each widget contains a list of id's of it's childrens.
Risle
@Risle
May 17 2017 10:19
I'm working on the Exact Change one... how do I display a number to a fixed decimal? I'm using someNum.toFixed(2), but that outputs a string ???
Ariel
@twomiya
May 17 2017 10:19

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

// Only change code above this line
}

Nish795
@Nish795
May 17 2017 10:19
@sjames1958gm My code is still not working
Stephen James
@sjames1958gm
May 17 2017 10:19
@Nish795 What do you have?
Nish795
@Nish795
May 17 2017 10:20

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

// Only change code above this line
}```

Matt Flynn
@flynnwebdev
May 17 2017 10:20
@Nish795 Is your code on a pen?
Stephen James
@sjames1958gm
May 17 2017 10:20
@Nish795 lookUpProfile.length ?
You are using the function and not the array here
Nish795
@Nish795
May 17 2017 10:22
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i < lookUpProfile.length; i++){
    if (contacts[i].firstName == firstName) {
      if (contacts[i].hasOwnProperty(prop)){
        return contacts[i][prop];
      }
      else{
        return "No such property";
      }
    } 
  }
 return "No such contact";

// Only change code above this line
}
Keon Samuel
@keonsam
May 17 2017 10:23
is freecodecamp.com written in JS?
Dan Couper
@DanCouper
May 17 2017 10:23
Yes, it's a Node application
Nish795
@Nish795
May 17 2017 10:23
@sjames1958gm Thank you so much
CamperBot
@camperbot
May 17 2017 10:23
nish795 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7346 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 17 2017 10:23
@Nish795 :+1:
Nish795
@Nish795
May 17 2017 10:24
@flynnwebdev My code is not on a pen, I was just sending posting my code incorrectly lol
<