These are chat archives for FreeCodeCamp/HelpJavaScript

16th
Feb 2018
Gersho
@Gersho
Feb 16 2018 02:18

@JLuboff Yes. Also a big interview next week. Have to figure out how to get the app hosted somewhere. Maybe github pages.

bring a laptop and put it in a VM ? also best of luck for your interview

Ahmad Abdolsaheb
@ahmadabdolsaheb
Feb 16 2018 08:38
quick git question. will git rebase delete the new local commits?
Pieter Stokkink
@forkerino
Feb 16 2018 10:15
I would do a push before rebase if you want to rebase a branch you are working on on another base branch, or do the rebase locally so I can fix the merge conflicts in my editor if there are any. @ahmadabdolsaheb
Tiago Correia
@tiagocorreiaalmeida
Feb 16 2018 11:01
gm everyone
function almostIncreasingSequence(sequence) {
    let checkIncreases = (array)=> array.every((curr,ind,arr)=> ind > 0 ? curr > arr[ind-1] : true)

    if(checkIncreases(sequence)) return false;

    for(let i = 0; i < sequence.length; i++){
        if(checkIncreases([...sequence.slice(0,i),...sequence.slice(i+1)])) return true;
    }
    return false;
}
any idea to make this dont fail on performance?failing one of the tests :\
Tiago Correia
@tiagocorreiaalmeida
Feb 16 2018 11:14
nm solved
Nick Cleary
@Hijerboa
Feb 16 2018 14:37
Hey all! I'm currently working on the simon game, and for some reason, my which is supposed to play whenever a area is highlighted only plays the first time it is highlighted. For instance, if the sequence of colors is blue, red, blue, the sound will play properly for the first two, but on the second blue no sound plays. The color changes as expected, but no sound. Here is the relevant code:
function playFunction(){
    var i = 0;
    var intervalID = setInterval(function() {
      if(sequence[i] == "g"){
        $("#middleLeft").css("background-color", "#00F000");
        audioGreen.play();
        setTimeout(function(){
          $("#middleLeft").css("background-color", "green");
        },1000);
      }else if(sequence[i] == "r"){
        $("#middleRight").css("background-color", "#990000");
        audioRed.play();
        setTimeout(function(){
          $("#middleRight").css("background-color", "red");
        }, 1000);
      }else if(sequence[i] == "b"){
        $("#bottomRight").css("background-color", "#38EEFF");
        audioBlue.play();
        setTimeout(function(){
          $("#bottomRight").css("background-color", "blue");
        },1000);
      }else if(sequence[i] == "y"){
        $("#bottomLeft").css("background-color", "#CCCC00");
        audioYellow.play();
        setTimeout(function(){
          $("bottomLeft").css("background-color", "yellow");
        },1000);
      }
      console.log(i);
      if(++i === sequence.length){
        window.clearInterval(intervalID);
      }
    }, 2000);
  }
Tom
@moT01
Feb 16 2018 14:51
@Hijerboa what does it do when it's a length of 4
is the problem when it repeats a color? or on the last one?
maybe try creating the audio in each area
Nick Cleary
@Hijerboa
Feb 16 2018 15:57
@moT01 the problem is whenever the audio is repeated more than once, regardless of it's location on the sequence
Tom
@moT01
Feb 16 2018 16:02
@Hijerboa did you try what i said there? I had a somewhat similar problem and that fixed it - create the audio when you want to play it
new Audio('file').play();
Jason Luboff
@JLuboff
Feb 16 2018 16:10
:wave:
Jim Homme
@jhomme
Feb 16 2018 16:46
IHi,
Jason Luboff
@JLuboff
Feb 16 2018 16:48
How's it going?
Jim Homme
@jhomme
Feb 16 2018 16:51
Hi, It looks like I may not understand something about JavaScript scope. I'm at https://www.freecodecamp.org/challenges/testing-objects-for-properties in the course. The sample code has an object outside the function. In my function, I say theObj = myObj; because I think that will make it so that my function can work with it. Then I check to see if theObj has a property. I'm getting a reference error.
Jason Luboff
@JLuboff
Feb 16 2018 16:54
@jhomme You need to use the object method hasOwnProperty() to check if myObj contains the parameter checkProp. For example
let obj = {
potato: 2,
onion: 4
};

function objectContains(property){
return obj.hasOwnProperty(property);
};

objectContains('potato'); //Here I am calling my function and passing in the argument 'potato' which will become the paramter, proptery
Jim Homme
@jhomme
Feb 16 2018 16:54

Here is the code I have.
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

}

// Test your code by modifying these values
checkObj("gift");
So that means my function can see the object even though it is outside my function?

Jason Luboff
@JLuboff
Feb 16 2018 16:55
You should be checking myObj for the property, not creating a new object
And you also need to use bracket notation, not dot noation
dot notation will search for a string literal
Jim Homme
@jhomme
Feb 16 2018 16:57
HWhen do you use bracket notation and when do you use dot notation?
Jason Luboff
@JLuboff
Feb 16 2018 16:59
If you're using a variable/parameter to search in an object, or there is spacing in the key name, you need to use bracket notation. If you are using the string literal of the key with no spacing, dot notation
Jim Homme
@jhomme
Feb 16 2018 17:01
The sample for this exercise does not show how to do this from inside a function and it does not explain what you just explained.
And one more question please, if that is OK.
Jason Luboff
@JLuboff
Feb 16 2018 17:02
Challenges build ontop of each other
Jim Homme
@jhomme
Feb 16 2018 17:04
In JavaScript, is it true that you cannot see simple variables from inside a function when you create them outside a function?
Jason Luboff
@JLuboff
Feb 16 2018 17:05
It depends on how you scope them
Jim Homme
@jhomme
Feb 16 2018 17:05
So far, I have only created them inside the same file.
Jason Luboff
@JLuboff
Feb 16 2018 17:07
Things can get very complicated with variables :D
As you continue to learn and practice, you'll find what works and what doesnt
I should say variable scope, not variable in general
Jim Homme
@jhomme
Feb 16 2018 17:12
Thanks. Is scope the same for objects as it is for simple variables?
Jason Luboff
@JLuboff
Feb 16 2018 17:12
Yes, since an object will still be a variable
Jim Homme
@jhomme
Feb 16 2018 17:17

So if I have a file, and the first thing in the file is the definition of an object, and the second thing is a function, should I be able to refer to the object inside my function without creatinga local variable that refers to the object?

e

Jason Luboff
@JLuboff
Feb 16 2018 17:17
Yes
Jim Homme
@jhomme
Feb 16 2018 17:19
Thank you. I think I may get what is happening now. You are so patient.
Jason Luboff
@JLuboff
Feb 16 2018 17:19
:+1: Glad to help
Nick Cleary
@Hijerboa
Feb 16 2018 17:29
@moT01 That worked! Thanks Mate! :D
CamperBot
@camperbot
Feb 16 2018 17:29
hijerboa sends brownie points to @mot01 :sparkles: :thumbsup: :sparkles:
:star2: 1001 | @mot01 |http://www.freecodecamp.org/mot01
Jason Luboff
@JLuboff
Feb 16 2018 17:47
@moT01 Congrats on 1000 :star2:
Tom
@moT01
Feb 16 2018 18:06
@JLuboff thanks
CamperBot
@camperbot
Feb 16 2018 18:06
mot01 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2332 | @jluboff |http://www.freecodecamp.org/jluboff
Tom
@moT01
Feb 16 2018 18:06
2332
geez
looks like youve been at it about a half year more than me here
Stephen James
@sjames1958gm
Feb 16 2018 18:19
I remember when @JLuboff was just a padawan.
Jason Luboff
@JLuboff
Feb 16 2018 18:21
:D
Markus Kiili
@Masd925
Feb 16 2018 18:21
@sjames1958gm I remember when he was a pesky 666 :imp:
Jason Luboff
@JLuboff
Feb 16 2018 18:21
I started I think May 2016 for FCC
Markus Kiili
@Masd925
Feb 16 2018 18:22
I didn't mean pesky. I meant something like a padawan, but it was just used.
Jason Luboff
@JLuboff
Feb 16 2018 18:23
Suuuurrreeee
I'd still call myself an amateur at best
Markus Kiili
@Masd925
Feb 16 2018 18:25
A hatchling was the word I was trying to grasp. Now you have wings. Someone just referred to you as ' The mongo person' .
@JLuboff
Jason Luboff
@JLuboff
Feb 16 2018 18:26
I like mongo.
but I'm going to have to learn to love SQL
Markus Kiili
@Masd925
Feb 16 2018 18:29
@JLuboff Mongo is fine for simple things and when you know in advance how you are going to use the data. When you have huge amounts of data and you might use it in different ways in the future, it is best to hack the information into pieces (and relations).
Stephen James
@sjames1958gm
Feb 16 2018 18:29
Or at least tolerate it
Jason Luboff
@JLuboff
Feb 16 2018 18:30
@Masd925 Oh I agree. Mongo can be used for large amounts of date and can run decently with indeces setup, but for large data sets, relational DB's will still rule
@sjames1958gm I need to love it enough to get my MCSA
Markus Kiili
@Masd925
Feb 16 2018 18:34
@JLuboff Yeah, I mean that if the information is complex and you store it in mongo to suit your current needs, it might become a nightmare to use it for some other purpose. Normalized SQL database avoids such problems but with a cost of course.
But knowing both is best.
Jason Luboff
@JLuboff
Feb 16 2018 18:42
Of course
I'm developing a database right now and its kind of tough to determine the proper database design. Particularly since I'm building it as I build my application so I'll end up redoing it I'm sure but trying to keep it normalized (at least to 3NF)