These are chat archives for FreeCodeCamp/HelpJavaScript

6th
Aug 2018
Dan Couper
@DanCouper
Aug 06 2018 00:42
What do you mean @Lia-Sue-Kim
Dr-D-M
@Dr-D-M
Aug 06 2018 02:13
hello there, humans I've got a really silly question
what is a markdown preview? I don't quite get it
abraham anak agung
@padunk
Aug 06 2018 02:18
Dr-D-M
@Dr-D-M
Aug 06 2018 02:19
I read that, but honestly I don't understand it
abraham anak agung
@padunk
Aug 06 2018 02:25
@Dr-D-M if you look at the example, you can write ## sub-heading instead of <h2>sub-heading</h2> it makes you easier to type and convert it to html
This gitter also use markdown.
Dr-D-M
@Dr-D-M
Aug 06 2018 03:16
oh I see
@padunk thanks a lot
Simon Cordova
@gbsimon87
Aug 06 2018 07:09
Morning
ATom M
@ATom-M
Aug 06 2018 08:26
Morning :)
Jason Luboff
@JLuboff
Aug 06 2018 15:10
Morning :wave:
Simon Cordova
@gbsimon87
Aug 06 2018 15:39
whats up whats up
Jason Luboff
@JLuboff
Aug 06 2018 15:49
@gbsimon87 Monday morning blues
Simon Cordova
@gbsimon87
Aug 06 2018 15:49
@JLuboff Man I've done it all today
An hour each on Sass, Redux, Typescript, Webpack, and NodeJS
I was excited today, I got a second offer actually!
Jason Luboff
@JLuboff
Aug 06 2018 15:50
Thats awesome man, congrats
Simon Cordova
@gbsimon87
Aug 06 2018 15:51
Yeah man, sticking with the first, but when it rains it pours
Went 2.5 months with 0 chances
Anyways you're launching your app today no?
Jason Luboff
@JLuboff
Aug 06 2018 15:52
Better benefits/pay at the first?
And ya, its been launched. I had it all up and ready Friday evening but it was officially announced today
Simon Cordova
@gbsimon87
Aug 06 2018 15:53

Nice, is this an app for the company or for the public?

Pay is lower at the first tbh but it's very closeby I'm going to walk to work - just got a better vibe overall I guess

Jason Luboff
@JLuboff
Aug 06 2018 15:54
Its strictly for internal use
Simon Cordova
@gbsimon87
Aug 06 2018 15:55
Cool, and you built in and its getting used, that's amazing man good stuff
Jason Luboff
@JLuboff
Aug 06 2018 15:55
Well if you think you'll be happier there, than lower pay isn't always an issue. Plus you gotta factor in how much you would spend on transportation for the other job, etc
Ya its really cool actually haha
\
Simon Cordova
@gbsimon87
Aug 06 2018 15:56
Yeah I've cut the transportation time and cost out, which is nice.
My stats app is actually looking a bit better too, starting to implement the different categories now.
Jason Luboff
@JLuboff
Aug 06 2018 15:57
Sweet!
Henry
@GitHub-Henry
Aug 06 2018 16:53
@gbsimon87 walking sounds nice, so much better than a commute drive, contrats on the job
Simon Cordova
@gbsimon87
Aug 06 2018 16:56
@GitHub-Henry thank you - yeah I used to walk to my last job and it was sweet
Ozarion
@Ozarion
Aug 06 2018 17:13
How to submit solution in npm challenge? What link to submit? I'm copying the glitch.com project link and pasting it inside solution box but test case are not passing. What am I doing wrong?
Aditya
@ezioda004
Aug 06 2018 17:15
@Ozarion What link are you pasting? You need to paste the live preview link IIRC
Ozarion
@Ozarion
Aug 06 2018 17:15
Unexpected token < in JSON at position 0
Im on the first challenge.
in npm challenges. Challenge is to change the "author" field. I did it and submitted but no success passing test.
@ezioda004 What am I doing wrong? Can you help please?
Ozarion
@Ozarion
Aug 06 2018 17:21
@ezioda004 It worked :)
BTW If I want to do the project locally and keep it on github. What Link will I have to share? Will I have to make a git page?
Jason Luboff
@JLuboff
Aug 06 2018 17:23
@Ozarion just share your github repo
Ozarion
@Ozarion
Aug 06 2018 17:25
I tried that. It didn't work. Will I have to fork this project? https://github.com/freeCodeCamp/boilerplate-npm/
Henry
@GitHub-Henry
Aug 06 2018 17:25
@JLuboff would it be the github.io page of the repo?
Aditya
@ezioda004
Aug 06 2018 17:26
@Ozarion For these challenges I think you'll have to use glitch
Jason Luboff
@JLuboff
Aug 06 2018 17:26
No, to turn in projects that have two links, the first link is your glitch/heroku/whatever and the second is the direct github link of your repo.
Ozarion
@Ozarion
Aug 06 2018 17:27
@ezioda004 Got it.
Aditya
@ezioda004
Aug 06 2018 17:28
@JLuboff Just 1 link is fine for projects? I've been submitting both glitch and github links
Jason Luboff
@JLuboff
Aug 06 2018 17:29
@ezioda004 Thats correct, you have two seperate links one for glitch/heroku (I assume if the project has a testing module than it must be done in glitch? ) and the second is the github link
J. Guidry
@J-Guidry
Aug 06 2018 20:07

I want to take a integer input, looping that many times and each time, push into an array, a random integer between 1-4, but each time after the first, it will remember the other previous random integers and push into the array before pushing the new value. Something like this

/* 
    1. after getting input
    2. have that input be an argument for a function
        1. inside the function, declare empty array
        2. use input as loop condition for a loop
            1. choose at random 1-4 inclusive
            2. push into empty array
            3. 2nd time through and beyond, remember all previous values and
                        4. push previous values and new value into array
               3. return array
*/

I am having trouble how to express the remembering all previous values part in code.

Diego Mayer
@Chrono79
Aug 06 2018 20:19
Write an example with numbers
check if this is what you want @J-Guidry
let arr1 = [], arr2 = [], n = 5; // n is your input value
for (let i = 0; i < n; i++) {
  arr1.push(Math.floor(Math.random()*4 + 1));
  arr2.push(...arr1); // or arr2 = arr2.concat(arr1);
}
console.log(arr2);
J. Guidry
@J-Guidry
Aug 06 2018 20:26
Ill check that.
Ah that works. Thanks @Chrono79
Diego Mayer
@Chrono79
Aug 06 2018 20:29
No problem
Basically you use another array to keep the random values
J. Guidry
@J-Guidry
Aug 06 2018 20:30
ah, I was considering a 2nd array but wasn't sure if this would mean another loop or perhaps implementing a higher order function or something
newmoon
@newmoon
Aug 06 2018 20:34
Without a second array, the first one just needs to be outside of your function:
const arr = [];
function addRandomValuesToArray(n) {
  for (let i = 0; i < n; i++) {
    arr.push(Math.floor(Math.random() * 4 + 1));
  }
}

console.log(arr); // []
addRandomValuesToArray(4);
console.log(arr); // [4 random values]
addRandomValuesToArray(8);
console.log(arr); // [12 random values]
Diego Mayer
@Chrono79
Aug 06 2018 20:52
@newmoon your code doesn't do the same, I understood from what he wrote the array must store things like this (let's suppose the random gives you 1, 2, 3 and 4 in that order):
//with n = 4
[1, 1, 2, 1, 2, 3, 1, 2, 3, 4]
But I'm not sure if either of our proposed code was ok, the instructions weren't so clear, that's why I asked for an example of what was expected and gave it a shot with what I thought
J. Guidry
@J-Guidry
Aug 06 2018 21:15

The reason for my problem is that I want to implement s data/console version of the Simon game before I move on to implementing full version (html, css, click listeners). I was thinking of a window prompt that for each pass in the loop it will ask for the data from the passthrough. If wrong, it will break the loop. The reason for the random integers is so they substitute the 4 colors. something like this, using @Chrono79 's code with some additions:

function simon(input){
    let arr1 = [], arr2 = [], prompt;
    for (let i = 0; i < input; i++) {
      arr1.push(Math.floor(Math.random()*4 + 1));
      arr2.push(...arr1); // or arr2 = arr2.concat(arr1);
      console.log(arr2[i]);
      prompt = window.prompt("what is the sequence?");
      if(parseInt(prompt) !== arr2[i]){
            console.log(arr2[i]);
            console.log("You lose");
            break;
        } else {
            continue;
        }
    }
 console.log(arr2);
}

Only works when asking for a single number. if it was !== arr2, then it wouldn't work because the prompt is converted into an int, and not an array

Diego Mayer
@Chrono79
Aug 06 2018 21:18
you could use strings
instead of arrays
and ask for a string like 1213412
J. Guidry
@J-Guidry
Aug 06 2018 21:18
Yeah, convert the arr2[i] into a string with toString() instead of parseInt on prompt
Diego Mayer
@Chrono79
Aug 06 2018 21:19
but if the prompt remains in the screen is like cheating :P
It's ok, in the real app it won't stay there
J. Guidry
@J-Guidry
Aug 06 2018 21:19
yeah, heh, but in the full version, it will do the flashing color thing instead of the cheating
Diego Mayer
@Chrono79
Aug 06 2018 21:20
go for it then
newmoon
@newmoon
Aug 06 2018 21:21
@J-Guidry Maybe I'm misunderstanding, but with a Simon game, I imagine you would create the sequence of expected colors first. If the user guesses the sequence correctly, maintain a counter variable that checks the index of your already-generated sequence.
J. Guidry
@J-Guidry
Aug 06 2018 21:23
@newmoon Hmm, that could work too. i just want to have a solid theory before I go onto a full version.
Diego Mayer
@Chrono79
Aug 06 2018 21:24
That sounds good, what would the sequence length be? 100?
I don't think someone can memorize much more than that, but...
newmoon
@newmoon
Aug 06 2018 21:25
The original Simon game starts at 1 and goes to 20, I think
J. Guidry
@J-Guidry
Aug 06 2018 21:26
I was thinking of a settings input with a placeholder text that says no more than than a certain amount. 20 sounds like a good stop
Diego Mayer
@Chrono79
Aug 06 2018 21:27
It's your Simon after all, your rules
I don't remember if there was something about that
J. Guidry
@J-Guidry
Aug 06 2018 21:30
Hmm, testing that function again, it looks like the second time it asks for the sequnce, it wants the whole array like, if it asks for 1 the first time, and then it does 1, 2 the second time, it will want 1,1,2 as an answer
Diego Mayer
@Chrono79
Aug 06 2018 21:30
yes, it will
it will be better to create the sequence as @newmoon suggested and keep a count, then slice the string and check
J. Guidry
@J-Guidry
Aug 06 2018 21:33
Yeah, I'll try that.
newmoon
@newmoon
Aug 06 2018 21:54
I was thinking that turnCount would be the index of the sequence to check. No need to slice.
const randomColor = () => Math.floor(Math.random() * 4 + 1);
const sequence = [randomNum()];
let turnCount = 0;

function simon(input) {
  if(input == sequence[turnCount]) {
    turnCount++;
    if(turnCount > 20) winner();
    if(turnCount > sequence.length - 1) {
      sequence.push(randomColor());
      showSequence(); // resets turnCount to 0 and shows the user the colors to repeat
      return;
    }
    return;
  }
  showSequence();
}
J. Guidry
@J-Guidry
Aug 06 2018 21:59
I'm having some trouble understanding one of those lines. input == sequence[turncount]. sequence was assigned the random color which is in an array. Then, since the turnCount was set to 0, the zero index of the array is the random color, which is checked against the input. That randomColor is checked against the input for equality. Ok, I see. I needed to type that out to understand it
J. Guidry
@J-Guidry
Aug 06 2018 23:01
What is the purpose of that if statement that checks if turncount is greater than array length? I get that a new color is pushed into the sequence array, but why would turnCount reset for getting it right?
newmoon
@newmoon
Aug 06 2018 23:09
@J-Guidry Starting at the beginning, we have one random number in the sequence array. If the player inputs that number correctly, we increase the turnCount by 1. Now turnCount == 1 and sequence.length - 1 == 0. So, we know they got all the numbers in the sequence correct. Add another number, show the player the numbers they have to input, and reset the turnCount back to 0.
newmoon
@newmoon
Aug 06 2018 23:15
I maybe confused you above by saying that we generate all the random numbers first - this example generates a new random number to push onto the sequence only after all the current ones have been entered correctly.
(and we probably need to return after calling the winner() function) just noticed that bug
J. Guidry
@J-Guidry
Aug 06 2018 23:16
Oh I see, at the end.