These are chat archives for FreeCodeCamp/HelpJavaScript

24th
Nov 2017
Lorena
@lore-code
Nov 24 2017 00:42

Hi everyone, I'm doing the DNA pairing in the algorithm section. I'm having trouble combining these two arrays into one. Who would like to pair program?
function pairElement(str) {

var splits = str.split("");
var pair =[];
var newArray = [];
var combine = [];

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

if(splits[i]==="G") {

  pair.push(splits[i]); 
  newArray.push("C");
}

else if (splits[i]==="C") {

  pair.push(splits[i]);
  newArray.push("G");
}

}

console.log(pair);
console.log(newArray);

}

pairElement("GCG");

Ogundele Olumide
@Lumexralph
Nov 24 2017 01:40
@lore-code have you tried using concat() method of an array?
Lorena
@lore-code
Nov 24 2017 01:56
I did but it didn't look right.
I did combine= push.concat(newArray) when I did console.log(combine) it's not correct.
Sherlock Holmes
@GGX666
Nov 24 2017 01:59
@lore-code str.split("").map(function(ch) {
use map and switch
return str.split("").map(function(ch) {
switch(ch) {
case "G":
return ["G", "C"];
case "C":
return ["C", "G"];
case "A":
return ["A", "T"];
case "T":
return ["T", "A"];
}
});
Ogundele Olumide
@Lumexralph
Nov 24 2017 02:05
@lore-code push.concat() doesn't look right,
Hendrik W.
@sol-idsnake
Nov 24 2017 02:24
Can anyone tell me how to implement JSON into my html to be able to extract and visualize data from it ?
Lorena
@lore-code
Nov 24 2017 02:55
I meant pair.concat(newArray)
@sol-idsnake yes you have to use key value pairs
@GGX666 thanks but want to solve it without looking at code. Will look into map. And yeah switch would look cleaner.
CamperBot
@camperbot
Nov 24 2017 02:57
lore-code sends brownie points to @ggx666 :sparkles: :thumbsup: :sparkles:
:cookie: 296 | @ggx666 |http://www.freecodecamp.org/ggx666
Sherlock Holmes
@GGX666
Nov 24 2017 02:59
haha next time
Stephen James
@sjames1958gm
Nov 24 2017 03:04
@lore-code instead of switch you could use a look up object
Brittany Rutherford
@brittanyrutherford
Nov 24 2017 03:28
what's the best source to study functional programming?
Alexander Køpke
@alexanderkopke
Nov 24 2017 05:04
Ken Haduch
@khaduch
Nov 24 2017 05:11
@brittanyrutherford - this looks like an interesting article to start with: https://medium.com/@cscalfani/so-you-want-to-be-a-functional-programmer-part-1-1f15e387e536
abraham anak agung
@padunk
Nov 24 2017 05:13
@brittanyrutherford i buy this book by Luis Atencio, good book imo.
texirv0203
@texirv0203
Nov 24 2017 09:38
hi,
  • I have a css issue.
  • when searchDateArea.length > 15 its working fine
  • but when searchDateArea.length < 8 its failing.
  • when its less than 8...I am seeing extra white block.
  • is there any way to fix for all screen.
  • providing whole code below

if ( $(window).width() > 739) { 
                //alert("I am here");
                $('.k-playerJumpingr-content').css({"height": "auto"});
                $('.k-playerJumpingr-content').css({"max-height": searchDateArea.length*70+"px"});
                $('.k-playerJumpingr-layout .k-playerJumpingr-times').eq(1).css({"height": "auto"});
                $('.k-playerJumpingr-layout .k-playerJumpingr-times').eq(1).css({"max-height": (searchDateArea.length*70)+"px"});
            }
            else {
                $('.k-playerJumpingr-content').css({"height": "auto"});
                $('.k-playerJumpingr-content').css({"max-height": searchDateArea.length*45+"px"});
                $('.k-playerJumpingr-layout .k-playerJumpingr-times').eq(1).css({"height": "auto"});
                $('.k-playerJumpingr-layout .k-playerJumpingr-times').eq(1).css({"max-height": (searchDateArea.length*45)+"px"});
            }
Tiago Correia
@tiagocorreiaalmeida
Nov 24 2017 10:36
gm everyone
@texirv0203 as people pointed you in otherchat's thissi the kind of thing that you use css to handle
texirv0203
@texirv0203
Nov 24 2017 11:06
@tiagocorreiaalmeida can you tell me how to handle??
Tiago Correia
@tiagocorreiaalmeida
Nov 24 2017 11:11
media queries
you can do what you are doing with js or trying to do but with css
Adel
@AdelMahjoub
Nov 24 2017 12:56
@texirv0203 use the resize event
@texirv0203 your code only run once the page is loaded, so one of the conditions will never run
@texirv0203 you need to listen to the resize event on window, and use that code within the callback function
Adel
@AdelMahjoub
Nov 24 2017 13:14
jQuery write more do less
Will White
@willnwhite
Nov 24 2017 16:19
@sol-idsnake How do you want to visualise the data? If you want graphs etc., D3.js is good.
AbrisM
@AbrisM
Nov 24 2017 17:15
What does Pclass stand for?
AbrisM
@AbrisM
Nov 24 2017 17:22
Also, can someone tell me why this code runs on CodePen and not directly through website https://codepen.io/anon/pen/vWrVKE
Donnie
@Donnie-D
Nov 24 2017 17:49
A QUICK QUESTION ALL. (perhaps a silly one but there we go again). If a variable (say var i;)has been declared globally and I am now creating a function declaration. If I use i as an argument in that function (function (i)), would it be the same i declraed globally?
Pieter Stokkink
@forkerino
Nov 24 2017 17:53
@Donnie-D No. It masks the global var.
Donnie
@Donnie-D
Nov 24 2017 17:54
@forkerino I take it the answer is same even if the global i is initialised globally too lol
honestly i am not trying to look stupid deliberately here. I was born this way
Pieter Stokkink
@forkerino
Nov 24 2017 18:10
lol
Blauelf
@Blauelf
Nov 24 2017 18:10
@Donnie-D Function parameters work similar to variables declared with var. They have the function as their scope. As such, they may shadow a variable of the same name in an outer scope.
var myName = "Joe"; // outer scope, in this case global
function greet(yourName, myName) { // inner scope
  // no way to access global myName, as it's shadowed
  console.log("Hello "+yourName+", my name is "+myName+".");
}
greet("Donnie", "John"); // Hello Donnie, my name is John.
Donnie
@Donnie-D
Nov 24 2017 18:19
where would I be without all you beautiful people :+1:
Donnie
@Donnie-D
Nov 24 2017 18:25
@Blauelf @forkerino just by the way how can we take that mask off. Sounds funny again I guess but I mean how can we use that global i inside the function argument?
Blauelf
@Blauelf
Nov 24 2017 18:31

Inside the argument? What do you mean? Like

var myName = "Joe"; // outer scope, in this case global
function greet(yourName) { // inner scope
  // uses global myName, as that's the first myName it finds when going outwards
  console.log("Hello "+yourName+", my name is "+myName+".");
}
greet("Donnie"); // Hello Donnie, my name is Joe.

?

Donnie
@Donnie-D
Nov 24 2017 18:31
yayyy I found one way of doing that
oh jinx
Yyyyes. So we initialise i as well in order to access it through the function argument. lovely jubbly
Blauelf
@Blauelf
Nov 24 2017 18:33
I have a strange feeling, while I think we're both using the English language, I'm still not sure I understand anything at all.
Donnie
@Donnie-D
Nov 24 2017 18:34
<!DOCTYPE html>
<html>
<body>

<div id='show' onclick="myFunction(i)">click here</div><br>


<script>
var i=0;
//myFunction(i);   or we can do it here
function myFunction(i){
    document.getElementById("show").innerHTML=i+1;
}
</script>

</body>
</html>
lol
@Blauelf i promise I am not wasting your time and really getting somewhere with every bit of confusion clearing from your help
Blauelf
@Blauelf
Nov 24 2017 18:38

Did you mean something like

<!DOCTYPE html>
<html>
<body>

<div id='show' onclick="myFunction()">click here</div><br>


<script>
var i=0;
function myFunction(){
    document.getElementById("show").innerHTML=i+=1;
}
</script>

</body>
</html>

?

Donnie
@Donnie-D
Nov 24 2017 18:40
basically I am working in AJAX and creating a algorithm to click on a button to get the information regarding the next city's history or geographical data. My problem started around these variable scopes and I couldn't get a clear answer on different forums. So threw it at you wonderful lot. I tend to break down the problem to my little brain's capacity and start working my way up again
@Blauelf
i guess the algo for the quote machine should be more or less same
Blauelf
@Blauelf
Nov 24 2017 18:43
So you can pass any value, for example that of a global variable, to a function. But you can also access a global variable directly within a function, unless it's shadowed. In the direct access case, you can also change it (as I do with the i+=1 part).
Donnie
@Donnie-D
Nov 24 2017 18:48
@Blauelf just what does it mean by 'being shadowed'?
like being in another scope?
Blauelf
@Blauelf
Nov 24 2017 18:51

It means that in your code

    document.getElementById("show").innerHTML=i+1;

the interpreter will search for the nearest declaration of i (in terms of scopes, from current scope outwards). It finds the declaration as parameter, and take that.

If you wouldn't have that parameter, it would go for the global i instead, but since there's the other variable in a closer scope, the global one is hidden behind the other.

Diego Mayer
@Chrono79
Nov 24 2017 18:51
var a = "foo"; //global scope
function foo(b) {
  var a = "frigo"; //local scope, now you can't see the global a var
  return a+b;
}
console.log(foo("bar")); //You'll get "frigobar" instead of "foobar"
Blauelf
@Blauelf
Nov 24 2017 18:52
frigobar? Sounds like ice cream. Maybe not something frozen, but chilled.
Diego Mayer
@Chrono79
Nov 24 2017 18:53
@Blauelf they're little refrigerators like the ones in the hotel rooms
normally with drinks inside ;)
Frigor is a Nestlé ice cream brand
Blauelf
@Blauelf
Nov 24 2017 18:56
Reminds me of the "frigidarium", the cold room (often with cold-water pool) in a Roman bath house. Not to be confused with the "caldarium" (no it's not cold). Those Romans bathed with style.
Diego Mayer
@Chrono79
Nov 24 2017 18:57
I prefer my water warm, I don't want to become a human popsicle :P
Blauelf
@Blauelf
Nov 24 2017 18:58
Winter is coming.
Blauelf
@Blauelf
Nov 24 2017 19:20
Japanese also know how to bath with style, as seen on 千と千尋の神隠し (sen to chihiro no kamikakushi - "spirited away" in English or "El viaje de Chihiro" in Spanish). :bath: :)
Diego Mayer
@Chrono79
Nov 24 2017 19:22
Great movie
sr3k4nth
@sr3k4nth
Nov 24 2017 19:28
hye guys ...which method is easiest way of adding web authentication to our app
Tiago Correia
@tiagocorreiaalmeida
Nov 24 2017 19:45
are you using node @sr3k4nth ?
Henry
@GitHub-Henry
Nov 24 2017 20:54

This link for Object Oriented JavaScript 2nd Edition by Stoyan Stefanov & Kumar Sharma from the book publisher indicates it is currently FREE.

:shipit: :dizzy:

GlobalDevelopment
@GlobalDevelopment2016
Nov 24 2017 20:56
Hi everyone
mstellaluna
@mstellaluna
Nov 24 2017 21:17
FYI:: If anyone is interested in helping out Beta to be released by Christmas :point_up: November 24, 2017 4:14 PM
Joshua Arnett
@josha5
Nov 24 2017 21:19
@sjames1958gm Hey stephen you here lol?
@mstellaluna Actually have you built the simon game?
mstellaluna
@mstellaluna
Nov 24 2017 21:21
@josha5 no.. I stopped at the tic tac toe
Joshua Arnett
@josha5
Nov 24 2017 21:22
@mstellaluna Damn.. Need help I'm so close to finishing it :(
mstellaluna
@mstellaluna
Nov 24 2017 21:22
tbh honest I think just the main room is the only room active at the moment
you can try and ask there
Joshua Arnett
@josha5
Nov 24 2017 21:22
Yeah guess I will
Stephen James
@sjames1958gm
Nov 24 2017 21:28
@josha5 yes
Joshua Arnett
@josha5
Nov 24 2017 21:30
@sjames1958gm Thank god. So I have the simon game working but I can't get the click sequence to work correctly. The user only has to click the last square highlighted and it progresses to the next series.
CamperBot
@camperbot
Nov 24 2017 21:30
josha5 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8710 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Joshua Arnett
@josha5
Nov 24 2017 21:31
var clickNum = 0;
function correctClick(buttons) {
  var displayCount = $("#display").text();
  $(".button").on("click", function() {
    var thisClick = $(this).attr("id");
    var matchBut = buttonPressValidate[clickNum];
    if(thisClick == matchBut) {
      clickNum++;
      setTimeout(function() {
        replayFlash(buttonPress);
           setTimeout(function() {
             highLightSquare(simonButtons);
           }, buttonPress.length * 1000);
      }, 1000);
    }
  });  
}
Stephen James
@sjames1958gm
Nov 24 2017 21:32
@josha5 Do you reset clickNum back to 0 when a series is successful?
Joshua Arnett
@josha5
Nov 24 2017 21:32
@sjames1958gm no I don't
Stephen James
@sjames1958gm
Nov 24 2017 21:33
IT seems you should, and only claim success when clickNum is equal to the length of the currect series.
Joshua Arnett
@josha5
Nov 24 2017 21:46
@sjames1958gm So after the user clicks the correct sequence reset clickNum back to 0?
Stephen James
@sjames1958gm
Nov 24 2017 21:47
I believe so, so that the next sequence you start with the first one
Brittany Rutherford
@brittanyrutherford
Nov 24 2017 21:49
is there a way to extract text from .html files into its own document?
for example, an html document that has 500 paragraphs, all with some text
i would need to take each paragraph and store it in its own word document, is that possible with javascript?
Stephen James
@sjames1958gm
Nov 24 2017 21:51
You could probably do that with nodejs and javascript, there is probably something like this written in perl or python.
Brittany Rutherford
@brittanyrutherford
Nov 24 2017 21:51
but I don't have the files locally, they are on another remote server, can it be done with node as well?
Stephen James
@sjames1958gm
Nov 24 2017 21:52
You can request a document from a URL in node using the HTTP client and then process them in js
Of course with curl or wget you can pull the files from the remote server to the local server if you are doing this once.
Brittany Rutherford
@brittanyrutherford
Nov 24 2017 21:53
nice
thanks Stephen
Stephen James
@sjames1958gm
Nov 24 2017 21:53
:+1:
Brittany Rutherford
@brittanyrutherford
Nov 24 2017 21:53
oh I should use these @sjames1958gm thank you
CamperBot
@camperbot
Nov 24 2017 21:53
brittanyrutherford sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8711 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Nov 24 2017 21:54
:)
Joshua Arnett
@josha5
Nov 24 2017 21:55
@sjames1958gm still can't get it to work
Stephen James
@sjames1958gm
Nov 24 2017 21:56
@josha5 buttonPressValidate[clickNum]; this is an array of correct buttons?
Joshua Arnett
@josha5
Nov 24 2017 21:59
@sjames1958gm Yeah it is
Stephen James
@sjames1958gm
Nov 24 2017 22:00
@josha5 When do you call correctClick? Do you call it more than once?
Joshua Arnett
@josha5
Nov 24 2017 22:00
@sjames1958gm I only call it once
I moved clickNum inside the second setTimeout in the correctClick function and now if the series is 2 or more you have to press all the buttons, but you don't have to press them in order
Stephen James
@sjames1958gm
Nov 24 2017 22:05
    if(thisClick == matchBut) {
      setTimeout(function() {
        replayFlash(buttonPress);
           setTimeout(function() {
             highLightSquare(simonButtons);
             clickNum++;
           }, buttonPress.length * 1000);
      }, 1000);
    }
So what is this code inside the if supposed to be doing?
Seems like to me it should be something like this.
if (thisClick === matchBut) {
    clickNum++
    if (clickNum === buttonPressValidate) {
       // Successful sequence
       reset clickNum to zero
    } else {
       // failed sequence - not sure what your behavior is when you fail to match
    }
}
Joshua Arnett
@josha5
Nov 24 2017 22:10
@sjames1958gm That worked! thank you
CamperBot
@camperbot
Nov 24 2017 22:10
josha5 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
api offline
Joshua Arnett
@josha5
Nov 24 2017 22:11
Also I haven't made the failed sequence behavior yet
Stephen James
@sjames1958gm
Nov 24 2017 22:17
@josha5 :+1:
AbrisM
@AbrisM
Nov 24 2017 22:28
Hi can someone tell me why the page isn't displaying properly? https://plnkr.co/edit/3uiftW6qRdSkUb0egZZo?p=preview Nothing is interactive and only the words I've typed in the header shows, nothing else and I can't type on the page
Stephen James
@sjames1958gm
Nov 24 2017 22:30
@AbrisM THe console shows error loading RansomNote.js and .css
Conor Murphy
@cmurphy580
Nov 24 2017 22:58
Anyone with react experience. If i want my state to persist through a reload do i need to save the data object to local storage?
Adel
@AdelMahjoub
Nov 24 2017 23:21
@cmurphy580 why persisting the state ?
AbrisM
@AbrisM
Nov 24 2017 23:53
@sjames1958gm I got it to work now, using an internal JSQuery file
https://plnkr.co/edit/3uiftW6qRdSkUb0egZZo?p=preview this site requires a live version. I'm using the offline version by including the JSQuery file in with the Javascript and HTML folder