These are chat archives for FreeCodeCamp/HelpJavaScript

3rd
Aug 2017
Bryan Reese
@breese8009
Aug 03 2017 00:06
who can tell me why its only giving the html for the last element of array of data?? I want it to spit out all the days ... https://github.com/breese8009/weatherApp
eeflores
@eeflores
Aug 03 2017 00:07
assignment to innerHtml instead of append
nah that's not it
was shooting from the hip on that one
insouciantone
@insouciantone
Aug 03 2017 00:28
Hey all, I have a syntax question. When is it required to use ";" to end a statement and when is it not?
Ken Haduch
@khaduch
Aug 03 2017 00:32
@insouciantone - you use it for most statements - just thinking about it for general things, anything that doesn't end with } except when you are initializing an object variable? Is that a reasonable rule of thumb? In CodePen, in the JS panel, there is an "Analyze JS" that will give you places where they are required and when they are not.
@breese8009 - you are repeatedly calling createHTML for each piece of data in the returned JSON. But it is always writing the information to the same DOM elements, so the only one that will show up at the end will be the last one. You would have to append or create some other elements on the fly and add the information to have them all show up.
insouciantone
@insouciantone
Aug 03 2017 01:01
@khaduch Yeah you can use it for most statements but you don't have to. I'm running through the backend challenges on freecode camp and I've written numerous apps where I didn't use one ; and everything works as expected.
I don't understand its usage.
Ken Haduch
@khaduch
Aug 03 2017 01:10
@insouciantone - you can find many articles and blog posts about this. It seems to be a topic along the lines of religion and politics. Just one article selected at random, and you have to just get into the comments to see the opinions pro and con: http://benalman.com/news/2013/01/advice-javascript-semicolon-haters/
Ginger
@GingerChew
Aug 03 2017 01:19
Can anybody help me figure out why my jquery isn't working?
Joseph
@revisualize
Aug 03 2017 01:22
@GingerChew Did you look at your browser console?
@GingerChew You need to also look at Darksky's TOS for the API
image.png
Ginger
@GingerChew
Aug 03 2017 01:26
Okay, so I saw that, but does that mean I can't use darksky api in codepen?
Joseph
@revisualize
Aug 03 2017 01:27
@GingerChew @GingerChew No

@GingerChew

      var api = "https://api.darksky.net/forecast/";
      var key = "558ba6f6a809f5387acecbc6f3645294/";

then later you do ... api + key

@GingerChew Try that?
Ginger
@GingerChew
Aug 03 2017 01:33
Okay so I implemented that, and it is still giving me the same error
maybe I'm calling the JSON wrong?
new link
Joseph
@revisualize
Aug 03 2017 01:35
Then I don't know.
Ginger
@GingerChew
Aug 03 2017 01:36
could it be that dark sky doesn't work inside of codepen?
Joseph
@revisualize
Aug 03 2017 01:36
It does work. People have used it.
It's just a pain.
Ken Haduch
@khaduch
Aug 03 2017 01:36

@GingerChew - you have to post "Powered by DarkSky" or somesuch on your page - that is one thing.

you also need to make a slight modification for your code, once you get the data to come back, and you need to use JSONP to overcome the "No 'Access-Control-Allow-Origin'" error. Add this to the end of your URL: ?callback=? append that substring. Then you need to make a code change for the data where you are using it. Basically, you have to reference things in the data object, and you have an error, missing the # in your #minutely selector:

      $("#temp").html(data.currently.temperature + "° F");
      $("#minutely").html(data.minutely.summary);
Ginger
@GingerChew
Aug 03 2017 01:38
@khaduch I just threw my hands up in the air and almost screamed
that did it
@khaduch Thanks so much!
CamperBot
@camperbot
Aug 03 2017 01:39
gingerchew sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3159 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Aug 03 2017 01:44
@GingerChew - you're welcome. I probably shouldn't have given all of the answers so quickly, but had you think about the individual problems and see the bad references to the data object - it would have been a good learning experience. But since anyone around you might have wondered what the screaming was about, I'm glad I did... ;) Good luck with the rest of the project!
@GingerChew - this: $('#location').innerhtml should just be $('#location').html( your_code_here, unless you've changed it and didn't save.
Ginger
@GingerChew
Aug 03 2017 01:49
Yeah I fixed that one on my own, so happy to see new error codes
I honestly have been working on that problem for a week
Ken Haduch
@khaduch
Aug 03 2017 01:50
@GingerChew - then you've probably learned a lot! Now I hope you make good forward progress on it. There's a lot to learn!
Greg Duncan
@GregatGit
Aug 03 2017 01:54
@GingerChew @khaduch sometimes you just need someone to give you the answer
Ken Haduch
@khaduch
Aug 03 2017 01:56
@GregatGit :+1: hard to know when that is, under all situations...
caneno
@caneno
Aug 03 2017 01:59
doe anyone know how to pass spaces in a string when converting them into ASCII code?
Ginger
@GingerChew
Aug 03 2017 01:59
@GregatGit very true!
Greg Duncan
@GregatGit
Aug 03 2017 02:04
@GingerChew data.minutely.summary there is no minutely
try currently
instead of minutely
Ginger
@GingerChew
Aug 03 2017 02:04
There is a minutely though? I'm confused by what you mean @GregatGit https://darksky.net/dev/docs/forecast I'm basing it off of this
caneno
@caneno
Aug 03 2017 02:05
function rot13(str) { // LBH QVQ VG!
    var str1 = "";
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) >= 78) {
            str1 += String.fromCharCode(str.charCodeAt(i) - 13);
        } else if (str.charCodeAt(i) < 78) {
            str1 += String.fromCharCode(str.charCodeAt(i) + 13);
        }

    }
    return str1;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
can you guys help me
Greg Duncan
@GregatGit
Aug 03 2017 02:06
@GingerChew no there isn't - put this line at 25 and you can see your data objece console.log(data);
Ginger
@GingerChew
Aug 03 2017 02:06
@GregatGit I just had it working with the minutely though? Thats where I'm confused
Greg Duncan
@GregatGit
Aug 03 2017 02:07
data.JPG
@GingerChew you need to look at the data object your bringing down
Ginger
@GingerChew
Aug 03 2017 02:09
okay, so even though it is listed in the docs, the actual data itself doesn't list it? is that what you're trying to say?
Greg Duncan
@GregatGit
Aug 03 2017 02:09
are you using chrome?
and do you have the console open
Ken Haduch
@khaduch
Aug 03 2017 02:10
@GingerChew "minutely" was definitely there before - I referenced it in this post :point_up: August 2, 2017 9:36 PM and saw that it worked.
Greg Duncan
@GregatGit
Aug 03 2017 02:11
@GingerChew @khaduch its gone
Ginger
@GingerChew
Aug 03 2017 02:11
I changed it now
but it definitely was working even if it wasn't present in the data object
Greg Duncan
@GregatGit
Aug 03 2017 02:11
@GingerChew that's why you have to look at the object when you get an undefined error like that
korzo
@korzo
Aug 03 2017 02:11
@caneno Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
caneno
@caneno
Aug 03 2017 02:13
ok Itryi that
Ken Haduch
@khaduch
Aug 03 2017 02:13
@GingerChew @GregatGit - it is mentioned on this page but listed as "optional"... not clear what the options are?
Ruchika Sharma
@ruchika90
Aug 03 2017 02:14
@Manish-Giri ty! I cleared the challenge
CamperBot
@camperbot
Aug 03 2017 02:14
ruchika90 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6350 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ken Haduch
@khaduch
Aug 03 2017 02:14

and on this page it shows it, and mentions "minutely" is there "when available"? @GregatGit @GingerChew ...

A Forecast Request returns the current weather conditions, a minute-by-minute forecast for the next hour (where available), an hour-by-hour forecast for the next 48 hours, and a day-by-day forecast for the next week.

Greg Duncan
@GregatGit
Aug 03 2017 02:15
@GingerChew function celsius() and .onClick(celcius()) two different spellings
@GingerChew you need to first check if it exits - then load it if it doesif(data.minutely.summary)
Ginger
@GingerChew
Aug 03 2017 02:18
ah screw it, I'm just gonna use currently since its more concise
John
@AnonymousLords
Aug 03 2017 02:19
Still not sure on why this wont work

function largestOfFour(arr) {
 var largest = 0;

for (var i =0; i < arr.length; i++) {
 for (var j = 0; j < arr[i].length; j++) { 
  if (arr[i][j] > largest) {
    largest = arr[i][j]
    if (arr[i][j] < largest) {
      arr[i] = arr[i][j]
      largest = arr[i];
    }
  }
}
}
  return largest;
}

 largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
https://www.freecodecamp.org/challenges/return-largest-numbers-in-arrays
Ken Haduch
@khaduch
Aug 03 2017 02:24
@AnonymousLords - you are trying to get the largest value from each of the sub-arrays into the array largest? So you should end up with an array of values. This means that you have to collect the largest value within each sub-array, and then maybe use .push() to add it to the array that you are going to return? It doesn't look like you are doing that. And this line arr[i] = arr[i][j] is going to clobber arr[i] - so there seems to be a few things going wrong here.
John
@AnonymousLords
Aug 03 2017 02:26
@khaduch .push was giving me errors and stuff.
No matter what i did with .push it was either invalid or undefined
largest.push(j); is not a function?
Ken Haduch
@khaduch
Aug 03 2017 02:29

@AnonymousLords - you need to have a couple things going - the inner loop, where you are using arr[i][j] accesses the individual elements of a sub-array. Within that loop, you can determine the largest value of a sub-array. After you find it, you should do this: largest.push(innerLargestValue); and then you will move on to the next sub-array. The other thing is that within your inner loop, you have to have a variable innerLargestValue that you will initialize and then use that to track the largest value in the sub-array.

You should initialize largest as var largest = []; to make it start as an empty array, then .push() will work.

John
@AnonymousLords
Aug 03 2017 02:33

  if (arr[i][j] > largest) {
    largest.push(j);
@khaduch
Joseph
@revisualize
Aug 03 2017 02:33
@AnonymousLords How can you compare a number to an array?
John
@AnonymousLords
Aug 03 2017 02:34
using index
Joseph
@revisualize
Aug 03 2017 02:34
@AnonymousLords Your code above almost works.
John
@AnonymousLords
Aug 03 2017 02:34
:point_up: August 2, 2017 10:33 PMthis?
Joseph
@revisualize
Aug 03 2017 02:34
John
@AnonymousLords
Aug 03 2017 02:35
How off am i?
Joseph
@revisualize
Aug 03 2017 02:35
You need to return arr
not a number
you need to move the var largest = 0 inside of the first for loop
John
@AnonymousLords
Aug 03 2017 02:36
So no i?
Joseph
@revisualize
Aug 03 2017 02:36
This: largest = arr[i]; should be i & j
John
@AnonymousLords
Aug 03 2017 02:36
for (var i =0; i < arr.length; i++) {
  var largest = 0
 for (var j = 0; j < arr[i].length; j++) { 
  if (arr[i][j] > largest) {
    largest = arr[i][j]
    if (arr[i][j] < largest) {
      arr[i] = arr[i][j]
      largest = arr[i][j];
Joseph
@revisualize
Aug 03 2017 02:36
@AnonymousLords Wow. WTH are you doing?
for (var i =0; i < arr.length; i++) {
  var largest = 0
 for (var j = 0; j < arr[i].length; j++) { 
  if (arr[i][j] > largest) {
    largest = arr[i][j];
   }
  }
   arr[i] = largest;
}
John
@AnonymousLords
Aug 03 2017 02:38
It was making largest the biggest number in that array. Only issue is that it didnt create a array .-.
Any only outputs one number
Joseph
@revisualize
Aug 03 2017 02:39
?
John
@AnonymousLords
Aug 03 2017 02:40
It would output 1001, the biggest number across all arrays
That was my issue
Joseph
@revisualize
Aug 03 2017 02:40
Because you are returning a number not arr
John
@AnonymousLords
Aug 03 2017 02:40
Okay
Ill return a array of number
Joseph
@revisualize
Aug 03 2017 02:41
@AnonymousLords You were also overwriting an arr[i] way too early.
John
@AnonymousLords
Aug 03 2017 02:41
Okay
caneno
@caneno
Aug 03 2017 02:42
sorry I cant figure out :(
function rot13(str) { // LBH QVQ VG!
    var str1 = "";
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) >= 78) {
            str1 += String.fromCharCode(str.charCodeAt(i) - 13);
        } else if (str.charCodeAt(i) < 78) {
            str1 += String.fromCharCode(str.charCodeAt(i) + 13);
        }

    }
    return str1;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Joseph
@revisualize
Aug 03 2017 02:43
@caneno what happens to spaces?
caneno
@caneno
Aug 03 2017 02:43
they disapear
Joseph
@revisualize
Aug 03 2017 02:43
That's bad
caneno
@caneno
Aug 03 2017 02:43
I know
Joseph
@revisualize
Aug 03 2017 02:43
Maybe add additional conditions
*hint*
@caneno like an or
to each condition.
caneno
@caneno
Aug 03 2017 02:45
yes I was thinking that but I don know how to put for space an punctuations
Joseph
@revisualize
Aug 03 2017 02:45
What is the character code for A?
caneno
@caneno
Aug 03 2017 02:45
65
Joseph
@revisualize
Aug 03 2017 02:45
What is the character code for Z?
caneno
@caneno
Aug 03 2017 02:45
im gonna say 90
Joseph
@revisualize
Aug 03 2017 02:45
@caneno Do you want to modify characters outside of that range?
caneno
@caneno
Aug 03 2017 02:46
aahh
men where were you these couple of days, you always make me think in the right directions
Joseph
@revisualize
Aug 03 2017 02:46
I've written that challenge two different ways/
caneno
@caneno
Aug 03 2017 02:47
nice
ok so write the range in the existing if statement ?
Joseph
@revisualize
Aug 03 2017 02:48
@caneno I would.
I did.
caneno
@caneno
Aug 03 2017 02:49
ok let me see what I can figure out
Joseph
@revisualize
Aug 03 2017 02:49
&& str... 90
&& str ... 65
Maximino V. Jardin III
@ma5one1
Aug 03 2017 02:50
trouble once again. HALP! - Confirm Ending -
function confirmEnding(str, target) {
for (var i=0; i<str.length; i++){
if (i<7){
return str + target.substr(6);
}
else {
return 'wrong';
}
}
return (str, target);
}
Joseph
@revisualize
Aug 03 2017 02:50
@caneno you need an else to just += the character without changing it.
John
@AnonymousLords
Aug 03 2017 02:53
@revisualize im honestly stuck on this one
Joseph
@revisualize
Aug 03 2017 02:53
@AnonymousLords What's your code?
John
@AnonymousLords
Aug 03 2017 02:53
It was what i first showed you, but i kinda have started over
Joseph
@revisualize
Aug 03 2017 02:54
@AnonymousLords Show me. Current code?
John
@AnonymousLords
Aug 03 2017 02:54
function largestOfFour(arr) {

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

    if () {




    } // if 
  } // j
} // i 
return largest;
} // function
Nothing yet
Ken Haduch
@khaduch
Aug 03 2017 02:54
@AnonymousLords - where are you at with this problem now? What you need to do:
  • at the top of your function, declare and initialize an array, maybe like var largestArray = [];
  • within your for loop that is using for( var i = 0; i < arr.length; i++) - declare another variable var largest = 0; (although initializing it to 0 is not necessarily the best thing, it depends on the values that are contained in the sub-arrays. If none of them is larger than "0", then you'll get the wrong answer. But I think it will work for the sets of numbers that are there.)
  • within your inner for loop, find the largest number by doing what you are doing, comparing each arr[i][j] to the variable largest and storing the results appropriately.
  • after you exit the inner for loop, do largestArray.push(largest)
  • at the end, return largestArray;
    you can also select your own variable names.
Joseph
@revisualize
Aug 03 2017 02:54
I gave the answer.
Maximino V. Jardin III
@ma5one1
Aug 03 2017 02:55
@AnonymousLords how did paste the actual code screen??
caneno
@caneno
Aug 03 2017 02:55
@revisualize so add anohter else after the else if
Ken Haduch
@khaduch
Aug 03 2017 02:56
@ma5one1 - use three backticks: ``` on a separate line at the top and bottom of your code block.
Maximino V. Jardin III
@ma5one1
Aug 03 2017 02:56
@khaduch thank you
CamperBot
@camperbot
Aug 03 2017 02:56
ma5one1 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3161 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Aug 03 2017 02:56
@ma5one1 - there is a blog post about it for further information: https://forum.freecodecamp.com/t/markdown-code-formatting/18391
Joseph
@revisualize
Aug 03 2017 02:56
function largestOfFour(arr) {

   var largest = [];
   var num = 0;
   for (var i = 0; i < arr.length; i++) {
     // here you need to reset num to 0 because if you hit 1000000000 and then your next arr is [2,4,1,5] .. You'll never reset below 1000000000 
     for (var j = 0; j < arr[i].length; j++) {
       if () {

       } // if 
     } // j
      // here you need to push the largest num to the largest array
   } // i 
   return largest;
} // function
John
@AnonymousLords
Aug 03 2017 02:59
@revisualize okay so num = 0?
Joseph
@revisualize
Aug 03 2017 02:59
sure.
Ken Haduch
@khaduch
Aug 03 2017 02:59
@ma5one1 - remember that you can edit your post for a few minutes after you make it, so if you don't get it right the first time, you can go to the ... menu at the top of your post and select "Edit".
John
@AnonymousLords
Aug 03 2017 03:02
@revisualize so now what
Joseph
@revisualize
Aug 03 2017 03:03
@AnonymousLords Do you have your comparison in the if?
John
@AnonymousLords
Aug 03 2017 03:04
@revisualize Would my original one work (teh idea)
Maximino V. Jardin III
@ma5one1
Aug 03 2017 03:04
@khaduch Do you have any thoughts for this challenge? I think i'm headed the right direction with this one. There is two approaches I tried but none seems to work.
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
   for (var i=0; i<str.length; i++){
     if (i<7){
       return str + target.substr(6);
       }
     else {
       return 'wrong';
     }
   }
  return (str, target);
}
//    for (var i=0; i<str.length; i++){
//      str.substr();

//    }
//     for( var j=0;j<str.length; j++){
//     target.substring();





confirmEnding("Bastian", "n");
Ken Haduch
@khaduch
Aug 03 2017 03:05
@ma5one1 - what is the goal of that challenge? I'm guessing that your hardcoded values of "7" and "6" aren't right? Or not the right thing to do...
John
@AnonymousLords
Aug 03 2017 03:06
// "Never give up and good luck will find you." // -- Falcor
:D
caneno
@caneno
Aug 03 2017 03:07
I still cant figure out how to put the else with a += without changingthem
Ken Haduch
@khaduch
Aug 03 2017 03:08
@ma5one1 - you do not need a for loop of any type here - you just need to compare the characters at the end of str with the characters in the variable target. You can find a way to just obtain the substring of str that matches the length of the target, and compare it directly. It can be one line of code within the function.
John
@AnonymousLords
Aug 03 2017 03:10
@revisualize here is my code in its current state
Maximino V. Jardin III
@ma5one1
Aug 03 2017 03:10
@khaduch
I'll try some more.
caneno
@caneno
Aug 03 2017 03:10
function rot13(str) { // LBH QVQ VG!
    var str1 = "";
    //var str = str.split(" ");
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) >= 78 && str.charCodeAt(i) <= 90) {
            str1 += String.fromCharCode(str.charCodeAt(i) - 13);
        } else if (str.charCodeAt(i) < 78 && str.charCodeAt(i) < 90) {
            str1 += String.fromCharCode(str.charCodeAt(i) + 13);
        }else{
          str1+= String.fromCharCode(str.charCodeAt(i));
        }

    }
    console.log(str1);
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Maximino V. Jardin III
@ma5one1
Aug 03 2017 03:10
@khaduch thank you.
CamperBot
@camperbot
Aug 03 2017 03:10
ma5one1 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: ma5one1 already gave khaduch points
caneno
@caneno
Aug 03 2017 03:10
this is what I got and I still get the same result @revisualize
John
@AnonymousLords
Aug 03 2017 03:12
Lets not ask him too many questions, hes only one guy :P
caneno
@caneno
Aug 03 2017 03:12
lol I know sorry dude
John
@AnonymousLords
Aug 03 2017 03:12
lol
Ill go ask more people if they can help out in this room
eeflores
@eeflores
Aug 03 2017 03:14
need help?
John
@AnonymousLords
Aug 03 2017 03:15
yup
me and @caneno do
caneno
@caneno
Aug 03 2017 03:15
Yes sir :P
Ken Haduch
@khaduch
Aug 03 2017 03:16
@caneno - I would say that this line: } else if (str.charCodeAt(i) < 78 && str.charCodeAt(i) < 90) { might be affecting too many characters? You want two ranges - "A" through "M" and "N" through "Z" - for one of them you add 13, for the other you subtract 13. Everything outsize of those ranges should not be modified. Make sure that your condition is properly selecting your ranges.
caneno
@caneno
Aug 03 2017 03:16
yes I got this
John
@AnonymousLords
Aug 03 2017 03:16
function largestOfFour(arr) {

   var largest = [];
   var num = 0;
   for (var i = 0; i < arr.length; i++) {
     num = 0
     for (var j = 0; j < arr[i].length; j++) {
       if (arr[i][j] > num) {
         num = arr[i][j]
         if (arr[i][j] < num) {
           // ? confused on what to go here
         } // if 2
       } // if 
     } // j
      largest.push(num)
   } // i 
   return largest;
} // function
Is my current code for the https://www.freecodecamp.org/challenges/return-largest-numbers-in-arrays challenge, do i need that second if statement, and is anything missing?
caneno
@caneno
Aug 03 2017 03:16
function rot13(str) { // LBH QVQ VG!
    var str1 = "";
    //var str = str.split(" ");
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) > 65 && str.charCodeAt(i) < 90) {
            str1 += String.fromCharCode(str.charCodeAt(i) - 13);
        } else if (str.charCodeAt(i) < 65 && str.charCodeAt(i) > 90) {
            str1 += String.fromCharCode(str.charCodeAt(i) + 13);
        }else{
          str1+= String.fromCharCode(str.charCodeAt(i));
        }

    }
    console.log(str1);
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
eeflores
@eeflores
Aug 03 2017 03:17
@AnonymousLords initialise num to the first element in the inner array
caneno
@caneno
Aug 03 2017 03:17
@khaduch I modified it I resolve the space and punctuation issue but now some letter are mising
eeflores
@eeflores
Aug 03 2017 03:17
yup I see that now
actually no
Ken Haduch
@khaduch
Aug 03 2017 03:17
@AnonymousLords - you do not need the second if - is it going to do anything useful?
John
@AnonymousLords
Aug 03 2017 03:17
Oh okay
eeflores
@eeflores
Aug 03 2017 03:18
@AnonymousLords so inner loop would be
num = arr[i][0];
for(var j = 1; j < arr[i].length; j++) {
John
@AnonymousLords
Aug 03 2017 03:18
I got it thanks @khaduch @eeflores @revisualize for your help!
CamperBot
@camperbot
Aug 03 2017 03:18
anonymouslords sends brownie points to @khaduch and @eeflores and @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4403 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 3162 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 1009 | @eeflores |http://www.freecodecamp.com/eeflores
John
@AnonymousLords
Aug 03 2017 03:19
function largestOfFour(arr) {

   var largest = [];
   for (var i = 0; i < arr.length; i++) {
     var num = 0;
     for (var j = 0; j < arr[i].length; j++) {
       if (arr[i][j] > num) {
         num = arr[i][j];
       } // if 
     } // j
      largest.push(num);
   } // i 
   return largest;
} // function

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Ken Haduch
@khaduch
Aug 03 2017 03:20
@caneno - str.charCodeAt(i) > 65 && str.charCodeAt(i) < 90 covers all of the characters from "B" through "Y"? Doesn't it?
John
@AnonymousLords
Aug 03 2017 03:20
Worked! :D
thanks guys. Thanks Joseph for sticking with me to get me on the right track! :D
eeflores
@eeflores
Aug 03 2017 03:21
it might be neater to declare var aChar = "A".charCodeAt(); instead of using numbers
John
@AnonymousLords
Aug 03 2017 03:21
@eeflores Whats better, num = arr[i][0]; or var num = 0;
eeflores
@eeflores
Aug 03 2017 03:22
@AnonymousLords initialising num to a value in the array will let you handle negative numbers
John
@AnonymousLords
Aug 03 2017 03:22
Okay
Ken Haduch
@khaduch
Aug 03 2017 03:23
@AnonymousLords - I would say to do num = arr[i][0]; - but you have to make sure that there is a location [0] in the array, to be safe.
John
@AnonymousLords
Aug 03 2017 03:23
Okay thanks guy
Is their such thing as a -1 index?
like 0,1,2 etc, but what about -1
eeflores
@eeflores
Aug 03 2017 03:24
you can use that in some functions to reference from the end, but I can't remember which ones
like split I think
caneno
@caneno
Aug 03 2017 03:25
@khaduch yes I just modify that
eeflores
@eeflores
Aug 03 2017 03:25
but for use in an array, usually not
caneno
@caneno
Aug 03 2017 03:25
but still nothing
John
@AnonymousLords
Aug 03 2017 03:25
Okay
Why do people critics JS a lot?
eeflores
@eeflores
Aug 03 2017 03:26
or try arr["-1"] = "havahvava!" - that should work
John
@AnonymousLords
Aug 03 2017 03:26
My code works, just asking :P
guys i gtg
eeflores
@eeflores
Aug 03 2017 03:28
cya
John
@AnonymousLords
Aug 03 2017 03:28
Thanks for the help, @ me and ill check tomorrow if you need anything
@eeflores are you a programmer?
eeflores
@eeflores
Aug 03 2017 03:28
kinda
John
@AnonymousLords
Aug 03 2017 03:28
Whats your job?
caneno
@caneno
Aug 03 2017 03:28
function rot13(str) { // LBH QVQ VG!
    var str1 = "";
    //var str = str.split(" ");
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) >= 78 && str.charCodeAt(i) <= 90) {
            str1 += String.fromCharCode(str.charCodeAt(i) - 13);
        } else if (str.charCodeAt(i) <= 65 && str.charCodeAt(i) > 78) {
            str1 += String.fromCharCode(str.charCodeAt(i) + 13);
        }else{
          str1+= String.fromCharCode(str.charCodeAt(i));
        }

    }
    console.log(str1);
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
eeflores
@eeflores
Aug 03 2017 03:28
programmer
John
@AnonymousLords
Aug 03 2017 03:28
Oh :P Do you build games?
caneno
@caneno
Aug 03 2017 03:29
I am running in cirlces u.u
eeflores
@eeflores
Aug 03 2017 03:29
no, but I'd like to
@caneno I'll have a look
Ken Haduch
@khaduch
Aug 03 2017 03:29

@caneno - if the letter is in the range A through M, you want to add 13 to it. If it is in the range "N" through "Z" you want to subtract 13 from it. Otherwise you just keep the character the same. These are the letter codes:

"A".charCodeAt(0)
65
"M".charCodeAt(0)
77
"N".charCodeAt(0)
78
"Z".charCodeAt(0)
90

So you can do something like if (char >= 65 && char <= 77) then add 13. else if (char >=78 && char <= 90) then subtract 13. Those are the ranges that you want.

John
@AnonymousLords
Aug 03 2017 03:29
You should make a mobile app or something.
caneno
@caneno
Aug 03 2017 03:30
oooh okk let me try that
eeflores
@eeflores
Aug 03 2017 03:30
@caneno the other thing you can do is add 26 to alphabetical chars, and only subtract 13 if the value is greater than "Z".charCodeAt()
John
@AnonymousLords
Aug 03 2017 03:31
@eeflores You could make a living off of it and be a game developer. It could also nail you a job as one, as you will get instantly hired if you can create your own mobile app.
Ayc guys
Brad
@bradtaniguchi
Aug 03 2017 03:31
@john JS has its share of flaws that ultimate can waste your (the programmers) time, on the dumbest stuff. It also dose not protect you in many ways from hurting your system, IE memory leaks, bad code, hard to debug glitches, ETC.
John
@AnonymousLords
Aug 03 2017 03:31
Okay
It has so many extras like ;, etc
eeflores
@eeflores
Aug 03 2017 03:32
@caneno what's that challenge name again?
John
@AnonymousLords
Aug 03 2017 03:32
Unlike Lua which is simple :P
er
Less ways to mess up
i gtg, @ me if anything else pops up, thanks @bradtaniguchi
CamperBot
@camperbot
Aug 03 2017 03:33
anonymouslords sends brownie points to @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 300 | @bradtaniguchi |http://www.freecodecamp.com/bradtaniguchi
caneno
@caneno
Aug 03 2017 03:33
@eeflores Caesars Cipher
eeflores
@eeflores
Aug 03 2017 03:33
ah thanks
Brad
@bradtaniguchi
Aug 03 2017 03:33
@AnonymousLords All programming languages has its flaws, and alright
eeflores
@eeflores
Aug 03 2017 03:34
@caneno you need to return str1
@caneno also check your second if range
> and < are wrong there
fix that, then it will work
eeflores
@eeflores
Aug 03 2017 03:39
@caneno second if should check between 65 and 78, not <= 65 and > 78
ThePineal
@ThePineal
Aug 03 2017 03:46
trying to make a tweet button for the quote machine, how do I not just link to a new page, but put text into that new link?
Brad
@bradtaniguchi
Aug 03 2017 03:48
@ThePineal there are a number of ways, I believe the demo changes the actual link with the text for the current quote
$(selector).attr('href', url) is a common way
ThePineal
@ThePineal
Aug 03 2017 04:17
@SkyC0der thanks
CamperBot
@camperbot
Aug 03 2017 04:17
thepineal sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2293 | @skyc0der |http://www.freecodecamp.com/skyc0der
heroiczero
@heroiczero
Aug 03 2017 04:19
@ThePineal check https://dev.twitter.com/web/tweet-button use the text component
Ginger
@GingerChew
Aug 03 2017 04:20
Hey can I get some help with this button function? I think I'm missing something obvious but its not recognizing a function in my js when I reference it in my html
heroiczero
@heroiczero
Aug 03 2017 04:22
@GingerChew probably need a jquery so when you click it changes the button to F and C
Ginger
@GingerChew
Aug 03 2017 04:23
I think I have that set up?
function degrees() {
    if (units === "us"){
      units = "si"
      $("button").html="° c"
    } if (units === "si") {
      units = "us"
      $("button").html="° f"
    }
  };
Darth Skywalker
@AdiSkywalker
Aug 03 2017 04:23
@heroiczero Move your deggrees function out of geolocation callback
heroiczero
@heroiczero
Aug 03 2017 04:23
@GingerChew something like https://api.jquery.com/click/
Darth Skywalker
@AdiSkywalker
Aug 03 2017 04:24
onclick expect the function you're calling on window (generally)
Ginger
@GingerChew
Aug 03 2017 04:24
okay, so I have the function changing things inside the geolocation callback, like the units being referenced in the json request
how do I keep it in the jquery but also trigger it with that button
heroiczero
@heroiczero
Aug 03 2017 04:26
@GingerChew you can either store both and hide one and display one or you can convert the temperature with a formula
Darth Skywalker
@AdiSkywalker
Aug 03 2017 04:26
@GingerChew YOur structure should look like this
$("document").ready(function() {
  navigator.geolocation.getCurrentPosition(success, error);
  // blah blah

  function success(position) {
    //blah blah
  }

  function error() {
    //blah blah
  }


}); // document.ready ends
function degrees() {
  //blah blah
};
Joseph
@revisualize
Aug 03 2017 04:28
"should" ?
Ginger
@GingerChew
Aug 03 2017 04:29
@heroiczero so I have it set up like this
 function degrees() {
    if ($("button").html === "° f") {
      // units = "si";
      $("button").html = "° c";
    }
    if ($("button").html === "° c") {
      // units = "us";
      $("button").html = "° f";
    }
  }
  $("#degrees").click(degrees();)
});
but it still won't recognize the degrees function
subtract that rogue semicolo
Joseph
@revisualize
Aug 03 2017 04:30
you can edit your posts.
heroiczero
@heroiczero
Aug 03 2017 04:30
@GingerChew i would make a switch like a light switch for this one. you can either turn on the light or off
@GingerChew press the button to make it F and press it again to make it a C
@GingerChew
Ginger
@GingerChew
Aug 03 2017 04:31
@revisualize gotcha
@heroiczero is that not what I am setting up?
Darth Skywalker
@AdiSkywalker
Aug 03 2017 04:34
@GingerChew $("button").html === "° f" this is wrong
it should be $("button").html() === "° f"
and I'd recommend you use .text instead of .html
Ginger
@GingerChew
Aug 03 2017 04:36
why .text instead of .html?
heroiczero
@heroiczero
Aug 03 2017 04:36
@GingerChew because you want to retrieve the text
Ginger
@GingerChew
Aug 03 2017 04:37
@heroiczero Are you saying I should use a switch statement?
heroiczero
@heroiczero
Aug 03 2017 04:39
@GingerChew you could do it your way. I just thought it as a light switch where it goes between 0 and 1. like electrical boards
Ginger
@GingerChew
Aug 03 2017 04:43
i get what youre getting at, but I am trying to get it to do what its supposed to do, then I can simplify and make cleaner
Ginger
@GingerChew
Aug 03 2017 04:53
$("button").click(function(){
    if ($("#degrees").html() === "° f") {
      $("#degrees").html = "° c"
    } else if ($("#degrees").html() === "° c") {
      $("#degrees").html = "° f"
    }
  });
shouldn't this change the html inside of the button when it is clicked if it has the id degrees?
Manish Giri
@Manish-Giri
Aug 03 2017 04:54
$("#degrees").html = "° c"
this is wrong
$("#degrees").html("° c");
should be this
you pass a string to .html which is what sets the new content
heroiczero
@heroiczero
Aug 03 2017 04:55
@GingerChew or you could use http://api.jquery.com/text/
Joseph
@revisualize
Aug 03 2017 04:56
@Manish-Giri If you link to jQuery doesn't all of jQuery get loaded into memory even if the .js file is cached?
Manish Giri
@Manish-Giri
Aug 03 2017 04:56
yup
@revisualize
Ginger
@GingerChew
Aug 03 2017 04:57
@Manish-Giri thanks m8 that was it exactly
CamperBot
@camperbot
Aug 03 2017 04:57
gingerchew sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6352 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ginger
@GingerChew
Aug 03 2017 04:57
I knew it was something stupid I was overlooking
Manish Giri
@Manish-Giri
Aug 03 2017 04:57
@GingerChew :v:
Joseph
@revisualize
Aug 03 2017 04:57
@Manish-Giri So, is it reasonable to link to jQuery if you're just saving yourself 15 lines of JavaScript?
Manish Giri
@Manish-Giri
Aug 03 2017 05:00
yeah well most of us aren't that smart to use vanilla JS.
Guderian Raborg
@hypercuber
Aug 03 2017 05:17
I want the squares near my mouse to turn full blue gradually. I am tire about to go to sleep.
https://codepen.io/hypercuber/pen/VzKrKY?editors=1010
prakash chandra yadav
@prakashyadav008
Aug 03 2017 05:41
has anyone completed the drop it challange from the intermediate javascript module
"drop it"
Markus Kiili
@Masd925
Aug 03 2017 05:53
@prakashyadav008 Yes.
caneno
@caneno
Aug 03 2017 05:58
@khaduch I got it thanks
CamperBot
@camperbot
Aug 03 2017 05:58
caneno sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3163 | @khaduch |http://www.freecodecamp.com/khaduch
hillsie
@Hillsie
Aug 03 2017 06:22
Not that we code like this, but who would have thunk this if you applied other programming lanugage paradigms.
Try this code:
if (MakeAGuessTowhichOneIsFirst) {
   function whichone() { console.log( "You win! If Function A is first?" ); }
}
else {
   function whichone() { console.log( "You loose ! Function B is first?" ); }
}
var MakeAGuessTowhichOneIsFirst = true;
whichone();
What I mean is I would have declared first before trying the conditional.
Markus Kiili
@Masd925
Aug 03 2017 06:27
@Hillsie Function declarations are not allowed inside control structure blocks. So such code is forbidden by the language standard and can cause fun.
whichone = function {...}; would be fine.
Markus Kiili
@Masd925
Aug 03 2017 06:33
@Hillsie When that if is evaluated, MakeAGuessTowhichOneIsFirst has value undefined. It only gets value true later.
Owais Ahmed
@owaisehmed
Aug 03 2017 07:16
How do i save sorted values in an array?
Darth Skywalker
@AdiSkywalker
Aug 03 2017 07:24
@owaisehmed array always sorts in place. No need to store it else where
Owais Ahmed
@owaisehmed
Aug 03 2017 07:26
@AdiSkywalker
arr.sort(function(a,b){
    return a-b;
  });
what should i do in place of return then
Darth Skywalker
@AdiSkywalker
Aug 03 2017 07:28
var arr = [5,4,3,2,1];
console.log(arr); // [ 5, 4, 3, 2, 1 ]
arr.sort(function(a,b){
    return a-b;
});
console.log(arr); //[ 1, 2, 3, 4, 5 ]
帮忙看看这题什么意思 啊?
Owais Ahmed
@owaisehmed
Aug 03 2017 07:28
@AdiSkywalker i dont wanna return. I want to save into a new array
Darth Skywalker
@AdiSkywalker
Aug 03 2017 07:29
@owaisehmed what do you mean you don't want to return?
okay. So you want your original array unaltered?
Owais Ahmed
@owaisehmed
Aug 03 2017 07:30
I want the sorted array to be used later on , rather then be returned
Darth Skywalker
@AdiSkywalker
Aug 03 2017 07:31
@owaisehmed Show your full code
If you want to sort, there is no way you can't not return
Owais Ahmed
@owaisehmed
Aug 03 2017 07:33
arr.sort(function(a,b){
    return a-b;
  });
Darth Skywalker
@AdiSkywalker
Aug 03 2017 07:33
var arr = [5,4,3,2,1];
var arrCopy = arr.slice();

arrCopy.sort( (a,b) => a - b);
Owais Ahmed
@owaisehmed
Aug 03 2017 07:41
Not working
Darth Skywalker
@AdiSkywalker
Aug 03 2017 07:44
@owaisehmed what do you mean not working?
Can you show your full code and explain what you're trying to do?
tahashin
@tahashinegp
Aug 03 2017 08:05

function mutation(arr) {
var firstData=arr[0];
var secondData=arr[1];
firstData=firstData.toLowerCase();
secondData=secondData.toLowerCase();
for(var i=0; i<firstData.length;i++){
var pos = firstData.indexOf(secondData[i]);
if(pos!==-1){
return true;
}

 return false;

}
}

mutation(["hello", "hey"]);
mutation problem all are ok but for only "hello" "hey" its not working any idea any one?

any help form any one
Owais Ahmed
@owaisehmed
Aug 03 2017 08:10
@AdiSkywalker I actually want to insert values in the array at specific location after sorting it up. Im done with the sorting bit but i want to save the sorted array so it can be used later. your solution requires es6 to work and i want it to do without that
Darth Skywalker
@AdiSkywalker
Aug 03 2017 08:11
@owaisehmed You can get rid of ES6 part
var arr = [5,4,3,2,1];
var arrCopy = arr.slice();

arrCopy.sort( function (a,b) { 
  return a - b
});
Owais Ahmed
@owaisehmed
Aug 03 2017 08:19
@AdiSkywalker had i simply done that with arr, it would have worked just like that
Vicky Lai
@vickylai
Aug 03 2017 08:20
This should result in a console.log when a pink square is clicked... right? https://codepen.io/vickylaiio/pen/dRWPra?editors=1111
Darth Skywalker
@AdiSkywalker
Aug 03 2017 08:22
@owaisehmed :point_up: That's what I told you initially
AdamCS
@csikos3d
Aug 03 2017 08:39
someone pls has any idea why this i not give any result? the url is in the trnDataFix variable.
function getTrain() {
  $.getJSON(trnDataFix, function(trn) {
    $.each(trn, function(index, value) {
      $("#container" + index).append(value.trainCategory);
    });
  });
}
tahashin
@tahashinegp
Aug 03 2017 08:39
what about the code
Adri Jenie
@Adrifajar
Aug 03 2017 08:40
what is the difference between str.slice() and str.substring()?
AdamCS
@csikos3d
Aug 03 2017 08:40
var sloUrl = "https://rata.digitraffic.fi/api/v1/live-trains?station=SLO";
var trnDataFix = "https://rata.digitraffic.fi/api/v1/compositions/955?departure_date=2017-08-02";

function getStation() {
  $.getJSON(sloUrl, function(stat) {
    $.each(stat, function(index, value) {
      $("#container" + index).text(value.trainType + value.trainNumber);
      $("#container" + index).append(
        "<br> Departure date: " + value.departureDate
      );

    });
  });
}

function getTrain() {
  $.getJSON(trnDataFix, function(trn) {
    $.each(trn, function(index, value) {
      $("#container" + index).append(value.trainCategory);
    });
  });

}

$(function() {
  getStation();
  getTrain();
});
the first function working fine but the second is not...
kumquatfelafel
@kumquatfelafel
Aug 03 2017 08:47
@Adrifajar Here are some examples. https://repl.it/JvNk
Pieter Stokkink
@forkerino
Aug 03 2017 08:47
@csikos3d $.each only works on arrays, I think. The second url returns an object
kumquatfelafel
@kumquatfelafel
Aug 03 2017 08:49
@Adrifajar You can read documentation for some more explanation. slice and substring
Pieter Stokkink
@forkerino
Aug 03 2017 08:50
@Adrifajar what @kumquatfelafel 's example shows is that the arguments mean different things to both. For .slice it is simple begin and endpoint (where negative numbers count from the end back). .substring works in a similar way, but handles negatives as zero and swaps the arguments if the latter is less than the former. I prefer .slice by a landslice. :P
@kumquatfelafel what's up?
No sleep yet?
kumquatfelafel
@kumquatfelafel
Aug 03 2017 08:51
@forkerino sleep already. :)
Pieter Stokkink
@forkerino
Aug 03 2017 08:51
@kumquatfelafel It's like 5 am there, right?
or are you elsewhere?
kumquatfelafel
@kumquatfelafel
Aug 03 2017 08:52
approx.
Abid Rahim
@abidRahim
Aug 03 2017 08:54
Hey guys!
kumquatfelafel
@kumquatfelafel
Aug 03 2017 08:54
hi
Abid Rahim
@abidRahim
Aug 03 2017 08:54
hi @kumquatfelafel
function chunkArrayInGroups(arr, size) {

 var chunkd = [];

 for(var i=0; i<arr.length; i+size)
  {
    var start=i;
    var end=size;

    var newArray = arr.slice(start, end);

   chunkd.push(newArray);
       end += size;

  }

 return chunkd;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
error says : "infinite loop at line 6"
is my code wrong ?
AdamCS
@csikos3d
Aug 03 2017 08:55
@forkerino huh...thanks, You must be right... I am checking
CamperBot
@camperbot
Aug 03 2017 08:55
csikos3d sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2909 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Aug 03 2017 08:55
@abidRahim i+size doesn't increase i
you have to assign!
Abid Rahim
@abidRahim
Aug 03 2017 08:55
oh right!
kumquatfelafel
@kumquatfelafel
Aug 03 2017 08:56

what's up?

Though yeah... not much. Spent entirety of yesterday in courtroom hoping I wouldn't get picked to serve on a jury.

Pieter Stokkink
@forkerino
Aug 03 2017 08:56
@kumquatfelafel and? Did it work?
Abid Rahim
@abidRahim
Aug 03 2017 08:56
@forkerino i think my code isnt right
ni it din
*no
kumquatfelafel
@kumquatfelafel
Aug 03 2017 08:56
:+1:
Pieter Stokkink
@forkerino
Aug 03 2017 08:56
@abidRahim you reset end everytime inside your loop
maybe set it to size before the loop
or omit the variable and just use i+size instead of end
Abid Rahim
@abidRahim
Aug 03 2017 08:57
Yessss!!!!!
@forkerino thank you !!!
CamperBot
@camperbot
Aug 03 2017 08:57
abidrahim sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2910 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Aug 03 2017 08:57
:+1:
Abid Rahim
@abidRahim
Aug 03 2017 08:58
is there a better code for this ?
Pieter Stokkink
@forkerino
Aug 03 2017 08:58
@kumquatfelafel jury duty is such a foreign concept to me. I only know it from movies. Is there some sort of compensation?
@abidRahim yes
Abid Rahim
@abidRahim
Aug 03 2017 08:58
please share
Pieter Stokkink
@forkerino
Aug 03 2017 08:59
@abidRahim your loop can be like so:
for (var i = 0; i<arr.length; i+=size) {
  chunkd.push(arr.slice(i,i+size));
}
I generally prefer not using too many variables when you only use them once.
Abid Rahim
@abidRahim
Aug 03 2017 09:00
@forkerino rgiht
Markus Kiili
@Masd925
Aug 03 2017 09:01
@abidRahim This is also quite elegant, but mutates the array:
function chunkArrayInGroups(arr, size) {
  var result = [];
  while (arr.length>0) result.push(arr.splice(0,size));
  return result;
}
Pieter Stokkink
@forkerino
Aug 03 2017 09:01
@abidRahim One important reason why is that if you make a mistake somewhere (like with updating end in your case), the bug can be in many places, in this code, it can only be in one place.
Abid Rahim
@abidRahim
Aug 03 2017 09:02
oh okay
@Masd925 thanks!
CamperBot
@camperbot
Aug 03 2017 09:02
abidrahim sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4371 | @masd925 |http://www.freecodecamp.com/masd925
Harut
@harut-g
Aug 03 2017 09:04
How is familiar with JS decorators?
kumquatfelafel
@kumquatfelafel
Aug 03 2017 09:05
@forkerino Would have gotten $40 a day, but that fails to take into account expense for transportation, food, etc. So all in all, the compensation isn't much. There's also other states where it's a lot less.
Adri Jenie
@Adrifajar
Aug 03 2017 09:06
what does "string in java script are immutable" meant?
Markus Kiili
@Masd925
Aug 03 2017 09:06
@Adrifajar There is no way to change a string character(s).
You always make new strings from the old.
Pieter Stokkink
@forkerino
Aug 03 2017 09:06
@kumquatfelafel wow. That's insane.
Adri Jenie
@Adrifajar
Aug 03 2017 09:06
@Masd925 thanks
CamperBot
@camperbot
Aug 03 2017 09:06
adrifajar sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4372 | @masd925 |http://www.freecodecamp.com/masd925
Pieter Stokkink
@forkerino
Aug 03 2017 09:07
@Masd925 how are you?
Markus Kiili
@Masd925
Aug 03 2017 09:07
@forkerino Fine. My jiujitsu career will start in couple of weeks.
How about you?
kumquatfelafel
@kumquatfelafel
Aug 03 2017 09:08
speaking of food, early breakfast. :laughing:
Surendra Karwasra
@skkarwasra02
Aug 03 2017 09:08
I have two div and i want to show them using javascript on if condition
<div id="claimSuccess" style="display: none;">Successfully Claimed Satoshi</div>
<div id="captchaError" style="display: none;">Incorrect captcha answer</div>
<script type="text/javascript">
    window.onload = function() {
    if (1 === 1) {
    document.getElementById('claimSuccess').style.display='block';
    setTimeout(window.onload = function(){ document.getElementById('claimSuccess').style.display='none'; }, 5000);
    }}
    window.onload = function() {
    if (1 === 2) {
    document.getElementById('captchaError').style.display='block';
    setTimeout(window.onload = function(){ document.getElementById('captchaError').style.display='none'; }, 5000);
    }}
</script>
Where 2 come from php code.
Yesterday it's working but today not. I made few changes on page and forgot.
Sorry, Where 1 come from php code.
in if condition
Pieter Stokkink
@forkerino
Aug 03 2017 09:11
@Masd925 Quite ok. Have the day off as we are having a strategy weekend with the company tomorrow and the day after. Need to find a proper home somewhere a bit closer, as the commute is killing me at the moment (only have to go once or twice a week, but it's 2 hours one way).
So I reckon jiujitsu is not a problem if you have had a herniated disc? That's good news! Maybe I'll pick it up once we're settled a bit.
@kumquatfelafel enjoy!
Markus Kiili
@Masd925
Aug 03 2017 09:11
@skkarwasra02 Second assignment to window.onload overwrites the first.
Surendra Karwasra
@skkarwasra02
Aug 03 2017 09:11
Please help me
@Masd925 What?
It works yesterday.
@Masd925 They are different in id
tahashin
@tahashinegp
Aug 03 2017 09:13

function mutation(arr) {
var firstData=arr[0];
var secondData=arr[1];
firstData=firstData.toLowerCase();
secondData=secondData.toLowerCase();
for(var i=0; i<firstData.length;i++){
var pos = firstData.indexOf(secondData[i]);
if(pos!==-1){
return true;
}

 return false;

}
}

mutation(["hello", "hey"]); only hello and hey are not wrking others ar ok for mutation any help

Tungsteni
@Tungsteni
Aug 03 2017 09:14
Hi; idk if this is the best place to ask for this but can someone give me advice to createa web that can run a java program?? Hope its clear
Markus Kiili
@Masd925
Aug 03 2017 09:14
@forkerino I wen't to a chiropractor. He saw no problems with wrestling.
@Tungsteni This is a javascript help room. java is another popular language.
Abid Rahim
@abidRahim
Aug 03 2017 09:15
function chunkArrayInGroups(arr, size) {
  var result = [];
  while (arr.length>0) result.push(arr.splice(0,size));
  return result;
}
Everytime it splices from the 0th index, then how is the second array formed? @Masd925
Tungsteni
@Tungsteni
Aug 03 2017 09:15
where should i ask for help with this issue @Masd925 ??
Surendra Karwasra
@skkarwasra02
Aug 03 2017 09:15
Please help me
Blauelf
@Blauelf
Aug 03 2017 09:16
@abidRahim splice is mutating. It returns an array of the elements it removed. The indices of the other elements are shifted to close the hole.
Markus Kiili
@Masd925
Aug 03 2017 09:16
@abidRahim Splice mutates arr by removing size elements from the start. So every time different elements are removed.
Abid Rahim
@abidRahim
Aug 03 2017 09:16
Ohh.. i got it now
Markus Kiili
@Masd925
Aug 03 2017 09:17
@forkerino So do you think they will hand me the black belt straight away or is there some waiting period doing pushups etc?
Blauelf
@Blauelf
Aug 03 2017 09:17
The shifting part is not very efficient, though. And if you operate on arr directly, you affect the calling code (meaning your function has the side-effect to destroy the array one passed to it).
Pieter Stokkink
@forkerino
Aug 03 2017 09:18
@Masd925 Of course I will check with a doctor too before I join a club, but this is good news! Black belt?!? I think they're gonna check if you get choked out easily for a year or two at least.
kumquatfelafel
@kumquatfelafel
Aug 03 2017 09:20
@tahashinegp You return in first iteration of your for loop. Return halts function immediately "returning" the specified value.
Markus Kiili
@Masd925
Aug 03 2017 09:20
@forkerino Nobody can choke out a freediver. His hands will tire before that happens.
Pieter Stokkink
@forkerino
Aug 03 2017 09:21
@Masd925 hahaha.
choke is maybe not the right term for stopping the blood circulation to your brain.
kumquatfelafel
@kumquatfelafel
Aug 03 2017 09:22
@tahashinegp So, basically, you're checking the h in hello and hey, and saying "Okay, it's the same letter? Then it must be true." This is not what you want
Blauelf
@Blauelf
Aug 03 2017 09:22
@Masd925 Jiujitsu? Just don't go the same route as one of my co-students, who when drunk wants to demonstrate all those Jiu Jitsu throws and grabs and whatever. He constantly keeps saying things like "I'll show you how I could make you unconscious, but I promise, I won't do that, just demonstrate how I could". Do I want to trust a drunk?
Pieter Stokkink
@forkerino
Aug 03 2017 09:24
@Blauelf sounds like a bastard.
Markus Kiili
@Masd925
Aug 03 2017 09:25
@Blauelf I don't think that conforms to the purpose of martial arts.
Blauelf
@Blauelf
Aug 03 2017 09:25
Really nice guy, if not drunk. Also no bad intention if drunk. I just doubt his Drunken Master skills.
Pieter Stokkink
@forkerino
Aug 03 2017 09:27
<3 Jackie Chan
Markus Kiili
@Masd925
Aug 03 2017 09:28
@Blauelf Those old Jackie Chan movies Snake in the Eagle's Shadow and Drunken master were superb.
Blauelf
@Blauelf
Aug 03 2017 09:28
Yeah.
:joy:
Markus Kiili
@Masd925
Aug 03 2017 09:32
@forkerino Snake style was my favorite. Must be easily as efficient as any Kung fu style.
Blauelf
@Blauelf
Aug 03 2017 09:32
I liked the cat. :cat:
danskeerththana
@danskeerththana
Aug 03 2017 09:35
hello
Markus Kiili
@Masd925
Aug 03 2017 09:36
@danskeerththana Hi.
danskeerththana
@danskeerththana
Aug 03 2017 09:40
hmm
Abhinav Mishra
@abhinav-m
Aug 03 2017 09:44
im having an issue where i update my sass css and it renders after 5-6 seconds
is this normal
Adri Jenie
@Adrifajar
Aug 03 2017 09:45
how to truncate a string.
function truncateString(str, num) {
// Clear out that junk in your trunk
str1=str.slice(0,num+1);
str1=str1.slice(0,str1.indexOf(" "));
this is a part of my code
i know the second command is wrong though.
kumquatfelafel
@kumquatfelafel
Aug 03 2017 09:47
@Adrifajar You want to truncate the string in different ways (or not at all) only if certain conditions are met.
Adri Jenie
@Adrifajar
Aug 03 2017 09:48
what i really try is to remove the excessive unfinished string. for example truncateString("A-tisket a-tasket A green and yellow basket", 11); when i slice it by 11. it would be "A-tisket a-tas"
but i just want "A-tisket..."
Blauelf
@Blauelf
Aug 03 2017 09:48
@Adrifajar For this challenge, words and spaces are no different. Treat all characters the same.
@Adrifajar Whenever the string is longer than num, truncate it to the correct length (which depends on num) and append three dots. If it isn't longer, then there's no need for any truncation.
Adri Jenie
@Adrifajar
Aug 03 2017 09:52
when i do slice
str1=str.slice(0,num+1);
Blauelf
@Blauelf
Aug 03 2017 09:58
  1. slice only if str is longer than num.
  2. If slicing, the length of the truncated string should be num. Now there's one catch, as
    • if num>3, this means the string including triple dots should be of length num
    • if num<=3, the string without triple dots should be of length num
  3. If truncating, always add "...", whether or not they count against num.
Eline
@elinerentinck
Aug 03 2017 10:05
Hey guys, I'm having my first epic frustration meltdown with coding. I am working on the Random Quote Machine & at first I just want to be able to make a machine without API, just to check if I understand the things I've learned with JavaScript so far. I've made it work with a simple array, but somehow I cannot make the quote-button work every time you click it.
Does anyone know if there is a simple, elegant solution to my problem?
This is my codepen https://codepen.io/lente/pen/XaJLrp
Cheers :)
Pieter Stokkink
@forkerino
Aug 03 2017 10:06
@elinerentinck you only take a random number once. You have to do it every time in your click handler.
Eline
@elinerentinck
Aug 03 2017 10:07
@forkerino so when I add my API code, I should not run into this problem? That is good news, thanks
CamperBot
@camperbot
Aug 03 2017 10:07
elinerentinck sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2911 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Aug 03 2017 10:07
it might still return the same quote twice in a row sometimes, because of the small number of quotes, but it will work if you put the line var randomQuoteSelector = Math.floor(Math.random() * (randomQuotes.length +1)); just above the line where you change the html
@elinerentinck no, with an API you will get a new quote each time (depending on how the api is implemented, but that is not your problem).
AdamCS
@csikos3d
Aug 03 2017 10:21
I am trying to fill an array with the number of the trains from a JSON and console.log the array but it gives very wierd outcome. Would You please tel me what is the problem
var sloUrl = "https://rata.digitraffic.fi/api/v1/live-trains?station=SLO";

var mainArr = [

 $.getJSON(sloUrl, function(stat) {
    $.each(stat, function(index, value) {
      return value.trainNumber;


    });
   })
  ];

console.log(mainArr);
Stephen James
@sjames1958gm
Aug 03 2017 10:24
@csikos3d $getJSON returns a promise which is what ends up in the array.
@csikos3d The return from the function inside of $.each has no affect on the array
AdamCS
@csikos3d
Aug 03 2017 10:27
@sjames1958gm Hi, thank You again. :-) I start over the whole project . this would be the new approach...before everything I would like to store the result of the each() in an array so at latter i can use tham for differenet purposis...but i got just stuck at the beggining as I see :-D. It´s better than befor the end :-)
CamperBot
@camperbot
Aug 03 2017 10:27
csikos3d sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8229 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 03 2017 10:28
@csikos3d The stat variable is an array, you can simply assign to a global variable to save it.
@csikos3d If you want an array of train numbers then use map.
trainNumbers = stat.map((train) => return train.trainNumber);
AdamCS
@csikos3d
Aug 03 2017 10:34
@sjames1958gm uh, make sense. but the trainNumber is the key itself in the JSON and I need the value pair from all object
Stephen James
@sjames1958gm
Aug 03 2017 10:37
@csikos3d train.trainNumber will be the train number, like 945 and map will process each train in the array.
AdamCS
@csikos3d
Aug 03 2017 10:38
@sjames1958gm i think i understand. I will try this approach right now, thank You
CamperBot
@camperbot
Aug 03 2017 10:38
csikos3d sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: csikos3d already gave sjames1958gm points
Owais Ahmed
@owaisehmed
Aug 03 2017 11:12

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  arr.sort( function (a,b) { 
  return a - b;
});
  var index = 0;

  for(var i = 0; i<arr.length;i++){
    if(num > arr[i]){
      if(num < arr[i+1]){
        arr.splice(i+1,0,num);
        index++;
        break;
      }
      if(num > arr[arr.length-1]){
        arr.splice(arr.length,0,num);
        index = arr.length-1;
        break;
      }
    }
    if(num == arr[i]){
      arr.splice(i,0,num);
      break;
    }
    if(num < arr[i]){
      arr.splice(i,0,num);
      index++;
      break;
    }
    index++;
}
  return index;

}

getIndexToIns([2, 5, 10,15,12,19], 20);
Just completed this code. Please post other solutions
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:12
@owaisehmed which question?
Markus Kiili
@Masd925
Aug 03 2017 11:12
@owaisehmed If you first push num into arr before sorting, you can get the solution with one method call.
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:12
oh..
that sort one..
Markus Kiili
@Masd925
Aug 03 2017 11:13
@owaisehmed There is also a clever way to solve it without sorting at all.
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:14
 return arr.push.(num).sort(function( a,b) {
return a-b; 
});
@Masd925 without sorting?
let me think..
Markus Kiili
@Masd925
Aug 03 2017 11:15
@abhinav-thinktank You cannot chain them like that because push returns the new length.
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:15
oooh
Markus Kiili
@Masd925
Aug 03 2017 11:15
@abhinav-thinktank You can do return arr.concat(num).sort...
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:15
aaah yes thats better
:+1:
Markus Kiili
@Masd925
Aug 03 2017 11:18
@abhinav-thinktank In order to find your spot on a by length queue on a classroom, you don't need to form the queue. There is a simpler way.
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:19
@Masd925 ok
sec..
the given array is unsorted though
in the problem
Markus Kiili
@Masd925
Aug 03 2017 11:20
@abhinav-thinktank Yes.
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:21
hmm maybe im misunderstanding the problem
how am i going to sort the array without sorting it :P
i need to apply some sort of logic which arranges the elements
which would be a sorting logic
@Masd925 could you examplify what you meant
Markus Kiili
@Masd925
Aug 03 2017 11:22
@abhinav-thinktank You can count the array elements that come before num in the sorted array. Those are just all the elements <num. You can calculate them without sorting.
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:23
oh, thats what i was referring to
you are getting an unsorted array
oh wait..
aah.. so you mean i position the given element at its correct position and don't sort the array
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number.
or just return this index
i see..
Markus Kiili
@Masd925
Aug 03 2017 11:24
@abhinav-thinktank Sorting is part of the problem definition, but the result can be calculated without using the costly sorting process.
hillsie
@Hillsie
Aug 03 2017 11:27
@Masd925 Thanks
CamperBot
@camperbot
Aug 03 2017 11:27
hillsie sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4373 | @masd925 |http://www.freecodecamp.com/masd925
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:34
@Masd925

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
 return arr.filter(function(elem){return elem<num;}).length;

}
ty!
@Masd925 ty!
CamperBot
@camperbot
Aug 03 2017 11:34
abhinav-thinktank sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4374 | @masd925 |http://www.freecodecamp.com/masd925
sky1095
@sky1095
Aug 03 2017 11:35
any help in Basic JavaScript: Record Collection?
Markus Kiili
@Masd925
Aug 03 2017 11:39
@abhinav-thinktank Even better is just calculating the elements (filter makes a new array). You could use a for loop or:
sky1095
@sky1095
Aug 03 2017 11:39
Capture.PNG
Markus Kiili
@Masd925
Aug 03 2017 11:39
function getIndexToIns(arr, num) {
  return arr.reduce(function(acc, curr){
    return curr<num ? acc+1 : acc;
  },0); 
}
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:39
@Masd925 aah, i was doing it with reduce earlier then filter came to my mind
nice :+1:
sky1095
@sky1095
Aug 03 2017 11:40
// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  if(prop != "tracks" && value != undefined){
    collection[id][prop] = value;
  }
  else if(prop == "tracks" && collection[id].hasOwnProperty(prop) != true){
           collection[id][prop] = [];
            collection[id][prop].push(value);

          }
  else if(prop == "tracks" && value != undefined){
    collection[id][prop].push(value);
  }
  else if(isEmpty(value) == true){

    delete collection[id][prop];
  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
any mistakes??
Markus Kiili
@Masd925
Aug 03 2017 11:41
@sky1095 Did the description say something about value being undefined?
sky1095
@sky1095
Aug 03 2017 11:42
yes @Masd925
If value is empty (""), delete the given prop property from the album.
Markus Kiili
@Masd925
Aug 03 2017 11:43
@sky1095 An empty string "" and undefined are different values.
The proper test is if (value==="")
sky1095
@sky1095
Aug 03 2017 11:45
tried all possible ways
thats why i tried isEmpty to make it sure
output is still same
@Masd925
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:48
 render(){
      if(this.state.makingRecipe)
        return(<div className="recipeMaker">
                 <h1 className="center">Recipe Maker</h1>
                 <h2 className="center">Title:</h2>
                 <textArea className="titleEditor"></textArea>
                 <h3 className="center"> Ingredients:</h3>
                 <div className ="ingredientPlace">
                 <textArea className="ingredientEditor"></textArea>
                 </div>
                 <div className="buttonContainer"><div className="button-primary saveButton" onClick={this.addRecipe} test={"abc"}>Save</div><div className="button-primary backButton">  Back</div></div>
               </div> )
        else
This is the render method for my react component
i want to get the value of the textArea in this component
how can i access that
:|
is there any alternative to refs
Moisés Man
@moigithub
Aug 03 2017 11:54
controlled component, n keep the value on a state
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:55
@moigithub hmm you mean i add an onChange method to that textArea and keep updating the state ? / something similar
Moisés Man
@moigithub
Aug 03 2017 11:55
ye
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:57
@moigithub ok... is there any alternative solution, i have a save button i want to be able to get the value of that textArea component on click of that save button
Moisés Man
@moigithub
Aug 03 2017 11:58
controlled components or refs are ur 2 alternatives
Jianhao Tan
@jaanhio
Aug 03 2017 11:58
i am trying to implement the edit recipe function. However, cant seem to be able to edit the values after trying to populate it in the field
Abhinav Mishra
@abhinav-m
Aug 03 2017 11:58
@moigithub ok!
@moigithub ty!
CamperBot
@camperbot
Aug 03 2017 11:59
abhinav-thinktank sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3549 | @moigithub |http://www.freecodecamp.com/moigithub
Jianhao Tan
@jaanhio
Aug 03 2017 11:59
<EditRecipe recipe={this.props.recipe} editRecipe={this.editRecipe.bind(this, this.props.recipe.id)}/>

lass RecipeEdit extends Component{

  constructor(props){
    super(props);
    this.state = {
      revisedRecipe:[],
      modalIsOpen: false,
      speed: 100
    };
    this.openModal = this.openModal.bind(this);
    this.closeModal = this.closeModal.bind(this);
  }

  openModal(){
    this.setState({modalIsOpen: true});
  }

  closeModal(){
    this.setState({modalIsOpen: false});
  }

  handleSubmit(e){
    if(this.refs.recipeName.value === ""){
      alert("Recipe name is required!");
    }
    else{
      this.setState({revisedRecipe:{
        id: uuid.v4(),
        food: this.refs.recipeName.value,
        ingredients: this.refs.ingredients.value.split(","),
        modalIsOpen: false
      }}, function(){
        this.props.editRecipe(this.state.revisedRecipe);
      });
    }
    e.preventDefault();
  }




  render(){
    const speed = this.state.speed;
    let recipe=this.props.recipe;
    let foodName=recipe.food;
    let ingredients=recipe.ingredients;

    return(
      <div>
        <button className="button is-primary" onClick={this.openModal}>Edit Recipe</button>
        <Modal
          isOpen={this.state.modalIsOpen}
          onAfterOpen={this.afterOpenModal}
          onRequestClose={this.closeModal}
          closeTimeoutMS={speed}
          contentLabel="Example Modal"
        >
        <div className="field">
          <h2 className="title is-2">Edit Recipe</h2>
          <form onSubmit={this.handleSubmit.bind(this)}>
            <label className="label">Recipe</label>
            <div className="control">
              <input className="input" type="text" placeholder="Recipe Name" ref="recipeName" value={foodName}/>
            </div>
            <div className="field">
            <label className="label">Ingredients</label>
            <div className="control has-icons-left has-icons-right">
              <input className="input" type="text" placeholder="Enter ingredients. (if more than 1 ingredient, separate them with commas)" ref="ingredients" value={ingredients}/>
              <span className="icon is-small is-left">
                <i className="fa fa-flask"></i>
              </span>
            </div>
            </div>
            <div className="field is-grouped">
              <div className="control">
                <button className="button is-primary" onClick={this.closeModal}>Edit Recipe</button>
              </div>
              <div className="control">
                <button className="button" onClick={this.closeModal}>Cancel</button>
              </div>
            </div>
            </form>
        </div>
        </Modal>
      </div>
    );
  }
}

export default RecipeEdit;
how do i make it such that it populates the edit form and still allows for editing?
Moisés Man
@moigithub
Aug 03 2017 12:01
@jaanhio u need to implement onchange event too on ur inputs
read about controlled components
Jianhao Tan
@jaanhio
Aug 03 2017 12:01
@moigithub ok! lemme give it a try
one question, when do we have to declare this.handleClick.bind(this) in the constructor props?
is it correct to say that for the code above, if onClick={this.closeModal.bind(this)}, i do not have to declare this.closeModal.bind(this) in the constructor prop?
Moisés Man
@moigithub
Aug 03 2017 12:08
u only need to bind it once, u can do on constructor or on the event
some guides recommends to do in the constructor, cuz it only bind 1 time (and not everytime it rerenders)
Jianhao Tan
@jaanhio
Aug 03 2017 12:29
@moigithub do you mind showing me how i can implement the onChange for the recipe name and recipe ingredients input?
im still stuck
Jianhao Tan
@jaanhio
Aug 03 2017 13:03
@moigithub thanks
CamperBot
@camperbot
Aug 03 2017 13:03
jaanhio sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3550 | @moigithub |http://www.freecodecamp.com/moigithub
Jianhao Tan
@jaanhio
Aug 03 2017 13:03

<EditRecipe recipe={this.props.recipe} editRecipe={this.editRecipe.bind(this, this.props.recipe.id)}/>

can i ask what does the second argument in bind mean? referring to this.props.recipe.id portion

Darth Skywalker
@AdiSkywalker
Aug 03 2017 13:05
@jaanhio 2nd argument (and onward) passed to bind will passed to the function as parameters
While 1st argument to bind will become value of this of that function
Jianhao Tan
@jaanhio
Aug 03 2017 13:06
@AdiSkywalker i see. so there is no limit to the number of argument that can be passed?
Darth Skywalker
@AdiSkywalker
Aug 03 2017 13:07
@jaanhio Nope.. No limit
Jianhao Tan
@jaanhio
Aug 03 2017 13:11
@AdiSkywalker thank you
CamperBot
@camperbot
Aug 03 2017 13:11
jaanhio sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Jianhao Tan
@jaanhio
Aug 03 2017 13:24

how to pass my edited recipe up?

from EditRecipe.js

handleSubmit(e){
    if(this.state.revisedRecipe.food === ""){
      alert("Recipe name is required!");
    }
    else{
        this.props.editRecipe(this.state.revisedRecipe);
      };
      e.preventDefault();
  }
<EditRecipe recipe={this.props.recipe} editRecipe={this.editRecipe.bind(this, this.props.recipe.id, recipe)}/>
  editRecipe(id, recipe){
    this.props.onEdit(id, recipe);
  }
handleEditRecipe(id, recipe){
    let recipes = this.state.recipes;
    let index = recipes.findIndex(x => x.id === id);
    recipes.splice(index,1,recipe);
    this.setState({recipes: recipes});
  }
Stephen James
@sjames1958gm
Aug 03 2017 13:40
editRecipe={this.handleEditRecipe.bind(this, this.props.recipe.id)} - seems that you should pass the reference to handleEditRecipe to EditRecipe
Then in handleSubmit:
this.props.editRecipe(this.state.revisedRecipe);
If you want to bind the id to the function you can also do that.
Ginger
@GingerChew
Aug 03 2017 13:58
Hey I'm trying to use darksky's skycons in my codepen but I can't find any docs on how to use them? can I get some help? https://codepen.io/WatchConnorCode/pen/LLqmKE?editors=0010
Will Waymel
@willwaymel
Aug 03 2017 14:03
@GingerChew did you see this? https://github.com/darkskyapp/skycons
AdamCS
@csikos3d
Aug 03 2017 14:05
@sjames1958gm hi, I am just not able to interpret your code idea for using map() method to iterate the JSON for the trainNumbers. Would You pls check it? My goal is to have a reusable array about all of the train number values... https://codepen.io/csikos/pen/gxwjOP?editors=0011
Stephen James
@sjames1958gm
Aug 03 2017 14:07
@csikos3d You don't use return in arrow function when you don't have {}
Also, if you need to use the array elsewhere you'll need to define it outside the getJSON
var trainNumbers = [];

 $.getJSON(sloUrl, function(stat) {

           trainNumbers = stat.map((train) => train.trainNumber);
   console.log(trainNumbers);

});
Ginger
@GingerChew
Aug 03 2017 14:11
@willwaymel yeah, I wasn't able to understand what that was suggesting I do
Stephen James
@sjames1958gm
Aug 03 2017 14:12
@GingerChew Here is some code from their site simplified.
https://codepen.io/silgarth/pen/VzKgKG?editors=1010
Will Waymel
@willwaymel
Aug 03 2017 14:13
@GingerChew looks like you have to link to the library in your javascript settings to this https://cdnjs.cloudflare.com/ajax/libs/skycons/1396634940/skycons.js
@GingerChew was going to say the same --- https://codepen.io/jeremylshepherd/pen/gaYqvP?editors=1010
AdamCS
@csikos3d
Aug 03 2017 14:14
@sjames1958gm thanks, I was close (i had an almost similar version previously). the problem was I didnt know the "arrow function". You saved me again, but i am MUCH farther from the end of this project just i was at tomorrow night ;-D this is how programing feels :-D
CamperBot
@camperbot
Aug 03 2017 14:14
csikos3d sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8230 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 03 2017 14:14
@csikos3d :)
Ginger
@GingerChew
Aug 03 2017 14:15
@willwaymel okay so I've done that, linked the library and added that code, but they still aren't showing up? even when I specifically call a single type of icon
nvm, was missing a freaking comma
Will Waymel
@willwaymel
Aug 03 2017 14:19
@GingerChew lol... i was looking for it
Ginger
@GingerChew
Aug 03 2017 14:21
@willwaymel thanks m8
CamperBot
@camperbot
Aug 03 2017 14:21
:cookie: 324 | @willwaymel |http://www.freecodecamp.com/willwaymel
gingerchew sends brownie points to @willwaymel :sparkles: :thumbsup: :sparkles:
Will Waymel
@willwaymel
Aug 03 2017 14:21
@GingerChew np
pramod goyal
@nightraven112
Aug 03 2017 14:26
hello guyz
i needed a bit of help
how shall i start making a code
to factoralize a number
adityac0620
@adityac0620
Aug 03 2017 14:29

Could anyone point out why this program does not work

``` function truthCheck(collection, pre)
{
// Is everyone being true?
//var td=false;
var ts;
var tp;
for (var i = 0; i < collection.length; i++)
{
ts = collection[i];
if (ts.hasOwnProperty(pre) && ts[pre] != null && ts[pre] != "")
{}
else
{
return false;
}
}
return true;
}

truthCheck([{"single": "double"}, {"single": NaN}], "single"); ```

Kelechi Chinaka
@ke1echi
Aug 03 2017 14:30
what have you done? @nightraven112
Pieter Stokkink
@forkerino
Aug 03 2017 14:31
@adityac0620 there are more falsy values than just null and empty string
false,NaN,undefined,0
remember the falsy bouncer exercise?
Blauelf
@Blauelf
Aug 03 2017 14:37
@nightraven112 There are two definitions of the factorial, and they are equivalent.
  1. (iterative) The factorial n!n! is given as the product of all integers up to nn. n!=12nn!=1\cdot2\cdot\ldots\cdot n. You'd have a variable holding the product, and multiply-assign numbers in a loop.
  2. (recursive) The factorial n!n! is given as the product of nn and (n1)!(n-1)!, with 0!=10!=1 as a base case. If n>0n>0, you'd call the function itself in your return statement, making it recursive.

To the more advanced on this channel: Is this proper tail call recursion?

const factorialize = (n, fact=1) => (n > 0 ? factorialize(n - 1, fact * n) : fact);

Not that many JavaScript engines supported tail call optimisation...

Darth Skywalker
@AdiSkywalker
Aug 03 2017 14:44
Another way
function fact(n){
  return n > 0 ? n * fact(n-1) : 1;
}

fact(5); // 120
Blauelf
@Blauelf
Aug 03 2017 14:45
That's not tail call recursion. The call to the function is not the last step, the multiplication comes after.
Darth Skywalker
@AdiSkywalker
Aug 03 2017 14:46
I never claimed it is.
Besides, I never understood the need to optimization on recursive functions.
Blauelf
@Blauelf
Aug 03 2017 14:47
That's true, you didn't. I still wanted to mention it. At the current point, there is probably no benefit in tail calls either.
dmitryt
@dmitryt
Aug 03 2017 14:47
@adityac0620 I think it works as expected. I launched it in Chrome console. It returned true
Darth Skywalker
@AdiSkywalker
Aug 03 2017 14:48
Recursion is not meant to be performant to begin with.. It's just more... expressive
Jianhao Tan
@jaanhio
Aug 03 2017 14:48
@AdiSkywalker what do you mean by more expressive?
Darth Skywalker
@AdiSkywalker
Aug 03 2017 14:49
@jaanhio You look at the code and you typically don't have to run it mentally to understand what's going on.
If the recursive code can express that, you have done recursion right.. Else.... nvm
Blauelf
@Blauelf
Aug 03 2017 14:49
@AdiSkywalker Tail call optimisation, in theory, allows you to replace a function call with a simple jump, which is much faster. Less call stack magic required. Nobody seems too sure how to apply that to JavaScript it seems.
Darth Skywalker
@AdiSkywalker
Aug 03 2017 14:51
Yeah.. Theoretically, I understand it very well... Never really got around doing that in JS at least...
Sonja
@sonjaSch
Aug 03 2017 14:51
````
Darth Skywalker
@AdiSkywalker
Aug 03 2017 14:51
I used to write dom tree parsers but saw no spectacular perf improvements in both type of recursions.
Sonja
@sonjaSch
Aug 03 2017 14:52

let ohStr = "Ohhhhhhh no";
let ohRegex = /h{3,6}/; // Change this line
let result = ohRegex.test(ohStr);
ohStr should not match.... :worried: what i'm doing wrong
Blauelf
@Blauelf
Aug 03 2017 14:53
@sonjaSch Why shouldn't it match? There are between 3 and 6 (both inclusive) h in a row.
Sonja
@sonjaSch
Aug 03 2017 14:54
@Blauelf the test say it should not match
Blauelf
@Blauelf
Aug 03 2017 14:54
Then you have the wrong regular expression. What are you supposed to match?
Pieter Stokkink
@forkerino
Aug 03 2017 14:56

Is this proper tail call recursion?

@Blauelf I would say so.

Blauelf
@Blauelf
Aug 03 2017 14:59
@sonjaSch You are meant to match "Oh no" with between 3 and 6 h. I think they meant something like /^Oh{3,6} no$/. The line start ^ and line end $ are probably not required.
@sonjaSch Your regular expression would also match for "Ahhhhhhhh I got it!" with more than 6 h ;) (it would match just the first six, but has no restrictions on what comes before or behind)
AdamCS
@csikos3d
Aug 03 2017 15:01
Someone has idea why i get undefined when I append the arrays althought the consol.log show those?
https://codepen.io/csikos/pen/gxwjOP?editors=0011
Stephen James
@sjames1958gm
Aug 03 2017 15:02
@csikos3d trainNumbers is not updated until the getJSON request returns, but your append runs immediately
If you want to use trainNumbers to render something do that in the callback
Sonja
@sonjaSch
Aug 03 2017 15:03
@Blauelf thank u :smile:
CamperBot
@camperbot
Aug 03 2017 15:03
sonjasch sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4553 | @blauelf |http://www.freecodecamp.com/blauelf
Stephen James
@sjames1958gm
Aug 03 2017 15:03
@csikos3d call append() right after your .map call
AdamCS
@csikos3d
Aug 03 2017 15:05
@sjames1958gm jeeeeeee :-DDDDDD thx with this i am ALMOST there where I was last night :-D
CamperBot
@camperbot
Aug 03 2017 15:05
csikos3d sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: csikos3d already gave sjames1958gm points
Stephen James
@sjames1958gm
Aug 03 2017 15:06
@csikos3d lol
Blauelf
@Blauelf
Aug 03 2017 15:07
@csikos3d Forgot to save last night?
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:26
String.prototype.toJadenCase = function () {
  //...
  var str = "How can mirrors be real if our eyes aren't real";
  return str.split(' ').map((element) => {
    return element[0].toUpperCase() + element.slice(1);
  }).join(' ');
};
guys am new to prototypes...it passes but fails random test..why?
Pieter Stokkink
@forkerino
Aug 03 2017 15:28
@kelechy I think you need to use this instead of hardcoding a string
Darth Skywalker
@AdiSkywalker
Aug 03 2017 15:28
@kelechy
String.prototype.toJadenCase = function () {
  //...

  return this.toLowerCase().split(' ').map((element) => {
    return element[0].toUpperCase() + element.slice(1);
  }).join(' ');
};
Pieter Stokkink
@forkerino
Aug 03 2017 15:28
^^
Darth Skywalker
@AdiSkywalker
Aug 03 2017 15:29
str shouldn't be defined inside the function and the string which call this function on will become this inside your function.
Gurpreet SIngh
@Gurpreet3131
Aug 03 2017 15:30
How can I check, whether the checkbox is ticked or not, in nodejs express
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:30
still not clear @forkerino @AdiSkywalker still does not pass
Darth Skywalker
@AdiSkywalker
Aug 03 2017 15:31
@kelechy post your full code
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:31
can i send u the kata link? @forkerino
Pieter Stokkink
@forkerino
Aug 03 2017 15:31
@kelechy sure
Stephen James
@sjames1958gm
Aug 03 2017 15:32
@Gurpreet3131 nodejs / express is the backend, checkboxes are front-end?
i need to get cleared on prototypes
Darth Skywalker
@AdiSkywalker
Aug 03 2017 15:33
@kelechy seems to pass all for me
Pieter Stokkink
@forkerino
Aug 03 2017 15:34
@kelechy code very similar to @AdiSkywalker 's worked for me!
@kelechy show your full code if you got any problems.
Stephen James
@sjames1958gm
Aug 03 2017 15:34
@kelechy Same here, passed
String.prototype.toJadenCase = function () {
  return this.toLowerCase().split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' ');
};
@kelechy Did you add the toLowerCase()?
Well toLowerCase doesn't matter
Darth Skywalker
@AdiSkywalker
Aug 03 2017 15:36
@sjames1958gm I added it...
Stephen James
@sjames1958gm
Aug 03 2017 15:36
@AdiSkywalker yes, but appears that it doesn't need it to pass the test.
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:36
String.prototype.toJadenCase = function () {
  //...
  var str = "How can mirrors be real if our eyes aren't real";
  return str.split(' ').map((element) => {
    return element[0].toUpperCase() + element.slice(1);
  }).join(' ');
};
Pieter Stokkink
@forkerino
Aug 03 2017 15:36
@kelechy that's your old code
it should have this
not str
Stephen James
@sjames1958gm
Aug 03 2017 15:37
@kelechy this holds the string in a prototype function
Darth Skywalker
@AdiSkywalker
Aug 03 2017 15:37
@sjames1958gm Yeah.. I hadn't looked at kata requirement and confused it with title case
Stephen James
@sjames1958gm
Aug 03 2017 15:37
@AdiSkywalker I would have done the same, the kata says nothing about it but I would have assumed the same biased by title case challenge
Darth Skywalker
@AdiSkywalker
Aug 03 2017 15:37
@kelechy return str.split(' ') should be return this.split(' ')
@sjames1958gm right :+1:
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:38
ooohhh
so this is more like the reference
Gurpreet SIngh
@Gurpreet3131
Aug 03 2017 15:39
@sjames1958gm yes checkbox are front, i am using handlebars
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:39
thanks guys @sjames1958gm @forkerino @AdiSkywalker
CamperBot
@camperbot
Aug 03 2017 15:39
kelechy sends brownie points to @sjames1958gm and @forkerino and @adiskywalker :sparkles: :thumbsup: :sparkles:
:star2: 2912 | @forkerino |http://www.freecodecamp.com/forkerino
:cookie: 327 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
:star2: 8231 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Pieter Stokkink
@forkerino
Aug 03 2017 15:39
@kelechy the idea when you create a prototype is that you can call it on instances of the object (and strings are implicitly converted to objects when you call methods on them). It is just like a class method where this refers to the instance of the class.
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:39
prototype noob :smile:
Moisés Man
@moigithub
Aug 03 2017 15:40
String.prototype.toJadenCase  = function (){
    return this.replace(/^[a-z]|\s[a-z]/g, s=>s.toUpperCase())
}
probably can refactor regex to (^|\s)[a-z]
Stephen James
@sjames1958gm
Aug 03 2017 15:42
@Gurpreet3131 You will have to send something from the front end (POST for form submission) or some sort of API request.
What are you expecting nodejs/express to do with the checkbox.
Gurpreet SIngh
@Gurpreet3131
Aug 03 2017 15:44
@sjames1958gm I want to assign value depending upon whether the checkbox is marked or not
Stephen James
@sjames1958gm
Aug 03 2017 15:45
@Gurpreet3131 So, from a form submission? POST?
Gurpreet SIngh
@Gurpreet3131
Aug 03 2017 15:45
@Gurpreet3131 req.body.checkbox is giving me one value if its marked but if unmarked it gives undefined
@sjames1958gm req.body.checkbox is giving me one value if its marked but if unmarked it gives undefined
Moisés Man
@moigithub
Aug 03 2017 15:46
@kelechy an easier way to "remember" what this is.. is "left side of the dot"
soo if u do "hello world".toJadenCase() this will refer to the string "hello world"
Gurpreet SIngh
@Gurpreet3131
Aug 03 2017 15:46
@sjames1958gm check your pm
@Gurpreet3131 If its undefined, assume it is not set
Kelechi Chinaka
@ke1echi
Aug 03 2017 15:47
hmm..true thanks @moigithub
CamperBot
@camperbot
Aug 03 2017 15:47
kelechy sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3551 | @moigithub |http://www.freecodecamp.com/moigithub
Gurpreet SIngh
@Gurpreet3131
Aug 03 2017 15:48
@sjames1958gm oh ok. thanks
CamperBot
@camperbot
Aug 03 2017 15:48
gurpreet3131 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8232 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 03 2017 15:49
@Gurpreet3131 It appears there are sneakier ways to do it. But, probably this is sufficient?
Abhinav Mishra
@abhinav-m
Aug 03 2017 16:04
 this.setState({
      newRecipe:{title:this.state.newRecipeTitle.trim(),ingredients:trimmedIngredients.split("")}
      })
this setState method doesn't seem to set the newRecipe to what i've set
Abhinav Mishra
@abhinav-m
Aug 03 2017 16:39
anyone here
ashish singh
@ashish1729
Aug 03 2017 16:39
@abhinav-thinktank go on
Abhinav Mishra
@abhinav-m
Aug 03 2017 16:40
 this.setState({
      newRecipe:{title:this.state.newRecipeTitle.trim(),ingredients:trimmedIngredients.split("")}
      })
i was trying to setState on an object in my state like this
this didn't work
but this did:
sanitizeNewRecipe(value){
    var trimmedIngredients = this.state.newRecipeIngredients.split(",")
    trimmedIngredients.forEach(str => str.trim())
    var existingRecipe = this.state.newRecipe;
     existingRecipe.title = this.state.newRecipeTitle
      existingRecipe.ingredients = trimmedIngredients

    this.setState({
      newRecipe : existingRecipe
      })
  }
im confused to why
i know it has something to do with object references and immutability
essentially, earlier i was creating a new object and trying to assign it's reference to my state's object
and now im modifying the reference to my state object by storing it first
@ashish1729 any clue?
ashish singh
@ashish1729
Aug 03 2017 16:43
no i am thinking
try this ..
this.setState({
  newRecipe:{ingredients:trimmedIngredients.split("")}
})
does this part work?
Abhinav Mishra
@abhinav-m
Aug 03 2017 16:47
the above mentioned code is working..
ashish singh
@ashish1729
Aug 03 2017 16:53
oh
this.setState({
  newRecipe:'testing to contradict nested objects'
})
Abhinav Mishra
@abhinav-m
Aug 03 2017 16:56
@ashish1729 the only explanation i found was on a stack overflow question which said it isn't allowed
syntactically..
ashish singh
@ashish1729
Aug 03 2017 16:56
what is not allowed?
Abhinav Mishra
@abhinav-m
Aug 03 2017 16:57
im not sure if thats correct
it just said not allowed syntactically
ashish singh
@ashish1729
Aug 03 2017 16:57
what is not allowed syntactically
ashish singh
@ashish1729
Aug 03 2017 16:57
thanks .. let me have a look
Abhinav Mishra
@abhinav-m
Aug 03 2017 16:57
when you try to setState(object: { } )
looking for a better explanation
i think the explanation is : immutability
i can't assign a new reference to that value
but i can change the properties inside that reference
ashish singh
@ashish1729
Aug 03 2017 17:01
i am not sue
sorry
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:01
@ashish1729 ok
ashish singh
@ashish1729
Aug 03 2017 17:04
try this
var x = this.state.newRecipeTitle.trim();
var y = trimmedIngredients.split("");
 this.setState({
      newRecipe:{title:x,ingredients:y}
      })
Moisés Man
@moigithub
Aug 03 2017 17:04
on that link.. it says.. if u have a object on a state...
ie: myObj : {name: 'boo', age: 666}
u CANT change a single property value like
this.setState({ myObj.name: 'new name'}) <-- Wrong!
u need to reassign the WHOLE Object
this.setState({myObj : {...myObj, name: 'new name'}} :+1:
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:05
@moigithub yes, but then this should work right?
 this.setState({
      newRecipe:{title:"abc",ingredients:"xyz"}
      })
it wasn't..
newRecipe was unmodified while debugging
Christopher McCormack
@cmccormack
Aug 03 2017 17:06
@abhinav-thinktank how were you debugging? setState is asynch so make sure you debug after it's completed
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:07
@cmccormack well.. the thing is newRecipe had title : "" and ingredients as ingredients:""
Stephen James
@sjames1958gm
Aug 03 2017 17:07
@abhinav-thinktank The next render() call should show newRecipe set, but in the same function, no.
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:07
@sjames1958gm hmm.. it wasn't though
ill try to recreate that problem
sanitizeNewRecipe(value){
    var trimmedIngredients = this.state.newRecipeIngredients.split(",")
    trimmedIngredients.forEach(str => str.trim())
    var existingRecipe = this.state.newRecipe;
     existingRecipe.title = this.state.newRecipeTitle
      existingRecipe.ingredients = trimmedIngredients

    this.setState({
      newRecipe : existingRecipe
      })
  }
this was what worked..
Moisés Man
@moigithub
Aug 03 2017 17:08
u could pass a callback to setState to check "after" update
this.setState({...}, ()=>{
   console.log(this.state) //execute after setState complete
})
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:08
is my statement about immutability incorrect?
then?
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:14
@moigithub err i wanna do what you're trying to tell me
this.setState(
     { newRecipe : {title:this.state.newRecipeTitle,ingredients:trimmedIngredients}},{()=>console.log(this.state.newRecipe.title+""+this.state.newRecipe.ingredients)}
      )
...
Moisés Man
@moigithub
Aug 03 2017 17:16
callback is a function (2nd parameter)
this.setState (newstate, callbackFunction)
this.setState(
     { newRecipe: {...} } ,
     ()=>{ console.log(....) }
)
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:16
don't i need to wrap the whole thing in { }
Christopher McCormack
@cmccormack
Aug 03 2017 17:17
@abhinav-thinktank only the items you're changing, the second argument is a callback
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:17
oh ok.
@moigithub so
it is going to the callback, but the value is still the old one in the debugger
im changing the newRecipe as :-
    this.setState(
    { newRecipe :{title:this.state.newRecipeTitle,ingredients:trimmedIngredients} },
    ()=>{console.log(this.state.newRecipe.title+"test"+this.state.newRecipe.ingredients)}
      )
its stored in my state as ->
newRecipe: {title:"",ingredients:""} ,
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:23
it's still the same value unless i do the above mentioned code
var existingRecipe = this.state.newRecipe;
     existingRecipe.title = this.state.newRecipeTitle
      existingRecipe.ingredients = trimmedIngredients

    this.setState({
      newRecipe : existingRecipe
      })
only reason that is coming to my mind is immutability
:(
im gonna sleep on it..
@moigithub @cmccormack @sjames1958gm ty :D
CamperBot
@camperbot
Aug 03 2017 17:26
abhinav-thinktank sends brownie points to @moigithub and @cmccormack and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1098 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 3552 | @moigithub |http://www.freecodecamp.com/moigithub
:star2: 8233 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Christopher McCormack
@cmccormack
Aug 03 2017 17:27
perhaps your issue is you're attempting to use state within your setState, not sure. Without a pen or something it's hard for us to play with it to see :D
Stephen James
@sjames1958gm
Aug 03 2017 17:28
@abhinav-thinktank That code is mutating the existing state object, because existingRecipe and this.state.newRecipe refer to the same object
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:30
:|
so.. @moigithub you were right
i need to move everything in the callback..
@sjames1958gm it was indeed being called before the setState() completed
:|
god...
@sjames1958gm @cmccormack @moigithub ty
CamperBot
@camperbot
Aug 03 2017 17:30
abhinav-thinktank sends brownie points to @sjames1958gm and @cmccormack and @moigithub :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave cmccormack points
:warning: abhinav-thinktank already gave moigithub points
:warning: abhinav-thinktank already gave sjames1958gm points
Stephen James
@sjames1958gm
Aug 03 2017 17:30
:+1:
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:31
im resetting the value in a chain of function calls after it..
Joseph
@Big-jo
Aug 03 2017 17:31
how can i use local storage to object propertie
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:31
should i move all those to the callback?
or should i use the method im using in the code above

ie

@abhinav-thinktank That code is mutating the existing state object, because existingRecipe and this.state.newRecipe refer to the same object

should i mutate it directly.. heard thats not a good practice
Christopher McCormack
@cmccormack
Aug 03 2017 17:32

@Big-jo

window.localStorage.setItem('storedObj', JSON.stringify(storedObj))
obj = JSON.parse(window.localStorage.storedObj)

this what you're looking for?

Abhinav Mishra
@abhinav-m
Aug 03 2017 17:32
sorry for the bad question , bit tired :D
Christopher McCormack
@cmccormack
Aug 03 2017 17:33
@abhinav-thinktank I think most of us have ran into issues with setState :D
Joseph
@Big-jo
Aug 03 2017 17:34
@cmccormack thanks
CamperBot
@camperbot
Aug 03 2017 17:34
big-jo sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1099 | @cmccormack |http://www.freecodecamp.com/cmccormack
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:34
@cmccormack yeah i have been debugging for a while now
Christopher McCormack
@cmccormack
Aug 03 2017 17:34
I honestly still have several questions but have just worked around them until I ask later
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:34
aah
yeah, atleast i learnt alot
:D
Joseph
@revisualize
Aug 03 2017 17:35
hi.
Joseph
@Big-jo
Aug 03 2017 17:35
@cmccormack so 'recipes' is an object
Christopher McCormack
@cmccormack
Aug 03 2017 17:36
@revisualize hiya
@Big-jo oops was parsing from my recipe site :)
@Big-jo I changed it to 'storedObj'. 'storedObj' is the property name you're adding so you can reference it again when you want to load it
Jason Luboff
@JLuboff
Aug 03 2017 17:37
@revisualize How's the arm healing?
Joseph
@Big-jo
Aug 03 2017 17:37
@cmccormack can you show me another example?
Stephen James
@sjames1958gm
Aug 03 2017 17:37
@abhinav-thinktank No you should not mutate it directly, but that is why it looked like it was working.
Christopher McCormack
@cmccormack
Aug 03 2017 17:38
@Big-jo I don't really have another example but it's pretty straight forward
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:38
@sjames1958gm what should be my approach in this case
Joseph
@Big-jo
Aug 03 2017 17:38
@cmccormack so i can't just save the entire objects
Stephen James
@sjames1958gm
Aug 03 2017 17:39
@abhinav-thinktank If you do setState, then when render is called it should be set.
You should be careful not to mutate the state - for example, using splice on an array stored in your state.
Christopher McCormack
@cmccormack
Aug 03 2017 17:39
var obj = {a: 'a', b: 'b', c: [1,2,3]}
// Stores obj as text within storedObj property in local storage
window.localStorage.setItem('storedObj', JSON.stringify(obj))
// Reads storedObj as text and parses it into an object to store in storedObj variable
var storedObj = JSON.parse(window.localStorage.storedObj)
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:40
@sjames1958gm aah, i need some sleep now. I'll work on a few solutions and post here if they seem bad
thanks!
Stephen James
@sjames1958gm
Aug 03 2017 17:40
@abhinav-thinktank :sleeping:
Abhinav Mishra
@abhinav-m
Aug 03 2017 17:40
goodnight :+1:
Stephen James
@sjames1958gm
Aug 03 2017 17:40
G'night
Christopher McCormack
@cmccormack
Aug 03 2017 17:40
@Big-jo sorry I may be using confusing variable names see if the update makes more sense
Joseph
@revisualize
Aug 03 2017 17:42
@JLuboff I don't know really. It hurts pretty bad.
Joseph
@Big-jo
Aug 03 2017 17:43
please*
@cmccormack where's the updated example
Jason Luboff
@JLuboff
Aug 03 2017 17:43
@revisualize Did you have to get screws/plate(s)?
Joseph
@revisualize
Aug 03 2017 17:43
@JLuboff yup
Jason Luboff
@JLuboff
Aug 03 2017 17:43
Ah...that could be why
Joseph
@revisualize
Aug 03 2017 17:44
12 to 15 screws.
Jason Luboff
@JLuboff
Aug 03 2017 17:44
Dang
Christopher McCormack
@cmccormack
Aug 03 2017 17:45
@Big-jo I modified my comments above
Joseph
@Big-jo
Aug 03 2017 17:46
Hey guys, so basically i'm working on a project , i want to get input from some text boxes and save it to local storage using javascript. Is it possible.
Jason Luboff
@JLuboff
Aug 03 2017 17:47
@Big-jo Yes...but don't ask me how :D
Christopher McCormack
@cmccormack
Aug 03 2017 17:48
@Big-jo did you even look at my code above? It's not very complicated, do you have questions about how it works?
Joseph
@Big-jo
Aug 03 2017 17:49
@cmccormack no it's okay, i'm looking at it now thanks a bunch
CamperBot
@camperbot
Aug 03 2017 17:49
big-jo sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: big-jo already gave cmccormack points
Christopher McCormack
@cmccormack
Aug 03 2017 17:50
@Big-jo np
Gurpreet SIngh
@Gurpreet3131
Aug 03 2017 17:56
Can anyone help me with handlebars?
with nodejs express framework
Jason Luboff
@JLuboff
Aug 03 2017 17:58
@revisualize Gnarly
Joseph
@Big-jo
Aug 03 2017 18:03
@cmccormack i just used it now but after i hit the submit button, i doesn't clear the textboxes
image.png
Christopher McCormack
@cmccormack
Aug 03 2017 18:08
@Big-jo you have to make it do that
you can use .value = ''
EpicTriffid
@EpicTriffid
Aug 03 2017 18:12
Is the logic of this sound in anyway?
var numArr = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  ];

function convertToRoman(num) {
  var romNum = [];
  var str = num.toString().split("").reverse();
  for (var i = 0; i <= num.length; i++) {
    if (num[i] < 10) {
      romNum.push(numArr(num[i]));
    }
  }
  return romNum;
}

convertToRoman(36);
Stephen James
@sjames1958gm
Aug 03 2017 18:20
@EpicTriffid That is a workable solution, you will need to have 10s, 100s, etc.
Also, you have to watch for zeros
EpicTriffid
@EpicTriffid
Aug 03 2017 18:21
@sjames1958gm So i'm right in thinking i can go through the numerals array and select the one that is at the index specified by the number?
Stephen James
@sjames1958gm
Aug 03 2017 18:22
@EpicTriffid Yes, just remember that arrays are zero indexed
Joseph
@Big-jo
Aug 03 2017 18:22
@cmccormack how?
Pieter Stokkink
@forkerino
Aug 03 2017 18:22
I'm gonna do a write up to answer some questions @revisualize had for me relating to how I learned to code and how I got my coding job. If you have any questions you would like me to answer, please let me know!
Christopher McCormack
@cmccormack
Aug 03 2017 18:22
@Big-jo you should research how to access values in an input. I believe at least one of the FCC exercises has you do this
Jason Luboff
@JLuboff
Aug 03 2017 18:25
@forkerino Whats the deal with frites and mayo and how does it relate to programming? (btw...mayo over there is tasty)
EpicTriffid
@EpicTriffid
Aug 03 2017 18:26
@sjames1958gm awesome. thankyou :) Currently im not getting anything returning. Im guessing there's a fundamental error there in my code?
CamperBot
@camperbot
Aug 03 2017 18:26
epictriffid sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8234 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Pieter Stokkink
@forkerino
Aug 03 2017 18:27
@JLuboff :joy: I'm not gonna put it in the write up, but mayo is basically the best on fries. But you gotta have good quality (both the fries and the mayo). I don't see a connection with coding.
Stephen James
@sjames1958gm
Aug 03 2017 18:28
@EpicTriffid num.length?
EpicTriffid
@EpicTriffid
Aug 03 2017 18:28
@sjames1958gm Thats the problem?
Stephen James
@sjames1958gm
Aug 03 2017 18:29
@EpicTriffid num is a number has no length, perhaps str is the item you need to loop over
Christopher McCormack
@cmccormack
Aug 03 2017 18:29
@forkerino try Sriracha+Mayo, yum!
EpicTriffid
@EpicTriffid
Aug 03 2017 18:30
@sjames1958gm facepalm
Jason Luboff
@JLuboff
Aug 03 2017 18:30
@forkerino :joy: Fair enough. There was a place by Artis we ate that had good mayo/fries. And a fancy burger place near where were staying
Pieter Stokkink
@forkerino
Aug 03 2017 18:31
@cmccormack I will! I love some good hot chili!
Kelechi Chinaka
@ke1echi
Aug 03 2017 18:33
how and why did you learn to code? @forkerino
Christopher McCormack
@cmccormack
Aug 03 2017 18:33
I think I'm done with my dungeon project, you guys mind taking one last look? https://mackville.net/react/dungeon/
EpicTriffid
@EpicTriffid
Aug 03 2017 18:34
@cmccormack That looks amazing bud
Christopher McCormack
@cmccormack
Aug 03 2017 18:35
@EpicTriffid thanks :)
CamperBot
@camperbot
Aug 03 2017 18:35
cmccormack sends brownie points to @epictriffid :sparkles: :thumbsup: :sparkles:
:cookie: 272 | @epictriffid |http://www.freecodecamp.com/epictriffid
Jason Luboff
@JLuboff
Aug 03 2017 18:36
@cmccormack What is this...a game for ants?
EpicTriffid
@EpicTriffid
Aug 03 2017 18:36
@JLuboff Bwahahahaha
Christopher McCormack
@cmccormack
Aug 03 2017 18:37
@JLuboff yes!
I should call it Ant Dungeon or something
Jason Luboff
@JLuboff
Aug 03 2017 18:37
:joy:
Pieter Stokkink
@forkerino
Aug 03 2017 18:38
@kelechy :+1:
will answer it!
Christopher McCormack
@cmccormack
Aug 03 2017 18:38
one bug with the page is zooming in and out with Chrome, for some reason the browser doesn't respect certain styles at different zoom levels
Ronique Ricketts
@RoniqueRicketts
Aug 03 2017 18:38
@cmccormack nice react game man I likex it
Christopher McCormack
@cmccormack
Aug 03 2017 18:38
@RoniqueRicketts thanks man
CamperBot
@camperbot
Aug 03 2017 18:38
cmccormack sends brownie points to @roniquericketts :sparkles: :thumbsup: :sparkles:
:cookie: 333 | @roniquericketts |http://www.freecodecamp.com/roniquericketts
Ronique Ricketts
@RoniqueRicketts
Aug 03 2017 18:40
@cmccormack I am still playing it hehee
Jason Luboff
@JLuboff
Aug 03 2017 18:40
@forkerino Ok, I have a serious question. What did you feel was the best learning environment? When experiencing burn out, how did you step back and regroup yourself?
Ronique Ricketts
@RoniqueRicketts
Aug 03 2017 18:41
Is something wrong with this https://www.freecodecamp.org/challenges/drop-it @camperbot
Christopher McCormack
@cmccormack
Aug 03 2017 18:41
@RoniqueRicketts try and beat it! @forkerino made me add an extra level and so I decided to also make it slightly more difficult, but I didn't test it much :)
EpicTriffid
@EpicTriffid
Aug 03 2017 18:41
@sjames1958gm It's kind of working!
var numArr = [
  '','I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
];

function convertToRoman(num) {
  var romNum = "";
  var str = num.toString().split("").reverse();
  str.forEach(function(dig) {
    if (dig < 10) {
      romNum = numArr[dig];
    }
  });
  return romNum;
}

convertToRoman(2);