These are chat archives for FreeCodeCamp/HelpJavaScript

29th
Apr 2017
ThePineal
@ThePineal
Apr 29 2017 00:00
:(
Joseph
@revisualize
Apr 29 2017 00:00
@ThePineal You're doing var titleCase = ""; then later you're doing titleCase +=
ThePineal
@ThePineal
Apr 29 2017 00:01
@revisualize how would i reword it to keep it an array? cause thats what i expected going this route
Stephen James
@sjames1958gm
Apr 29 2017 00:01
@ThePineal There is a super convenient place to put the titled word.
back in lwrStrArr[x]
Joseph
@revisualize
Apr 29 2017 00:02
@ThePineal As @sjames1958gm 's trying to point out. I wouldn't even make a titleCase variable. I'd just replace the current array element.
ThePineal
@ThePineal
Apr 29 2017 00:03
so have it as 'lwrStrArr[x] = lwrStrArr[x].charAt(0).toUpperCase() + lwrStrArr[x].slice(1);'?
lwrStrArr[x].charAt(0).toUpperCase() + lwrStrArr[x].slice(1);
oops
sorry
Joseph
@revisualize
Apr 29 2017 00:03
@ThePineal Let me know how that works for you.
ThePineal
@ThePineal
Apr 29 2017 00:04
@revisualize i see, got rid of the titleCase variable
set lwrStrArr[x] = lwrStrArr[x].charAt(0).toUpperCase() + lwrStrArr[x].slice(1);
its back into an array now, thanks
Vamp
@the-vampiire
Apr 29 2017 00:05
well I feel pretty dumb now. I had been using reduce wrong, missing adding those brackets
function steamrollArray(arr) {

    return arr.reduce(flatten, []).reduce(flatten, []).reduce(flatten, []);

    function flatten(a, b) {
        return a.concat(b);
    }
}
is this cheating?
ThePineal
@ThePineal
Apr 29 2017 00:05
accessing and iterating through arrays is hard :D
Vamp
@the-vampiire
Apr 29 2017 00:09
I dont see anywhere in the documentation why [] is passed to reduce can anyone explain that?
Gulsvi
@gulsvi
Apr 29 2017 00:09
Not really cheating, but if you have to flatten 4 times, the code won't work. This is where recursion and Array.isArray() can be useful
Vamp
@the-vampiire
Apr 29 2017 00:09
ya :9
Gulsvi
@gulsvi
Apr 29 2017 00:10
[] is the starting value - it says to reduce it starting with an empty array
Vamp
@the-vampiire
Apr 29 2017 00:10
I did find you can add an infinite number of reduces though since if it doesnt find an array to reduce it juse returns that element as is
but why?
I dont see in the documentation why [] is the starting value
shouldnt arr[0] be the starting value?
Joseph
@revisualize
Apr 29 2017 00:11
Vamp
@the-vampiire
Apr 29 2017 00:11
I thought in the ‘flatten function’ I was returning arr[0].concat(arr[1]) and so forth
Gulsvi
@gulsvi
Apr 29 2017 00:11
var ourArray = [1,2,3,4] // sum of these digits is 10

var answer = ourArray.reduce(function(a,b) {
  return a + b;
},10)

console.log(answer) // 20
With 10 as the starting value, you get 20 as the answer, with 0 as the starting value, you would get 10
Vamp
@the-vampiire
Apr 29 2017 00:12
okay that makes sense
but how is an empty array a starting ‘value'
Gulsvi
@gulsvi
Apr 29 2017 00:13
var ourArray = [1,2,3,4] // sum of these digits is 10

var answer = ourArray.reduce(function(a,b) {
  return a + b;
},[])

console.log(answer) // "1234"
Ryan Nelson
@iamryandnelson
Apr 29 2017 00:13
@cmccormack Thanks for your help. I took your advice and figured out how to run an array through ajax. It cut my code from nearly 400 lines to 100, lol. Sort of embarrassed that I let it get that far... Everything seems to be working except for the if statement at the end of my JS code. Instead of marking channels that are offline it's marking all channels as offline which isn't true. Can you see what I might be doing wrong?
http://codepen.io/iamryandnelson/pen/vmXzXz?editors=0010
CamperBot
@camperbot
Apr 29 2017 00:13
iamryandnelson sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 456 | @cmccormack |http://www.freecodecamp.com/cmccormack
Vamp
@the-vampiire
Apr 29 2017 00:15
@SkyCoder01 I am not following. I can see the results but I am not following exactly what it is doing. an empty array is not a value in my mind
it seems an empty array is telling it to “remove the array” but I don’t see how it is doin that programatically
Gulsvi
@gulsvi
Apr 29 2017 00:16
Let me see if I can find a link that explains it better
Vamp
@the-vampiire
Apr 29 2017 00:16
thank you
Gulsvi
@gulsvi
Apr 29 2017 00:16
You can use {} too for objects
Vamp
@the-vampiire
Apr 29 2017 00:16
i think if I understand it better I will actually be able to build it
er build the recursive one
Stephen James
@sjames1958gm
Apr 29 2017 00:20
@iamryandnelson As far as cleaner code I would pass either the index or the user into the two ajax functions.
accessing the global like that is not consider the best practice.
Csaba Balogh
@JasonCorp84
Apr 29 2017 00:20
@sjames1958gm thank you
CamperBot
@camperbot
Apr 29 2017 00:20
jasoncorp84 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: jasoncorp84 already gave sjames1958gm points
Csaba Balogh
@JasonCorp84
Apr 29 2017 00:20
my next question is the nested for loop
for (var i =0; i <arr.length; i++){
for (var j = 0; j < arr[i].length; j++){
product *= arr[i][j];
}
}
Ryan Nelson
@iamryandnelson
Apr 29 2017 00:22
@sjames1958gm Am I not doing that with the user1 and user2 arrays?
Gulsvi
@gulsvi
Apr 29 2017 00:22

@sjames1958gm Maybe you can help explain this better, lol
Why does passing an empty array as the initialValue to .reduce() convert an array to a string?

var ourArray = [[1,2],[2,3],[3,4],[4,5]] // sum of these digits is 10

var answer = ourArray.reduce(function(a,b) {
  return a + b;
},[])

console.log(answer) // '1,22,33,44,5'

Trying to explain this to @the-vampiire but all I can say is - that's what it does...can't explain the *why*

it's the same as:
var ourArray = [[1,2],[2,3],[3,4],[4,5]] // sum of these digits is 10

var answer = ourArray.reduce(function(a,b) {
  return a + b;
},'')

console.log(answer) // '1,22,33,44,5'
Stephen James
@sjames1958gm
Apr 29 2017 00:23
@iamryandnelson like this.
  for (var i = 0; i < users1.length; i++) {
    ajax1(users1[i]);
  }

  function ajax1(user) {
    $.ajax({
      url: "https://api.twitch.tv/kraken/channels/" + user,
Vamp
@the-vampiire
Apr 29 2017 00:23
lol im in the same boat sky
I know what it does, but I am currently under the belief that black magic is at play until someone can explain it to me
MDN itself doesnt even explain it..theyre just like ya it does this so...
Gulsvi
@gulsvi
Apr 29 2017 00:24
I've always been comfortable going, well, that's how it works. At least enough to predict how it would work in similar scenarios.
Vamp
@the-vampiire
Apr 29 2017 00:24
I wish I was comfortable like that
I ask too many goddamn questions
Stephen James
@sjames1958gm
Apr 29 2017 00:24
@SkyCoder01 @the-vampiire It doesn't convert it to a string. This does adding two arrays
[] + [1, 2]
"1,2"
Vamp
@the-vampiire
Apr 29 2017 00:24
wtf youre right @sjames1958gm
why is this happening
its some sort of trick with concatenating arrays..?
Gulsvi
@gulsvi
Apr 29 2017 00:25
I know that's what it's doing, but *why* is what I can't really articulate
Karol Gruszka
@Sniadekk
Apr 29 2017 00:25
Hello guys
Vamp
@the-vampiire
Apr 29 2017 00:25
so it says every time set the initial value to [] so when they are concatenated it will turn into a string
how fucking bizarre
Herman Fassett
@HermanFassett
Apr 29 2017 00:26
Learn something new everyday
Gulsvi
@gulsvi
Apr 29 2017 00:26
It adds an empty array in the first iteration of the loop, and then accumulates based on that answer
Vamp
@the-vampiire
Apr 29 2017 00:26
if any more dicussion occurs on this matter can you please tag me, im going for a walk with the dogs but I can see it on mobile if i get tagged. thanks @sjames1958gm @SkyCoder01
CamperBot
@camperbot
Apr 29 2017 00:26
the-vampiire sends brownie points to @sjames1958gm and @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1220 | @skycoder01 |http://www.freecodecamp.com/skycoder01
:star2: 7020 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Karol Gruszka
@Sniadekk
Apr 29 2017 00:26
function start(){
  var tresc="";
  for (i=0;i<35; i++){
    litera=literki.charAt(i);
    tresc= tresc+ '<div class="litera">' + litera + '</div>';
    if((i+1) %7==0 ){
        tresc= tresc+ '<div style="clear:both"></div>';
}
Why my variable named "litera" doesnt do anything in my code? I declared var before function
Stephen James
@sjames1958gm
Apr 29 2017 00:26
@iamryandnelson
```
"<p class=' game" + user + "'><span style='color:green'>LIVE: </span>"
Then your user can modify you class and when you replace it it will only reaplce the one
Karol Gruszka
@Sniadekk
Apr 29 2017 00:26
It's supposed to add another letter from alphabet into code but nothing really happens
Gulsvi
@gulsvi
Apr 29 2017 00:26
#TIL
Karol Gruszka
@Sniadekk
Apr 29 2017 00:28
anyone alive there? :D
Herman Fassett
@HermanFassett
Apr 29 2017 00:28
@Sniadekk maybe a bit more explanation? Is litera a class name?
Randall S.
@reylas81
Apr 29 2017 00:28

Ok I am doing the Profile Lookup tutorial... I am trying not to look at the Lesson Review for the answer (glanced at the tips)...

Here is what I have:

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

var noContact = "No such cotact";

if (firstName === contacts[firstName] && prop === contacts.hasownproperty[prop]) {
return prop;
} else if (contacts[firstName] === firstName && prop != contacts.hasownproperty[prop]) {
return "No such property";
} else {
return noContact;
}
// Only change code above this line
}

Am I at least on the right course?

Stephen James
@sjames1958gm
Apr 29 2017 00:28
@Sniadekk looks ok can you show input / output?
Karol Gruszka
@Sniadekk
Apr 29 2017 00:29
Well, its best when i put my whole code and explain everything, wait a sec
Kyle Holm
@thekholm80
Apr 29 2017 00:29
Any React folks here?
Karol Gruszka
@Sniadekk
Apr 29 2017 00:29
function start(){
  var tresc="";
  for (i=0;i<35; i++){
    litera=literki.charAt(i);
    tresc= tresc+ '<div class="litera">' + litera + '</div>';
    if((i+1) %7==0 ){
        tresc= tresc+ '<div style="clear:both"></div>';
}
Dan Couper
@DanCouper
Apr 29 2017 00:29
@Sniadekk you seem to be missing closing brackets for the loop and the if statement. What's literki as well?
Karol Gruszka
@Sniadekk
Apr 29 2017 00:29
var haslo="Gruszka Karol";
haslo= haslo.toUpperCase();
var haslo1="";
var dlugosc=haslo.length;
var literki="AĄBCĆDEĘFGHIJKLŁMNŃOÓPRSŚTUWYZŹŻ";
var litera="";
for (i=0; i<dlugosc;i++){
  if(haslo.charAt(i)==" "){
  haslo1=haslo1 + " ";
  }
  else{
     haslo1=haslo1 + "-";
}

}
function wypisz_haslo(){
  document.getElementById("przyslowie").innerHTML=haslo1;
}
window.onload = start;

function start(){
  var tresc="";
  for (i=0;i<35; i++){
    litera=literki.charAt(i);
    tresc= tresc+ '<div class="litera">' + litera + '</div>';
    if((i+1) %7==0 ){
        tresc= tresc+ '<div style="clear:both"></div>';
}




}

  }
document.getElementById("alfabet").innerHTML=tresc;

wypisz_haslo();

}
Stephen James
@sjames1958gm
Apr 29 2017 00:30
@Sniadekk And no return?
@Sniadekk You can use up arrow to edit the last post
@reylas81 contacts is an array - you should loop and test the array entries
@Sniadekk Your function doesn't return and tresc is out of scope of that last line
Herman Fassett
@HermanFassett
Apr 29 2017 00:31
@thekholm80 a bit
Kyle Holm
@thekholm80
Apr 29 2017 00:32
@HermanFassett got an error I can't figure out
class GameBody extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      gameBoard: generateInitialBoard()
    }
  }

  render() {
    const gameBoardKeys = Object.keys(this.state.gameBoard);
    console.log(this.state.gameBoard);
    console.log(gameBoardKeys);
    return (
      <div className='game-body'>
        {gameBoardKeys.map(function(key) {
          <GameCell 
            id={key}
            gameBoard={this.state.gameBoard}
          />
        })}
      </div>
    )
  }
}
the console.logs show what they should, but i'm getting:
Uncaught TypeError: Cannot read property 'state' of undefined
at pen.js:239:26
at Array.map (native)
Herman Fassett
@HermanFassett
Apr 29 2017 00:33
Able to share the pen perhaps?
Ryan Nelson
@iamryandnelson
Apr 29 2017 00:34
@sjames1958gm Thanks for the best practice! I implemented it, but it doesn't fix the problem. All channels are still displaying as offline, which isn't true. The channel Music4Studying is live.
CamperBot
@camperbot
Apr 29 2017 00:34
iamryandnelson sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7021 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Raihan Habib
@mrh07
Apr 29 2017 00:34
https://www.freecodecamp.com/challenges/generate-random-whole-numbers-within-a-range
can't understand the formula
Math.floor(Math.random() * (max - min + 1)) + min
Jonathan Marx Domah
@marxcom
Apr 29 2017 00:34
var myStr = "I am a \"double qouted\" string inside \"double qoutes\"."; // Change this line
what is wrong with this code?
Stephen James
@sjames1958gm
Apr 29 2017 00:35
@iamryandnelson Did you try setting the class on that div to something specific to the user?
@marxcom qouted should be quoted - also later qoutes.
I find it best to copy / paste strings from the instructions - avoid typos
Jonathan Marx Domah
@marxcom
Apr 29 2017 00:37
@sjames1958gm thanks
CamperBot
@camperbot
Apr 29 2017 00:37
marxcom sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7022 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 29 2017 00:37
@thekholm80 this inside the map function is not the component this.
put this.state.gameboard in a local before the map
caneno
@caneno
Apr 29 2017 00:37
hi guys can you guys help me what am I doing wrong
Herman Fassett
@HermanFassett
Apr 29 2017 00:37
@thekholm80 I think it's just an issue with this being for your function.
@sjames1958gm got you xd
Stephen James
@sjames1958gm
Apr 29 2017 00:37
@HermanFassett Yep, me too
caneno
@caneno
Apr 29 2017 00:37
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

// Change these values to test your function
lookUpProfile("Bob", "number");
Kyle Holm
@thekholm80
Apr 29 2017 00:38
@sjames1958gm @HermanFassett thank you!
CamperBot
@camperbot
Apr 29 2017 00:38
thekholm80 sends brownie points to @sjames1958gm and @hermanfassett :sparkles: :thumbsup: :sparkles:
:star2: 7023 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 1723 | @hermanfassett |http://www.freecodecamp.com/hermanfassett
Dan Couper
@DanCouper
Apr 29 2017 00:38
@the-vampiire the plus operator is used either for adding numbers, or for joining strings. JS attempts to coerce the arrays into something it can use the plus operator with - in this case, it's a string, although i think if you make all those arrays have a single number it will treat it as a number. It won't tell you you're doing anything wrong, it will just go ahead and try to do that - this is [one of] the major problems with JS. Plus cannot be used to concatenate anything other than values JS thinks should be strings, or sum values JS thinks are numbers (the fact plus has two discrete uses is another wart)
Kyle Holm
@thekholm80
Apr 29 2017 00:39
the this keyword always screws me up
Stephen James
@sjames1958gm
Apr 29 2017 00:39
@caneno Please don't post the whole array -
everywhere inside the loop you should use contacts[i]
Also, if you were going through a set of contacts when would you decide that you didn't have the contact?
Jonathan Marx Domah
@marxcom
Apr 29 2017 00:39
var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; // Change this line
Stephen James
@sjames1958gm
Apr 29 2017 00:39
@thekholm80 :) yeah me too
Jonathan Marx Domah
@marxcom
Apr 29 2017 00:39
still not working
Stephen James
@sjames1958gm
Apr 29 2017 00:40
Try refreshing the page - it looks correct
Jonathan Marx Domah
@marxcom
Apr 29 2017 00:41
@sjames1958gm cool thanks
CamperBot
@camperbot
Apr 29 2017 00:41
marxcom sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: marxcom already gave sjames1958gm points
Steven
@LemonTruth
Apr 29 2017 00:43
is there any way to compress this code?
function lookUpProfile(firstName, prop){
// Only change code below this line
    if (((contacts[0]).firstName === undefined) || ((contacts[1]).firstName === undefined || ((contacts[2]).firstName === undefined || ((contacts[3]).firstName === undefined)))) {
  return "No such contact";
Lola
@smokingboudicca
Apr 29 2017 00:46
how do you turn off notifications for this chat board?
Herman Fassett
@HermanFassett
Apr 29 2017 00:47
Room settings in the upper right and then notifications
Lola
@smokingboudicca
Apr 29 2017 00:47
@HermanFassett thanks
CamperBot
@camperbot
Apr 29 2017 00:47
smokingboudicca sends brownie points to @hermanfassett :sparkles: :thumbsup: :sparkles:
:star2: 1724 | @hermanfassett |http://www.freecodecamp.com/hermanfassett
Stephen James
@sjames1958gm
Apr 29 2017 00:47
@LemonTruth Use a for loop
Herman Fassett
@HermanFassett
Apr 29 2017 00:48
Or functional js
Stephen James
@sjames1958gm
Apr 29 2017 00:48
@LemonTruth In that challenge - if you have a loop and return the prop or no such property when you match a firstName
Then when the loop ends the code can assume that there is no contact
Vamp
@the-vampiire
Apr 29 2017 00:49
@DanCouper thank you. I posted on stack overflow and got the same answer. Makes a lot more sense now
CamperBot
@camperbot
Apr 29 2017 00:49
the-vampiire sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 668 | @dancouper |http://www.freecodecamp.com/dancouper
Steven
@LemonTruth
Apr 29 2017 00:50
@sjames1958gm ahh, so the whole undefined in unnecessary?
Dan Couper
@DanCouper
Apr 29 2017 00:50
@the-vampiire :thumbsup: JS is really bad for this in some situations, it's a pretty major reason why some people despise it. The coercian can work well in some situation though - like if you want to make sure something (call it n) you know should be number might come back like "1" instead of 1, you can do +n, the unary plus will coerce it to an actual number
Stephen James
@sjames1958gm
Apr 29 2017 00:50
@LemonTruth yes
Joseph
@revisualize
Apr 29 2017 00:51
Anyone want a free JavaScript course from Udemy?
caneno
@caneno
Apr 29 2017 00:51
for(var i = 0; i < contacts.length; i++){
  if(firstName == contacts[i].firstName && contacts[i].hasOwnProperty(prop)){
    return contacts[i][prop];
  }else if(firstName == contacts[i].firstName){
    return "No such contact";
  }else{
    return "No such property";
  }
}
Randall S.
@reylas81
Apr 29 2017 00:52

Here is what I have for the profile lookup:
function lookUpProfile(firstName, prop){
// Only change code below this line

var noContact = "No such cotact";
contacts.some(function(biteMe) ) {
if (biteMe.firstName === firstName && biteMe.hasOwnProperty(prop) === true) {
return prop;
} else if (biteMe.hasOwnProperty(prop) === false) {
return "No such property";
} else {
return noContact;
}

// Only change code above this line
}

this is really annoying me now

caneno
@caneno
Apr 29 2017 00:52
I still have this if I remove the else i get the first three point correct
Herman Fassett
@HermanFassett
Apr 29 2017 00:53
@LemonTruth yeah can be a bit cleaner
Dan Couper
@DanCouper
Apr 29 2017 00:54
@caneno you're returning inside the loop for every one - that's fine for the first condition, because you want to return it as soon as you find it. But for the others, if the first value isn't one you want, the function will end because you return immediately
caneno
@caneno
Apr 29 2017 00:55
oo ok
Herman Fassett
@HermanFassett
Apr 29 2017 00:55
I don't get it:
else if(firstName == contacts[i].firstName){
    return "No such contact";
}
Steven
@LemonTruth
Apr 29 2017 00:55
@revisualize nooo way. thanks babe
CamperBot
@camperbot
Apr 29 2017 00:55
lemontruth sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3843 | @revisualize |http://www.freecodecamp.com/revisualize
Herman Fassett
@HermanFassett
Apr 29 2017 00:56
My favorite lookup solution uses find array function
Dan Couper
@DanCouper
Apr 29 2017 00:57
@HermanFassett heh, I missed that, @caneno you need to look at that condition as well
yeah, find is pretty good for this
Ryan Nelson
@iamryandnelson
Apr 29 2017 00:58
@sjames1958gm Yup! You got it! Check it out: http://codepen.io/iamryandnelson/pen/vmXzXz?editors=0010
Stephen James
@sjames1958gm
Apr 29 2017 00:59
@iamryandnelson :checkered_flag:
Ryan Nelson
@iamryandnelson
Apr 29 2017 00:59
@sjames1958gm Thanks! Now onto adding the functionality to the buttons ;)
CamperBot
@camperbot
Apr 29 2017 00:59
iamryandnelson sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: iamryandnelson already gave sjames1958gm points
Csaba Balogh
@JasonCorp84
Apr 29 2017 01:02
I would like to write all first Names to an array from a nested object
for(i = 0; i < contacts.length; i++){
var allName = contacts[i].firstName;
return allName;
}
what is wrong with this ?
FlashHero
@FlashHero
Apr 29 2017 01:03
I struggle with intermediate JavaScript algorithms what should I do, I've been working on those challenges for weeks still can't solve it.
Stephen James
@sjames1958gm
Apr 29 2017 01:03
@JasonCorp84 You cannot return inside an loop like that
@JasonCorp84 Return leaves the function immedialtely.
Also you need to use something like push to put more than one value into the array
caneno
@caneno
Apr 29 2017 01:07
I Finally got it thanks @DanCouper @sjames1958gm
CamperBot
@camperbot
Apr 29 2017 01:07
caneno sends brownie points to @dancouper and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 669 | @dancouper |http://www.freecodecamp.com/dancouper
:star2: 7024 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kickkick479
@kickkick479
Apr 29 2017 01:08
@reylas81 some method return only boolean value.
See MND. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
So you need seek another way to resolve the algolythm.
Randall S.
@reylas81
Apr 29 2017 01:09
I figured it out...
Joseph
@revisualize
Apr 29 2017 01:10
@HermanFassett :wave:
Csaba Balogh
@JasonCorp84
Apr 29 2017 01:14
I got this then: var allName = [""];
for(i = 0; i < contacts.length; i++){
allName += contacts[i].firstName;
}
return allName;
how to add push there ?
I got an infinite loop
I got everything bulked without the push method
Joseph
@revisualize
Apr 29 2017 01:15
@JasonCorp84 Are you doing profile lookup?
Csaba Balogh
@JasonCorp84
Apr 29 2017 01:15
yes
Joseph
@revisualize
Apr 29 2017 01:15
@JasonCorp84 You don't need to return the firstName.
Stephen James
@sjames1958gm
Apr 29 2017 01:16
@JasonCorp84 allName.push(contacts[i].firstName);
var allName = [] should be the start
@JasonCorp84 += doesn't work with arrays - probably turned it all into a string.
Csaba Balogh
@JasonCorp84
Apr 29 2017 01:17
yest exactly that what is happened
@revisualize thank you
CamperBot
@camperbot
Apr 29 2017 01:18
jasoncorp84 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3845 | @revisualize |http://www.freecodecamp.com/revisualize
kickkick479
@kickkick479
Apr 29 2017 01:18
@reylas81
My code which is passed looks like this.
1 loop all contacts
  - check if each contact first name equals to the firstName given as an argument.
    +  if the first name matches, check if the contact has the property given as second argument.
      @  if the contact has the property, return the property value
   +  if the contact does not have the property, return "No such property";

2 out of the loop, return "No such contact". That's because no first name match the argument first name.
Joseph
@revisualize
Apr 29 2017 01:19
I think I'm gonna take a nap. Or watch some tv.
:v:
kickkick479
@kickkick479
Apr 29 2017 01:19
haha take a rest.
barki mustapha
@barkinet
Apr 29 2017 01:43

$ lighthouse --help

lighthouse <url>

Logging:
--verbose Displays verbose logging [boolean]
--quiet Displays no progress or debug logs [boolean]

Configuration:
--disable-device-emulation Disable device emulation [boolean]
--disable-cpu-throttling Disable cpu throttling [boolean]
--disable-network-throttling Disable network throttling [boolean]
--save-assets Save the trace contents & screenshots to disk [boolean]
--save-artifacts Save all gathered artifacts to disk [boolean]
--list-all-audits Prints a list of all available audits and exits [boolean]
--list-trace-categories Prints a list of all required trace categories and exits [boolean]
--config-path The path to the config JSON.
--perf Use a performance-test-only configuration [boolean]
--port The port to use for the debugging protocol. Use 0 for a
random port. [default: 9222]
--max-wait-for-load The timeout (in milliseconds) to wait before the page is
considered done loading and the run should continue.
WARNING: Very high values can lead to large traces and
instability. [default: 25000]

Output:
--output Reporter for the results, supports multiple values
[choices: "json", "html"] [default: "html"]
--output-path The file path to output the results. Use 'stdout' to write to
stdout.
If using JSON output, default is stdout.
If using HTML output, default is a file in the working
directory with a name based on the test URL and date.
If using multiple outputs, --output-path is ignored.
Example: --output-path=./lighthouse-results.html [default: "stdout"]

Options:
--help Show help [boolean]
--version Show version number [boolean]
--skip-autolaunch Skip autolaunch of Chrome when accessing port 9222 fails [boolean]
--select-chrome Interactively choose version of Chrome to use when multiple
installations are found [boolean]

Lighthouse by google
Ellyria
@Ellyria
Apr 29 2017 02:13
@revisualize, if you're still here, I just wanted to thank you. Your discussion Gist about the nested for loops helped a lot in my getting a grasp of accessing nested array elements. It took me two days to do it, but by golly, I finally did.
CamperBot
@camperbot
Apr 29 2017 02:13
ellyria sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3849 | @revisualize |http://www.freecodecamp.com/revisualize
Ellyria
@Ellyria
Apr 29 2017 02:15
It turns out that much of my self-inflicted torture was as the result of sloppy copying of the freeCodeCamp code when I put it into a text file to work on offline. I had accidentally added an extra } to the end of the file and that made it so that everything I tried failed, even when I was certain my code was good. Apparently one bracket can ruin two perfectly good days if you leave it laying around in the wrong place.
Jason Luboff
@JLuboff
Apr 29 2017 02:18
Matching opening and closing brackets is very important
Ellyria
@Ellyria
Apr 29 2017 02:19
Yeah, I was pretty much tearing my hair out over it.
Do any of you ever feel like complete idiots when facing some of these challenges?
Jason Luboff
@JLuboff
Apr 29 2017 02:22
Absolutely
Ellyria
@Ellyria
Apr 29 2017 02:31
Oh, good to know. This is definitely an undertaking that makes you feel like less than what you thought you were before you began!
Csaba Balogh
@JasonCorp84
Apr 29 2017 02:37
I am still working on the lookup function, but now I have a code:
function lookUpProfile(firstName, prop){
// Only change code below this line
for ( i = 0; i < contacts.length; i++) {
if (contacts[i].hasOwnProperty(firstName) === true) {
return contacts[i][prop];
}
else {
return "No such contact";
}
}
what is wrong with this ?
Ellyria
@Ellyria
Apr 29 2017 02:41
I see four opening curly brackets and three closing curly brackets. Is the fourth one in the part you didn't paste?
<--- has brackets on her mind tonight
Csaba Balogh
@JasonCorp84
Apr 29 2017 02:42
there is no syntax error here, but only logical errors
:(
but you are right, I have one more that I forgot to paste
barki mustapha
@barkinet
Apr 29 2017 02:42
npm install next react react-dom --save
Herman Fassett
@HermanFassett
Apr 29 2017 02:43
@JasonCorp84 I don't know why you're checking if the object has a property of a name... It always will have the property of firstName, but probably not the property held in firstName. You should check if the object has the property firstname equal to firstName and then check if it has the property prop
Ellyria
@Ellyria
Apr 29 2017 02:43
Also, why is [prop] an array?
Herman Fassett
@HermanFassett
Apr 29 2017 02:44
?
Ellyria
@Ellyria
Apr 29 2017 02:44
I should say, why is [prop] an array element?
Herman Fassett
@HermanFassett
Apr 29 2017 02:44
It's an object property, not an array element
Ellyria
@Ellyria
Apr 29 2017 02:44
Ah, never mind me. Sorry about that.
kickkick479
@kickkick479
Apr 29 2017 02:45
@JasonCorp84 Your code is ok when a contact has the first name and the prop. But what if no contact has the first name. Your code ends when first if check is false. That's wrong. After loop without matching, you should retrun "no such contact;
barki mustapha
@barkinet
Apr 29 2017 02:45

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
createServer((req, res) => {
// Be sure to pass true as the second argument to url.parse.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl

if (pathname === '/a') {
  app.render(req, res, '/b', query)
} else if (pathname === '/b') {
  app.render(req, res, '/a', query)
} else {
  handle(req, res, parsedUrl)
}

})
.listen(3000, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
})
})

Csaba Balogh
@JasonCorp84
Apr 29 2017 02:47
I guess it is time to take a rest till tomorrow. do not understand now :D
@HermanFassett thank you
CamperBot
@camperbot
Apr 29 2017 02:47
jasoncorp84 sends brownie points to @hermanfassett :sparkles: :thumbsup: :sparkles:
:star2: 1725 | @hermanfassett |http://www.freecodecamp.com/hermanfassett
Csaba Balogh
@JasonCorp84
Apr 29 2017 02:48
@kickkick479 thank you
Herman Fassett
@HermanFassett
Apr 29 2017 02:48
:thumbsup:
kickkick479
@kickkick479
Apr 29 2017 02:48
@JasonCorp84 BTW, if (contacts[i].hasOwnProperty(firstName) === true) { can be shortened like if (contacts[i].hasOwnProperty(firstName) ) {. Cuz hasOwnProperty return boolean value.
Csaba Balogh
@JasonCorp84
Apr 29 2017 02:48
@kickkick479 so that part is ok ?
barki mustapha
@barkinet
Apr 29 2017 02:49

404 or 500 import React from 'react'
export default class Error extends React.Component {
static getInitialProps ({ res, jsonPageRes }) {
const statusCode = res ? res.statusCode : (jsonPageRes ? jsonPageRes.status : null)
return { statusCode }
}

render () {
return (
<p>{
this.props.statusCode
? An error ${this.props.statusCode} occurred on server
: 'An error occurred on client'
}</p>
)
}
}

kickkick479
@kickkick479
Apr 29 2017 02:50

@JasonCorp84 Soory if (contacts[i].hasOwnProperty(firstName) === true) { return contacts[i][prop]; } is wrong. sould if (contacts[i].hasOwnProperty(prop) === true) { return contacts[i][prop]; }

But you should re-think else part and outside of the loop. You are almost there and can do it.

Csaba Balogh
@JasonCorp84
Apr 29 2017 02:50
@kickkick479 nice thanks
CamperBot
@camperbot
Apr 29 2017 02:50
jasoncorp84 sends brownie points to @kickkick479 :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @kickkick479 |http://www.freecodecamp.com/kickkick479
kickkick479
@kickkick479
Apr 29 2017 02:51
^ Sorry. I fixed, cus you should check whether each contact has the property given as an argument.
barki mustapha
@barkinet
Apr 29 2017 02:52
Framework for server-rendered React apps https://zeit.co/blog/next2
anderson
@anderson2825
Apr 29 2017 03:06
<script>
  // Only change code below this line.
 $(document).ready(function(){
    if(navigator.geolocation){
    navigator.geolocation.getCurrentPosition(function(position){
     $('#data').html("latitude:"+position.coords.latitude+"<br>longitude:"   +position.coords.longitude);
     });
       };
   });



  // Only change code above this line.
</script>
<div id = "data">
  <h4>You are here:</h4>

</div>
why is wrong?? pls help me check it !
json445.png
kickkick479
@kickkick479
Apr 29 2017 03:08
@anderson2825 What's the stage name?
Never mind. I found it.
kerafyrm02
@kerafyrm02
Apr 29 2017 03:10
Dont need semicolon on if
anderson
@anderson2825
Apr 29 2017 03:11
@kerafyrm02 it's Get Geolocation Data
kerafyrm02
@kerafyrm02
Apr 29 2017 03:11
};
don't need that semicolon.
anderson
@anderson2825
Apr 29 2017 03:13
@kerafyrm02 Or wrong!
kerafyrm02
@kerafyrm02
Apr 29 2017 03:13
It also says "within the data div"
so rename your <h4 id="geo"></h4>
and make your $('#data').html to $("#geo").html
Jean Saint-Hilaire
@Wisestjean
Apr 29 2017 03:15
help me here please
var myStr = "FirstLine\nSecondLine\rThirdLine"
kerafyrm02
@kerafyrm02
Apr 29 2017 03:15
what are you trying to do jean?
Jean Saint-Hilaire
@Wisestjean
Apr 29 2017 03:16
want to break the line
it doesn't give me what is required
kickkick479
@kickkick479
Apr 29 2017 03:18
@Wisestjean Not only break lines, bu also need display \.
mamun
@fsdmamun
Apr 29 2017 03:19
\n makes a new line, \r makes a new line too but like 'enter' of a key board or 'carriage return' of type machine, now read the instruction and example given there, it will work
@Wisestjean
Jean Saint-Hilaire
@Wisestjean
Apr 29 2017 03:23
I have got it using codepen
"FirstLine\n\SecondLine\\rThirdLine";
var myStr = "FirstLine\n\SecondLine\\rThirdLine";
console.log(myStr);
Pagnito
@Pagnito
Apr 29 2017 03:25
pretty confused on what apply does
kickkick479
@kickkick479
Apr 29 2017 03:25
@Wisestjean I dont remeber exact instraction. It looks close, but that looks wrong, cuz \\r ends up \ and r.
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:26
Can somebody help me?
kickkick479
@kickkick479
Apr 29 2017 03:26
@Wisestjean If you want to show up \, you should put double \ in variable value.
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:26
It's a regex challenge
kickkick479
@kickkick479
Apr 29 2017 03:27
@rodrigo-fontes What's wrong.
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:27
let repeatNum = "42 42 42";
let reRegex = /(\d{2,3}\s)\1/; // Change this line
let result = reRegex.test(repeatNum);
fails tests 2, 3 and 6
anderson
@anderson2825
Apr 29 2017 03:30
@kerafyrm02 like this??
``````
 $(document).ready(function(){
    if(navigator.geolocation){
    navigator.geolocation.getCurrentPosition(function(position){
     $('#data h4').html("latitude:"+position.coords.latitude+"<br>longitude:"   +position.coords.longitude);
     })
       }
 })
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:31
don't know what to do
kickkick479
@kickkick479
Apr 29 2017 03:31
@rodrigo-fontes Follow Your regex should reuse the capture group twice. , so that you can return "42 42 42". or "100 100 100". Long story shot, you should return triple same numbers.
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:32
I'm not sure if I understood this part
kickkick479
@kickkick479
Apr 29 2017 03:33
@rodrigo-fontes You re-used the captured group, (\d{2,3}\s) , using \1.
Herman Fassett
@HermanFassett
Apr 29 2017 03:34
@rodrigo-fontes you're also only using one capture group... You'll need a \1 and a \2 as far as I can see
kickkick479
@kickkick479
Apr 29 2017 03:34
we can re-use capture groups many times like \1\1
anderson
@anderson2825
Apr 29 2017 03:34
@kerafyrm02 Has been resolved, I know the reason!
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:35
If i change it to \1\1 tests 3, 4, 5,6 and 10 fails
Herman Fassett
@HermanFassett
Apr 29 2017 03:36
@rodrigo-fontes never mind me it works without using \2
anderson
@anderson2825
Apr 29 2017 03:36
The $('#data h4') to be replaced by $("#data") ;
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:37
let repeatNum = "42 42 42";
let reRegex = /(\d+\s\s)\1\1/; // Change this line
let result = reRegex.test(repeatNum);
I've adjusted to this, but now
Tests 4,5,6 and 10 fails
kickkick479
@kickkick479
Apr 29 2017 03:38
@anderson2825 It is ok to replace the code inside ready(function) with the exapmple code. I donot still find differences but it passed.
Herman Fassett
@HermanFassett
Apr 29 2017 03:38
@rodrigo-fontes all you need in the capture group is (\d+) then just copy the example for the 2nd and 3rd time...
Eduar Tua
@eduartua
Apr 29 2017 03:39
Hello there, I am doing the Return Largest Numbers in Arrays challenge. How can I find the highest value in a array without using loops?
kickkick479
@kickkick479
Apr 29 2017 03:39
@rodrigo-fontes (\d+\s\s) never show up in repeatNum. repeatNum is separated with single space.
anderson
@anderson2825
Apr 29 2017 03:40
I changed $('#data') to $("#data") can be passed !
Gabe Rotberg
@grotberg
Apr 29 2017 03:40
@eduartua you might consider some of the array specific functions, like .map()
anderson
@anderson2825
Apr 29 2017 03:40
@kickkick479
Eduar Tua
@eduartua
Apr 29 2017 03:41
@grotberg I am using map with a callback, but do not want to use loop inside the callbak
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:41
@kickkick479 But it says: "Your regex should have two spaces separating the three numbers.""
kickkick479
@kickkick479
Apr 29 2017 03:42
@rodrigo-fontes let reRegex =/(set of numbers)\s\1\s\1/; works.
Gabe Rotberg
@grotberg
Apr 29 2017 03:42
@eduartua what about a map inside the callback?
@eduartua or just comparing against an external variable that keeps track of the highest value so far?
Eduar Tua
@eduartua
Apr 29 2017 03:43
@grotberg So, Will I be using ,ap twice?
Map*
kickkick479
@kickkick479
Apr 29 2017 03:43
@rodrigo-fontes One space between 2 sets of numbers makes two, cuz there are 3 sets of numbers. English is my second language, so if you have complaint for the instraction, please publish a issue on github :smile:
Gabe Rotberg
@grotberg
Apr 29 2017 03:44
@eduartua well, I'm trying to remember the exact exercise. that's the one where you have an array of arrays with 4 numbers each, and you need to return an array with the largest numbers? you could map the (outer) array, and then have that callback map each inner array, then figure out the logic to find the largest number in there.
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:45
@kickkick479 Thank you for your help
CamperBot
@camperbot
Apr 29 2017 03:45
rodrigo-fontes sends brownie points to @kickkick479 :sparkles: :thumbsup: :sparkles:
:cookie: 320 | @kickkick479 |http://www.freecodecamp.com/kickkick479
Rodrigo Fontes
@rodrigo-fontes
Apr 29 2017 03:45
I'll try that
Eduar Tua
@eduartua
Apr 29 2017 03:45
Yes, that one
@grotberg
Gabe Rotberg
@grotberg
Apr 29 2017 03:46
@eduartua Yeah. I'd try it with maps. Seems like it should work?
Alexx Martínez
@AlexxMart
Apr 29 2017 03:48

I have a problem with the lesson "Testing Objects for Properties".

I really don't understand how to perform this task: "Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found"."

my code:

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkObj)===true) // Your Code Here

return "Not Found";
}

// Test your code by modifying these values
checkObj("gift");

Vamp
@the-vampiire
Apr 29 2017 03:51
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkObj)===true) // Your Code Here
return "Not Found";
}
// Test your code by modifying these values
checkObj("gift");
you are passing a boolean to the hasOwnProperty method. you have to pass a property you are looking to confirm the existance of
kickkick479
@kickkick479
Apr 29 2017 03:52

@AlexxMart Like example, you can check if the object has a given property, using hasOwnProperty. Like this,

myObj.hasOwnProperty("top");    // true
myObj.hasOwnProperty("middle"); // false

And you can use checkProp which represents "gift" in the case checkObj("gift");
So you should check if myObj has "gift" property, using checkProp.
And if it's true, you can return property value, like returnn myObj[Property Name].
Note that if you use myObj's property value using variable, .(dot) notation can not be used and you can use only [] notation.

Vamp
@the-vampiire
Apr 29 2017 03:53
in this case you have your hasOwnProperty method in a function. that function is being passed a property to check ‘checkProp’. so if you want your function to test whether the property exists you should check if the property ‘checkProp’ exists

you can check a specific property by passing the string (‘top’, ‘middle’) like @kickkick479 reiterated from the example. in the case of checking if a variable property exists you would pass that variable name into the method. this way you can run your function to check for any property you pass to it.

this is called the difference between static (single use) code [‘top’, ‘middle’] and dynamic (multi use) code [checkProp]

Alexx Martínez
@AlexxMart
Apr 29 2017 04:04
I have changed my code to:

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
if (myObj.hasOwnProperty[checkProp]);
{return myObj[checkProp];}
return "Not Found"; }// Your Code Here



// Test your code by modifying these values
checkObj("house");
Conor Murphy
@cmurphy580
Apr 29 2017 04:04
is there anyway to count the instances of an constructor?
Alexx Martínez
@AlexxMart
Apr 29 2017 04:06
and is still not working for the objective: checkObj("house") should return "Not Found".
PhoenixFarhan
@PhoenixFarhan
Apr 29 2017 04:08

var myVar = 87;

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

does any one know why that is not increasing by one
kickkick479
@kickkick479
Apr 29 2017 04:09
@AlexxMart if (myObj.hasOwnProperty[checkProp]);
last ; semicolon is not needed. But still it won't pass. I am examing.
@AlexxMart Aha. your hasOwnProperty[checkProp] is wrong. use ()
h1tag
@h1tag
Apr 29 2017 04:11
@PhoenixFarhan myVar++ equals myVar = myVar + 1, so you don't need the second myVar=
kickkick479
@kickkick479
Apr 29 2017 04:11
@AlexxMart hasOwnProperty is METHOD, not array nor object.
jhobotuck
@jhobotuck
Apr 29 2017 04:12
Is there a way to look at your pervious mentions. I have someone who really helped and I would like to reward them with brownie points they deserve.
h1tag
@h1tag
Apr 29 2017 04:13
@jhobotuck you can check the chat log of that day
archive*
CamperBot
@camperbot
Apr 29 2017 04:13
Archives for HelpJavaScript
Ken Haduch
@khaduch
Apr 29 2017 04:14
@jhobotuck - you can try to go to the left side navbar, there is a search icon (a magnifying glass) and you click that in the room you want to search. Type the @username to find mentions. They seem to come out in some non-chronological order. Usually you can find it that way. Good luck, I hope that helps!
Alexx Martínez
@AlexxMart
Apr 29 2017 04:14
@kickkick479 is still not working even after changing that
kickkick479
@kickkick479
Apr 29 2017 04:14
@PhoenixFarhan That's the interesting syntax. There is difference myVar = ++myVar and myVar = myVar++.
jhobotuck
@jhobotuck
Apr 29 2017 04:15
@longnt80 Thanks for the trim recommendation!
CamperBot
@camperbot
Apr 29 2017 04:15
jhobotuck sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 200 | @longnt80 |http://www.freecodecamp.com/longnt80
Ken Haduch
@khaduch
Apr 29 2017 04:15
@AlexxMart - you have an extra semicolon after your if line - that makes it a null statement and does not execute the bracketed code, if you are still working with the code that you posted.
jhobotuck
@jhobotuck
Apr 29 2017 04:16
Thanks @fortMaximus and @khaduch for the help of how to search through pervious posts.
CamperBot
@camperbot
Apr 29 2017 04:16
jhobotuck sends brownie points to @fortmaximus and @khaduch :sparkles: :thumbsup: :sparkles:
:cookie: 753 | @fortmaximus |http://www.freecodecamp.com/fortmaximus
:star2: 2809 | @khaduch |http://www.freecodecamp.com/khaduch
kickkick479
@kickkick479
Apr 29 2017 04:16
@AlexxMart can you paste current code? it's helpful , indent is inserted.
Ken Haduch
@khaduch
Apr 29 2017 04:17
@jhobotuck :+1:
Alexx Martínez
@AlexxMart
Apr 29 2017 04:17
@kickkick479 is working now! Thanks
CamperBot
@camperbot
Apr 29 2017 04:17
alexxmart sends brownie points to @kickkick479 :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @kickkick479 |http://www.freecodecamp.com/kickkick479
webster
@T3j4s
Apr 29 2017 04:22

Challenge Understanding Uninitialized Variables has an issue.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

// Initialize these three variables
var a;
var b;
var c;

a = 6;
b = 15;
c = "I am a String!";

// Do not change code below this line

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

can u please help me out
kickkick479
@kickkick479
Apr 29 2017 04:23

@PhoenixFarhan
myVar = myVar++ is proccessed like this.

  1. re-assign current value of myVar to myVar. Of couse, value remain same.
  2. myVar + 1 is calculated, but the result is not used.

myVar = ++myVar is proccessed like this.

  1. myVar + 1 is calculated
  2. the result is assigned to myVar. so myVar increments.

I never read ECMAScript specification, so that that's just my guess.
like @fortMaximus said, I reccomend you to use only myVar++.

Jor
@joreyesl
Apr 29 2017 04:25
@T3j4s you initilized c to I am a String!,
then when c = c + " String!" runs, c will end up being I am a String! String!.
You need to rethink what you need to initialize c to
webster
@T3j4s
Apr 29 2017 04:25
k got it
Pagnito
@Pagnito
Apr 29 2017 04:28
can someone tell me why this works, but for ([23,18]) it creates an infinite loop
function leastCommon(arr){
  var big = Math.max(arr[0],arr[1]);
  var multiples = [];

  for(var j=1; j<=big; j++){
    multiples.push(j);
  }

  function test(num){
    return i%num===0;
  }
  var i=0;
  var pecker = false;
  while (pecker === false){
    i++;
    if(multiples.every(test)===true){

      pecker=true;
      console.log( i);
    }
  }
}
leastCommon([5,1]);
cotolany
@cotolany
Apr 29 2017 04:34
Hi all need a help. I write var a=['a','b'];
in console and get undefined why?
kickkick479
@kickkick479
Apr 29 2017 04:35
@cotolany Cuz you are not calling a. Try input only a , following that declaration.
Juan
@jukxz
Apr 29 2017 04:36
Hello guys, Im new in freecodecamp. Im looking for learn JS and PHP. (I know how or where JS goes) but Im looking to code from 0 . so, what is the best way to learn it?
cotolany
@cotolany
Apr 29 2017 04:37
@kickkick479 ty but why when I'm colling both there is still an error
CamperBot
@camperbot
Apr 29 2017 04:37
cotolany sends brownie points to @kickkick479 :sparkles: :thumbsup: :sparkles:
:cookie: 324 | @kickkick479 |http://www.freecodecamp.com/kickkick479
cotolany
@cotolany
Apr 29 2017 04:38
@kickkick479 var a=['a','b']; var b; b.push(a); console.log(b);
@jukxz do the exersises
h1tag
@h1tag
Apr 29 2017 04:39
@Pagnito you need to shorten your code , because when it's ([23,18]), it takes more than 1000 steps
Juan
@jukxz
Apr 29 2017 04:39
@cotolany you're saying here? thanks :D
CamperBot
@camperbot
Apr 29 2017 04:39
jukxz sends brownie points to @cotolany :sparkles: :thumbsup: :sparkles:
:cookie: 352 | @cotolany |http://www.freecodecamp.com/cotolany
Pagnito
@Pagnito
Apr 29 2017 04:39
@fortMaximus so when does infinite loop error kick in?
cotolany
@cotolany
Apr 29 2017 04:40
@fortMaximus Ahh even more 1000 is not a loop it geves an error?
kickkick479
@kickkick479
Apr 29 2017 04:40

@cotolany push method is Array's method. So as error message tell, undefined b is wrong.
Instead, assign array object to b, so you can use push.

var a=['a','b'];
 var b = []; 
b.push(a); 
console.log(b);

Or assign a to b. var b; b = a;
It depends on what you want to archive.

h1tag
@h1tag
Apr 29 2017 04:41
it may not be an infinite loop literary, but when it takes too long the freecodecamp console will display this error @Pagnito
Pagnito
@Pagnito
Apr 29 2017 04:42
@fortMaximus yea i feel u, im not sure how to make it work tho, i thought this was gonna be the best way , should i use some type multiplication to make the numbers?
cotolany
@cotolany
Apr 29 2017 04:42
@kickkick479 thanks again :)
CamperBot
@camperbot
Apr 29 2017 04:42
cotolany sends brownie points to @kickkick479 :sparkles: :thumbsup: :sparkles:
:warning: cotolany already gave kickkick479 points
Pagnito
@Pagnito
Apr 29 2017 04:46
@fortMaximus even iterating by the largest number in the array argument gives the same error O.o
ClanceyQin
@CLANCEYQIN
Apr 29 2017 04:49

\\ //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 lookUp(firstName, prop){
// Only change code below this line
for(var i=0;i<contacts.length;i++){
if(contacts[i].firstName==firstName){

    if (prop in contacts[i])
    {
      return contacts[i][prop];

        }

return "No such property";
}} return "No such contact";
// Only change code above this line
}

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

kickkick479
@kickkick479
Apr 29 2017 04:50
@CLANCEYQIN use hasOwnProperty method.
Markus Kiili
@Masd925
Apr 29 2017 04:52
@CLANCEYQIN The in operator also finds inherited built-in property keys like "toString". We don't wan't that.
Pagnito
@Pagnito
Apr 29 2017 04:53
@fortMaximus k thanks
CamperBot
@camperbot
Apr 29 2017 04:53
pagnito sends brownie points to @fortmaximus :sparkles: :thumbsup: :sparkles:
:cookie: 754 | @fortmaximus |http://www.freecodecamp.com/fortmaximus
kickkick479
@kickkick479
Apr 29 2017 04:55
@Pagnito BTY, I thought var pecker = false; while (pecker === false){ is a bit confusing. It works, but I suggest this fix.
  var pecker = true;
  while ( pecker ){
      ...
      pecker=false;
      ...
    }
  }
Pagnito
@Pagnito
Apr 29 2017 04:57
k holdo n
what does bty mean
kickkick479
@kickkick479
Apr 29 2017 04:58
By the way
Oops , my typo, lol
Pagnito
@Pagnito
Apr 29 2017 04:59
hehe
but yea i tihnk im gonna have to redo the whole code
so at a thousandth loop is when it throws the infinte loop error?
kickkick479
@kickkick479
Apr 29 2017 05:03

@Pagnito
And how to get sequential numbers between the two numbers is not correct.

  for(var j=1; j<=big; j++){
    multiples.push(j);
  }

you should start j from smaller number of the two arguments, not from 1.

Pagnito
@Pagnito
Apr 29 2017 05:05
well i did that tonot push the 0 in
ooh wait how come
hold on
ooh yea u right, i get it now
it works now haha, now that it doesnt have to loop so much
kickkick479
@kickkick479
Apr 29 2017 05:08
:+1:
Pagnito
@Pagnito
Apr 29 2017 05:08
fck ya man, u the man, thanks
kickkick479
@kickkick479
Apr 29 2017 05:08
Np :)
Pagnito
@Pagnito
Apr 29 2017 05:08
pretty happy i my code actually worked
kickkick479
@kickkick479
Apr 29 2017 05:09
But still I'm struggling same stage, haha
Pagnito
@Pagnito
Apr 29 2017 05:09
lol
werid thing is tho, even tho my code works, and it returns all the right numbers, it wont pass me
i can see the result bar showing my answers all right
but all the cases are still x'd
T.T
kickkick479
@kickkick479
Apr 29 2017 05:10
Tried reset and re-past your code?
Pagnito
@Pagnito
Apr 29 2017 05:10
truueee
nop still didnt work
k it passed me now
weird
well ima retire for the night
gd night
kickkick479
@kickkick479
Apr 29 2017 05:15
Gd night
Csaba Balogh
@JasonCorp84
Apr 29 2017 05:16
re
Baibhav Gautam
@baibhavx
Apr 29 2017 05:19
function calculateOrbitalPeriod(avgAlt) {
  var GM = 398600.4418
  var earthRadius = 6367.4447
  var a = avgAlt + earthRadius;
  var aCubed = Math.pow(a, 3);
  var PI = Math.PI;
  var orbitalRadius = (2 * PI) * Math.sqrt(aCubed, GM);
  return Math.floor(orbitalRadius);
}
var output = calculateOrbitalPeriod(35873.5553);
console.log(output); //=> Returns 54548291  BUT SHOULD RETURN   86400   ?
Can anyone please help me with this
kickkick479
@kickkick479
Apr 29 2017 05:21
@baibhavx What is the stage name?
Baibhav Gautam
@baibhavx
Apr 29 2017 05:22
Thats from advanced algorithm scripting
Second Last problem Map The Derbis
Jor
@joreyesl
Apr 29 2017 05:23
@baibhavx the formula is 2*PI*Sqr(aCubed / GM)
Baibhav Gautam
@baibhavx
Apr 29 2017 05:23
o really? Lemme check real quick
Jor
@joreyesl
Apr 29 2017 05:23
you should be dividing aCubed by GM
Baibhav Gautam
@baibhavx
Apr 29 2017 05:24
awesome thank you so much @joreyesl
__SharifTarver__
@Sharifdesigns22
Apr 29 2017 05:30

A little lost on the gold code can someone help?

function golfScore(par, strokes) {
// Only change code below this line
if (stroke <= par - 2){
return "Change Me";}

// Only change code above this line
}

// Change these values to test
golfScore(5, 4);

Never mind figured it out!
cotolany
@cotolany
Apr 29 2017 05:32
@Sharifdesigns22 :)
__SharifTarver__
@Sharifdesigns22
Apr 29 2017 05:32
```
function golfScore(par, strokes) {
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
}
// Change these values to test
golfScore(5, 9);
kickkick479
@kickkick479
Apr 29 2017 05:33
Looks good
cotolany
@cotolany
Apr 29 2017 05:33
@Sharifdesigns22 add ``` at the last empty line
@kickkick479 I do it without else just if is it ok?
kickkick479
@kickkick479
Apr 29 2017 05:36
@cotolany While you can get desired result, any code is ok, I think.
lightarcade
@lightarcade
Apr 29 2017 05:47
Hi Folks..I am a newbie here
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:47
@lightarcade welcome
lightarcade
@lightarcade
Apr 29 2017 05:47
I am stuck in the "Counting Cards" section
kickkick479
@kickkick479
Apr 29 2017 05:47
hi
lightarcade
@lightarcade
Apr 29 2017 05:48
I am not sure what i am doing wrong here
can someone help

var count = 0;

function cc(card) {
// Only change code below this line
if (card > 1 && card < 7) {
count ++;
return count +" Bet";
}
else if (card >= 7 && card <= 9) {
count = count + 0;
return count +" Hold";
}
else if ( card == 10||card == "J"||card == "Q"||card =="K"||card =="A") {
count --;
return count +" Hold";
}
else {
return "Change Me";
}
// Only change code above this line
}

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

It does not work for two sequences
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
Cards Sequence 2, 2, 10 should return "1 Bet"
not sure where I screwed things up
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:48
if (card > 1 && card < 7) {
lightarcade
@lightarcade
Apr 29 2017 05:48
Thanks @NahuelOvejero
CamperBot
@camperbot
Apr 29 2017 05:48
lightarcade sends brownie points to @nahuelovejero :sparkles: :thumbsup: :sparkles:
:cookie: 341 | @nahuelovejero |http://www.freecodecamp.com/nahuelovejero
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:48
when was that going to be true?
lightarcade
@lightarcade
Apr 29 2017 05:49
this is the problem statement
"You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space."
if the value passed is 2, 3, 4, 5, 6
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:49
I think you have to use a switch
not sure tho
lightarcade
@lightarcade
Apr 29 2017 05:50
Ohh ok..I initially used switch case statements, but this seemed simple and straightforward
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:50
well, you are rigth, but remember that the count is global, and you need to call it many times
lightarcade
@lightarcade
Apr 29 2017 05:50
yes
i guess thats where i am missing something
the count value is not being properly set is my doubt
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:51
but lets say, you have a -3 value in count, and you get a 3 value card
you get -2 in count
lightarcade
@lightarcade
Apr 29 2017 05:51
yes
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:51
so bet with -2 is wrong
you need to check if you need to bet, hold, at the end of the function, after the operation ++ , -- or do nothing
Joseph
@revisualize
Apr 29 2017 05:52
Counting Cards is a challenge where your function will receive a card parameter. You're supposed to increment or decrement the global count variable according to the card's value
If the value of the card parameter is 2, 3, 4, 5 or 6 you need to increment the global variable count.
If the value of the card parameter is 10, 'J', 'Q', 'K' or 'A' you need to decrement the global variable count.
...
Then the function will return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.
The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
...
...
Things to note: You should NOT be returning based on the value of the card. The value of card should only be adding or subtracting 1 from the global variable count.
The value of the global variable count is used to determine the return statement.
count --; <--- The space is an issue.
@lightarcade
lightarcade
@lightarcade
Apr 29 2017 05:54
Thanks @NahuelOvejero and @revisualize
CamperBot
@camperbot
Apr 29 2017 05:54
lightarcade sends brownie points to @nahuelovejero and @revisualize :sparkles: :thumbsup: :sparkles:
:warning: lightarcade already gave nahuelovejero points
:star2: 3850 | @revisualize |http://www.freecodecamp.com/revisualize
lightarcade
@lightarcade
Apr 29 2017 05:54
Let me try and ping back here
Joseph
@revisualize
Apr 29 2017 05:54
@lightarcade if you're using ++ or -- to modify a variable the operation needs to be right next to the variable. myVar++ and myVar--
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:54
I think the space is not an issue
lightarcade
@lightarcade
Apr 29 2017 05:54
ok
with or without space, it will still work
tried removing the space and it is two specific conditions that doesn't work
Joseph
@revisualize
Apr 29 2017 05:55
@NahuelOvejero Not sure. Just one thing I saw out of the many.
lightarcade
@lightarcade
Apr 29 2017 05:55
Thanks @revisualize . I agree that space should not be ter.
CamperBot
@camperbot
Apr 29 2017 05:55
lightarcade sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: lightarcade already gave revisualize points
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:55
Just tested out, a-- or a -- works both
Joseph
@revisualize
Apr 29 2017 05:56
Okay, then I'm mistaken. Thanks.
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:57
It is more clear if its all together tho
a27-suryansh
@a27-suryansh
Apr 29 2017 05:57
@revisualize Can i call some jquery function if screen width is less than 1024px
?
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:58
they don't have any relation @a27-suryansh
you can call anything if you have 90000 px or 1 px
a27-suryansh
@a27-suryansh
Apr 29 2017 05:59
@NahuelOvejero I want to load JS file only in mobile view
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:59
oh, well, you can call any function
Ogundele Olumide
@Lumexralph
Apr 29 2017 05:59
@a27-suryansh an event that has to do with resizing the window/ viewport ?
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 05:59
depends what it does if you can see it properly
a27-suryansh
@a27-suryansh
Apr 29 2017 05:59
i want to call this function $.fn.fullpage.destroy('all'); if width of browser is less than 1024px
@Lumexralph @NahuelOvejero
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:00
@a27-suryansh why don't you search online?
a27-suryansh
@a27-suryansh
Apr 29 2017 06:00
tried it
But it was executing it on all screens
@Lumexralph
Nahuel Ovejero
@NahuelOvejero
Apr 29 2017 06:01
mhhh, not sure, I know you have to search trhought the DOM, the navigator element
the width info is there for sure
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:02
@a27-suryansh there's a resize event in jQuery
@a27-suryansh you'll need to get the clientWidth, clientHeight, innerWidth, innerHeight, outerWidth, outerHeight, offsetWidth and/or offsetHeight properties of window object to get the size you want for the callback to be fired
a27-suryansh
@a27-suryansh
Apr 29 2017 06:05
@Lumexralph I am using this script
@Lumexralph i want to disable it when screen is less than 1024px
<script type="text/javascript">
$(document).ready(function() {
    $('#fullpage').fullpage({
        //Navigation
        menu: '#menu',
        lockAnchors: false,
        anchors:['home', 'eventSection', 'scheduleSection', 'contactSection', 'reikiSection', 'classSchedule'],
        navigation: true,
        navigationPosition: 'right',
        navigationTooltips: [''],
        showActiveTooltip: false,
        slidesNavigation: true,
        slidesNavPosition: 'bottom',

        //Scrolling
        css3: false,
        scrollingSpeed: 700,
        autoScrolling:true,
        fitToSection: true,
        fitToSectionDelay: 700,
        scrollBar: true,
        easing: 'easeInOutCubic',
        easingcss3: 'ease',
        loopBottom: false,
        loopTop: false,
        loopHorizontal: true,
        continuousVertical: false,
        continuousHorizontal: false,
        scrollHorizontally: false,
        interlockedSlides: false,
        resetSliders: false,
        fadingEffect: false,
        normalScrollElements: '#element1, .element2',
        scrollOverflow: false,
        scrollOverflowOptions: null,
        touchSensitivity: 15,
        normalScrollElementTouchThreshold: 5,
        bigSectionsDestination: null,

        //Accessibility
        keyboardScrolling: true,
        animateAnchor: true,
        recordHistory: true,

        //Design
        controlArrows: true,
        verticalCentered: true,
        sectionsColor : ['#ccc', '#fff'],
        paddingTop: '0',
        paddingBottom: '0',
        fixedElements: '#header, .footer',
        responsiveWidth: 1024,
        responsiveHeight: 0,
        responsiveSlides: false,

        //Custom selectors
        sectionSelector: '.section',
        slideSelector: '.slide',

        //events
        onLeave: function(index, nextIndex, direction){},
        afterLoad: function(anchorLink, index){},
        afterRender: function(){},
        afterResize: function(){},
        afterResponsive: function(isResponsive) {};,
        afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex){},
        onSlideLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){}
    });
});
</script>
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:06
@a27-suryansh you can console.log(this); in your browser, you can see the properties
a27-suryansh
@a27-suryansh
Apr 29 2017 06:07
@Lumexralph though we have a parameter here responsiveWidth: 1024, but still it doesn't stops the script in the mobile
If i resize the browser on desktop then it is stopping the script
but if i access the webpage in real mobile then it doesn't works
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:08
@a27-suryansh i don't need your full script, you need to access the window properties i suggested
a27-suryansh
@a27-suryansh
Apr 29 2017 06:09
ok
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:09
@a27-suryansh that's what I can think of, there'll be better ways too
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:12
can i say: the prototype is the same as the class from which the objects were created?
if am asked what is prototype in javascript
so if you add property to the prototype, you are adding it to the class?
is my definition correct?
Markus Ivancsics
@ivancsicsmarkus
Apr 29 2017 06:14
@a27-suryansh Did you add?
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:14
@brittanyrutherford prototype is a property of an object, and all other objects are linked together through it..... prototype is not class
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:15
in w3schools, it says: > All JavaScript objects inherit the properties and methods from their prototype.
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:16
@brittanyrutherford Each object has a private property (referred to as [[Prototype]] ) which holds a link to another object called its prototype.
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:17
so what's the difference between adding property to the class function, and adding property using prototype property?
if they are going to add the property to the same place, doesn't this mean that the prototype of an object, is the class of that object?
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:19
@brittanyrutherford the question you should ask is what is a class in JS?
@brittanyrutherford i don't like the way JS tries to use class cos in the end it's still Objects linked to each other through the [[prototype]] property
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:20
i would say it's the prototype that holds a blueprint of what properties and functions will be included in the instances of this prototype
yes, i know you are referring to prototype as a property, but i think it also means the class
it's like jquery when you say.parent
i think it's the same here, object.prototype means get me the root class
am i right?
am right
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:26
@Masd925 @Lumexralph mornin
Markus Kiili
@Masd925
Apr 29 2017 06:27
@Lumexralph @HeebieGeeBee Morning.
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:27
@Masd925 but if we add a property to the prototype, it's adding it to the class right?
let me read the article you posted
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:28
@brittanyrutherford there's nothing classy in JS
@HeebieGeeBee @Masd925 Morning Bro
@brittanyrutherford if you add a property to the prototype object, it doesn't mean you're adding property to the class which I prefer to call an object with a different mechanism
Jor
@joreyesl
Apr 29 2017 06:33
@brittanyrutherford you shouldn't try to make sense of prototype in an OOP sense. They are different things. Trying to compare it to classes will create confusion. Instead try to understand it as its own concept.
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:33
@Masd925 the article assumes that the only way of adding a function to a class-function is by using a prototype which is wrong.. what prevented him from adding a function directly to the class-function?
@joreyesl I am trying to understand it by explaining it to myself, and that's the way I could say it
Markus Kiili
@Masd925
Apr 29 2017 06:34
@brittanyrutherford That is the way you should do it (add methods to the prototype).
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:34
@Masd925 why?
what could happen if i do: this.play = function(){} ..
Markus Kiili
@Masd925
Apr 29 2017 06:35
@brittanyrutherford No reason to have a copy of the method on all objects. Better to have one method accessed through the prototype chain.
samiirshad
@samiirshad
Apr 29 2017 06:35

```
function chunkArrayInGroups(arr, size) {
// Break it up.
var str = arr.join('');
//arr.length =0;
var finalArray = [];

var start, end, temp;
var inArray = [];
for(var i=0; i<size; i++)
{
start = isize; end = (isize)+size;
temp = str.slice(start,end);
inArray.length=0;
for(var j=0; j<size; j++)
{
inArray.push(temp.slice(j,j+1));
}
finalArray.push(inArray);
console.log(inArray);
}

console.log(finalArray);

return arr;
}

Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:35
@Masd925 but if you add the method to the prototype, it's now available on all objects as well ..
Markus Kiili
@Masd925
Apr 29 2017 06:36
@brittanyrutherford Yes, but no reason to make many copies of the method.
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:36
you will copy the method with the objects when you add it to the prototype
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:36
@brittanyrutherford OOP in JS is objects linking to each other by using [[prototype]] which points to the "class" prototype object
samiirshad
@samiirshad
Apr 29 2017 06:36


function chunkArrayInGroups(arr, size) {
  // Break it up.
  var str = arr.join('');
  //arr.length =0;
  var finalArray = [];

  var start, end, temp;
  var inArray = [];
  for(var i=0; i<size; i++)
  {     
      start = i*size; end = (i*size)+size;
      temp = str.slice(start,end);            
      inArray.length=0;
      for(var j=0; j<size; j++)
      {
          inArray.push(temp.slice(j,j+1));
      }
      finalArray.push(inArray); 
      console.log(inArray);
  }

console.log(finalArray);

  return arr;
}
cotolany
@cotolany
Apr 29 2017 06:37
@Masd925 is prototype function like static functions in Java?
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:37
if you know beforehand than you need this method, what difference will it make?
samiirshad
@samiirshad
Apr 29 2017 06:37
please help me
jinshen
@jinshenyongzai
Apr 29 2017 06:37
what's the mean?
Markus Kiili
@Masd925
Apr 29 2017 06:37
@brittanyrutherford No. There will be only one method on the prototype and it is used along the prototype chain.
samiirshad
@samiirshad
Apr 29 2017 06:37
i can not push arrays in final array
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:37
@cotolany OOP in Java and JS are not same concept
cotolany
@cotolany
Apr 29 2017 06:37
@samiirshad code
samiirshad
@samiirshad
Apr 29 2017 06:37

function chunkArrayInGroups(arr, size) {
  // Break it up.
  var str = arr.join('');
  //arr.length =0;
  var finalArray = [];

  var start, end, temp;
  var inArray = [];
  for(var i=0; i<size; i++)
  {     
      start = i*size; end = (i*size)+size;
      temp = str.slice(start,end);            
      inArray.length=0;
      for(var j=0; j<size; j++)
      {
          inArray.push(temp.slice(j,j+1));
      }
      finalArray.push(inArray); 
      console.log(inArray);
  }

console.log(finalArray);

  return arr;
}
cotolany
@cotolany
Apr 29 2017 06:38
@Lumexralph see
@Lumexralph just looking for analogs
Markus Kiili
@Masd925
Apr 29 2017 06:38
@brittanyrutherford If the method is defined on the constructor, a copy of the method is assigned to all the objects.
samiirshad
@samiirshad
Apr 29 2017 06:38
@cotolany challenge number 210
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:38
@samiirshad why using 2 for loops?
cotolany
@cotolany
Apr 29 2017 06:38
@samiirshad return finallarray
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:38
@Masd925 this will happen too with prototype.play = function
samiirshad
@samiirshad
Apr 29 2017 06:39
first loop decides how many sub arrays and second loop create the sub array with required elements
problem is with finalArray.push
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:39
@cotolany okay..... that's why it's best to understand JS when it comes to OOP as it's with JS, if you compare it with other languages like Java, Python.... it might not make big sense
samiirshad
@samiirshad
Apr 29 2017 06:39
it only contains the last sub array and not the first two arrays
Jor
@joreyesl
Apr 29 2017 06:39
@brittanyrutherford first the object will be checked to see if it has the property/function, if it doesnt then it looks up the prototype chain.
Markus Kiili
@Masd925
Apr 29 2017 06:39
@brittanyrutherford No. When you call myObj.play() it will look for the property, look at the prototype reference, and find the method on the prototype object.
a27-suryansh
@a27-suryansh
Apr 29 2017 06:40
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:40
@joreyesl ggm :smiling_imp:
cotolany
@cotolany
Apr 29 2017 06:40
@Lumexralph hmm
a27-suryansh
@a27-suryansh
Apr 29 2017 06:40
@Lumexralph but it is doing it on click
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:40
aha got you
rugano
@rugano
Apr 29 2017 06:41
Good morning campers
a27-suryansh
@a27-suryansh
Apr 29 2017 06:41
@Lumexralph how to automatically call this event when width is less any idea?
Jor
@joreyesl
Apr 29 2017 06:41
@Lumexralph senpai ggm :smiling_imp: :bow:
jinshen
@jinshenyongzai
Apr 29 2017 06:41

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

// Your code above this line
return result;
}

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

Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:41
so it's one instance of the method, hanging on the prototype
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:41
@joreyesl shifu
Jor
@joreyesl
Apr 29 2017 06:41
@brittanyrutherford yea you got it
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:42
@jinshenyongzai assign your string to result not += and separate them with spaces " "
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:42
what if I do: prototype.someproperty = 29
Markus Kiili
@Masd925
Apr 29 2017 06:42
@brittanyrutherford This is how the JS standard describes the difference between JS and class based languages In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, and structure, behaviour, and state are all inherited. That does not change with ES6 class sugar.
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:42
it's shared between all objects?
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:42
@a27-suryansh when width is less than what?
a27-suryansh
@a27-suryansh
Apr 29 2017 06:42
@Lumexralph when browser width is less than 1024 px
Jor
@joreyesl
Apr 29 2017 06:43
@brittanyrutherford then there will be 1 instance of that property on the proptotype object and yes it will be shared. In they need to be different then you would need to define it in the constructor.
jinshen
@jinshenyongzai
Apr 29 2017 06:43
thank you@ @Lumexralph
CamperBot
@camperbot
Apr 29 2017 06:43
jinshenyongzai sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1607 | @lumexralph |http://www.freecodecamp.com/lumexralph
Markus Kiili
@Masd925
Apr 29 2017 06:43
@brittanyrutherford Objects only share the same reference to the prototype.
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:43
@Masd925 but they said: "methods carried by objects" they didn't say prototypes
cotolany
@cotolany
Apr 29 2017 06:43
@samiirshad can you geve the lesson name ?
Jor
@joreyesl
Apr 29 2017 06:45
@brittanyrutherford a prototype is an object though
Markus Kiili
@Masd925
Apr 29 2017 06:46
@brittanyrutherford Prototypes are objects.
rugano
@rugano
Apr 29 2017 06:46
I am in the titleCase challenge.May someone help me interpret this statement://use brackets or charAt() to get the first letter and uppercase it,then use slice or another string method to get the rest of the word and concatenate it.//replace the word with its modified version
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:46
so why people say: you can do inheritance in javascript with prototypes
then that's not true
if you add something to prototype and it's "shared" not "copied" , then that's not inheritance
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:47
@a27-suryansh i already told you, responsive or not, if you want the callback to be fired when width is less than what you asked, you need to get the window object property clientWidth, innerWidth etc in your JS script play around with them and see where that leads you
a27-suryansh
@a27-suryansh
Apr 29 2017 06:47
ok
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:48
@rugano you can access characters in strings by using the index in in brackets str[0] or with charAt() method str.charAt(0)
Vivek
@vivekmittal7
Apr 29 2017 06:48
how does the expression /anyword/gi knows we are talking about a particular string or not
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:48
@vivekmittal7 it's regExp
@vivekmittal7 regular expression, you might think of reading up on that
lightarcade
@lightarcade
Apr 29 2017 06:49
Finally figured it out
Vivek
@vivekmittal7
Apr 29 2017 06:49
``
// Setup
var testString = "Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.";

// Example
var expressionToGetSoftware = /software/gi;
var softwareCount = testString.match(expressionToGetSoftware).length;


// Only change code below this line.

var expression = /and/gi;  // Change this Line

// Only change code above this line

// This code counts the matches of expression in testString
var andCount = testString.match(expression).length;
lightarcade
@lightarcade
Apr 29 2017 06:49

var count = 0;

function cc(card) {
// Only change code below this line
if (card > 1 && card < 7) {
count++;
}
else if (card >= 7 && card <= 9) {
count = count + 0;
}
else if ( card == 10||card == "J"||card == "Q"||card =="K"||card =="A") {
count--;
}
else {
return "Change Me";
}

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

// Only change code above this line
}

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

HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:49
so you can add the first letter converted to uppercase to a slice of the rest of the word @rugano
lightarcade
@lightarcade
Apr 29 2017 06:49
Thanks @NahuelOvejero and @revisualize for the help
CamperBot
@camperbot
Apr 29 2017 06:49
lightarcade sends brownie points to @nahuelovejero and @revisualize :sparkles: :thumbsup: :sparkles:
:cookie: 342 | @nahuelovejero |http://www.freecodecamp.com/nahuelovejero
:warning: lightarcade already gave revisualize points
Jor
@joreyesl
Apr 29 2017 06:49
@brittanyrutherford its prototypal inheritance
Vivek
@vivekmittal7
Apr 29 2017 06:50
in the above code how does the var 'expression know that we want to apply our formula to var 'testString'
Brittany Rutherford
@brittanyrutherford
Apr 29 2017 06:50
how is that?
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:52
@vivekmittal7 youre passing in the expression variable in as an argument for the match method
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:52
@joreyesl Prototype Inheritance :joy: .... i like an easier way for me..... Object Delegation
Vivek
@vivekmittal7
Apr 29 2017 06:52
ok so it doesnt do anything on its own, it has to be used in some other code to make use of it
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:53
@vivekmittal7 yes by itself its just holding a regular expression
rugano
@rugano
Apr 29 2017 06:53
@HeebieGeeBee thanks,how about the use of slice or another string method to get the rest of the word and concatenate it?
CamperBot
@camperbot
Apr 29 2017 06:53
rugano sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1490 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Vivek
@vivekmittal7
Apr 29 2017 06:53
thanks @HeebieGeeBee
CamperBot
@camperbot
Apr 29 2017 06:53
vivekmittal7 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1491 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Jor
@joreyesl
Apr 29 2017 06:53
@Lumexralph :laughing: yea thats pretty much what it is. But we still have to use the fancy words :p
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:53
you can fore go the variable and just directly write in a regular expression for the argument of the match method
@vivekmittal7
Vivek
@vivekmittal7
Apr 29 2017 06:54
ok can you tell me whats the diff between & and &&
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:54
@rugano str[0].toUpperCase() + str.slice(1)
@vivekmittal7 && is the logical AND operator used for general javascript in things like conditionals
rugano
@rugano
Apr 29 2017 06:57
@HeebieGeeBee awesome,how about //replace the word with its modified version?
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:57
& is just an ampersand i dont know if its an operator for anything
maybe someone else knows better
Jor
@joreyesl
Apr 29 2017 06:57
single & is the bitwise AND operator
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:57
@vivekmittal7 yeah
iamingh
@iamingh
Apr 29 2017 06:58
need help in this code below:
blob
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 06:58
@rugano str = str[0].toUpperCase() + str.slice(1) if thats what you mean
Ogundele Olumide
@Lumexralph
Apr 29 2017 06:59
@iamingh contacts[i],firstName
Vivek
@vivekmittal7
Apr 29 2017 06:59
// Setup
var testString = "There are 3 cats but 4 dogs.";

// Only change code below this line.

var expression = /\d+/g;  // Change this line

// Only change code above this line

// This code counts the matches of expression in testString
var digitCount = testString.match(expression).length;
why does the answer show 2 when there is only 1 'd' in the testString
Long Nguyen
@longnt80
Apr 29 2017 07:00
@vivekmittal7 i saw 2 digít
iamingh
@iamingh
Apr 29 2017 07:00
@Lumexralph hi O, i am trying to compare the value of array in the first variable passed and trying to compare the property in the second variable
Jor
@joreyesl
Apr 29 2017 07:00
@vivekmittal7 \d is meta-character for match digits,
Vivek
@vivekmittal7
Apr 29 2017 07:01
i didnt understand it, can you please explain me
rugano
@rugano
Apr 29 2017 07:01
@HeebieGeeBee thanks very much,i have known where i was messing.
CamperBot
@camperbot
Apr 29 2017 07:01
rugano sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:warning: rugano already gave heebiegeebee points
iamingh
@iamingh
Apr 29 2017 07:01
A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.
The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
If both are true, then return the "value" of that property.
If firstName does not correspond to any contacts then return "No such contact"
If prop does not correspond to any valid properties then return "No such property"
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:01
havent learned anything about bitwise
does it come up much?
Long Nguyen
@longnt80
Apr 29 2017 07:02
@vivekmittal7 you need to search Regular Expression and read up on it
Jor
@joreyesl
Apr 29 2017 07:02
@vivekmittal7 regex
Vivek
@vivekmittal7
Apr 29 2017 07:02
ok
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:02
after looking quickly looks like it might be needed to make a calculator without eval
but meh its too early for looking at these things
Ogundele Olumide
@Lumexralph
Apr 29 2017 07:03
@iamingh that's why I showed you, you need to do index the object before you can compare the firstName property with the firstName parameter
@HeebieGeeBee i'm making my Calculator without it
__SharifTarver__
@Sharifdesigns22
Apr 29 2017 07:04

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

 switch (1){
   case 'alpha':
     console.log ('alpha');
     break;
 }

  switch (2){
    case 'beta':
      console.log ('beta');
      break;
  }

  switch (3){
    case 'gamma':
      console.log ('gamma');
      break;
  }

  switch (4){
    case 'delta':
      console.log ('gamma');
      break;
  }
  // Only change code above this line  
  return answer;  
}

// Change this value to test
caseInSwitch(1);
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:04
@Lumexralph sweet
Ogundele Olumide
@Lumexralph
Apr 29 2017 07:04
@Sharifdesigns22 switch statement and cases
__SharifTarver__
@Sharifdesigns22
Apr 29 2017 07:04
whats wrong with my code? "Selecting from many options with Switch Statements"
Okay @Lumexralph
Ogundele Olumide
@Lumexralph
Apr 29 2017 07:05
@HeebieGeeBee but it might be a tough nut... i just have to deal with design itch
Jor
@joreyesl
Apr 29 2017 07:05
@Lumexralph but whats the fun if ppl can't inject code into your calculator? :laughing:
Ogundele Olumide
@Lumexralph
Apr 29 2017 07:06
@joreyesl i like the sound of that...... inject
__SharifTarver__
@Sharifdesigns22
Apr 29 2017 07:06
Thats invalid @Lumexralph
Ogundele Olumide
@Lumexralph
Apr 29 2017 07:06
@joreyesl my code is not sick, so doesn't need a code doctor
@Sharifdesigns22 take a look at this link to have more understanding of switch statement https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
Corey Lovett-Hendrey
@corza334
Apr 29 2017 07:07
Hey guys, I've made this terrible algorithm for the Prime Numbers challenge

function sumPrimes(num) {
  var newNum = 0;
  var prime = true;

  for(var x = 2; x <= num; x++)
  {
    prime = true;
    for(var i = 2; i <= x; i++)
      {
        for(var j = 2; j<= x; j++)
          {
            if(j*i == x)
              {
                 prime = false;
              }
             console.log(x + ' IS PRIME!');
          }
      }

      if(prime)
        newNum += x;
  }
  return newNum;
}

sumPrimes(11);
It works, but it is sooooooooooooo slowwwwwwww
Am I able to get a couple tips on how to approach it better
ignore that console log, I was supposed to delete that
Jor
@joreyesl
Apr 29 2017 07:09
@Lumexralph i agree, maybe the ppl that use eval will need a code doctor tho :/
__SharifTarver__
@Sharifdesigns22
Apr 29 2017 07:14

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 ('gamma');
      break;
  }
  // Only change code above this line  
  return answer;  
}

// Change this value to test
caseInSwitch(1);
@Lumexralph Like so? Thanks for the reference
CamperBot
@camperbot
Apr 29 2017 07:14
sharifdesigns22 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1608 | @lumexralph |http://www.freecodecamp.com/lumexralph
Joseph
@revisualize
Apr 29 2017 07:16
@Sharifdesigns22 You shouldn't be console.log()ing. You should be re-assigning the value to the variable answer
kickkick479
@kickkick479
Apr 29 2017 07:22
@corza334 I tried the challenge now. I can solve that with 2 for loop and one if statement.
Anyway, console.log seems to be heavy to perform.
Corey Lovett-Hendrey
@corza334
Apr 29 2017 07:23
@kickkick479 Thanks :) I'll take another look at it
CamperBot
@camperbot
Apr 29 2017 07:23
corza334 sends brownie points to @kickkick479 :sparkles: :thumbsup: :sparkles:
:cookie: 331 | @kickkick479 |http://www.freecodecamp.com/kickkick479
Vivek
@vivekmittal7
Apr 29 2017 07:24
do we have to learn javascript on mdn before doing it on freecodecamp
kickkick479
@kickkick479
Apr 29 2017 07:24
What I've done is,
  1. make a block to check if a number is prime or not.
  2. nest the block and iterate it for given number's times.
    NOTE: I used label syntax for exit inner loop and continue outside loop.
Aaron Bell
@awb715
Apr 29 2017 07:37
@JLuboff the node course is good but so I don't think it goes into fundamentals of node, its just about building projects
Aizaz Shahid
@aizazshahid
Apr 29 2017 07:40
@vivekmittal7 learn it by doing exercises, suppose if an exercise covers something that you don't know then go to MDN.
Rigel Leith
@Rigelleith
Apr 29 2017 07:40
myStr should have two correctly escaped backslash characters \ var myStr="FirstLine\n\SecondLine\r\ThirdLine"; What am I doin qwwrong
Aizaz Shahid
@aizazshahid
Apr 29 2017 07:40
@Rigelleith you also have to escape backslash \
Rigel Leith
@Rigelleith
Apr 29 2017 07:41
How? @forwebtech
Aizaz Shahid
@aizazshahid
Apr 29 2017 07:41
\\ actually this is a escape character also, so in order to print it, also needs backslash !
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:42
@Rigelleith needs to be \\\r
Jor
@joreyesl
Apr 29 2017 07:42
@Rigelleith you have to switch the \r and \\ around
Aizaz Shahid
@aizazshahid
Apr 29 2017 07:44
@Rigelleith you have the instruction about order of characters, so just print in that manner.
Rigel Leith
@Rigelleith
Apr 29 2017 07:44
@HeebieGeeBee thank you!!
CamperBot
@camperbot
Apr 29 2017 07:44
rigelleith sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1492 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:49
@forwebtech just to let you know when ppl dont put it in markup the chat will remove some backslashes
so in that challenge makes it look like they havent put enough backslashes even though they have
Joseph
@revisualize
Apr 29 2017 07:53

@Rigelleith
You have to assign 'FirstLine newline backslash SecondLine backslash carriage-return ThirdLine' to the variable myStr.
But, You have to replace the escape words with the proper escape sequences. (And per the instructions: remove all spaces.)
How do you escape a newline? With: \n
How do you escape a backslash? With: \\
How do you escape a carriage-return? With \r
So, you have break the problem down.
FirstLine newline backslash SecondLine backslash carriage-return ThirdLine
FirstLine \n backslash SecondLine backslash carriage-return ThirdLine
FirstLine \n \\ SecondLine backslash carriage-return ThirdLine
FirstLine \n \\ SecondLine \\ carriage-return ThirdLine
FirstLine \n \\ SecondLine \\ \r ThirdLine
You have to follow the instructions and remove all of the spaces
Then assign that to myStr as a string.

This lesson is not trying to teach you how to get some green check marks to pass onto the next lesson. It is trying to teach you a really valuable skill. If you have a string in JavaScript that is instantiated with double quotes (") (Example: var myStr = "Hello World";) you can also instantiate a string with single quotes (') (Example: var myStr = 'Hello World';)

How do you add a " to that string? Let's say you instantiated the string with double quotes and you want to put in a quote that someone said. You have to use an escape character.
Example: var myQuote = "Happy Feet said, \"I really like the rhythm.\"";
Or what happens if you want to add a tab to your string? You can't really add 3 spaces and expect it to show up as a tab. You have to use the escape character for a tab (\t).

OR let's say your trying to output a bunch of text and paragraphs within your JavaScript string. You can't really just make a bunch of variables.
var myParagraph1 = "a bunch of characters";
var myParagraph2 = "a bunch more characters";
I mean you could... but, why not just:
var myStr = "A bunch of characters/sentences.\nThe second paragraph of characters and sentences.";

HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:53
@revisualize hi.
Joseph
@revisualize
Apr 29 2017 07:54
@HeebieGeeBee Hello.
I need to get my ass back to bed.
about @revisualize
CamperBot
@camperbot
Apr 29 2017 07:54
:star2: 3850 | @revisualize |http://www.freecodecamp.com/revisualize
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:54
sleep well
@revisualize ty
CamperBot
@camperbot
Apr 29 2017 07:54
heebiegeebee sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3851 | @revisualize |http://www.freecodecamp.com/revisualize
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:55
ruined your nice even number ;P
Joseph
@revisualize
Apr 29 2017 07:55
@HeebieGeeBee Thank you.
CamperBot
@camperbot
Apr 29 2017 07:55
:star2: 1493 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
revisualize sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
Joseph
@revisualize
Apr 29 2017 07:55
@HeebieGeeBee I'm actually going sailboat racing today. I'll be on a boat for 30 hours. So, I got up to try and get a brownie point to not lose my streak.
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 07:56
@revisualize sweet have fun
Faisal Rusheidat
@lostandfound24
Apr 29 2017 07:57
Hi guys, I'm stuck on the profile lookup section and I need help.
function lookUpProfile(firstName, prop){
// Only change code below this line
if (contacts[i].firstName[i] && prop){
  return contacts[i].firstName[i] && contacts[i].prop[i];
} else if (firstName===false){
  return "No such contact";
} else {return "No such property";}
Joseph
@revisualize
Apr 29 2017 07:58
@lostandfound24 You have several issues.
@lostandfound24 else if (firstName===false) this will never be true.
@lostandfound24 contacts[i].firstName[i] the firstName property in the array element object is not an array. It's a string.
@lostandfound24 You're not looping through the array elements of contacts
@lostandfound24 i doesn't actually have anything associated to it.

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

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

@lostandfound24 I'm off to bed. Good luck.
Faisal Rusheidat
@lostandfound24
Apr 29 2017 08:00
@revisualize Thanks
CamperBot
@camperbot
Apr 29 2017 08:00
lostandfound24 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3853 | @revisualize |http://www.freecodecamp.com/revisualize
rugano
@rugano
Apr 29 2017 08:02
Hey campers,what could be wrong with my code?
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 08:04
@rugano its invisible?
rugano
@rugano
Apr 29 2017 08:09
function titleCase(str) {
var tCaseStr = str.toLowerCase(' ').split(' ');

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

if(str == str[0].toUpperCase() + str.slice(1)){
str = str[0].toUpperCase() + str.slice(1);
}
return str;
}

titleCase("I'm a little tea pot");
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 08:10
@rugano you need to loop through each word
and change them
str = str[0].toUpperCase() + str.slice(1); when i showed you this earlier i didnt mean this is all you had to do in the challenge
rugano
@rugano
Apr 29 2017 08:12
@HeebieGeeBee ok,but when i use a for loop,i get an error,may you show me how to loop correctly,
HeebieGeeBee
@HeebieGeeBee
Apr 29 2017 08:13
@rugano lol im gonna end up just showing you the solution
you try and and do a loop and then post what you try
@rugano i will say that you should use your tCaseStr variable to base it around though
@rugano you could also use a map instead of a loop too
Yahia
@y-zaky
Apr 29 2017 08:18
hey guys hope your all well!
i have a question
for the bonfire:meet bonfire question
how do we even start?
i don't understand the question... and can't seem to edit anything
i just see 4 images
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:23
@bowssy88 ? what's that
Yahia
@y-zaky
Apr 29 2017 08:25
@forwebtech hey dude ! how r u?
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:25
Fine, you ?
Yahia
@y-zaky
Apr 29 2017 08:25
all good!... just started the reverse a string challenge... will let you know how it goes
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:26
ok !
are you stuck ?
RuthCollins
@RuthCollins
Apr 29 2017 08:27
please I need help with card counting
Yahia
@y-zaky
Apr 29 2017 08:28
@forwebtech nope just started ! xD
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:28
@RuthCollins yes ! don't ask to ask !
Yahia
@y-zaky
Apr 29 2017 08:28
@RuthCollins show us your work so far
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:28
just post you problem !
RuthCollins
@RuthCollins
Apr 29 2017 08:29
var count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4: 
    case 5:
    case 6:
      count += 1;
      break;
    case 7:
    case 8:
    case 9:
      count = 0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count -=1;
      break;
    default:
      coount =NaN;
  }


  return "-1 Hold";
Faisal Rusheidat
@lostandfound24
Apr 29 2017 08:29
I'm stuck on this but I think I'm getting closer to solving this. Any help is appreciated

function lookUpProfile(firstName, prop){
// Only change code below this line
if (contacts.firstName && contacts[firstName]){
  return contacts.firstName && contacts[firstName];
} else if (contacts.firstName!==true){
  return "No such contact";
} else {return "No such property";}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "address");
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:30
@RuthCollins if your count is positive then, have to return count and bet either return count and hold !
@lostandfound24 you need a loop for that because you have more then one contacts!
Faisal Rusheidat
@lostandfound24
Apr 29 2017 08:31
While loop? @forwebtech
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:31
@lostandfound24 you can use any loop, but for is good here !
Faisal Rusheidat
@lostandfound24
Apr 29 2017 08:32
Ok I'll give it a try. Thank you @forwebtech
CamperBot
@camperbot
Apr 29 2017 08:32
lostandfound24 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 357 | @forwebtech |http://www.freecodecamp.com/forwebtech
RuthCollins
@RuthCollins
Apr 29 2017 08:32
@forwebtech I return hold but it didnt pass all the test cases
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:33
@RuthCollins you have two statements, but need to print only one, so for that you have to use conditional statement !
like: if ( count is positive ) return count + " bet"
else return count + " hold"
RuthCollins
@RuthCollins
Apr 29 2017 08:34
thanks
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:35
@RuthCollins and also in your switch remove that case where you did count=0, don't need for that !
just +ve / -ve needed !
rugano
@rugano
Apr 29 2017 08:45
function titleCase(str){
var tCaseStr = str.toLowerCase(' ').split(' ');
for(tCaseStr = str[0].toUpperCase() + str.slice(1)){
if(tCaseStr == str[0].toUpperCase() + str.slice(1)){
tCaseStr = str[0].toUpperCase() + str.slice(1);
}
}
return tCaseStr;
}
titleCase("I'm a little tea pot");
Faisal Rusheidat
@lostandfound24
Apr 29 2017 08:45
@forwebtech I tried for loop, can't figure out what's wrong with the code.

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

  if (contacts.firstName && contacts[firstName]){

    return contacts.firstName & contacts[firstName];

  } else if (contacts.firstName!==true) {

    return "No such contact";

  } else {return "No such property";}
}
}
rugano
@rugano
Apr 29 2017 08:46
am getting many errors
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:46
@rugano what type of error ?
@lostandfound24 visit For Loop
rugano
@rugano
Apr 29 2017 08:47
@forwebtech it says i should not use a function inside a loop
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:48
paste your code !
@rugano ?
may be calling your function inside switch.
rugano
@rugano
Apr 29 2017 08:50
@forwebtech i posted at 11:45 East African Time
@forwebtech up alittle there
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:51
got it !
rugano
@rugano
Apr 29 2017 08:51
@forwebtech ok
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:51
function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4: 
    case 5:
    case 6:
      count++;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
  }
  if(count > 0){
        return  count + " bet";
} else {
        return  count + " hold";
}
}
you just need that !
@rugano
Mohammedabuqass
@Mohammedabuqass
Apr 29 2017 08:54
Remove all the backslashes ()
You should have two single quotes ' and four double quotes "
Only remove the backslashes \ used to escape quotes.
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:55
@Mohammedabuqass you should to quote your string into single quotes, like mystr = ' ..... '
and after that also remove \ backslashes !
Mohammedabuqass
@Mohammedabuqass
Apr 29 2017 08:55
How
@forwebtech
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:56
@Mohammedabuqass just delete them !
myStr = ' <a href=" ksdjflkdsjf " > ';
@Mohammedabuqass when you use same quotes inside of a string, (which are using for quoting) then you have to escape them, and if they are differ from each other then you don't need to escape it,
var str1 = "  some \"text\" ";
var str2 = 'some "text"';
Faisal Rusheidat
@lostandfound24
Apr 29 2017 08:58
What am I missing here?
function lookUpProfile(firstName, prop){
// Only change code below this line
for (contacts; [contacts.firstName && contacts[firstName]];) {return contacts.firstName && contacts[firstName];}

  if (contacts.firstName!==true){

    return "No such contact";

  } else {return "No such property";}

  }
Aizaz Shahid
@aizazshahid
Apr 29 2017 08:59
@lostandfound24 your for loop syntax is wrong, did you visit that sit e??
that is correct one:
for (var i = 0; i < 9; i++) {
   console.log(i);
   // more statements
}
@lostandfound24 further reading For Loop
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:00
I'm confused, i has nothing associated with it.
rugano
@rugano
Apr 29 2017 09:00
@forwebtech i am trying to remove some of curly braces ,but,not passing
Vivek
@vivekmittal7
Apr 29 2017 09:01
@lostandfound24 search the exercise name on google,first result will be of github, there you will get the full answer and an awesome explanation
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:01
@rugano try to copy your code and then reset your code and try !
@lostandfound24 first you have to learn how loops work, then try to do that exercise and also learn how to access object properties
rugano
@rugano
Apr 29 2017 09:02
@forwebtech ok
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:03
What am I substituting i for here?
I'm reading further on loops @forwebtech
RuthCollins
@RuthCollins
Apr 29 2017 09:04
@forwebtech thank you very much
CamperBot
@camperbot
Apr 29 2017 09:04
ruthcollins sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 358 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:04
@lostandfound24 we use i for counting number of iteration !
@RuthCollins You're welcome !
RuthCollins
@RuthCollins
Apr 29 2017 09:05
@Streeter220 yeah I did
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:05
Yes, but instead of just i should I not show it as contacts.firstName?
@forwebtech
Yes, but instead of just i should I not show it as contacts.firstName?
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:06
@lostandfound24 because contacts have more than one contacts !
and to get properties from contacts, index will use: contacts[i].firstName
Mohammedabuqass
@Mohammedabuqass
Apr 29 2017 09:08
@forwebtech
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:08
contacts[i].firstName is initializer?
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:09

@lostandfound24 just do that, and check your console you will get it, hopefully:

```
for ( i = 0 ;i < contacts.length; i++ ) {
console.log( contacts[i].firstName );
}

@lostandfound24 no its not initializer !
@Mohammedabuqass yes ?
look at that :smile:
for ([initialization]; [condition]; [final-expression])
   statement
that is called initialization:
var a = 10;,
when we assign something to any variable that process is called initialization !
and as it is we do in our for loop: for ( var i = 0; ....
so our loop number starts from 0 zero, and it will stop until the provided condition will not becomes false.
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:12
ok
my for loop so far

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

  if(contacts.firstName && contacts[firstName]){

    return contacts.firstName && contacts[firstName];

  } else if (contacts.firstName!==true){

    return "No such contact";

  } else {return "No such property";}

}}
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:13
@lostandfound24 but to access contacts property you have to use contacts[i]
because it is a array which contains some objects !
rugano
@rugano
Apr 29 2017 09:14
@forwebtech when i run the code,i get syntax error:unexpected token )
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:14
@rugano so where it pointed ?
r2d2
@UsamaHameed
Apr 29 2017 09:14
Anyone familiar with babel.js?
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:15
@forwebtech Got it.
I'm using contacts[i] now, but can't seem to solve it.
rugano
@rugano
Apr 29 2017 09:16
@forwebtech i didn't see the point
Vivek
@vivekmittal7
Apr 29 2017 09:16
```
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:16
@rugano paste your code again !
rugano
@rugano
Apr 29 2017 09:17
@forwebtech ok
Vivek
@vivekmittal7
Apr 29 2017 09:17
var myCar = new Object();
myCar.make = 'Ford';
myCar.model = 'Mustang';
myCar.year = 1969;
i understood most of it but what is the use of new Object() here
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:17
@lostandfound24 correct your for statement :smile:
for (i=0; i < contacts.length; i++){

@vivekmittal7 to make an object ! but if you do like that:

var myCar = {
   make = 'ford',
....
}

so it is same as new

Vivek
@vivekmittal7
Apr 29 2017 09:20
so basically 'new' is an inbuilt function that notifies computer that following thing would be an object
@forwebtech
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:20
Done! Still missing something
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:20
@vivekmittal7 well it's a reserved keyword ! obviously behind it some methods works !
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:20
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i=0; i < contacts.length; i++) {

  if(contacts[i].firstName && contacts[i][firstName]){

    return contacts[i].firstName && contacts[i][firstName];

  } else if (contacts[i].firstName!==true){

    return "No such contact";

  } else {return "No such property";}

}}
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:21

@lostandfound24
https://gist.github.com/forwebtech/1f65fafb8570903b1de8e105fff4061f

see that for further instructions !

Vivek
@vivekmittal7
Apr 29 2017 09:21
@forwebtech thanks. one last thing whats the use of object here, do we have to write it every time we make a new object
CamperBot
@camperbot
Apr 29 2017 09:21
vivekmittal7 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 359 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:24
@vivekmittal7 well objects are used to define structure of variables and methods that we have to use with single call:
var employee = {
    name,
    salary,
}

employee.name = "... Name";
but if you want that same structure or object for more than once then you have to make a template like:
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:25
Thank you @forwebtech
CamperBot
@camperbot
Apr 29 2017 09:25
lostandfound24 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:warning: lostandfound24 already gave forwebtech points
rugano
@rugano
Apr 29 2017 09:25
function titleCase(str) {
var tCaseStr = str.toLowerCase(' ').split(' ');

for(tCaseStr = str[0].toUpperCase() + str.slice(1)) {
if(tCaseStr == str[0].toUpperCase() + str.slice(1)) {
tCaseStr = str[0].toUpperCase() + str.slice(1);
}
}
return tCaseStr;
}
titleCase("I'm a little tea pot");
@forwebtech there it is
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:27
@vivekmittal7
function Person(first, last, age, eye) {
    this.firstName = first;
    this.lastName = last;
    this.age = age;
    this.eyeColor = eye;
}

var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");
and new keyword is not recommended, the better way is that
var obj = { ... };
@rugano visit that For Loop
@vivekmittal7 but when you are using defined prototypes like i mentioned then you have to use new keyword !
Vivek
@vivekmittal7
Apr 29 2017 09:30
thanks @forwebtech
CamperBot
@camperbot
Apr 29 2017 09:30
vivekmittal7 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:warning: vivekmittal7 already gave forwebtech points
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:30
@lostandfound24 @vivekmittal7 You're welcome !
Carlos Pulido
@carlosfrontend
Apr 29 2017 09:34
hi /@all
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:34
@carlosfrontend Welcome !
Carlos Pulido
@carlosfrontend
Apr 29 2017 09:34
hi @forwebtech
somebody can help me in Smallest Common Multiple challenge?
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:35
:sparkles:
LCM ?
Carlos Pulido
@carlosfrontend
Apr 29 2017 09:36
yes @forwebtech
function smallestCommons(arr) {
 var newArr = [];
 var factors = [];
 arr.sort(function(a,b){
 return a - b;
 });

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

 return newArr;
}


smallestCommons([5,1]);
i don't know to obtain multiples for nums from A to B
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:38
@carlosfrontend well i didn't do that challenge but i know atleast from maths :D
Carlos Pulido
@carlosfrontend
Apr 29 2017 09:38
good @forwebtech
i find the minimum number that mod for primes numbers from 1, 2,3,4,5 for example give me 0 @forwebtech
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:41
you could start multiplying the smallest number from 1 to ... and by that every time you get answer like:
1 x 2 =  2   =>     5  % 2  == 0   then that is the lcm
:D i think am wrong !
suppose we have (3 and 5 )
Carlos Pulido
@carlosfrontend
Apr 29 2017 09:43
not we have 1,2,3,4,5 because they are paremeters primes between two parameters
is the problem
@forwebtech
Aizaz Shahid
@aizazshahid
Apr 29 2017 09:43
// starting x 3  from 1
3 * 1 = 3             =>      5 %  3 == 0    // false
3 * 2 = 6             =>      5 %  6 == 0    // false
3 * 3 = 9             =>      5 %  9 == 0    // false
3 * 4 = 12          =>      5 %  12 == 0    // false
3 * 5 = 15           =>     5 %  15 == 0    // true
Faisal Rusheidat
@lostandfound24
Apr 29 2017 09:44
I know it's ridiculous, but I'm still missing something.
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i=0; i < contacts.length; i++) {

  if(contacts[i].firstName===true){

    if (contacts[i][firstName]===true) {

      return contacts[i][firstName];

    } else {return "No such property";}
  }
  }

 {return "No such contact";}

}