These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Jul 2017
awwsoclose
@awwsoclose
Jul 15 2017 00:00
jquery or jquery UI>
?*
CallMeOrange
@EgnaroDev
Jul 15 2017 00:00
jQuery
Christopher Blakely
@chrisbchrist
Jul 15 2017 00:01
Can anyone explain the problems with my code for the update inventory challenge? The object is to update the first array with the count and content of the second. I don't think I'm using nested for loops correctly.

function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    var updated = arr1;

  for (var i = 0; i < arr2.length;i++) {
    var match = false;

    for (var j = 0; j < arr1.length; j++) {

      if (arr1[j][1] == arr2[i][1]) {
        arr1[j][0] += arr2[i][0];
        match = true;
      } if (j == arr1.length - 1 && match === false) {
        updated.push(arr2[i]);
        match = false;
      }

    }
  }
  return updated;
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
awwsoclose
@awwsoclose
Jul 15 2017 00:02
this is giving me an error
 $(document).ready(function() {  $("#getMessage").on("click",function(){
    });

  });
Nathaniel Suchy
@nsuchy
Jul 15 2017 00:04
@awwsoclose Can you please post your full source code?
awwsoclose
@awwsoclose
Jul 15 2017 00:04
uuhmm, i probably am completely misinterpreting the code description
Nathaniel Suchy
@nsuchy
Jul 15 2017 00:05
So I’m trying to help you but it’s difficult if I don’t have the full source code to diagnose the problem
It limits my ability to help you
Nathaniel Suchy
@nsuchy
Jul 15 2017 00:07
<script>
  $(document).ready(function() {
    // Only change code below this line.

    // Only change code above this line.
  });
</script>
To confirm nothing above or below those lines has been changed?
awwsoclose
@awwsoclose
Jul 15 2017 00:07
no. it keeps telling me to delete the semicolon
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 00:10
@awwsoclose reset the code and try again
awwsoclose
@awwsoclose
Jul 15 2017 00:11
for the random quote generator, am i going to have to create a folder on my desktop?
CallMeOrange
@EgnaroDev
Jul 15 2017 00:12
@awwsoclose why?
Oh so you are not on codepen?
awwsoclose
@awwsoclose
Jul 15 2017 00:13
i am. i googled search "how to build a quote generator" because i have no idea where to start, and some freecodecamp website popped up saying something about that and sublime text
ooooh. an api is another website
i am so slow
CallMeOrange
@EgnaroDev
Jul 15 2017 00:14
lol
You can use that API with $.getJSON to access objects
awwsoclose
@awwsoclose
Jul 15 2017 00:15
can i use just any ol' api or?
CallMeOrange
@EgnaroDev
Jul 15 2017 00:15
You should've learn that or you can make your objects on your own
Doesn't matter
Fulfill the below user stories. Use whichever libraries or APIs you need. Give it your own personal style.
awwsoclose
@awwsoclose
Jul 15 2017 00:17
i was just wondering if they were all free
CallMeOrange
@EgnaroDev
Jul 15 2017 00:18
Hm.. thats depend on calls
But all API for random quote machine should be free I think
awwsoclose
@awwsoclose
Jul 15 2017 00:19
ok thanks
CallMeOrange
@EgnaroDev
Jul 15 2017 00:20
If you want to practice, you should try quotes on design API
awwsoclose
@awwsoclose
Jul 15 2017 00:20
oh sweet thanks
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 00:21
@JLuboff @forkerino Finally completed all the learnyoumongo challenges on c9. :relaxed:
gn @awwsoclose @MCTwoDigitZero
:wave:
CallMeOrange
@EgnaroDev
Jul 15 2017 00:21
Night :zzz:
awwsoclose
@awwsoclose
Jul 15 2017 00:21
night!
Chris McFarland
@PrincessColumbia
Jul 15 2017 00:51
OK, so if anyone is still here and not out enjoying their Friday (I’m divorced and my ex has our daughter this weekend so I have no life right now), I’ve run into a problem.
awwsoclose
@awwsoclose
Jul 15 2017 00:51
well, i have no life, i'm here but idk if i can help lol
Chris McFarland
@PrincessColumbia
Jul 15 2017 00:51

function repeatStringNumTimes(str, num) {
  // repeat after me

  if (num < 0) {
    str = "";
  } else {
    for ( i = 1, i < num; i++;) {
     str += str; 
    }
  }

  return str;
}

repeatStringNumTimes("abc", 3);
This is for the "Repeat a string repeat a string” exercise.
I’m getting a “RangeError: Invalid String Length"
When I test each individual component in the console, it works just fine (though my troubleshooting may have borked an operator in the math) so I’m kinda lost as to why it’s not working.
Moisés Man
@moigithub
Jul 15 2017 00:54
for ( i = 1, i < num; i++) {
should be ;
Chris McFarland
@PrincessColumbia
Jul 15 2017 00:57
Oh, g-d*it! I’ve been doing that all day!
@moigithub thanks
CamperBot
@camperbot
Jul 15 2017 00:57
princesscolumbia sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3505 | @moigithub |http://www.freecodecamp.com/moigithub
awwsoclose
@awwsoclose
Jul 15 2017 00:58
brb
Nick Janne
@njanne19
Jul 15 2017 01:01
Is there any good algorithm out there to be able to create the map for my dungeon game?
awwsoclose
@awwsoclose
Jul 15 2017 01:18
back
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:21
@awwsoclose Welcome back
@njanne19 the fun part is coding your own :)
Christopher Blakely
@chrisbchrist
Jul 15 2017 01:21
Trying to solve the inventory update challenge, objective is to update one array with the values and keys from a second. Think there's a problem with my nested for loop
function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    var updated = arr1;

  for (var i = 0; i < arr2.length;i++) {
    var match = false;

    for (var j = 0; j < arr1.length; j++) {

      if (arr1[j][1] == arr2[i][1]) {
        arr1[j][0] += arr2[i][0];
        match = true;
      } if (j == arr1.length - 1 && match === false) {
        updated.push(arr2[i]);
        match = false;
      }

    }
  }
  return updated;
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
Nick Janne
@njanne19
Jul 15 2017 01:22
@nsuchy There's no way I can code this all on my own it's literally a 10,000 square map
I'll be here for 10 years, and then probably not even know how to export my data for it
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:22
of course you aren’t going to design a 10k square map
you are going to write an equation
that does for you
CallMeOrange
@EgnaroDev
Jul 15 2017 01:24
@nsuchy Did you complete Wikipedia Viewer?
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:24
@MCTwoDigitZero
Joseph
@revisualize
Jul 15 2017 01:24
Hello.
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:24
I took a break
CallMeOrange
@EgnaroDev
Jul 15 2017 01:24
I see
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:24
completed intermediate algos
Why do you need help with something?
CallMeOrange
@EgnaroDev
Jul 15 2017 01:25
Yea I saw
Nothing, was just wondering why there is no Wikipedia Viewer on your profile if you completed random quote m..., weather app and twitch.tv
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:26
I took a break from it
doing the algos has changed my thinking patterns
I’m working my way up from 15 to 20 hour days now
I need more time to read and write code
Nick Janne
@njanne19
Jul 15 2017 01:27
@nsuchy But I don't even understand how you could do it in such a way where you can write an algorithm that makes rooms for you
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:27
Is the dungeon game for freeCodeCamp or a side project
Nick Janne
@njanne19
Jul 15 2017 01:28
the dungeon game
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:28
is it a free code camp thing?
I’m just curious
CallMeOrange
@EgnaroDev
Jul 15 2017 01:29
Build a Roguelike Dungeon Crawler Game Incomplete
Nick Janne
@njanne19
Jul 15 2017 01:29
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:29
Oh
cool
I should just live stream myself coding this wikipedia viewer like the freecodecamp live streams it - then there’d be pressure to get it done :D
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:39
@MCTwoDigitZero Wanna pair code with me?
CallMeOrange
@EgnaroDev
Jul 15 2017 01:39
No thanks :p
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:42
@nsuchy how far are you in FCC?
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:42
@RoniqueRicketts freecodecamp.org/nsuchy
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:43
your ahead of me then
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:43
I have the Wikipedia Viewer, Advanced Algos, and Advanced Projects left
@RoniqueRicketts Wanna pair code with me?
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:44
@nsuchy I am still struggling through the intermediate algorithms.
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:44
@RoniqueRicketts If you call on Google Hangouts I can try and help
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:44
What time is it where you are?
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:44
9:44PM
I go to sleep some time between 1 and 4 am and wake up at 10am
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:45
We could in the morning.
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:45
time zones are not an issue for me :P
I’ve trancended the boundaries of time
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:45
Like 10am we count hang out and code some fcc
its 8:45pm here in the Caribbean
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:46
so your an hour behind me then
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:47
Yeah, but I had a long day at work
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:47
I understand
I wish Gitter had voice chatrooms
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:47
I'd rather pair up on the FCC advance project I wanna struggle with my algorithms by myself (they are my babies)
Joseph
@revisualize
Jul 15 2017 01:49
Mastering Web Application Development with AngularJS
https://www.packtpub.com/packt/offers/free-learning
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:50
@revisualize This probably isn’t the best place to link freebies
And it requires registration :/
awwsoclose
@awwsoclose
Jul 15 2017 01:51
what was the link to the quote api?
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:51
@nsuchy what say you?
Nick Janne
@njanne19
Jul 15 2017 01:51
Bruh there has to be an algorithm usable for this
Nathaniel Suchy
@nsuchy
Jul 15 2017 01:52
@RoniqueRicketts I’m willing to help with whatever - pair programming helps two people learn rather than just one person
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 01:52
makes sense I am game man.
Nick Janne
@njanne19
Jul 15 2017 01:54
Is it possible to map over a 2D array in this way?
       {this.props.board.map((row) => {
          row.map((cell, i) => {
            return (<div id={cell.id} className={cell.status}></div>)
          });
            })}
Niels3030
@niels3030
Jul 15 2017 02:03
Hey there so, ummm.... wtf? Resource interpreted as Document but transferred with MIME type text/javascript: "file:///Users/grammy/Desktop/mod4.js".
Joseph
@revisualize
Jul 15 2017 02:18
@nsuchy You have your opinion.
Christopher Blakely
@chrisbchrist
Jul 15 2017 02:18
Can anyone tell me what's wrong with this? Trying to update 1st array with info from 2nd.
function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    var updated = arr1;

  for (var i = 0; i < arr2.length;i++) {
    var match = false;

    for (var j = 0; j < arr1.length; j++) {

      if (arr1[j][1] == arr2[i][1]) {
        arr1[j][0] += arr2[i][0];
        match = true;
      } if (j == arr1.length - 1 && match === false) {
        updated.push(arr2[i]);
        match = false;
      }

    }
  }
  return updated;
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
Joseph
@revisualize
Jul 15 2017 02:18
@nsuchy I'm not forcing you to register for anything,
@chrisbchrist Which free code camp challenge is that?
Nathaniel Suchy
@nsuchy
Jul 15 2017 02:19
@revisualize I was simply letting you know know because a lot of people use this room for getting help - it might be better to post in causual or the freecodecamp room
Joseph
@revisualize
Jul 15 2017 02:19
@nsuchy You have your opinion.
Christopher Blakely
@chrisbchrist
Jul 15 2017 02:20
@revisualize Inventory Update, you get 1 2D array of counts and item names and have to add to it a 2nd array of numbers and names
Joseph
@revisualize
Jul 15 2017 02:21
@chrisbchrist Can you link me?
Joseph
@revisualize
Jul 15 2017 02:22
@chrisbchrist have you tried www.pythontutor.com/javascript.html
Christopher Blakely
@chrisbchrist
Jul 15 2017 02:23
@revisualize I've not, I will try it now though
Niels3030
@niels3030
Jul 15 2017 02:23
trying to access an external file, & use w/ chrome dev tools console log, but it keeps saying this... Resource interpreted as Document but transferred with MIME type text/javascript: "file:///Users/grammy/Desktop/mod4.js". Anyone dealt w/ this? Is it npm? Is it chrome? is it apache? is it ///, or am just an f&%$@ idiot?
Christopher Blakely
@chrisbchrist
Jul 15 2017 02:28
@revisualize The mere fact of how confused these visualizations make me causes me to seriously question my future in programming
Glen Westbrook
@glynnw
Jul 15 2017 02:35
@niels3030 So what are you trying to do now?
You want to execute the js and see the output in your dev tools console or are you trying to edit the file with dev tools?
Niels3030
@niels3030
Jul 15 2017 02:36
Output in dev console log....
Glen Westbrook
@glynnw
Jul 15 2017 02:36
Then yeah it doesn't work that way as far as I'm aware.
Niels3030
@niels3030
Jul 15 2017 02:37
I've done this before, it doesn't make sense, but the more I look into it could be kind of tough concerning that error, atleast above my head so far..
maybe something to do w/ my local Host server... hmm, bet my brother knows.. thanks tho
Glen Westbrook
@glynnw
Jul 15 2017 02:41
@niels3030 Sorry phonecall, just create an html document and include the js
You are trying to do something I've never seen someone do...
Though it does seem kinda logical
@niels3030 You can use dev tools in chrome to do something like that. You just open it in sources and evaluate it in console.
That is more like what you might be thinking
intcreate
@intcreate
Jul 15 2017 03:21
can any1 help me with this i have an error
function lookUpProfile(firstName, prop){
  for(var j = 0; j < contacts.length; j++) {
     if(contacts[j].firstName === firstName) {
        var index = j;
        break;
     }
     else {
       return "No such contact";
     }
  }

  if(contacts[j].prop === undefined) {
    return "No such property";
  }
  return contacts[index].prop; // SAYING "index" is used out of scope
}
its saying error index is used out of scope
but there is no scope in a for or if
Joseph
@revisualize
Jul 15 2017 03:22
@intcreate Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
@intcreate youre returning "No such contact"; toooooooo early
intcreate
@intcreate
Jul 15 2017 03:24
I am returning it if the name wasnt found
Joseph
@revisualize
Jul 15 2017 03:24
@intcreate are you really?
intcreate
@intcreate
Jul 15 2017 03:24
im on the profile lookup part in the basic javascript
Joseph
@revisualize
Jul 15 2017 03:24
@intcreate I know
@intcreate youre returning "No such contact" way too early
intcreate
@intcreate
Jul 15 2017 03:25
why is that?
Joseph
@revisualize
Jul 15 2017 03:25
@intcreate look.
@intcreate
var value = "e"
var arr = ["a", "b", "c", "d", "e"];
for (var i = 0; i < arr.length; i++) {
     // at the first iteration i is 0
     // arr[i] is arr[0] and arr[0] holds the value of "a"
     // if ("e" === "a") ... return "True" ... Well, "e" is not "a" so, no.
      if (value === arr[i]) { 
         break;
      }
     // okay so next block
     // if "e" is not equal to "a" ... that's true ... so ... return "False"
      else { return "False" }
}
@intcreate
The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
So, @intcreate You're returning "No such contact" way too early
@intcreate because if you're looking for "Kristian"
intcreate
@intcreate
Jul 15 2017 03:29
OH OK
thanks i will work this out
Joseph
@revisualize
Jul 15 2017 03:30
You're doing "Kristian" === "Akira"
nope
return no contact
intcreate
@intcreate
Jul 15 2017 03:38
okay i fixed it
but now its still saying the same thing
function lookUpProfile(firstName, prop){
  for(var j = 0; j < contacts.length; j++) {
     if(contacts[j].firstName === firstName) {
        var index = j;
        break; 
     }
  }

  if(index === undefined || null) { // SAYING "index" IS USED OUT OF SCOPE
    return "No such contact";
  }

  if(contacts[index].prop === undefined) {
    return "No such property";
  }

  return contacts[index].prop; // SAYING "index" IS USED OUT OF SCOPE
}

@intcreate How to write an if conditional statements with OR and AND operators:
I am seeing a large number of people writing if conditions using OR and AND operators incorrectly.
Here is an example of what I'm seeing:

if (param1 == "a" || "c" || "e") { // incorrect
   var output = "Odd lowercase alpha character"; 
}

What I think people think is that it will compare param1 to "a" then compare param1 to "c" then compare param1 to "e"
However, that's not actually what the computer is processing.

if conditions need to be evaluated to true for the if statement to run:

if ((condition1) || (condition2) || (condition3) {
    // true statement
}

And how we would code that up from our example above where we're trying to get the odd character from a parameter (param1):

if (param1 == "a" || param1 == "c" || param1 == "e") {
   var output = "Odd lowercase alpha character"; 
}

I'm also seeing people writing and statements like this:

if (param1 == "a" && param1 == "e") {
}

The problem with this is the fact that a variable can't really be two strings or two different numbers at the same time.

CallMeOrange
@EgnaroDev
Jul 15 2017 03:42
Hey is this only way to generate random number between two numbers?
Math.floor(Math.random() * (max - min + 1)) + min
Guderian Raborg
@hypercuber
Jul 15 2017 03:46
Are there some things you can not do with i++ in a for loop so you gotta use ++i?
Pagnito
@Pagnito
Jul 15 2017 03:46
anybody heard of the styled components in for react?
CallMeOrange
@EgnaroDev
Jul 15 2017 03:47
@hypercuber No, I have never heard of it
Ryan Williams
@Ryanwfile
Jul 15 2017 03:48
Anyone experienced with React know if mutating an array that is part of the state is ok? For instance, in the component's render function I use the array.pop() method on the array that is part of this.state, the code is working fine but I'm wondering if this is the wrong way to go about coding this. I can link the codepen if it helps. I greatly appreciate any help with this. Sample of the code in question is the following
 {arr1.map(function(val2, idx2, arr2){
                i++;               
                if (this.state.array.length > 0 && (i === this.state.array[rngLength])){ 
                  rngLength--;
                  this.state.array.pop();
                      return (
                        <td><Cell /> </td>
                      )                     
                }            

                else {
                  return <td>{i} </td>
                }

              }.bind(this))}
Guderian Raborg
@hypercuber
Jul 15 2017 03:49
@MCTwoDigitZero let x = Math.floor(Math.random() * 2);
CallMeOrange
@EgnaroDev
Jul 15 2017 03:50
so thats 1 to 2?
Guderian Raborg
@hypercuber
Jul 15 2017 03:50
0 or 1
Michael Cavataio
@MCavataio
Jul 15 2017 03:50
hmm are you just trying to remove that item from the state @ryan?
Guderian Raborg
@hypercuber
Jul 15 2017 03:50
but I think you want something more complex let me think
@MCTwoDigitZero Thanks anyways
CamperBot
@camperbot
Jul 15 2017 03:50
hypercuber sends brownie points to @mctwodigitzero :sparkles: :thumbsup: :sparkles:
:cookie: 480 | @mctwodigitzero |http://www.freecodecamp.com/mctwodigitzero
Ryan Williams
@Ryanwfile
Jul 15 2017 03:51
@MCavataio No it's not removing it from the state, just popping a number from an array. Thanks for helping
CamperBot
@camperbot
Jul 15 2017 03:51
ryanwfile sends brownie points to @mcavataio :sparkles: :thumbsup: :sparkles:
:cookie: 16 | @mcavataio |http://www.freecodecamp.com/mcavataio
Michael Cavataio
@MCavataio
Jul 15 2017 03:54
could you send the codepen @Ryanwfile
CallMeOrange
@EgnaroDev
Jul 15 2017 03:56
@hypercuber No problem, i was just wondering if there is shorter formula for this
Ryan Williams
@Ryanwfile
Jul 15 2017 03:59
@MCavataio I'm altering the this.state.startingCells array by using the pop method on it in the render function
Michael Cavataio
@MCavataio
Jul 15 2017 04:04
hmm yeahh i just started to learn react what would then be managing the status of the cells?
i think it may be benefecial to modify the state outside of the render prior to rendering the function
Guderian Raborg
@hypercuber
Jul 15 2017 04:07
@MCTwoDigitZero
let min = 5;
let max = 10;
let binary = Math.floor(Math.random() * 2); //0 || 1
let result = binary === 0 ? min : max;
console.log(result);
binary === 0 ? min : max; works like a if else statement
CallMeOrange
@EgnaroDev
Jul 15 2017 04:08
Yeah ternary
Looks good but I didn't need a complicated code :o
Guderian Raborg
@hypercuber
Jul 15 2017 04:08
:)
:smile:
Flashtzu
@Flashtzu
Jul 15 2017 04:09
function colormatic(){
var cbr = document.getElementById("chkr");
var cbb = document.getElementById("chkb");
var cbg = document.getElementById("chkg");
var hiddeninputs = document.getElementsByClassName("color");
for (var i = 0; i != hiddeninputs.length; i++){
if (cbr.checked){
hiddeninputs[i].style.color = "rgb(250,0,0)";
}
else if(cbb.checked){
hiddeninputs[i].style.color = "rgb(0,0,200)";
}
else if (cbr.checked && cbb.checked){
hiddeninputs[i].style.color = "rgb(200,200,200)";
}
else{
hiddeninputs[i].style.color = "black";
}
}
}
Nitin Sahu
@globefire
Jul 15 2017 04:09

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var a = "";
  if(num != str.length){
    if(num >= 3){
      a = str.slice(0, num-3) + "...";
    }
      else{
      a = str.slice(0, num) + "...";
    }
  }
  else{
    a = str;
  }
  return a;
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
what's wrong in this for the last case ?
Flashtzu
@Flashtzu
Jul 15 2017 04:09
any ideas how to get the 2nd else if to work?
Nitin Sahu
@globefire
Jul 15 2017 04:10
anyone ?
Flashtzu
@Flashtzu
Jul 15 2017 04:12
the last else? does the first if/else not cover every case why have the last one?
CallMeOrange
@EgnaroDev
Jul 15 2017 04:12
why not just return str instead of last else?
Guderian Raborg
@hypercuber
Jul 15 2017 04:13
@Flashtzu You should do 3 then shift+enter, paste code, shift+enter, 3
then enter
this is kinda difficult to explain
Flashtzu
@Flashtzu
Jul 15 2017 04:15
@hypercuber im sorry i dont understand what your saying
my goal is to check if both checkboxes are checked
Ryan Williams
@Ryanwfile
Jul 15 2017 04:16
@MCavataio There's a different array managing the cells, I'm probably going to modify the code a few times I was just wondering if it needed to be modified now. Thanks again for taking a look.
CamperBot
@camperbot
Jul 15 2017 04:16
ryanwfile sends brownie points to @mcavataio :sparkles: :thumbsup: :sparkles:
:warning: ryanwfile already gave mcavataio points
Guderian Raborg
@hypercuber
Jul 15 2017 04:17
@MCTwoDigitZero I hope I helped. I was lagging
I was just talking about typing code in chat box
CallMeOrange
@EgnaroDev
Jul 15 2017 04:18
@hypercuber You helped enough :wink:
Flashtzu
@Flashtzu
Jul 15 2017 04:21
 function colormatic(){
        var cbr = document.getElementById("chkr");
        var cbb = document.getElementById("chkb");
        var cbg = document.getElementById("chkg");
        var hiddeninputs = document.getElementsByClassName("color");
        for (var i = 0; i != hiddeninputs.length; i++){
          if (cbr.checked){
            hiddeninputs[i].style.color = "rgb(250,0,0)";
          }
            else if(cbb.checked){
            hiddeninputs[i].style.color = "rgb(0,0,200)";
          }
        else if (cbr.checked && cbb.checked){
          hiddeninputs[i].style.color = "rgb(200,200,200)";
        }
          else{
            hiddeninputs[i].style.color = "black";
          }    
        }
      }
the 2nd else if is where i am stuck
not sure how to get it to check both
CallMeOrange
@EgnaroDev
Jul 15 2017 04:26
Are you making random rgb colors?
M-C-Haker
@M-C-Haker
Jul 15 2017 04:28

Quick Question: I have the code correct through a quick trial and error and wondering if someone can explain something to me. Here's my code: ```

function getIndexToIns(arr, num) {
var newArr = arr.push(num);
var sorted = arr.sort(function(a,b) {
return a - b;
});
return sorted.indexOf(num);
}

getIndexToIns([10, 20, 30, 40, 50], 35);
```

in my sorted variable i initially wanted to do var sorted = newArr.sort(function ...etc. but I was getting any error. Is it because I'm not creating a new array with push? it just adds to the original?
Flashtzu
@Flashtzu
Jul 15 2017 04:30
kind of
M-C-Haker
@M-C-Haker
Jul 15 2017 04:30
think i just answered my own question
Pagnito
@Pagnito
Jul 15 2017 04:36
anyone work with react-native?
CallMeOrange
@EgnaroDev
Jul 15 2017 04:42
@Pagnito Hey is react part of Data-vis?
Pagnito
@Pagnito
Jul 15 2017 04:42
@MCTwoDigitZero yea
all the projects i think are supposed to be made with react
CallMeOrange
@EgnaroDev
Jul 15 2017 04:43
I see
Why not try Data-vis room?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 04:44
@M-C-Haker push returns the length of modified array. (yup)
Yuserah Din
@YuserahN
Jul 15 2017 04:46
So I just finished my Local Weather App. It would be great if someone can take a look and tell me if it's working properly or not. Any feedback would be much appreciated. Thanks in advance.
https://codepen.io/Yuserah/full/xrQyPd/
Pagnito
@Pagnito
Jul 15 2017 04:47
@MCTwoDigitZero data-vis-room?
oooh char toom
CallMeOrange
@EgnaroDev
Jul 15 2017 04:47
yea
Pagnito
@Pagnito
Jul 15 2017 04:47
true holdo n
CallMeOrange
@EgnaroDev
Jul 15 2017 04:48
@YuserahN Works fine for me, the location is different but I know it is timezone, why not use this api https://ipinfo.io/json based on ISP?
And You have to covert F to C... C to F etc.
Its also a part of that challenge
Pagnito
@Pagnito
Jul 15 2017 04:49
i couldnt find the data-vs room
i tried looking thru fcc site
but they changed the get help button to get hint
and data vis projects dont even have those buttons
CallMeOrange
@EgnaroDev
Jul 15 2017 04:50
Strange they should have one
Yuserah Din
@YuserahN
Jul 15 2017 04:50
@MCTwoDigitZero There are two buttons below where the temp is displayed. One button converts to Fahrenheit and the other to Celsius.
Did it not work for you?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 04:50
@M-C-Haker In any case, I would avoid doing it like this, since you are modifying the original array. The goal with this function is not to insert anything, but simply to determine what the index would be for insertion.
CallMeOrange
@EgnaroDev
Jul 15 2017 04:50
@YuserahN Oh thats right, I saw it don't know why I said it lol
Yeah working fine
Yuserah Din
@YuserahN
Jul 15 2017 04:51
Good to know. Thanks for checking it out.
CallMeOrange
@EgnaroDev
Jul 15 2017 04:51
/rooms
Pagnito
@Pagnito
Jul 15 2017 04:51
@MCTwoDigitZero i think they spending most time working on the beta
CallMeOrange
@EgnaroDev
Jul 15 2017 04:51
@YuserahN No problem
/rooms
CamperBot
@camperbot
Jul 15 2017 04:51

freeCodeCamp rooms:

:point_right: Here is a list of our official chat rooms
Pagnito
@Pagnito
Jul 15 2017 04:51
sweeeet thanks
CallMeOrange
@EgnaroDev
Jul 15 2017 04:52
Im still looking for it :o
Pagnito
@Pagnito
Jul 15 2017 04:52
found it
HelpDataViz
CallMeOrange
@EgnaroDev
Jul 15 2017 04:52
Oh yeah
Viz... thats why it was hard to find
@Pagnito Do you know how to make the text exactly middle on any screen size?
Or do I have to adjust it with margin-top?
Pagnito
@Pagnito
Jul 15 2017 04:54
i usually use flexbox
CallMeOrange
@EgnaroDev
Jul 15 2017 04:54
Hm..
Can you do it with css property?
Pagnito
@Pagnito
Jul 15 2017 04:55
i think there are other ways to do it too tho, but so far flexbox satsified my needs
Mukul Agrawal
@mukul09
Jul 15 2017 04:56

could anybody please tell me why we include

"?callback=?"

in the api link while using $.getJSON()

CallMeOrange
@EgnaroDev
Jul 15 2017 04:56
Eh, looks like I have to figure it out after this program
Pagnito
@Pagnito
Jul 15 2017 04:57
@MCTwoDigitZero u can display the parent as table and child as cell
and use vertical-align on child
CallMeOrange
@EgnaroDev
Jul 15 2017 04:57
Honestly, Im confused with parent and child thingy
parent = body, child = html?
Pagnito
@Pagnito
Jul 15 2017 04:58
#parent {display: table;}

#child {
    display: table-cell;
    vertical-align: middle;
}

its mad simple hehe
```

<div id="parent> <div id="child></div>

<div/>

<div id="parent"> 
         <div id="child"></div>
<div/>
CallMeOrange
@EgnaroDev
Jul 15 2017 05:00
hm..
Pagnito
@Pagnito
Jul 15 2017 05:00
child elements are the elements inside of other lements
CallMeOrange
@EgnaroDev
Jul 15 2017 05:00
ah
Pagnito
@Pagnito
Jul 15 2017 05:00
parent elements are elemnts containing those child elements
Ogundele Olumide
@Lumexralph
Jul 15 2017 05:01
@MCTwoDigitZero parent == html child == body
CallMeOrange
@EgnaroDev
Jul 15 2017 05:02
looks like the opposite of what I said
Pagnito
@Pagnito
Jul 15 2017 05:03
u get it now tho?
its a simple concept
CallMeOrange
@EgnaroDev
Jul 15 2017 05:04
Yeah
Remember random number between two numbers?
I have this Math.floor(Math.random()* 255 - 0 + 1) - 0;
is - 0 needed?
at the end
@MCTwoDigitZero
CallMeOrange
@EgnaroDev
Jul 15 2017 05:05
@Pagnito thanks :p
CamperBot
@camperbot
Jul 15 2017 05:05
mctwodigitzero sends brownie points to @pagnito :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @pagnito |http://www.freecodecamp.com/pagnito
Pagnito
@Pagnito
Jul 15 2017 05:05
np
CallMeOrange
@EgnaroDev
Jul 15 2017 05:05
Will read it later
Pagnito
@Pagnito
Jul 15 2017 05:06
hmm, i really dont see why that -0 would be needed
CallMeOrange
@EgnaroDev
Jul 15 2017 05:06
yeah I agree
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:06
I'm not sure why either -0 would be necessary. what is this in reference to?
Viktor Tiutiun
@vittorioVT
Jul 15 2017 05:06
@mukul09 in end query
Pagnito
@Pagnito
Jul 15 2017 05:07
well im off to sleep, gd night
CallMeOrange
@EgnaroDev
Jul 15 2017 05:09
@kumquatfelafel for random rgb
@Pagnito Night
@kumquatfelafel
Well that is really easier than I thought
I might need to add a button, because its harder to copy it
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:13
@MCTwoDigitZero You shouldn't need the - 0 inside the parentheses either
CallMeOrange
@EgnaroDev
Jul 15 2017 05:14
isn't that required for between 0 to 255?
Math.floor(Math.random() * 255 - 0 + 1) 0 to 255, Math.floor(Math.random() * 10 - 0 + 1)0 to 10
Viktor Tiutiun
@vittorioVT
Jul 15 2017 05:14
@MCTwoDigitZero why $("body, html").on("click"...... you can just $("html").on("click".... and will work
CallMeOrange
@EgnaroDev
Jul 15 2017 05:15
I know its same thing :/
@vittorioVT Well at least that makes the code shorter
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:15
Math.floor(Math.random() * 255 + 1) and Math.floor(Math.random() * 255 - 0 + 1) are equivalent.
CallMeOrange
@EgnaroDev
Jul 15 2017 05:15
hm...
but will code be able to get 0?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:16
That - 0, mathematically, subtracts 0 from your result so it does nothing
CallMeOrange
@EgnaroDev
Jul 15 2017 05:16
Yeah you are right
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:16

but will code be able to get 0?

@MCTwoDigitZero yes, because of Math.floor

CallMeOrange
@EgnaroDev
Jul 15 2017 05:16
Doesn't Math.floor just round the numbers?
0.8 => 1 for example
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:17
Rounds down.
.99999 => 0
CallMeOrange
@EgnaroDev
Jul 15 2017 05:18
ah..
I think I know why its called
Math.floor()
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:19

:p

Then you've got ceil, which rounds up

CallMeOrange
@EgnaroDev
Jul 15 2017 05:20
oh yeah
Make senses
Viktor Tiutiun
@vittorioVT
Jul 15 2017 05:20
@MCTwoDigitZero just to try without " - 0"
CallMeOrange
@EgnaroDev
Jul 15 2017 05:20
I already removed it
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:20
But yeah, I was wrong. Your code won't be able to reach 0. For that, you'd actually need to get rid of the + 1 :laughing:
CallMeOrange
@EgnaroDev
Jul 15 2017 05:21
...
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:21
sorry
CallMeOrange
@EgnaroDev
Jul 15 2017 05:21
So keep - 0?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:21
neither one is necessary
CallMeOrange
@EgnaroDev
Jul 15 2017 05:21
I see
Yeah I saw something like Math.floor(Math.random()* 7) to get 1 to 6
Should I change 255 to 256?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:22
Math.random results in a value between 0 (inclusive) and 1(exclusive). So when you multiply it by 5, for example, you get value between 0 (inclusive) and 5(exclusive), which when you floor becomes 0 to 4.
CallMeOrange
@EgnaroDev
Jul 15 2017 05:23
Yeah thats what I was saying :o
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:23
posted first, but yeah, if you want 0 to 255, you'd multiply by 256 then floor
CallMeOrange
@EgnaroDev
Jul 15 2017 05:24
Yea I changed it already :p
Since getting 255 is impossible with 255
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:24
yup
CallMeOrange
@EgnaroDev
Jul 15 2017 05:24
what if you had 255 + 1?
Pemdas, it add to 256 so that should work?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:24
1 to 255
CallMeOrange
@EgnaroDev
Jul 15 2017 05:24
hm..
No PEMDAS?
P first?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:25
@MCTwoDigitZero if you had Math.random() * (255 + 1) you mean?
CallMeOrange
@EgnaroDev
Jul 15 2017 05:26
Yeah
255+1 would be 256? then multiply by Math.random
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:26
Equivalent to Math.random() * 256
CallMeOrange
@EgnaroDev
Jul 15 2017 05:26
Thats what I was saying :/
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:27
But not equivalent to Math.random() * 255 + 1
CallMeOrange
@EgnaroDev
Jul 15 2017 05:27
But ()?
(255 + 1) = 256
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:27
with parentheses yeah.
CallMeOrange
@EgnaroDev
Jul 15 2017 05:28
so Math.random() * (255 + 1) is the same as Math.random() * 256
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:29
gotta love the formatting :laughing:
CallMeOrange
@EgnaroDev
Jul 15 2017 05:29
:p
@kumquatfelafel Do you know which color is most visible to any color?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:29
yup. Parentheses takes precedent
CallMeOrange
@EgnaroDev
Jul 15 2017 05:30
So JS operators works like PEMDAS
It would be fun to make Math formulas in JS
hm... most visible text color to any color would be black and bold
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:35
@MCTwoDigitZero If you're talking about our ability to contrast between two colors, you're dealing with a spectrum so it's not entirely straightforward. Black on black, for example, wouldn't be easy to see. If you wanted to have a random background color, for example, while still having a visible text color, you might have to do something like limit the values that your rng could generate so that it won't get too close to the text color you're using. If you randomly generated both colors without mutually exclusive ranges, then there's no guarantee that the text would be visible.
CallMeOrange
@EgnaroDev
Jul 15 2017 05:37
:o
I got an idea
Christopher Blakely
@chrisbchrist
Jul 15 2017 05:46
function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    var updated = arr1;

  for (var i = 0; i < arr2.length;i++) {
    var match = false;

    for (var j = 0; j < arr1.length; j++) {

      if (arr1[j][1] == arr2[i][1]) {
        arr1[j][0] += arr2[i][0];
        match = true;
      } if (j == arr1.length - 1 && match === false) {
        updated.push(arr2[i]);
        match = false;
      }

    }
  }
  return updated;
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:47
@chrisbchrist Why are you assigning false to match (in if statement) if one of the prerequisite conditions for that line being executed is that match is false?
CallMeOrange
@EgnaroDev
Jul 15 2017 05:48
I could give random color to background and different color to text
Christopher Blakely
@chrisbchrist
Jul 15 2017 05:49
@kumquatfelafel Well I assign it to false initially because it would only be set to true if the desired match condition is met
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:49
see edit :p
Christopher Blakely
@chrisbchrist
Jul 15 2017 05:51
So if the loop completes and the condition is not met it should push the array
but I don't want it to push the next iteration automatically so i reset it to false in the nested loop
Unless I am misunderstanding how things execute, which is likely the case since my code doesn't work
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:55
match is never reset to false. It either remains false (i.e. match = false in if statement redundant), or becomes true, in which case never resets to false since if statement where match is reset explicitly checks that match is false before executing. Note...
} if (j == arr1.length - 1 && match === false) {
Maybe this is good enough..
There is a really low chance that they might match
kumquatfelafel
@kumquatfelafel
Jul 15 2017 05:58
@MCTwoDigitZero https://stackoverflow.com/questions/7260989/how-to-pick-good-contrast-rgb-colors-programmatically
Haven't checked content so dunno, but might be helpful.
@chrisbchrist haven't done this one yet. Gimme sec to check what it actually wants. :p
CallMeOrange
@EgnaroDev
Jul 15 2017 06:00
eh..
@kumquatfelafel thanks for all of your helps
CamperBot
@camperbot
Jul 15 2017 06:00
mctwodigitzero sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 467 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Christopher Blakely
@chrisbchrist
Jul 15 2017 06:00
@kumquatfelafel Well my thought is I want it to be false initially and if it doesn't become true and remains false I want it to execute the second if statement
Perhaps the declaration within the first for loop doesn't reset the value to false
CallMeOrange
@EgnaroDev
Jul 15 2017 06:04
@kumquatfelafel Maybe I can make background color that match text color but with transparent
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:04
ah. didn't see that for. Yes, or rather you will have new variable match with value of false. Will be no reset in inner loop though (if that's what you want)
CallMeOrange
@EgnaroDev
Jul 15 2017 06:04
It has text-shadow so it should be visible enough
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:09
okay... think have better idea of what your algorithm is attempting, and what is going wrong. @chrisbchrist
@chrisbchrist I suspect what is happening is that when you push the toothpaste, since length changes, you then check toothpaste, see that there's a match, and add those 7 toothpaste.
as for why it fails when your current inventory is empty, arr1.length is 0 so inner for loop never runs. Ergo, nothing is ever pushed
CallMeOrange
@EgnaroDev
Jul 15 2017 06:14
Omg, I keeps forgetting to use var
Codepen don't even tell me
Unless I analyze it..
Looks better now :/
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:24
@chrisbchrist Essentially, you have a duplication problem. Changing a couple of things, I can get your code to get right answer, albeit still marked as incorrect by FCC haha
Ah, because it's not in alphabetical order
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:39
@chrisbchrist suppose you didn't use the boolean variable match at all. How would you go about coding that inner loop?
CallMeOrange
@EgnaroDev
Jul 15 2017 06:41
huh...
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:43
@MCTwoDigitZero ?
CallMeOrange
@EgnaroDev
Jul 15 2017 06:44
huh?
:trollface:
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:44

huh?

Indeed :o

calling it a night, I think. :waning_gibbous_moon:
abraham anak agung
@padunk
Jul 15 2017 06:45
Hi guys, could aybody give an advice? I have an array var arr = [...]; and want to call it randomly like var random = arr[Math.method(Math.random()*arr.length)]; what method is appropriate for it? round/floor?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:45
floor
abraham anak agung
@padunk
Jul 15 2017 06:45
why?
CallMeOrange
@EgnaroDev
Jul 15 2017 06:46
so you can round it..
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:46
round might round up.
abraham anak agung
@padunk
Jul 15 2017 06:46
ah ok i see. thanks @kumquatfelafel
CamperBot
@camperbot
Jul 15 2017 06:46
padunk sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 468 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
CallMeOrange
@EgnaroDev
Jul 15 2017 06:46
@padunk What happen if Math.random()* 5
It can be 4.42, 2.22, 1.99 I don't know...
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:47
@padunk If you had * (arr. length - 1), round could be fine I suppose
abraham anak agung
@padunk
Jul 15 2017 06:49
nah...i'm not using it
CallMeOrange
@EgnaroDev
Jul 15 2017 06:49
:octocat:
kumquatfelafel
@kumquatfelafel
Jul 15 2017 06:52
@padunk the thing about using round though is that the endpoints would be problematic. For example, index 0 would only get used if rng gave you number less than .5, whereas, index 1 would be for randomly generated value from .5 to 1.49999999. So if you want it fully randomized (well... pseudorandom anyway), floor would still be more appropriate
Sakitha
@Sakitha
Jul 15 2017 06:57
Hey,can one write a script that automate the process of online money making by clicking advertisements?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 07:00
If you're asking whether you could, for example, generate ad revenue for a site by artificially inflating your click count... I would not recommend it. They tend to have ways of catching that kind of thing, and could actually penalize you for doing it.
Ankur sharma
@ankur1163
Jul 15 2017 07:02
i have code something like this
<div class="g-container">
                             <div class="g-grid">
                                  <div class="g-block size-25">
                                         <div class="g-content g-particle">
                                         <a href="#" title="" rel="home"  class="g-logo">
                                           <img src="images/logotrans.png" height="60px" width="70px" alt="">    </a> <p>MOCL UGANDA</p>                                      </div>
                                   </div>
issue is text comes below the logo
doesnt come on same line
i want text just next to logo
it comes on next line
kumquatfelafel
@kumquatfelafel
Jul 15 2017 07:03
Though yeah. This time, really am gonna call it a night :p
G'night!
CallMeOrange
@EgnaroDev
Jul 15 2017 07:07
Night
Ghost
@ghost~56ec5e3985d51f252ab99021
Jul 15 2017 07:31
hi there
Maks Ushakov
@maks-ushakov
Jul 15 2017 07:40
@ankur1163
you used the tag 'p' after 'img'. This tag is block. Just use some inline tag span, strong, em ...
https://jsfiddle.net/0v6hk834/
Ankur sharma
@ankur1163
Jul 15 2017 07:44
ok
thanks @maks-ushakov
CamperBot
@camperbot
Jul 15 2017 07:44
ankur1163 sends brownie points to @maks-ushakov :sparkles: :thumbsup: :sparkles:
:cookie: 369 | @maks-ushakov |http://www.freecodecamp.com/maks-ushakov
Pieter Stokkink
@forkerino
Jul 15 2017 08:17
Good morning
Stanley Su
@stanley-su
Jul 15 2017 08:18
Hello :)
Pieter Stokkink
@forkerino
Jul 15 2017 08:19
I'm trying to solve the Mine Sweeper challenge on Codewars today. https://www.codewars.com/kata/mine-sweeper/train/javascript
Wish me luck!
Stanley Su
@stanley-su
Jul 15 2017 08:23
Wow that’s difficult, good luck
Pieter Stokkink
@forkerino
Jul 15 2017 08:25
@stanley-su thanks. I started yesterday evening and I'm mostly there, but still need to work out some edge cases.
CamperBot
@camperbot
Jul 15 2017 08:25
forkerino sends brownie points to @stanley-su :sparkles: :thumbsup: :sparkles:
:cookie: 22 | @stanley-su |http://www.freecodecamp.com/stanley-su
MadsSN
@MadsSN
Jul 15 2017 08:37
@forkerino Looks fun :)
Pieter Stokkink
@forkerino
Jul 15 2017 08:38
@MadsSN it is!
Ala Pota
@alapota
Jul 15 2017 08:41
Thank you @Takumar for explanation
CamperBot
@camperbot
Jul 15 2017 08:41
alapota sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star2: 3774 | @takumar |http://www.freecodecamp.com/takumar
MadsSN
@MadsSN
Jul 15 2017 08:42
@forkerino So many things I want to do and code and so little time!
Ankur sharma
@ankur1163
Jul 15 2017 09:14
i am unadnle to access my image files
i used ../
can someone check it out
Pieter Stokkink
@forkerino
Jul 15 2017 09:16
@ankur1163 are you sure you are not in aboutus.html in the main folder?
it looks like that one is selected
Ankur sharma
@ankur1163
Jul 15 2017 09:16
let me check
@forkerino
yes it worked
:)
thanks @forkerino
CamperBot
@camperbot
Jul 15 2017 09:17
ankur1163 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2846 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 15 2017 09:17
:+1:
Vaibhav Agrawal
@vaibhav1729
Jul 15 2017 09:28
Can anyone help me with setting up JavaScript
陈建
@NoProble
Jul 15 2017 09:30
Pieter Stokkink
@forkerino
Jul 15 2017 09:30
@vaibhav1729 can you be more specific?
what do you need help with?
Vaibhav Agrawal
@vaibhav1729
Jul 15 2017 09:34
I wanna code in js but I'm not able to set up a perfect editor for it
@forkerino
Pieter Stokkink
@forkerino
Jul 15 2017 09:34
@vaibhav1729 There are a couple of good ones: Atom, Sublime, VS Code
Vaibhav Agrawal
@vaibhav1729
Jul 15 2017 09:36
Yeah I know that ... But things are not working properly
I am currently using Ubuntu linux
Pieter Stokkink
@forkerino
Jul 15 2017 09:37
@vaibhav1729 ok, me too
@vaibhav1729 which editor do you use?
and what goes wrong?
Vaibhav Agrawal
@vaibhav1729
Jul 15 2017 09:38
Atom
@forkerino I am confused on how to compile and test it
The code*
Pieter Stokkink
@forkerino
Jul 15 2017 09:39
@vaibhav1729 usually you let the browser do that.
or use a node js / webpack dev server for more complex stuff.
but yeah, for smaller projects you just use a html page that includes the script and open that in the browser
Vaibhav Agrawal
@vaibhav1729
Jul 15 2017 09:41
But to test my algorithm challenges in js ... How can browser help that
Pieter Stokkink
@forkerino
Jul 15 2017 09:41
@vaibhav1729 that would be a bit convoluted
@vaibhav1729 what you can do is install node if you haven't already
and then open a terminal and type node algorithm.js to run the file on your machine
Vaibhav Agrawal
@vaibhav1729
Jul 15 2017 09:42
@forkerino Ok I try that
a27-suryansh
@a27-suryansh
Jul 15 2017 09:42
Hi i need help with Twitch Viewer can someone please help?
Pieter Stokkink
@forkerino
Jul 15 2017 09:43
@vaibhav1729 :+1:

@a27-suryansh I'm getting the following error:

Uncaught ReferenceError: getInput is not defined

heroiczero
@heroiczero
Jul 15 2017 09:44

@a27-suryansh you should use the list

var channels = [
    "ESL_SC2",
    "OgamingSC2",
    "cretetion",
    "freecodecamp",
    "storbeck",
    "habathcx",
    "RobotCaleb",
    "noobs2ninjas"
  ];

before letting the user put their own input, but each their own.

a27-suryansh
@a27-suryansh
Jul 15 2017 09:44
one minute @forkerino let me fix it
Ashish Kumar Sangwan
@KsangwanA
Jul 15 2017 09:47

Hey guys for the basic algorithm challenge - to find the longest word in the string
I did something like this -

function findLongestWord(str) {
var singleStr = str.split(' ');
var strLength = [];
for (var i = 0; i < singleStr.length; i++) {
strLength = singleStr[i].length;

strLength.sort(function(a,b) {
return b-a;
});

return strLength[0];
}
}

findLongestWord("The quick brown fox jumped over the lazy dog");
but it is not working and showing this --
TypeError: Object doesn't support property or method 'sort'.

Can you tell me if this can work or not?

heroiczero
@heroiczero
Jul 15 2017 09:48
@a27-suryansh if you want to do it that way you you should either use a loop to make new links for each channel or use each
a27-suryansh
@a27-suryansh
Jul 15 2017 09:49
Why is my offline list not coming
makalohri
@makalohri
Jul 15 2017 09:49
@knrt10 thank younmate
CamperBot
@camperbot
Jul 15 2017 09:49
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 458 | @knrt10 |http://www.freecodecamp.com/knrt10
heroiczero
@heroiczero
Jul 15 2017 09:50
@a27-suryansh i can see your offline list in the offline list starts here?
a27-suryansh
@a27-suryansh
Jul 15 2017 09:50
See but it is not coming in the white wrapper
@heroiczero
Ghulam Shabir
@ghulamshabir
Jul 15 2017 09:52
@KsangwanA strLength will hold only the last word length, either use push on strLength or index notation strLength[i] to fill all words lengths
Pieter Stokkink
@forkerino
Jul 15 2017 09:53
@a27-suryansh looks like you put it in the wrong element on the page then
@ghulamshabir :wave: Long time no see! How are you?
Ghulam Shabir
@ghulamshabir
Jul 15 2017 09:54
@forkerino hi I am fine :smile: how about you ? yeah finally I am back
a27-suryansh
@a27-suryansh
Jul 15 2017 09:54
No @forkerino
Pieter Stokkink
@forkerino
Jul 15 2017 09:55
@ghulamshabir I'm good. I found a job as a developer a few weeks ago. Have been learning a ton on the job.
heroiczero
@heroiczero
Jul 15 2017 09:55
@KsangwanA personally i would either use a if statement or use reduce to find the word that is the longest if(previousWordlength>currentWordlength)
Ashish Kumar Sangwan
@KsangwanA
Jul 15 2017 09:55
@ghulamshabir I did the push method and it did show 2 objectives complete but not all.
Pieter Stokkink
@forkerino
Jul 15 2017 09:56
@a27-suryansh well, if you want it in the white wrapper, you need to put it in an element that is actually inside the white wrapper in the html
Ghulam Shabir
@ghulamshabir
Jul 15 2017 09:56
@forkerino wow congrats I knew it because you were working hard :smile:
Ashish Kumar Sangwan
@KsangwanA
Jul 15 2017 09:56
@forkerino wow nice to hear
a27-suryansh
@a27-suryansh
Jul 15 2017 09:56
@forkerino I am targetting .offline-result
It is under white wrapper only @forkerino
Pieter Stokkink
@forkerino
Jul 15 2017 09:57
@ghulamshabir yeah, hard work pays off.
@a27-suryansh ah, ok, I understand the misconception.
@a27-suryansh I thought you talked about the first .getJSON
Ghulam Shabir
@ghulamshabir
Jul 15 2017 09:58
@forkerino any guidelines for unlucky ones like myself to walk on the right path if you don't mind
Pieter Stokkink
@forkerino
Jul 15 2017 09:58
You cannot really use the offline array outside of the callback.
@a27-suryansh
@a27-suryansh so you have to nest your getJSON calls
a27-suryansh
@a27-suryansh
Jul 15 2017 09:59
@forkerino Thanks
CamperBot
@camperbot
Jul 15 2017 09:59
a27-suryansh sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2847 | @forkerino |http://www.freecodecamp.com/forkerino
Ankur sharma
@ankur1163
Jul 15 2017 10:01
when i use something like this
Pieter Stokkink
@forkerino
Jul 15 2017 10:01
@ghulamshabir have a clear idea of where you want to go and work towards that. Always try to stretch your mind so that you can grow and do more complex things. Make sure that every new project or challenge you take on either helps you learn something new or helps you integrate the things you have learned previously.
Ankur sharma
@ankur1163
Jul 15 2017 10:02
<p> some randomg text</p><p>other text</p>
the second p blobk goes below the first one
Pieter Stokkink
@forkerino
Jul 15 2017 10:02
yes
Ankur sharma
@ankur1163
Jul 15 2017 10:02
i want to achieve something like this
basically same line
Ghulam Shabir
@ghulamshabir
Jul 15 2017 10:02
@forkerino great suggestion thank you :smile:
CamperBot
@camperbot
Jul 15 2017 10:02
ghulamshabir sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2848 | @forkerino |http://www.freecodecamp.com/forkerino
Ankur sharma
@ankur1163
Jul 15 2017 10:02
but first few words have different ocolor
Pieter Stokkink
@forkerino
Jul 15 2017 10:02
@ankur1163 use a span tag
and add a CSS class to that
@ghulamshabir you're welcome
great to have you with us again!
Ankur sharma
@ankur1163
Jul 15 2017 10:04
so wrap both p tag inside span?
ahh ok
Pieter Stokkink
@forkerino
Jul 15 2017 10:05
@ankur1163 You can wrap everything in ONE p tag and use span around the words you want to give different style
Michiel
@MichielHuijse
Jul 15 2017 10:05
Want to make a dropdown in withbootstrap in codepen and somehow it does not toggle the class. What is wrong? Think I followed the documentation: http://getbootstrap.com/javascript/#dropdowns https://codepen.io/michiel-huijse/pen/MoxLoz
Ankur sharma
@ankur1163
Jul 15 2017 10:05
worked
:)
Pieter Stokkink
@forkerino
Jul 15 2017 10:05
:+1:
Ankur sharma
@ankur1163
Jul 15 2017 10:06
@forkerino how do i improve my css ckills?
Pieter Stokkink
@forkerino
Jul 15 2017 10:06
@ankur1163 don't ask me, I suck at css and don't like doing the graphical side of things too much. However..... Practice makes perfect.
I like flexbox
and enjoyed the free course by Wes Bos at flexbox.io
heroiczero
@heroiczero
Jul 15 2017 10:07
@MichielHuijse you are using bootstrap 3 documentation but you linked bootstrap 4 in your setting of your codepen
Ankur sharma
@ankur1163
Jul 15 2017 10:07
cool @forkerino
Michiel
@MichielHuijse
Jul 15 2017 10:07
@heroiczero aah stupid me thanks
CamperBot
@camperbot
Jul 15 2017 10:07
michielhuijse sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1490 | @heroiczero |http://www.freecodecamp.com/heroiczero
Ankur sharma
@ankur1163
Jul 15 2017 10:07
there should be bootcamp for css as well
:)
a27-suryansh
@a27-suryansh
Jul 15 2017 10:08
@forkerino Congrats for your First Developer Job!, if you don't mind can i ask you a question?
Ghulam Shabir
@ghulamshabir
Jul 15 2017 10:09
@forkerino are you working on server side ? nodejs ?
Pieter Stokkink
@forkerino
Jul 15 2017 10:11
@ghulamshabir I'm working mostly frontend (Angular with Redux). Server is Python/Django. It's a small team, so we do code reviews from others and I will look at backend stuff as well and learn from it.
@a27-suryansh ask!
a27-suryansh
@a27-suryansh
Jul 15 2017 10:13
@forkerino Are you graduated from college? I am asking this coz i think you learned all the skills from FCC
Ghulam Shabir
@ghulamshabir
Jul 15 2017 10:14
@forkerino oh it's not what you have practiced so far :worried: , are you struggling to learn ? them, because I found angular very difficult and redux is too complicated
Michiel
@MichielHuijse
Jul 15 2017 10:15
@heroiczero still doesn't work.. https://codepen.io/michiel-huijse/pen/MoxLoz
Pieter Stokkink
@forkerino
Jul 15 2017 10:16
@a27-suryansh I have a master's degree in Philosophy, so that helps with thinking in abstract concepts and using logic, but other than that no real prior coding experience (beside building a few websites with wordpress/joomla in the past, but the coding is hidden away and you just work with an interface).
a27-suryansh
@a27-suryansh
Jul 15 2017 10:17
@forkerino Work Good to know that
Means employers are not concerned about degrees anymore right? @forkerino Can i get a good job without degree but only based on my skills
Pieter Stokkink
@forkerino
Jul 15 2017 10:18
@ghulamshabir Yeah, the angular part is a bit difficult, but I got a great colleague who knows it inside and out and he's helping me to slowly understand the different parts of the existing app. I did actually learn some Redux before starting (it was part of the technical interview as well) . They were looking for someone who could code well (which I think I can, at least am well on the way) and learn fast, not necessarily someone who knew everything about Angular/Redux.
@a27-suryansh you definitely can. A degree will demonstrate that you have the ability to do a certain type of work and a certain level of intellectual skill, but it is definitely not everything and you can demonstrate these things in other ways as well.
a27-suryansh
@a27-suryansh
Jul 15 2017 10:20
@forkerino Thanks
CamperBot
@camperbot
Jul 15 2017 10:20
a27-suryansh sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: a27-suryansh already gave forkerino points
Alan Alickovic
@alan2207
Jul 15 2017 10:21
@forkerino hey, what do you think about react in comparison to angular?
Ghulam Shabir
@ghulamshabir
Jul 15 2017 10:21
@forkerino lucky you are to have a kind colleague, I think you should spend all of your spare time on learning angular/redux
Markus Kiili
@Masd925
Jul 15 2017 10:24
@forkerino Is it with the new Angular version?
Pieter Stokkink
@forkerino
Jul 15 2017 10:24
@alan2207 I prefer React to Angular. And I think in today's market learning React is a good decision. However, I don't mind learning Angular. It's just a framework, no magic.
@Masd925 no, 1.5. We might switch to React at some point, as my frontend colleague is also not the biggest fan of Angular and we are now building the capacity in the team to handle such a shift.
Ogundele Olumide
@Lumexralph
Jul 15 2017 10:26
@ghulamshabir is this an array-like object or an array? whaaaaat!!
@forkerino @Masd925 Good Morning
Pieter Stokkink
@forkerino
Jul 15 2017 10:27
@ghulamshabir I'm already learning it on the job. Not sure if spending all my spare time on it would be beneficial for my mental health.
@Lumexralph Bro!
Markus Kiili
@Masd925
Jul 15 2017 10:28
@forkerino Ok. I don't mind working with angular but never started to love it.
Ghulam Shabir
@ghulamshabir
Jul 15 2017 10:28
@Lumexralph hey bro :wave: , I was helping a camper, he just named the array like that
WAINGOR
@WAINGOR
Jul 15 2017 10:28
@a27-suryansh I used to pose these exact questions. Thoughts running through my mind were ones of this kind:
"hmmm I never excelled at math or other exact sciences, this probably isnt for me"
or "hmmm I wont have anything to show for (eg degrees), how will I get a job"
Fact is I got hired as a developer after only 6 months of self teaching. Mind you: those were 6 months of long days, hard work and dedication. Imo those 2 outweigh all the rest
Alan Alickovic
@alan2207
Jul 15 2017 10:28
@forkerino thanks for the answer, and congrats for the job :smile:
CamperBot
@camperbot
Jul 15 2017 10:28
alan2207 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2849 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 15 2017 10:29
@WAINGOR :clap:
WAINGOR
@WAINGOR
Jul 15 2017 10:29
@forkerino right back at ya colleague :D
Pieter Stokkink
@forkerino
Jul 15 2017 10:29
@Masd925 I hear that from a lot of people.
Markus Kiili
@Masd925
Jul 15 2017 10:29
@Lumexralph Yo.
@forkerino A bit too complex for my taste.
Ogundele Olumide
@Lumexralph
Jul 15 2017 10:30
@ghulamshabir is champ around ?
Ghulam Shabir
@ghulamshabir
Jul 15 2017 10:30
@Masd925 he Markus :wave:
Markus Kiili
@Masd925
Jul 15 2017 10:30
@ghulamshabir Yo.
Pieter Stokkink
@forkerino
Jul 15 2017 10:30
@Masd925 that's also why I prefer React. Fewer balls to juggle.
Ghulam Shabir
@ghulamshabir
Jul 15 2017 10:31
@Lumexralph haha you still remember :smile: , he will be coming in a week or two
Markus Kiili
@Masd925
Jul 15 2017 10:31
@forkerino I am probably trying to apply for one master/apprentice program one firm is offering. Working on my own is quite bad on the long run.
Ashish Kumar Sangwan
@KsangwanA
Jul 15 2017 10:32
hey guys how to turn the first letter of a string to uppercase.
Markus Kiili
@Masd925
Jul 15 2017 10:32
@KsangwanA Strings are immutable, so you need to make a new string from the old.
You can assign it back to the same variable if you like.
Pieter Stokkink
@forkerino
Jul 15 2017 10:32
@Masd925 That's what I bumped into before finding this job. I really needed to be part of a team so I could continue to grow.
WAINGOR
@WAINGOR
Jul 15 2017 10:34
@forkerino how are you liking angular? I hear so many different things about it.. I
@WAINGOR it's ok, but haven't had the Aha moment I had when starting to work with React.
WAINGOR
@WAINGOR
Jul 15 2017 10:35
Lol stop it please. I was just about to join the cool kids and understanding ES6 XD
Markus Kiili
@Masd925
Jul 15 2017 10:35
@WAINGOR No hurry. Most of production front ES6 js is still transpiled into ES5.
Ashish Kumar Sangwan
@KsangwanA
Jul 15 2017 10:36
@heroiczero yeah but if I want to uppercase only the first letter of the string then what should I use as endIndex.
WAINGOR
@WAINGOR
Jul 15 2017 10:36
whats the difference between compiling and transpiling? I would guess there is a shift of form happening in the latter but I have no idea rlly
Pieter Stokkink
@forkerino
Jul 15 2017 10:37
@WAINGOR after ES6 the changes have become a lot smaller, because ES5 was 6 years old by the time ES6 came around and now they do yearly additions to the spec. So it's easier to learn ES7/8 coming from 6 compared to ES6 coming from 5.
heroiczero
@heroiczero
Jul 15 2017 10:38
@KsangwanA i would do something like word[0]+ word.slice(begin,end) or something like that
Markus Kiili
@Masd925
Jul 15 2017 10:39
@WAINGOR I think it is called transpiling if the code stays at the same level of abstraction. ES6->ES5 would be transpiling. Java to bytecode would be compiling.
WAINGOR
@WAINGOR
Jul 15 2017 10:39
OK thnx both :)
Ashish Kumar Sangwan
@KsangwanA
Jul 15 2017 10:43
@heroiczero can you give an example ? thanks
CamperBot
@camperbot
Jul 15 2017 10:43
ksangwana sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1491 | @heroiczero |http://www.freecodecamp.com/heroiczero
heroiczero
@heroiczero
Jul 15 2017 10:47
@KsangwanA
var word="free";
word= word[0].toUpperCase()+word.slice(1);
return word;
abraham anak agung
@padunk
Jul 15 2017 10:50
@heroiczero you should write var word = "free"
Ashish Kumar Sangwan
@KsangwanA
Jul 15 2017 10:54
@heroiczero okkk let me try that thx again
CamperBot
@camperbot
Jul 15 2017 10:54
ksangwana sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:warning: ksangwana already gave heroiczero points
WAINGOR
@WAINGOR
Jul 15 2017 11:35

Hi guys, I wanna check if I got my facts right:

( !func(arr[0]))

this piece of code says "( !func(arr[0]))" returns a falsy value right?

korzo
@korzo
Jul 15 2017 11:39
@WAINGOR ! before expression means negation. If return value of func is true, it will return false.
Pieter Stokkink
@forkerino
Jul 15 2017 11:45
* truthy
Diego Mayer
@Chrono79
Jul 15 2017 12:01
:wave: @all
ioakeimo
@ioakeimo
Jul 15 2017 12:10
ES6 question:
When should i declare my functions as function name(args){} and when should I use anonymous function declarations like const name = () => {} ??
Vikram
@vikramnr
Jul 15 2017 12:13
Beta returning LoopProtect not defined error?? the challenge is finding longest word in the string
Pieter Stokkink
@forkerino
Jul 15 2017 12:13
@vikramnr what's your code?
Vikram
@vikramnr
Jul 15 2017 12:14
image.png
@forkerino this passes test in freecodecamp.org
Pieter Stokkink
@forkerino
Jul 15 2017 12:16
@vikramnr it'll be good if you report the error even when you pass the test. Probably something is not set up entirely correct on FCC's side.
@ioakeimo named functions are a lot easier to debug and in my opinion are easier to read if the function is more than a few lines. Also this behaves differently in both, so you can leverage that (both have their use cases)
@Chrono79 :wave:
@Chrono79 this one is kicking my butt now: https://www.codewars.com/kata/mine-sweeper/train/javascript
a few edge cases really mess with my head.
ioakeimo
@ioakeimo
Jul 15 2017 12:22
@forkerino my issue is that I want to make the best out of scoping capabilities and I'm trying to understand When and How to decide one or the other depending on the case
Pieter Stokkink
@forkerino
Jul 15 2017 12:25
@ioakeimo I cannot really give a definitive answer on this. There's a discussion on precisely this subject in Kyle Simpsons ES6 book: https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20%26%20beyond/ch2.md#arrow-functions
WAINGOR
@WAINGOR
Jul 15 2017 12:28
thanks @korzo
CamperBot
@camperbot
Jul 15 2017 12:28
waingor sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 251 | @korzo |http://www.freecodecamp.com/korzo
ioakeimo
@ioakeimo
Jul 15 2017 12:29
@forkerino thanks!
CamperBot
@camperbot
Jul 15 2017 12:29
ioakeimo sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2850 | @forkerino |http://www.freecodecamp.com/forkerino
WAINGOR
@WAINGOR
Jul 15 2017 12:30
Hi all, when looking for documentation on .splice @ mozilla they say:
Index at which to start changing the array (with origin 0). If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end of the array (with origin 1) and will be set to 0 if absolute value is greater than the length of the array.
What doe they mean with origin?
Stephen James
@sjames1958gm
Jul 15 2017 12:33
@WAINGOR The first index of the array is zero
@WAINGOR For backwards the last element of the array is -1
Basically what is the starting value going in each direction
ioakeimo
@ioakeimo
Jul 15 2017 12:39
@forkerino btw, what cases are troubling you with minesweeper?
Pieter Stokkink
@forkerino
Jul 15 2017 12:41

stuff like:

0 0 0 0 1 ? ? ? ? ?
0 0 0 1 2 ? ? 2 ? ?
0 1 1 2 x 2 2 x 2 1
1 2 x 2 1 1 1 1 1 0
? ? 2 1 0 0 0 0 0 0
? ? 1 0 0 0 0 0 0 0

when there are 3 bombs left

@ioakeimo
I can solve it in my head, but in code is a different animal
WAINGOR
@WAINGOR
Jul 15 2017 12:43
@sjames1958gm I find it hard to find the added value of putting this info(by mozilla) Am I right to think that this explanation changes nothing about the status quo of arrays being zero-indexed?
ioakeimo
@ioakeimo
Jul 15 2017 12:44
@forkerino that is actually hard to solve even in the head. Looking at the lower left edge which seems a bit simpler the problem seems to actually be probabilistic...
Pieter Stokkink
@forkerino
Jul 15 2017 12:45
@ioakeimo My current idea is to make a selection of ?s that might have a bomb in them, count distinct groups and check against the number of bombs left. Open the rest if possible.
But not sure how to implement
Vikram
@vikramnr
Jul 15 2017 12:46
@forkerino Will raise an issue..?
Stephen James
@sjames1958gm
Jul 15 2017 12:46
@WAINGOR I think they are only stressing the fact that backwards starts at one vs zero. Basically because minus zero has now meaning
Pieter Stokkink
@forkerino
Jul 15 2017 12:46
@vikramnr might be a good idea.
ioakeimo
@ioakeimo
Jul 15 2017 12:48
@forkerino just thinking aloud, left bottom edge can be opened
Pieter Stokkink
@forkerino
Jul 15 2017 12:48
@ioakeimo yes, top row 4 last ? as well
ioakeimo
@ioakeimo
Jul 15 2017 12:49
let me check
you have 3 left right? 1 is 100% on left bottom edge and there might be 2. Because of the upper right grid, you know that at least one other bomb is in 2nd row last 2 ? and one MUST be on the left of that same row area
so Now you DO know that left there is only 1 bomb
for a total of 3
so left bottom should look like
1x
11
for my previous reasoning you are also free to open up the whole 1st row
And work from there
Pieter Stokkink
@forkerino
Jul 15 2017 12:53
@ioakeimo yeah, that was my idea as well, but now to the code. Writing your thinking out like you just did is helpful. I can work with that. Thanks for thinking along.
CamperBot
@camperbot
Jul 15 2017 12:53
forkerino sends brownie points to @ioakeimo :sparkles: :thumbsup: :sparkles:
:cookie: 304 | @ioakeimo |http://www.freecodecamp.com/ioakeimo
ioakeimo
@ioakeimo
Jul 15 2017 12:55
@forkerino my pleasure, I've always liked challenges like that. For your coding just find a way to model that counting... You can find a way to evaluate that there must be 2 bombs on an area which produces a MUST rule for an other area to only have a limited number of bombs
Ashley Owens
@yelhsa
Jul 15 2017 13:10
Hello. I am on the card counting challenge and I was wondering if someone could explain why my code does not satisfy the 5 and 6 situations.
image.png
which are:
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
Cards Sequence 2, 2, 10 should return "1 Bet"
Alex
@alexandrupintilei
Jul 15 2017 13:16
https://codepen.io/balexoy/pen/VWbNaQ
I want to show a pic in function of weather,can someone help me?
Ashley Owens
@yelhsa
Jul 15 2017 13:16
Oh. Wait I get it. Can you put an if statement within an if statement?
Pieter Stokkink
@forkerino
Jul 15 2017 13:18
@yelhsa you can, but in this case it is better to separate the part where you increment/decrement count from the part where you return
ioakeimo
@ioakeimo
Jul 15 2017 13:18
@yelhsa you should return the string depending on whether count>0 or not, you are returning that string depending on what the card is
Also, checking for 7..9 and running count=count +0; is redundant you can just skip it
Ashley Owens
@yelhsa
Jul 15 2017 13:21
I figured it out. Thanks :)
Thanks @forkerino @ioakeimo
CamperBot
@camperbot
Jul 15 2017 13:22
yelhsa sends brownie points to @forkerino and @ioakeimo :sparkles: :thumbsup: :sparkles:
:star2: 2851 | @forkerino |http://www.freecodecamp.com/forkerino
:cookie: 305 | @ioakeimo |http://www.freecodecamp.com/ioakeimo
Moisés Man
@moigithub
Jul 15 2017 13:26
@alexandrupintilei u need to find which field on ur data can be used as weather identifier (ie: rain, clouds, sun, storm or sometihng similar values )
then add some conditions to select a background pic name
@alexandrupintilei also u should TEST more often (run ur code.. to check if it works) do not wait untill u have > 10~20 lines of code to test... will make harder to debug
Alex
@alexandrupintilei
Jul 15 2017 13:30
@moigithub Thanks
CamperBot
@camperbot
Jul 15 2017 13:30
alexandrupintilei sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3506 | @moigithub |http://www.freecodecamp.com/moigithub
Alex
@alexandrupintilei
Jul 15 2017 13:31
Should i add bckg img with addClass?
Dan Couper
@DanCouper
Jul 15 2017 13:33
@ioakeimo function declarations (function myFunc(){} are hoisted to the top of the scope, function expressions (const myFunc = () => {}) aren't. So if you have a variable you're using inside the function that's defined outside the function, you have to declare it before the function expression (ie due to closure, the environment that exists when the function is called will include values existing in the scope it was defined in. With expressions you need to physically define those values before the actual expression). Also, if you want self-executing functions, use expressions. And use often need to use arrow functions if you're using this (eg inside class methods and want to refer to the class object). Otherwise very often just stylistic choice
shivam gupta
@shivamg11000
Jul 15 2017 13:38
how to make XMLHttpRequest make work with jsonp
Moisés Man
@moigithub
Jul 15 2017 13:39
probably easier if u use jQuery instead of XMLHttpRequest
jsonp is not exactly an ajax request @shivamg11000
ioakeimo
@ioakeimo
Jul 15 2017 13:39
@DanCouper doesn't that first point mean that you are obliged to produce better structured code when using expressions? I mean functions could in that matter give you the freedom of constructing spaghetti code with no issues, while using expressions wouldn't allow that. I'm only trying to pick up good practices so I'm trying to figure things out early on with every step I make... This first point is what troubles me more, because everything else is mostly backed by difference in functionality and capabilities. What I want to know is when both would work, which shall I choose?
mithun
@dmithun
Jul 15 2017 13:42

function truncateString(str, num) {
// Clear out that junk in your trunk

if(str.length>num ){
return str.slice(0, num-3)+ '...';
}
else if (st.length<=3){
return str.slice(0, num)+ '...';
}
else{
return str;
}
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);

guys help me
shivam gupta
@shivamg11000
Jul 15 2017 13:44
@moigithub I know it easier to use jquery, but still I want to know a way with XMLHttpRequest
Moisés Man
@moigithub
Jul 15 2017 13:45
@shivamg11000 jsonp request dont use XMLHttpRequest at all... it use the script tag to bypass the browser cors restriction
u can find some/many code snippets on stackoverflow/google
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 13:46
@dmithun make sure that the string has to be greater than the number provided then once the string is greater then you can have those is statements.
shivam gupta
@shivamg11000
Jul 15 2017 13:47
@moigithub I saw the explanation on stackoverflow but a live example would be aprreciated
If you can give me a example , give with this
https://codepen.io/shivamg11000/pen/VWRqaq?editors=1010
Dan Couper
@DanCouper
Jul 15 2017 13:50
@ioakeimo In a sense, yes: you have to write your code sequentially. And if you see code written by ML (SML,F#,Haskell,OCAML) programmers, they have to do that, in their language, and their JS code always looks like that. But what it also means is you have to be a lot more careful about doing things like write helper functions, they have to come before the rest of the code. Being able to write functions in any order generally makes things easier when you're structuring your code, you can write them in an order that makes logical sense, grouping similar things together. Note that in practise, the hoisting issue generally isn't an that much of an issue; usage is generally interchangeable.
mithun
@dmithun
Jul 15 2017 13:54
i'm not getting it man @RoniqueRicketts , can u give me more hints???????
ioakeimo
@ioakeimo
Jul 15 2017 13:57
@DanCouper I see. So what would your personal point and advice be when I come to the question "I could use both here, what should I choose?" ?
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 13:59
@dmithun 1. ensure that the string is greater than the number. Once that's met, you want to check to see if the number is less or equal to 3 if its not less then 3 then do something else and if both criteria fail then just return the string that was given.
Moisés Man
@moigithub
Jul 15 2017 14:01
https://codepen.io/MMan/pen/ZyPZNR?editors=1010 @shivamg11000
jsonp uses (like said above) the script tag to load data to bypass cors restriction
it DO NOT uses XML/ajax request
ofc most of the snippets u find on stackoverflow/other sites do that using pure code only instead of hardcoding like this EXAMPLE
Dan Couper
@DanCouper
Jul 15 2017 14:03
@ioakeimo Whatever is easier in the context. IMO use function declarations everywhere, use expressions inside those functions for throwaway things as they're often shorter and you can put them on a single line. Always use them for callbacks for the same reason (arr.map(v => v + 1) rather than arr.map(function(v){ return v + 1})), and particularly if you need to keep hold of this. The difference a fair % of the time is cosmetic, they're going to do the same thing 99% of the time, so up to you.
ioakeimo
@ioakeimo
Jul 15 2017 14:04
@DanCouper ok, thanks for the insight! :)
CamperBot
@camperbot
Jul 15 2017 14:04
ioakeimo sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 840 | @dancouper |http://www.freecodecamp.com/dancouper
Dan Couper
@DanCouper
Jul 15 2017 14:05
☺️👍
shivam gupta
@shivamg11000
Jul 15 2017 14:18
@moigithub thanks for the example,
CamperBot
@camperbot
Jul 15 2017 14:18
shivamg11000 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3507 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Jul 15 2017 14:19
jsonp https://stackoverflow.com/questions/6132796/how-to-make-a-jsonp-request-from-javascript-without-jquery/6132828#6132828
function doSomething(data){
  console.log(data)
}

var url ="https://en.wikipedia.org/w/api.php?action=opensearch&search=India&origin=*&callback=doSomething";
var script = document.createElement('script');
script.src = url

document.getElementsByTagName('head')[0].appendChild(script);
a27-suryansh
@a27-suryansh
Jul 15 2017 14:20
https://codepen.io/a27suryansh/pen/WOmWJR?editors=1111
Why is my Code Not working ? Please help
@WAINGOR Thanks you have inspired me today
CamperBot
@camperbot
Jul 15 2017 14:21
a27-suryansh sends brownie points to @waingor :sparkles: :thumbsup: :sparkles:
:cookie: 243 | @waingor |http://www.freecodecamp.com/waingor
shivam gupta
@shivamg11000
Jul 15 2017 14:22
@moigithub the script is loading the data as object
a27-suryansh
@a27-suryansh
Jul 15 2017 14:28
@forkerino as you said earlier i am nesting it within the callback why is it not working then any idea?
Siphils
@Siphils
Jul 15 2017 14:52
function reverseString(str){
            var strArray = str.split(" ");
            var strNewArray = strArray.reverse();
            var newStr = "";
            var NewArray = [];
            for(var i=0;i<strNewArray.length;i++){
                for(var j=strNewArray[i].length-1;j>-1;j--){
                    newStr+=strNewArray[i][j];
                }
                NewArray.push(newStr);
                newStr="";
            }
            str=NewArray.join(" ");
            return str;
        }
Reverse a String. How can I make it more simple?
Pieter Stokkink
@forkerino
Jul 15 2017 14:53
@a27-suryansh what is not working exactly? I see a list of users with their user images.
@Siphils split on empty string, then you won't need a loop. You can also chain methods.
Siphils
@Siphils
Jul 15 2017 14:56
@forkerino Thx :) I will try it later.
CamperBot
@camperbot
Jul 15 2017 14:56
siphils sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2852 | @forkerino |http://www.freecodecamp.com/forkerino
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 14:57
Gm nerds. How's it going ?
Yes u r
Siphils
@Siphils
Jul 15 2017 14:58
I make it so complex...:P
BrianWilliams28
@BrianWilliams28
Jul 15 2017 15:27
Could someone take a look at my pen and tell me why they think my click function at the bottom isn't hiding/showing the streamers? (yes I copied the example project's layout lol)
https://codepen.io/BrianWilliams28/pen/QgOZob?editors=1010
Kevin
@kevinwr
Jul 15 2017 15:28

Hey, guys. I need some help figuring out how to submit my form data with javascript.

RIght now, I'm working on the wikipedia project. I have my input field in a form, and when the user submits the form, I need that text to be submitted to the wikipedia API by attaching it to the request URL.

With a form, you normally have the "action" attribute to submit data, which I don't want to use. Instead, I want to use javascript to control the form data and what happens to it. My question is, how do I get that user input from the form into the API url?

cowCrazy
@cowCrazy
Jul 15 2017 15:37
@BrianWilliams28 you should better work with hidden attribute, change the add/removeClass to attr("hidden", true / false)
BrianWilliams28
@BrianWilliams28
Jul 15 2017 15:37
@cowCrazy is the "hidden-xs" class in the right spot to fully hide the row with the current code?
cowCrazy
@cowCrazy
Jul 15 2017 15:39
with adding a css rule, you need to make sure it is not colliding with other classes, and other rules, makes it a bit more tricky....
Alex
@alexandrupintilei
Jul 15 2017 15:40
https://codepen.io/balexoy/pen/VWbNaQ?editors=0010
Why cTemp it dosent taked as default?
BrianWilliams28
@BrianWilliams28
Jul 15 2017 15:40

@cowCrazy so how would you write the part that shows/hides those classes? something like this?

$(".online").attr(hidden, false);

?

cowCrazy
@cowCrazy
Jul 15 2017 15:41
yes, with hidden as a string => "hidden"
BrianWilliams28
@BrianWilliams28
Jul 15 2017 15:45
@cowCrazy thanks for the tip, but I still can't figure out why when i click on the selectors the rows are not showing/hiding. the example project's code is written the same way and it works in that version =/
cowCrazy
@cowCrazy
Jul 15 2017 15:46
@kevinwr you can look a bit into js eventListeners and see which one is fitting for you, somethign like onkeyup or onchange
BrianWilliams28
@BrianWilliams28
Jul 15 2017 15:49
@cowCrazy nvm i figured it out, i changed bootstrap version to 3.5 and its working now
cowCrazy
@cowCrazy
Jul 15 2017 15:51
@BrianWilliams28 also a point to notice when you use external css libraries is that you need to check sometimes what do their class really do, then you can better figure out how to overcome such bugs/difficulties
BrianWilliams28
@BrianWilliams28
Jul 15 2017 15:52
@cowCrazy yeah i understand, ive been building most of my front end projects in bootstrap 4, it creates confusion for me when referencing the example project which is using version 3
Jiri Laza
@N4thyra
Jul 15 2017 16:31
Hey folks, could anyone help me figure out a problem with ajax? I'm working on a quote machine, but it always loads no data for the first time.

``` $(() => {

const url = 'https://random-quote-generator.herokuapp.com/api/quotes/random';
const click = $('#next-quote');
let author = '';
let quote = '';

function genQuote() {
$.ajax({
type: 'GET',
url,
success: data => {
author = '- ' + data.author;
quote = data.quote;
if (!quote) {
console.log('generating new data');
genQuote();
}
}
});
}

(function defaultData() {
$('#text').html(quote);
$('#author').html(author);
}());

click.on('click', () => {
genQuote();
console.log('author', author);
console.log('quote', quote);
$('#text').html(quote);
$('#author').html(author);
});
});
```

Pieter Stokkink
@forkerino
Jul 15 2017 16:46
@N4thyra you mean that it doesn't run the first time only? Maybe you should call genQuote() in your defaultData() function.
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 16:46
@forkerino :wave:
Pieter Stokkink
@forkerino
Jul 15 2017 16:59
@saifsmailbox98 yo
Aata-allah
@Atalaa
Jul 15 2017 17:01

Hello

var tile = dGrid[xx + yy*w];
this.score = tile.value;
this.score.innerHTML = "Score = " + this.score;

it says undefined in the console, why ?

im stuck
    this.score = document.getElementById("score");
Ken Haduch
@khaduch
Jul 15 2017 17:22
@Atalaa do you have an element with the id value equal to "score"? That's the first place to look - do you have a URL for your project that you can share?
Nerando Johnson
@Nerajno
Jul 15 2017 17:31
greetings
hope all is well
can someone look at this an tell me whats up with this piece of code
``````
``````
//Change the icon based on the weather description
      var iconChange = data.weather[0].icon;
      switch (iconChange) {
        case "04d";
             $("#weather-icon").html(weather-icon="http://openweathermap.org/img/w/04d.png");
          break;
        default:
          console.log("nothing to see here" );
      }
Pieter Stokkink
@forkerino
Jul 15 2017 17:34
.html(weather-icon="http://openweathermap.org/img/w/04d.png"); looks weird...
@Nerajno
Nerando Johnson
@Nerajno
Jul 15 2017 17:35
@forkerino i am trying to write the icon to the index page , i am considering to jus to a document.write
Pieter Stokkink
@forkerino
Jul 15 2017 17:37
@Nerajno well the html you write doesn't look like html
so I think there's the problem
Nerando Johnson
@Nerajno
Jul 15 2017 17:39
@forkerino i am trying to switch out an id that is an icon
Pieter Stokkink
@forkerino
Jul 15 2017 17:41
@Nerajno .html will change the html inside the element you selected.
Nerando Johnson
@Nerajno
Jul 15 2017 17:42
i am reworking on it
reworking in rather @forkerino
thanks @forkerino
CamperBot
@camperbot
Jul 15 2017 17:43
nerajno sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2853 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 15 2017 17:44
@Nerajno the argument to .html should be a string . Maybe you can just change and attribute? https://api.jquery.com/attr/
Scott Rhoades
@srhoades
Jul 15 2017 17:56
@Nerajno document.getElementById("ID").style.backgroundImage ='url("URL")';
Nerando Johnson
@Nerajno
Jul 15 2017 17:59
@srhoades i want to change an icon
Scott Rhoades
@srhoades
Jul 15 2017 18:00
is the icon a image or text?
Nerando Johnson
@Nerajno
Jul 15 2017 18:00
that looks like it should change the background
Scott Rhoades
@srhoades
Jul 15 2017 18:01
of a tag
Nerando Johnson
@Nerajno
Jul 15 2017 18:02
``````
<img class="weather-icon" src="http://openweathermap.org/img/w/10d.png">
it was targetting that
i need to target that an change it based on it
on the information via a JSON CAll
Scott Rhoades
@srhoades
Jul 15 2017 18:04
thats easier give it an id then document.getElementById("ID").src = "x"
Nerando Johnson
@Nerajno
Jul 15 2017 18:05
define "x" ?
would be the source ?
Scott Rhoades
@srhoades
Jul 15 2017 18:08
yeah
Nerando Johnson
@Nerajno
Jul 15 2017 18:08
ok thanks
hold on lemmie try ?
Scott Rhoades
@srhoades
Jul 15 2017 18:08
no problem
Brooks
@Brodavis
Jul 15 2017 18:10
Im working on the Check for Palindromes exercise,
function palindrome(str) {
  var testStr = str.toLowerCase;
  function reverseString(testStr) {
    return testStr.split("").reverse().join("");
}
  if (testStr == str){
  return true;
  }
  else{
    return false;
  }
}

palindrome("eye");
Some things i know i need to do but am kinda lost- remove special characters and spaces from the str input.
though im not understanding why my function right now isnt printing out false for palindrome("eye");
Pieter Stokkink
@forkerino
Jul 15 2017 18:13
@Brodavis a Regular Expression would be helpful for the replacing. mdn.io/regexp
teevik
@teevik
Jul 15 2017 18:14
@Brodavis You are checking if "eye" == "eye".toLowerCase() which is true
Stephen James
@sjames1958gm
Jul 15 2017 18:14
@Brodavis You are tno calling toLowerCase - you are assign teh reference to the function to testStr
you haven't called the function reverse stringe either
Nerando Johnson
@Nerajno
Jul 15 2017 18:14
i think i fixed it @srhoades
teevik
@teevik
Jul 15 2017 18:15
Oh nevermind
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 18:15
@Nerajno make sure that the last part of http://openweathermap.org/img/w/10d.png has a place holder like http://openweathermap.org/img/w/ + placeholder +.png or http://openweathermap.org/img/w/ + placeholder depending on what the api brings back
kumquatfelafel
@kumquatfelafel
Jul 15 2017 18:19
@Brodavis Also, the testStr inside your reverseString function will not necessarily be the same as the testStr outside of it. It depends on what you pass when you call the function. And since you haven't called that function, it won't reverse the string.

At moment, you are essentially saying "if str is the same as the function str.toLowerCase then return true, otherwise return false."

So you're pretty much guaranteed to return false.

Nerando Johnson
@Nerajno
Jul 15 2017 18:35
@RoniqueRicketts i am a bit lost
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 18:39
@Nerajno dont bother
Stephen James
@sjames1958gm
Jul 15 2017 18:39
@Nerajno You can build a string from your icon from the API.
var url = "http://openweathermap.org/img/w/" + iconChange + ".png";
Then assign to the src attribute of the img tag.
$(".weather-icon).attr("src", url);
Brooks
@Brodavis
Jul 15 2017 18:40
Alright, I used RegEx and called my function
function palindrome(str) {
  var testStr = str.toLowerCase().replace(/\W/g);
  function reverseString(str) {
    return testStr.split("").reverse().join("");
  }
 reverseString();
  if (testStr == str){
  return true;
  }
  else{
    return false;
  }
}

palindrome("eye");
kumquatfelafel
@kumquatfelafel
Jul 15 2017 18:40
@Brodavis Not gonna work. you aren't storing result of calling your function anywhere
Nerando Johnson
@Nerajno
Jul 15 2017 18:41
@Nerajno dont bother @RoniqueRicketts do u need ice cream ?
Stephen James
@sjames1958gm
Jul 15 2017 18:41
@Brodavis Your replace function doesn't have anything to replace.
kumquatfelafel
@kumquatfelafel
Jul 15 2017 18:42
:point_up: this too
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 18:42
@Nerajno lol no, I want to fix my pomodoro clock
Nerando Johnson
@Nerajno
Jul 15 2017 18:42
no there yet but i understand @RoniqueRicketts
thanks @RoniqueRicketts @sjames1958gm
CamperBot
@camperbot
Jul 15 2017 18:44
nerajno sends brownie points to @roniquericketts and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 283 | @roniquericketts |http://www.freecodecamp.com/roniquericketts
:star2: 8074 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ronique Ricketts
@RoniqueRicketts
Jul 15 2017 18:45
@Nerajno Your welcome and I have given myself a target to complete this clock in 2 weeks and I haven't as yet.
kumquatfelafel
@kumquatfelafel
Jul 15 2017 18:45
With regards to your reverse string function itself, since you're saying testStr.split(), and your parameter is str you don't have to worry about testStr being masked anymore, but at the same time the fact you're not actually using the str parameter makes it completely unnecessary. More generally, you don't really need a reverse string function here... it's kinda just gumming up the works at this point.
kumquatfelafel
@kumquatfelafel
Jul 15 2017 18:53

@Brodavis More generally, it's worth noting that because strings are immutable, any string functions that return a "modified" string are not actually achieved by modifying the original string, but returning an entirely new string.

So if I were to, for example, say...

var strA = "Hello World";
var strB = strA.toUpperCase();
console.log(strA) //Hello World. Note that capitalization unchanged.
console.log(strB) //HELLO WORLD
Brooks
@Brodavis
Jul 15 2017 18:55
I get it @kumquatfelafel. I ended up looking at the solution and seeing what i was doing wrong. I was trying to make it much much harder than it needed to be
@kumquatfelafel Thank you !
CamperBot
@camperbot
Jul 15 2017 18:55
brodavis sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 469 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
all your base
kumquatfelafel
@kumquatfelafel
Jul 15 2017 18:58
@MCTwoDigitZero :o
'ello
CallMeOrange
@EgnaroDev
Jul 15 2017 18:58
Yo
With button, looks better and visible
Im going to make another one for hex colors
Brooks
@Brodavis
Jul 15 2017 19:05
I'm having soooo much trouble with the basic algorithm scripting. I want to punch a baby whenever I even look at one. Is there anyway to make learning it easier or does anyone have any suggestions? Or is it more so just keep trying until it clicks sorta thing?
cowCrazy
@cowCrazy
Jul 15 2017 19:09
@Brodavis it is hard in the beginning for most of us, at least for those that are real beginners in programming, take a deep breathe and try again, and if you have problems make sure to read the suggested help sources or to ask here :)
Chasls
@Chasls
Jul 15 2017 19:12
hey all. Im stuck on Check for Palindromes. Does anyone have a doc thats not given to use on the page. I am stuck and the documents they gave don't help as much as I would like
Pieter Stokkink
@forkerino
Jul 15 2017 19:14
@Chasls a RegExp will come in handy. mdn.io/regexp
to replace the non-alphanumeric characters
Chasls
@Chasls
Jul 15 2017 19:15
@forkerino YES! this is the one I was looking for. I found it a couple days ago and couldn't find it! THANK YOU!!
CamperBot
@camperbot
Jul 15 2017 19:15
chasls sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2854 | @forkerino |http://www.freecodecamp.com/forkerino
Stephen James
@sjames1958gm
Jul 15 2017 19:15
@Brodavis Try to reason about the problem before committing to code. Too often you start writing code too soon and get stuck
CallMeOrange
@EgnaroDev
Jul 15 2017 19:15
Really? its in Check for Palindromes' instructions
I guess I created enough fun projects... Going to work on Twitch.tv
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:17
Yup. If you notice there are certain "fundamentals" that are giving you problems, I'd recommend also reviewing/practicing those. Not only asking questions on here, but trying to answer questions on here can also help as well, since trying to explain things to other people can force you to think about things in ways you might not expect... It can also be a sort of informative look at what not to do and why not to do it, at times. ;)
@Brodavis
Stephen James
@sjames1958gm
Jul 15 2017 19:18
@Brodavis There is a technique called rubber duck debugging, where you pretend to explain your code to your rubber duck, The idea is if you cannot explain what your code is doing,
Then it probably isn't going to work
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:19
@sjames1958gm well... you may pretend. :p
Stephen James
@sjames1958gm
Jul 15 2017 19:19
@kumquatfelafel lol
Brooks
@Brodavis
Jul 15 2017 19:22
@sjames1958gm great idea. I'm going to look at all the solutions, try explaining them outloud, then come back later and see if I can do them on my own. Thanks
CamperBot
@camperbot
Jul 15 2017 19:22
brodavis sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8075 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Chasls
@Chasls
Jul 15 2017 19:24
okay with this one. I assuming I use a split to add it all to one string. then reverse it and if its the same = true else return false.

function palindrome(str) {
  if (str.split(" ").join("").reverse() === plaindrome) {


    return true;
  }
    else {
      return false;
    }

  // Good luck!
  return true;
}


palindrome("eye");
This is the first thing that came to my mind for the palindrome. But I am not sure its not working.
Stephen James
@sjames1958gm
Jul 15 2017 19:27
@Chasls you are splitting on " " and joining on "" ?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:27
@Chasls You're chaining your functions improperly. Beyond that, there are other things you have to consider, but let's start here.
tommy
@tommygebru
Jul 15 2017 19:27
Can I use reduce to solve Fibonacci challenge in Freecodecamp??
Stephen James
@sjames1958gm
Jul 15 2017 19:27
@Chasls Review the reverse a string challenge?
Chasls
@Chasls
Jul 15 2017 19:28
@sjames1958gm Yes. so I assuming just change the order of reverse and join?
Stephen James
@sjames1958gm
Jul 15 2017 19:28
@Chasls Yes, but your split parameter is wrong
tommy
@tommygebru
Jul 15 2017 19:28
@Chasls I think you have an extra return true...
Stephen James
@sjames1958gm
Jul 15 2017 19:28
@tommygebru Yes, but I wouldn't suggest it.
@Chasls plaindrome where did this come from?
tommy
@tommygebru
Jul 15 2017 19:29
@sjames1958gm my solution doesnt pass.. with reduce
Chasls
@Chasls
Jul 15 2017 19:29
@sjames1958gm from the function...
Stephen James
@sjames1958gm
Jul 15 2017 19:29
@Chasls 1) it is mispelled, 2) you are trying to compare a string to a function?
@tommygebru you built an array to reduce?
tommy
@tommygebru
Jul 15 2017 19:30
yep
its basically freecodecamps solution
I didnt understand the basic solution, the intermediate made more sense
Stephen James
@sjames1958gm
Jul 15 2017 19:30
@tommygebru Seems like while building the array, you could just sum the values right then.
Show your code
Chasls
@Chasls
Jul 15 2017 19:30
@sjames1958gm so just compare it to the str?
Stephen James
@sjames1958gm
Jul 15 2017 19:31
@Chasls That is a step in the right direction
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:31
:point_up:
There will still be more to do though. ;)
Chasls
@Chasls
Jul 15 2017 19:32
@sjames1958gm okay. Ill do that.
function palindrome(str) {
  if (str.split().revese().join("") === str) {


    return true;
  }
    else {
      return false;
    }

  // Good luck!
  return true;
}
I know this isn't 100% correct yet but this is better than before?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:32
*reverse
Stephen James
@sjames1958gm
Jul 15 2017 19:32
Watch those typos.
Chasls
@Chasls
Jul 15 2017 19:32
yikes! thanks I corrected that.
hmm..
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:33
@Chasls Try palindrome("Eye");
Chasls
@Chasls
Jul 15 2017 19:33
Ahh. @kumquatfelafel I forgot about the lowercase.
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:35
And palindrome("Eye Eyeeye");(should return true)
palindrome("Eye, Eye"); similarly should return true.
Chasls
@Chasls
Jul 15 2017 19:40
@kumquatfelafel hmmm. i confused myself..
korzo
@korzo
Jul 15 2017 19:40
@Chasls You also need regex to remove certain characters
Chasls
@Chasls
Jul 15 2017 19:40
@kumquatfelafel now I am thinking it would be easier to use a RegExp
@korzo hahah yup just thought of that.. haha
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:40
yup
Darren
@DarrenfJ
Jul 15 2017 19:41

i think @kumquatfelafel was hinting at that here:

And palindrome("Eye Eyeeye");(should return true)
palindrome("Eye, Eye"); similarly should return true.

;)
Chasls
@Chasls
Jul 15 2017 19:41
@kumquatfelafel this is why it takes 50 hours to do 15 problems haha. its testing me..
@DarrenfJ yeah I saw that.. I was trying to figure out how to get there. then remembered how kinda.
Darren
@DarrenfJ
Jul 15 2017 19:43
i can't remember if they hinted at it more in earlier versions of fCC
Chasls
@Chasls
Jul 15 2017 19:43
Thank you all. right now I am confused. and need to read the form and docs. Because I don't know how to do that yet.
Darren
@DarrenfJ
Jul 15 2017 19:44
but i just checked and it's not there now (at least not mentioning regex)
Chasls
@Chasls
Jul 15 2017 19:45
no someone sent me a doc on it a little while ago. Im going to read up on it because I still don't know what it all does. or which type I should use
so they did hint at it. It just took me a few to figure it out haha
is this the correct regex?
var re = /\w+/
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:50
@Chasls try and see what happens. Worst comes to worst, have to change it :)
cowCrazy
@cowCrazy
Jul 15 2017 19:51
@Chasls not sure what you are trying to check with regex but this website can be a good sand-box - https://regex101.com
Chasls
@Chasls
Jul 15 2017 19:51
@cowCrazy thanks! This looks interesting.
CamperBot
@camperbot
Jul 15 2017 19:51
chasls sends brownie points to @cowcrazy :sparkles: :thumbsup: :sparkles:
:cookie: 260 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
cowCrazy
@cowCrazy
Jul 15 2017 19:52
Glad I could help :)
Chasls
@Chasls
Jul 15 2017 19:52
@kumquatfelafel i am trying to figure out the best way to add it to my code. stumped on that.
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:54
@Chasls Well... say we have the string "E ye e ,.?( , $ ye"
do we care about all the gobbledigook in the middle?
Chasls
@Chasls
Jul 15 2017 19:54
no..
?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:54
What do we care about?
Chasls
@Chasls
Jul 15 2017 19:55
alphabetical ?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:55
we care about alphabetical. We also care about numerical (excluded from example).
korzo
@korzo
Jul 15 2017 19:55
@kumquatfelafel @Chasls I think alphanumeric
Chasls
@Chasls
Jul 15 2017 19:56
So alphanumerical
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:57
So in checking for palindrome, would we want to compare eyee,.?(,&ye with ey&,(?.,eeye? If not, what would we want to compare instead?
Chasls
@Chasls
Jul 15 2017 19:58
eyeeye..
kumquatfelafel
@kumquatfelafel
Jul 15 2017 19:58
yup
Anthony Contreras
@AmazeCPK
Jul 15 2017 19:58
Chasls
@Chasls
Jul 15 2017 20:06
Okay. so The best way to do that is overlooking the rest.
/(\w+)\s(\w+)/ this is the cloest ht
var pla = str.replace(/\w_/gi, '').toLowerCase();
opps didn't mean that top part.
CallMeOrange
@EgnaroDev
Jul 15 2017 20:07
omg... this is pissing me off
tommy
@tommygebru
Jul 15 2017 20:07
@sjames1958gm this is about as far as I got ...
logic is messed up somewhere
function sumFibs(num) {
    var arrFib = [1];
    var results = 0;
    for (var i = 1; i <= num;) {
        arrFib.push(i);
        i = arrFib[arrFib.length - 1] + arrFib[arrFib.length - 2];
        if (i % 2 !== 0) {
            results = i;
        } //conditional
    } //loop
    return results;
} //function
sumFibs(4);
Darren
@DarrenfJ
Jul 15 2017 20:09
@Chasls i think you get a bot of an intro for free here too: https://www.codeschool.com/courses/breaking-the-ice-with-regular-expressions
WAINGOR
@WAINGOR
Jul 15 2017 20:10

hi all, can someone tell me what

...

is called in JS and what it does?

Chasls
@Chasls
Jul 15 2017 20:10
@DarrenfJ bot of an intro?
@DarrenfJ i love free resources!
kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:11
bit
Chasls
@Chasls
Jul 15 2017 20:11
@kumquatfelafel thanks. My mind is thinking hmm wondering what that function does.
CamperBot
@camperbot
Jul 15 2017 20:11
chasls sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 470 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Chasls
@Chasls
Jul 15 2017 20:14
@kumquatfelafel @DarrenfJ FINALLY ! thanks for all the help. took me a bit but I got it.
CamperBot
@camperbot
Jul 15 2017 20:14
chasls sends brownie points to @kumquatfelafel and @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 1904 | @darrenfj |http://www.freecodecamp.com/darrenfj
:warning: chasls already gave kumquatfelafel points
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:14
evening coders! :wave:
tommy
@tommygebru
Jul 15 2017 20:14
tips for the Fibonacci challenge?
@kjuchtmans hello :)
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:15
@tommygebru I followed this rule of thumb: borrow your Fibonacci generator elsewhere. StackOverflow is a good source. I did the same for a prime numbers generator.
building my code around someone else's is creative stealing in my book. (Didn't Picasso have a quote in this sense?)
kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:16
@tommygebru Suppose arrFib = [1];. What is arrFib.length?
CallMeOrange
@EgnaroDev
Jul 15 2017 20:17
5!
High Five
tommy
@tommygebru
Jul 15 2017 20:20
this is where im at right now @kumquatfelafel @kjuchtmans
function sumFibs(num) {
    var arrFib = [1];
    var results = 0;
    for (var i = 1; i <= num;) {
        arrFib.push(i);
        i = arrFib[arrFib.length - 1] + arrFib[arrFib.length - 2];
        if (i % 2 !== 0) {
            results = i;
        } //conditional
    } //loop
    return results;
} //function
sumFibs(4);
kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:22
@tommygebru That doesn't answer my question.
tommy
@tommygebru
Jul 15 2017 20:22
oh
then answer is 0
length of index 0 is 1
kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:24
nope. arrFib is the array itself. So when I say arrFib.length, I am getting the number of elements in the array arrFib. If arrFib = [1];, then what is arrFib.length? And by extension, what is arrFib.length - 1 and arrFib.length - 2?
LiamAumann
@Aumann-Liam
Jul 15 2017 20:25
im having some trouble on my weather app
any help will be appreciated :)
oops
fixed one bug i found and it still didnt work??
tommy
@tommygebru
Jul 15 2017 20:31
@kumquatfelafel arrFib.length-1 would simply be the length minus 1
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:34
@Aumann-Liam try to use console.log() to check if your JSON data is arriving correctly. You can use your browser's console function to see if a JSON object has been created. Does that make sense to you?
Veronica Eulenberg
@HappyViki
Jul 15 2017 20:34
Dudddde what is heppening with this code?
function hasValue(newInv, oldValue) {
  for (var i in newInv) {
    if (newInv[i][1] === oldValue[1]) {
      console.log(oldValue[0] += newInv[i][0]) // Why is Bowling Ball 88 here,
      oldValue[0] += newInv[i][0]; // and 67 here? This doesn't add up! lol pun :P
      return newInv.concat();
    }
  }
  return newInv.concat([oldValue]);
}

function alpha(a, b) {
  if (a[1] < b[1]) return -1;
  if (a[1] > b[1]) return 1;
  return 0;
}

function updateInventory(curInv, newInv) {
  return curInv.reduce(hasValue, newInv).sort(alpha);
}

// I want the result to be:
// [
//[88, "Bowling Ball"], 
//[2, "Dirty Sock"], 
//[3, "Hair Pin"], 
//[3, "Half-Eaten Apple"], 
//[5, "Microphone"], 
//[7, "Toothpaste"]
//]


console.log(updateInventory(
  [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"], 
    [1, "Hair Pin"], 
    [5, "Microphone"]
  ],
  [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
  ]
));
LiamAumann
@Aumann-Liam
Jul 15 2017 20:34
i think so @kjuchtmans should i put the console.log below it?
ohhhhh its a stupid https issue
the api uses http
and i guess codepen only allows https
GRRR
Anyone know any good weather api to use?
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:37
@Aumann-Liam yes, console.log(result) should come right after the $.getJSON block finishes. If nothing is returned to console you should check http vs https, like you just did, or similar connection issues
LiamAumann
@Aumann-Liam
Jul 15 2017 20:39
i think im going to have to use a different api sadly :(
i just dont know of any others
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:42
I used api.darksky.net
tip: you need to address any CORS issues when connecting. Check the CORS wiki, or the JQuery docs here
An easy fix for CORS issues is here
darksky also do the weather icons, if you need those later on
kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:44

@tommygebru Let's approach this from a slightly different tack. Suppose I just want to take an array and sum all the elements... no fibonacci or anything, just sum an array.

Would I say

sum = 0;
for (var i = -1; i < arr.length; i++) {
  sum = arr[i];
}

Or is this asking for trouble?

LiamAumann
@Aumann-Liam
Jul 15 2017 20:44
ok thanks
tommy
@tommygebru
Jul 15 2017 20:46
@kumquatfelafel what is arr
kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:47
@tommygebru an array
tommy
@tommygebru
Jul 15 2017 20:47
what i mean is the value
values
kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:47
@tommygebru doesn't matter. Is the code sound?
CallMeOrange
@EgnaroDev
Jul 15 2017 20:47
lol
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:47
:+1: This challenge is a bit of a pain in the *rse but a good introduction into working with JSON data, which is very popular
LiamAumann
@Aumann-Liam
Jul 15 2017 20:48
ok
off been struggling for a while with it
tommy
@tommygebru
Jul 15 2017 20:48
perhaps @kumquatfelafel but i would need to see the console
LiamAumann
@Aumann-Liam
Jul 15 2017 20:48
ive**
tommy
@tommygebru
Jul 15 2017 20:50
@kumquatfelafel well i guess not
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:52

"Drop It" challenge: who can help iterate array and stop at first match?

My below code continues until array.length but I want it to stop at the first matched instance
code:


function dropElements(arr, func) {
  // Drop them elements.
  var i,
      shifted=[]; 

  for(i=arr[0]; i<=arr.length; i++){
    if(func(i)===false){
      shifted.push(i);
    }
  } //return shifted;

  Array.prototype.diff = function(a) {
    return this.filter(function(i) {return a.indexOf(i) < 0;});
  };

  return arr.diff(shifted);
}

dropElements([1, 2, 3, 4], function(n) {return n > 5; });

cheers!
k

kumquatfelafel
@kumquatfelafel
Jul 15 2017 20:55

@tommygebru You don't need to see the console. It's unsound.

Problem 1:
this for loop starts with arr[-1]. Which (in javascript anyway) is undefined. Because of problem 2, doesn't really make a difference, but if you were actually summing numbers, undefined + any number is NaN.
Problem 2:
sum = arr[i] will not actually add all the values. It will overwrite the previous value of sum with the latest element of the array.
So if you had the array [1,2,3,4,5], at the end of this code, sum would be 5, not 15.

cowCrazy
@cowCrazy
Jul 15 2017 20:55
@kjuchtmans you can add break; inside the if statement, then in case there is a match the loop would stop
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:56
@cowCrazy would you use .some?
cowCrazy
@cowCrazy
Jul 15 2017 20:58
@kjuchtmans what do you mean by use .some? never came across that before....
Jonathan Meier
@jntme
Jul 15 2017 20:59
hey folks =) tricky question incoming. why is the output of the following object when it obvisouly should be array?
function sym(...arr) {
  console.log(typeof arr[0]);
}

sym([1, 2, 3], [5, 2, 1, 4]);
Chris Juchtmans
@kjuchtmans
Jul 15 2017 20:59
@cowCrazy some as in MDN docs here. I doubt it though
cowCrazy
@cowCrazy
Jul 15 2017 21:00
hmmm.... I just so it on mdn now.... interesting, try why not :) worst case you would learn something new :)
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:01
@cowCrazy good thinking, thanks. maybe I also try indexOf() here
CamperBot
@camperbot
Jul 15 2017 21:01
kjuchtmans sends brownie points to @cowcrazy :sparkles: :thumbsup: :sparkles:
:cookie: 261 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
alpox
@alpox
Jul 15 2017 21:01
@kjuchtmans no need for some here. Just break;. Also, its no good practice to add methods to the array prototype except you really know what you are doing - you would usually not do that. Especially not for single use in the same function.
Markus Kiili
@Masd925
Jul 15 2017 21:02
@jntme Only things typeof returns for any objects are "object" or "function". So it doesn't differentiate arrays from other objects.
cowCrazy
@cowCrazy
Jul 15 2017 21:02
@jntme typeof Array is still an object
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:02
@jntme arrays are objects
alpox
@alpox
Jul 15 2017 21:02
@kjuchtmans its easier to remove elements directly from the current array or a copy of it instead of first push elements into an array and then filter the elements from one array of the other array.
alpox
@alpox
Jul 15 2017 21:03
Idea: loop through a copy if the original and just .shift the elements out as long as needed until the predicate doesnt hold anymore. Then you just break; the loop
alpox
@alpox
Jul 15 2017 21:03
@kjuchtmans
LiamAumann
@Aumann-Liam
Jul 15 2017 21:03
it says undefined... any help on fixing this? :)
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:03
@alpox indeed. I agree on break being the most convenient option. thanks for the opinion on prototype too
CamperBot
@camperbot
Jul 15 2017 21:03
kjuchtmans sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1259 | @alpox |http://www.freecodecamp.com/alpox
Jonathan Meier
@jntme
Jul 15 2017 21:04
@Masd925 @cowCrazy @kumquatfelafel Ah ok I see.. But can I despite of that call filter on them?
cowCrazy
@cowCrazy
Jul 15 2017 21:04
filter on array? yes
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:04
Filter is function associated with the array prototype so yes
If that's what you're asking
Jonathan Meier
@jntme
Jul 15 2017 21:04
Or how do I find out which object it actually is? So which prototype it is using
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:05
You can't call filter on any object regardless of what it actually is thouhg
Jonathan Meier
@jntme
Jul 15 2017 21:05
@Masd925 @cowCrazy @kumquatfelafel aight - thank you guys
CamperBot
@camperbot
Jul 15 2017 21:05
:cookie: 471 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
jntme sends brownie points to @masd925 and @cowcrazy and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 262 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
:star2: 4296 | @masd925 |http://www.freecodecamp.com/masd925
alpox
@alpox
Jul 15 2017 21:05
@jntme as long as the variable holds an array, you can run filter on it. Only call filter on a variable if you are sure that its nothing else than an array
cowCrazy
@cowCrazy
Jul 15 2017 21:06
@jntme you can use .isArray to check if something is an Array
CallMeOrange
@EgnaroDev
Jul 15 2017 21:07
What is GET request?
Christopher Blakely
@chrisbchrist
Jul 15 2017 21:08
Hey @kumquatfelafel I still can't seem to figure out my duplication problem from last night , it's only supposed to push once on the last iteration of the loop, but the pushed elements are being doubled

function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    var updated = arr1;

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


    for (var j = 0; j < arr1.length; j++) {

      if (arr1[j][1] == arr2[i][1]) {
        updated[j][0] += arr2[i][0];
        break;
      } if (j == arr1.length - 1) {
        updated.push(arr2[i]);

      }

    }
  }
  return updated;
}

// Example inventory lists
var curInv = [[21, "Bowling Ball"], [2, "Dirty Sock"], [1, "Hair Pin"], [5, "Microphone"]];

var newInv = [[2, "Hair Pin"], [3, "Half-Eaten Apple"], [67, "Bowling Ball"], [7, "Toothpaste"]];

updateInventory(curInv, newInv);
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:09
@chrisbchrist It's because the pushed element has been added to the end of the loop. So when for loop continues (because length has increased), it then finds that element at end.
Pieter Stokkink
@forkerino
Jul 15 2017 21:10
@kumquatfelafel @chrisbchrist isn't it because updated = arr1? push to one, push to the other.
@kumquatfelafel or are we saying the same thing?
tommy
@tommygebru
Jul 15 2017 21:11
ok @kumquatfelafel i am trying this again ... staring at this problem for 5 hours kind of just melts my brain though
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:11
@forkerino I think code may have changed slightly from last night and operating off memory here, sec :p
tommy
@tommygebru
Jul 15 2017 21:11
@forkerino drop a hint! fibonacci
Pieter Stokkink
@forkerino
Jul 15 2017 21:12
@MCTwoDigitZero when you open a website, you do a get request for the content and the server gives it back to you. You can also do POST, PUT, DELETE and some other requests. GET is the most common.
LiamAumann
@Aumann-Liam
Jul 15 2017 21:12
gtg see yall later!!!
Christopher Blakely
@chrisbchrist
Jul 15 2017 21:12
@forkerino Though that's only declared once initially, does performing an action on updated alter arr1?
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:12
@forkerino same thing more or less. Pushed to both, ergo it finds it and duplicates
LiamAumann
@Aumann-Liam
Jul 15 2017 21:12
thanks @kjuchtmans
CamperBot
@camperbot
Jul 15 2017 21:12
aumann-liam sends brownie points to @kjuchtmans :sparkles: :thumbsup: :sparkles:
:cookie: 286 | @kjuchtmans |http://www.freecodecamp.com/kjuchtmans
Pieter Stokkink
@forkerino
Jul 15 2017 21:13
@chrisbchrist yeah, arrays are reference types, so if you assign one to the other, it is the same array in memory
CallMeOrange
@EgnaroDev
Jul 15 2017 21:13
Hm.. I think I understand
@forkerino thanks
CamperBot
@camperbot
Jul 15 2017 21:13
mctwodigitzero sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2855 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 15 2017 21:13
@chrisbchrist you can make an actual copy by using .slice() for example
@MCTwoDigitZero :+1: When you do .getJSON, for example, you perform a get request
Christopher Blakely
@chrisbchrist
Jul 15 2017 21:14
@forkerino Interesting, I didn't know they behaved that way, I supposed I could use a blank array and join them, or use slice
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:14
@Aumann-Liam :+1: keep it up
Christopher Blakely
@chrisbchrist
Jul 15 2017 21:14
Thanks
Pieter Stokkink
@forkerino
Jul 15 2017 21:14
@tommygebru many different ways to solve it, let me check your code. Just a sec.
tommy
@tommygebru
Jul 15 2017 21:15

this is what i have

function sumFibs(num) {
    var arrFib = [1];
    var results = 0;
    for (var i = 1; i <= num;) {
        arrFib.push(i);
        i = arrFib[arrFib.length - 1] + arrFib[arrFib.length - 2];
        if (i % 2 !== 0) {
            results += i;
        } //conditional
    } //loop
    return results;
} //function
sumFibs(4);

i have been staring at this too long... there is a hole where my brain should be

kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:15
You can also "logic" that once pushed, no need to search for it. @chrisbchrist
Was trying to force you to use break statements on both (not necessarily because you have to do it that way, but to realize that as soon as either action takes place, you're finished with that item). You went about it a different way than I was expecting though (which is invalid, provided you make deep copy as opposed to shallow). :p
Pieter Stokkink
@forkerino
Jul 15 2017 21:16
@tommygebru wait, it's quite long ago you posted it. Has it changed?
ah, there it is
:wave: hey y'll
Pieter Stokkink
@forkerino
Jul 15 2017 21:17
@tommygebru where is the part where you sum the odd fibonaccis?
pzimn
@pzimn
Jul 15 2017 21:17
Hey guys, got a question about AngularJS services, is anyone here into that?
Jonathan Meier
@jntme
Jul 15 2017 21:17
what do you think of my .removeDuplicate function:
Array.prototype.removeDuplicates = function () {
  var newArr = [];

  this.forEach(x => {
    if (newArr.indexOf(x) === -1) newArr.push(x);
  });

  return newArr;
}
CallMeOrange
@EgnaroDev
Jul 15 2017 21:17
@saifsmailbox98 Hey, and thanks
CamperBot
@camperbot
Jul 15 2017 21:17
mctwodigitzero sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 781 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
tommy
@tommygebru
Jul 15 2017 21:18
@forkerino I edited it from = to +=
Pieter Stokkink
@forkerino
Jul 15 2017 21:18
@tommygebru I see.
tommy
@tommygebru
Jul 15 2017 21:18
function sumFibs(num) {
    var arrFib = [1];
    var results = 0;
    for (var i = 1; i <= num;) {
        arrFib.push(i);
        i = arrFib[arrFib.length - 1] + arrFib[arrFib.length - 2];
        if (i % 2 !== 0) {
            results += i;
        }  }
    return results; } 
sumFibs(4);
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 21:19
@tommygebru why are you changing i on the go?
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:19

'Drop It' challenge

Why is my below code not returning [ ] empty array, but instead I get [3, 4]?
No clue why

code:


function dropElements(arr, func) {

  var i,
      shifted=[]; 

  shifted = arr;

  for(i=shifted[0]; i<=shifted.length; i++){
    if(func(i)===false){
      shifted.shift();
    } else {break;}
  } return shifted;

}

dropElements([1, 2, 3, 4], function(n) {return n > 5; });
Pieter Stokkink
@forkerino
Jul 15 2017 21:19
@tommygebru you add numbers after incrementing i, but I think you should do that before. Otherwise you might add a too large number to the sum (and you miss the first two ones as well).
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:21
@kjuchtmans why i = shifted[0];?
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 21:21
@kjuchtmans I think in this challenge you have to keep removing elements until you get func on an element as true.
Pieter Stokkink
@forkerino
Jul 15 2017 21:24
@kjuchtmans your for loop skips a few elements because you .shift() them over.
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:24
@kjuchtmans w/regards to why you are returning 3, 4... say I shift two elements from an array that was length 4. what happens to length? This :point_up: :point_down:
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 21:25
@kjuchtmans shifting with incrementing i
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:25
@forkerino yeah, it's skipping, shouldn't
Markus Kiili
@Masd925
Jul 15 2017 21:25
@jntme Seems fine. With built-in methods you could do it like:
Array.prototype.removeDuplicates = function () {
  return this.filter(function(elem,index,array){
    return array.indexOf(elem)===index;
  });
};
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:26
@kumquatfelafel yeah, I don't quite get how to make shift and iterate play nicely together..
@kumquatfelafel I would then probably want arr.length over shifted.length wouldn't I?
Jonathan Meier
@jntme
Jul 15 2017 21:29
@Masd925 wow cool thanks! didn’t know about the third param on filter
CamperBot
@camperbot
Jul 15 2017 21:29
jntme sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: jntme already gave masd925 points
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:29
@kjuchtmans shifted and array are shallow copies of one another. They are essentially the same array.
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:29
@kumquatfelafel right
Pieter Stokkink
@forkerino
Jul 15 2017 21:29
@kjuchtmans if you really want to use .shift(), a while loop will make it easier.
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 21:30
while(func not true){
shift
}
@kjuchtmans
Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:31
@forkerino because it would be more easily stopped, I get that, thanks! @saifsmailbox98 thanks as well
CamperBot
@camperbot
Jul 15 2017 21:31
kjuchtmans sends brownie points to @forkerino and @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 782 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
:star2: 2856 | @forkerino |http://www.freecodecamp.com/forkerino
Saif Ur Rahman
@saifsmailbox98
Jul 15 2017 21:31
@forkerino but still you need some iterator. And shifting with incrementing iterator is a bad idea.
kumquatfelafel
@kumquatfelafel
Jul 15 2017 21:31

for (i = shifted[0]; i<=shifted.length; i++)
In any case, this line is dangerous.

Consider what would happen if the array were instead [1, 6, 7]

Chris Juchtmans
@kjuchtmans
Jul 15 2017 21:31
@saifsmailbox98 my conundrum exactly