7th
Aug 2015
DTing
@dting
Aug 07 2015 00:00
@DanStockham also since your lcm function arguements match what arguments reduce calls the callback with, you dont have to create that anonymous function. You can just use `rng.reduce(lcm)`
it might be a good excercise to figure out how to solve it with out using reduce and using a normal for loop for the range of numbers. It will give you some insight on how reduce works (impertive vs functional)
Dan Stockham
@DanStockham
Aug 07 2015 00:04
@dting I tried using a for loop prior and to be honest I just want to get this done.
Already have 11 hours into it.
Alright so I'm getting close, I'm getting values that are tangible but I have feeling the values being passed aren't correct:
``````function gcd(a,b) {

while (b !== 0) {
a = [b, b = a % b][0];
}
return a;

}

function lcm(a, b) {
return (a * b) / gcd(a, b);

}

function smallestCommons(arr) {
var rng = [];

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

for(var i = arr[0]; i < arr[1]; i++) {
rng.push(i);

}
return rng.reduce(lcm);
}

smallestCommons([1, 5]);``````
DTing
@dting
Aug 07 2015 00:08
@DanStockham you are missing one number
@DanStockham you have an off by 1 error
you want 1-5 inclusive right now you are getting 1-4
Dan Stockham
@DanStockham
Aug 07 2015 00:10
@dting hallu-f*ing-luah, she passed with flying colors!
Thank you so much, you have no idea how frustrating it was to figure it out lol
BoomTheFace
@BoomTheFace
Aug 07 2015 00:13
@DanStockham hey, thats what I'm working on... and took a completely different path... :)
@DanStockham but mine is failing... :(
@thefreethinker
Aug 07 2015 00:13
Hey guys I'm having an issue, how do you paste the command line here?
Dan Stockham
@DanStockham
Aug 07 2015 00:13
@thefreethinker use the three backticks above and below your code.
@thefreethinker
Aug 07 2015 00:14
Also, am I using that phrase right? "Command line" is where we type the code right?
Dan Stockham
@DanStockham
Aug 07 2015 00:14
@BoomTheFace I really want to know how you approached it
Richard Gay
@willbonds
Aug 07 2015 00:14
I found Where Art Thou very obfuscating, in that the run commentary on the second test was very misleading, and the instructions weren't at all clear.
BoomTheFace
@BoomTheFace
Aug 07 2015 00:15
``````function smallestCommons(arr) {
arr.sort(function(a,b) {
return a - b;
});
var i, j, x = arr[1], y;
console.log("i: " + i + " j: " + j + " x: " + x + " y: " + y);

do {

for (j = arr[0]; j < arr[1]; j++) {
if (x % j === 0) {
y = true;
console.log(y + " " + x + " " + j);
}else {
y = false;
console.log(y + " " + x + " " + j);
break;
}
}
x =+ x;
} while (y === false);
return x;
}

smallestCommons([1,5]);``````
@DanStockham its an infinite loop for some reason though
@DanStockham I can't figure out where my logic is breaking down
@thefreethinker
Aug 07 2015 00:17
@DanStockham Not sure what you mean, there are no backticks above or below my code.
Bill
@kirah1314
Aug 07 2015 00:18
help format
CamperBot
@camperbot
Aug 07 2015 00:18

## :point_right: pasting formatted code in gitter [wiki]

Use three ticks [ ` ] -- on American keyboards, that's the key in the corner between [1] and [Tab]. Then press [Enter]+[Shift]. Gitter will usually fill in the closing ticks for you, but if they aren't there remember to end your code with a line of three ticks. Ticks must always be on their own lines. When you are ready to send your message press [Ctrl]+[Enter].

You can edit your previously sent messages by hovering over the message and clicking the ...,
so if you accidentally paste unformatted code, just fix it.

If your code is long, you can create a Gist and paste the link in Gitter. This also allows fellow campers to collaborate with you more directly.
:pencil: read more about pasting formatted code in gitter on the FCC Wiki

Dan Stockham
@DanStockham
Aug 07 2015 00:19
@thefreethinker If you look at the bottom right hand corner of your input chat box there is a page looking with three horizontal lines.
Bill
@kirah1314
Aug 07 2015 00:19
bf format
CamperBot
@camperbot
Aug 07 2015 00:19
Sorry, can't find a bonfire called format. [ Check the map? ]
Dan Stockham
@DanStockham
Aug 07 2015 00:19
It has the markdown list.
Bill
@kirah1314
Aug 07 2015 00:19
format
Joris Labie
@labiej
Aug 07 2015 00:19
thanks @kirah1314 tried to get camperbot to do that earlier
CamperBot
@camperbot
Aug 07 2015 00:19
:star: 95 | @kirah1314 | http://www.freecodecamp.com/kirah1314
labiej sends brownie points to @kirah1314 :sparkles: :thumbsup: :sparkles:
Bill
@kirah1314
Aug 07 2015 00:20
lol sometimes I forget camperbot's commands too
Dan Stockham
@DanStockham
Aug 07 2015 00:24
@BoomTheFace It looks like you did the other method of checking if each value is true or false.
@thefreethinker
Aug 07 2015 00:24
``var code = "formatted";``
Got it, post my question in a sec
Dan Stockham
@DanStockham
Aug 07 2015 00:24
@BoomTheFace I wonder if you could somehow incorporate Euclid's algorithm?
@thefreethinker
Aug 07 2015 00:24
'''
Bill
@kirah1314
Aug 07 2015 00:26
``` is the button left of 1 (one)
@thefreethinker
Aug 07 2015 00:26

I'm supposed to create a green border with class "thick green border" in my image tag but nothing is happening, what am I missing?
'''

<style>
.red-text {
color: red;
}

h2 {
font-family: Lobster, Monospace;
}

p {
font-size: 16px;
font-family: Monospace;
}

.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
}

.smaller-image {
width: 100px;
}
</style>

<h2 class='red-text'>CatPhotoApp</h2>

<img class='smaller-image' class="thick-green-border" src='https://bit.ly/fcc-kittens'/>

<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>

<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
'''

``````var code = "formatted";
<style>
.red-text {
color: red;
}

h2 {
font-family: Lobster, Monospace;
}

p {
font-size: 16px;
font-family: Monospace;
}

.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
}

.smaller-image {
width: 100px;
}
</style>

<h2 class='red-text'>CatPhotoApp</h2>

<img class='smaller-image' class="thick-green-border" src='https://bit.ly/fcc-kittens'/>

<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>``````
TiffanyM
@Knowingo
Aug 07 2015 00:28
``````function titleCase(str) {
var lowercase = str.toLowerCase();
var array = lowercase.split(' ');
for (var i=0 ;i<array.length ;i++) {
var word = array[i];
var letter = word.charAt(0);
var uppercase = letter.toUpperCase();
}
var join = array.join(' ');
return join;
}

titleCase("I'm a little tea pot");``````
this is Bonfire: Title Case a Sentence, but it isn't working. This is what I get: expect(titleCase("I'm a little tea pot")).to.equal("I'm A Little Tea Pot");expected 'i\'m a little tea pot' to equal 'I\'m A Little Tea Pot'
keagan goetsch
@misterrorypond
Aug 07 2015 00:31
Dan Stockham
@DanStockham
Aug 07 2015 00:31
Alright, taking a break
Logan Tegman
@ltegman
Aug 07 2015 00:31
@CodingHelp You're not doing anything with the uppercase letter you create. You need to change that word in your `array` variable to have the capitalized first letter.
Sophanarith Sok
@sok213
Aug 07 2015 00:31
TiffanyM
@Knowingo
Aug 07 2015 00:33
Okay, that makes sense, what do I do?
Sophanarith Sok
@sok213
Aug 07 2015 00:33
@CodingHelp Declare all your variables outside of the loop first, then go from there.
Logan Tegman
@ltegman
Aug 07 2015 00:33
@CodingHelp Well, how would you change an element of an array?
TiffanyM
@Knowingo
Aug 07 2015 00:35
Thank you! I am going to try stuff now
Logan Tegman
@ltegman
Aug 07 2015 00:35
@CodingHelp Good luck!
Bill
@kirah1314
Aug 07 2015 00:35
This message was deleted
Sophanarith Sok
@sok213
Aug 07 2015 00:37
@CodingHelp Also, look at your var array, it is not being affected by anything, so basically you are splitting it and then just joining it back together, resulting in the same exact string as it was before.
Logan Tegman
@ltegman
Aug 07 2015 00:41
@kirah1314 They're calling charAt on one of the array's elements, which contains a string
Bill
@kirah1314
Aug 07 2015 00:41
@ltegman ok, I read it wrong then
Reggie
@Reggie01
Aug 07 2015 00:42
@misterrorypond The app lookds good, seems to be working just fine.
keagan goetsch
@misterrorypond
Aug 07 2015 00:42
@Reggie01 thank you!
@Reggie01 what browser/system are you using?
Reggie
@Reggie01
Aug 07 2015 00:43
@misterrorypond Chrome
keagan goetsch
@misterrorypond
Aug 07 2015 00:43
@Reggie01 wonderful! Thank you for your input!
i'm seeing how it works on multiple devices, etc
Reggie
@Reggie01
Aug 07 2015 00:43
@misterrorypond I can test on FireFox if you like
keagan goetsch
@misterrorypond
Aug 07 2015 00:43
@Reggie01 that'd be nice!
Gah Tang
@gkt5015
Aug 07 2015 00:47
'''
'''
'''
am I using the right symbol
Bill
@kirah1314
Aug 07 2015 00:49
@gkt5015 it should be ```
Gah Tang
@gkt5015
Aug 07 2015 00:49
'''
var testing = 'asdf';
'''
oh
woops :P
Reggie
@Reggie01
Aug 07 2015 00:50
@misterrorypond Ran it in ie 10 and firefox its fine. Not sure if your concerned about responsive design.
Gah Tang
@gkt5015
Aug 07 2015 00:50
``var testing = "asdf";``
Reggie
@Reggie01
Aug 07 2015 00:51
@misterrorypond You will have to adjust your breakpts if you want it to look right on a phone.
Gah Tang
@gkt5015
Aug 07 2015 00:52
``````var frequentOnline = ["freecodecamp", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "comster404", "brunofin", "thomasballinger", "noobs2ninjas", "beohoff","TSM_theoddone"];
var status = [];
var getStatus = function() {
frequentOnline.forEach(function(x) {
\$.getJSON('https://api.twitch.tv/kraken/streams/' + x, function(y) {
if(y.stream === null){
status.push("asdf");
};
});

});
};
getStatus();
console.log(status);``````
Can anyone telleme why the status can't be using inside even if I declared it outisde
be used*
Logan Tegman
@ltegman
Aug 07 2015 00:53
@gkt5015 The problem is that your `console.log(status)` gets run before the JSON response is returned and pushed into the `status` array.
Gah Tang
@gkt5015
Aug 07 2015 00:53
Oh it's back to another async problem huh
:(
Logan Tegman
@ltegman
Aug 07 2015 00:54
@gkt5015 Yup. async can be a really doozy to wrap your head around. I had countless bugs when I first started doing async stuff. Still do when I'm using it for unfamiliar stuff.
Jelani Thompson
@JelaniThompson
Aug 07 2015 00:55
Hey guys, is this an effective method of removing Falsy values from an array or is there a better one/
*?
``````var a=[1,2,"b",0,{},"",NaN,3,undefined,null,5];
var b=a.filter(Boolean); // [1,2,"b",{},3,5]``````
Tyler St. Onge
@tylerstonge
Aug 07 2015 00:56
What's the recommended way to instantiate a string?
``````var str = String();
//or?
var str = "";``````
Jelani Thompson
@JelaniThompson
Aug 07 2015 00:58
The second one
Logan Tegman
@ltegman
Aug 07 2015 00:59
@tylerstonge depends what you want. `var str = String()` will instantiate a string with the value of `undefined` and `var str = "";` will create an empty string. `var str = "";` is much more commonplace though.
Bill
@kirah1314
Aug 07 2015 01:00
@JelaniThompson, you're very close! Try this `return arr.filter(Boolean);`
Tyler St. Onge
@tylerstonge
Aug 07 2015 01:02
Ah, I see. Thanks for clarifying.
Is a variable with the value `undefined` considered an "empty string"?
Logan Tegman
@ltegman
Aug 07 2015 01:05
@tylerstonge Not quite. If you `console.log("")` you'll get back `""` but if you `console.log(String())` you'll get back `undefined`. You play around with the differences on http://repl.it/ if you want to try it out yourself.
Gah Tang
@gkt5015
Aug 07 2015 01:05
``````var frequentOnline = ["freecodecamp", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "comster404", "brunofin", "thomasballinger", "noobs2ninjas", "beohoff","TSM_theoddone"];
var status = [];
var getStatus = function() {
frequentOnline.forEach(function(x) {
\$.getJSON('https://api.twitch.tv/kraken/streams/' + x, function(y) {
if(y.stream === null){
status.push("asdf");
};
});

});
};
getStatus();
setTimeout(function(){
console.log(status);
}, 7000);``````
so I set it to wait 7 seconds before executing the console.log for status. It still doesn't let me use status.push.
M Used
@mildused
Aug 07 2015 01:11
@dting Hi!
Tyler Haas
@tylerthehaas
Aug 07 2015 01:17
wondering if anyone can figure out this issue with my pomodoro clock. I’m passing in the time using jquery’s .val() method the val is returning the number but the property within the object is undefined for some reason. Any help would be appreciated http://codepen.io/haasDev/pen/LVMmBL?editors=101
Liz Rezes
@queenlizo
Aug 07 2015 01:21
Howdy, all! I'm doing Bonfire: Pig Latin. In the `if` statement, if the first letter is a consonant, it executes the code. But it won't work. Anyone have any suggestions? Thanks!
``````function translate(str) {
var myArray = str.split("");
var newArray = [];

if (myArray[0] === /[^aeiouAEIOU]/i) {
myArray.push(myArray[0]);
myArray.splice([0], 1);
myArray.push("w", "a", "y");
newArray = myArray.join('');
} else {
myArray.push(myArray[0]);
myArray.splice([0], 1);
myArray.push("a", "y");
newArray = myArray.join('');
}

return newArray;
}

translate("consonant");``````
@SaintPeter
Aug 07 2015 01:22
@queenlizo myArray is an array. myArray is made up of strings. myArray[0] returns the first string in myArray.
Liz Rezes
@queenlizo
Aug 07 2015 01:23
@SaintPeter right. I'm trying to compare that to the regular expression
@SaintPeter
Aug 07 2015 01:24
@queenlizo In order to use a regular expression to test a string, you need to do:
``if(/regex/i.test(stringToTest))``
@queenlizo RegExp.test() returns a boolean, RegExp.match() returns an array of matches.
Liz Rezes
@queenlizo
Aug 07 2015 01:24
@SaintPeter Ah, ha! Thanks! I looked into .test, but didn't think it was the one I needed.
@SaintPeter
Aug 07 2015 01:25
@queenlizo As far as I know, you can do `thing === /regexp/` - it would be testign to see if `thing` was literally that specific regular expression.
Liz Rezes
@queenlizo
Aug 07 2015 01:26
@SaintPeter Hmm... That sounds easier
@SaintPeter
Aug 07 2015 01:27
@queenlizo Well, that's not how javascript works . . sorry :D Perl has the `~=` operator which does work like that. I'm afraid js just has /regex/.text()
Liz Rezes
@queenlizo
Aug 07 2015 01:28
@SaintPeter Ah. Ok. I'll figure it out. Thanks.
@SaintPeter @SaintPeter This ended up working: `if ( /[aeiou]/.test(myArray[0])`
@SaintPeter
Aug 07 2015 01:35
@queenlizo Awesome! Note that you can put the `i` in there if you want: `/[aeiou]/i.test(myArray[0])` is valid too
Liz Rezes
@queenlizo
Aug 07 2015 01:36
@SaintPeter Hmm.... That didn't work. It says that i is undefined.
@SaintPeter
Aug 07 2015 01:36
@queenlizo Humm . . I thought I had that work . . .
SaintPeter @SaintPeter goes to try
Moisés Man
@moigithub
Aug 07 2015 01:36
probably the other way... myArray[0].test(/[aeiou]/)
Ingrid
@voodoobettie
Aug 07 2015 01:37
Can anyone give me a hand with the longest string bonfire? I'm stuck. :(
I'm trying to figure out why I can't use the .length() method
I created a gist for it https://gist.github.com/voodoobettie/51a0acf70e26babf7a55
@SaintPeter
Aug 07 2015 01:37
@moigithub Nope, .test is a member function of a RegExp object
Gah Tang
@gkt5015
Aug 07 2015 01:38
Can anyone help me with the problem i posted above :O
@SaintPeter
Aug 07 2015 01:38
@queenlizo I just ran this code: `/[aeiou]/i.test('abcd');` and it worked just fine
@gkt5015 sure, lemme look
Liz Rezes
@queenlizo
Aug 07 2015 01:38
@SaintPeter Let me try that.
Ingrid
@voodoobettie
Aug 07 2015 01:39
(Also I can't remember how we are meant to include code here so a tip on that would be great too. :))
@SaintPeter
Aug 07 2015 01:39
wiki format
CamperBot
@camperbot
Aug 07 2015 01:39

## :point_right: pasting formatted code in gitter [wiki]

Use three ticks [ ` ] -- on American keyboards, that's the key in the corner between [1] and [Tab]. Then press [Enter]+[Shift]. Gitter will usually fill in the closing ticks for you, but if they aren't there remember to end your code with a line of three ticks. Ticks must always be on their own lines. When you are ready to send your message press [Ctrl]+[Enter].

You can edit your previously sent messages by hovering over the message and clicking the ...,
so if you accidentally paste unformatted code, just fix it.

If your code is long, you can create a Gist and paste the link in Gitter. This also allows fellow campers to collaborate with you more directly.
:pencil: read more about pasting formatted code in gitter on the FCC Wiki

Liz Rezes
@queenlizo
Aug 07 2015 01:39
@SaintPeter Yep. I got that to work
thanks @SaintPeter
CamperBot
@camperbot
Aug 07 2015 01:39
queenlizo sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 8 | @saintpeter | http://www.freecodecamp.com/saintpeter
SaintPeter @SaintPeter clap! Yay, Brownie points!
@SaintPeter
Aug 07 2015 01:40
@gkt5015 ok, so your issue is you need help understanding the async nature of AJAX queries?
Gah Tang
@gkt5015
Aug 07 2015 01:40
I'm not sure if it's an async problem
It's not letting me push anything into the global variable
Moisés Man
@moigithub
Aug 07 2015 01:41
@voodoobettie length is a property... so no ()
Gah Tang
@gkt5015
Aug 07 2015 01:41
From within the call
Ingrid
@voodoobettie
Aug 07 2015 01:42
``````function findLongestWord(str) {

var wordList = str.toLowerCase().split(" ");

var result = 0;
var firstWord = wordList[0]; // the string of the first index, initially
var current = firstWord.length(); // stores length of initial string
var longest = firstWord.length();  // number of characters in the current longest

for (i in wordList[i], i = 0, i++)
current = this.length;
if (current >= longest) {
var longest = current();
console.log(current);
return result;
//    console.log(longest);
console.log(wordLength[longest]);
}
console.log(result);
console.log(longest);
};
findLongestWord('The quick brown fox jumped over the lazy dog');``````
Gah Tang
@gkt5015
Aug 07 2015 01:42
@SaintPeter Maybe it's a .getJSON thing that my code isn't incorporating? But I can't seem to understand what the problem with my code is
@SaintPeter
Aug 07 2015 01:42
@gkt5015 You do not need a semicolon after an if statement - that might break things:
``````if(y.stream === null){
status.push("asdf");
};   // <-- Remove this semicolon``````
Gah Tang
@gkt5015
Aug 07 2015 01:44
@SaintPeter That didn't work
@SaintPeter
Aug 07 2015 01:44
@voodoobettie `current` is not a function: `var longest = current();` Remove the parentheses
Kolloom
@Kolloom
Aug 07 2015 01:44
bonfire common
CamperBot
@camperbot
Aug 07 2015 01:44

## :fire:Bonfire: Smallest Common Multiple :link:

``````function smallestCommons(arr) {
return arr;
}

smallestCommons([1,5]);``````

Find the smallest number that is evenly divisible by all numbers in the provided range.
The range will be an array of two numbers that will not necessarily be in numerical order.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

@SaintPeter
Aug 07 2015 01:45
@gkt5015 Ah - the REAL problem is that you're getting errors in your console and you're not looking at them.
@gkt5015 You're getting `No 'Access-Control-Allow-Origin' header is present on the requested resource.` errors, I bet.
Gah Tang
@gkt5015
Aug 07 2015 01:46
@SaintPeter naw i'm using CORS
@SaintPeter
Aug 07 2015 01:46
@gkt5015 What is CORS?
Liz Rezes
@queenlizo
Aug 07 2015 01:46
Any idea why the else if statement works, but the if and else statements don't work? Thanks!
``````function translate(str) {
var myArray = str.split("");
var newArray = [];

if ( /[aeiou]/i.test(myArray[0])){
myArray.push(myArray[0]);
myArray.splice([0], 1);
myArray.push("w", "a", "y");
newArray = myArray.join('');
} else if (/[b-df-hj-np-tv-z]/.test(myArray[0], myArray[1])) {
myArray.push(myArray[0], myArray[1]);
myArray.splice([0], 2);
myArray.push("a", "y");
newArray = myArray.join('');
}

else {
myArray.push(myArray[0]);
myArray.splice([0], 1);
myArray.push("a", "y");
newArray = myArray.join('');
}

return newArray;

}

translate("clonsonant");``````
Gah Tang
@gkt5015
Aug 07 2015 01:47
@SaintPeter It's a chrome extension. I fixed that problem yesterday. I'm looking at my console and it's saying status.push is not a function
Ingrid
@voodoobettie
Aug 07 2015 01:47
@SaintPeter You are right. Thank you for the fresh eyes! I think I have been working on this one too long. I also didn't write var in my for loop. I'm going to look into it again. I think I'm getting tired of this one :)
@SaintPeter
Aug 07 2015 01:48
@gkt5015 That's not a valid solution long term. You need to use a callback function.
@gkt5015 My immediate suggestion would be to remove the if statement from your callback and just do the status.push()
@queenlizo Does test take two inputs?
Kolloom
@Kolloom
Aug 07 2015 01:49
@queenlizo wasn't the input is `consonant` ?
Gah Tang
@gkt5015
Aug 07 2015 01:49
@SaintPeter Yeah I tried that too. I understand that this is a callback function error but I can't seem to understand why. The callback function is for the .getJSON correct?
Liz Rezes
@queenlizo
Aug 07 2015 01:49
@SaintPeter It works, but now it's working for all the words' first 2 letters.
@Kolloom right. I was testing a certain condition
Moisés Man
@moigithub
Aug 07 2015 01:50
@queenlizo `myArray.splice([0], 2);`
what do u think.. this does ?
@SaintPeter
Aug 07 2015 01:51
@queenlizo You're trying to get all of the constantants, right? Why not invert your vowel regexp (`/[^aeiou]/`? Also, you can match one or more with a plus after the character class.
Liz Rezes
@queenlizo
Aug 07 2015 01:51
@moigithub This removes the first 2 string values in the array, i.e. the first 2 letters
@SaintPeter you mean, put it in the other lines?
Gah Tang
@gkt5015
Aug 07 2015 01:53
@queenlizo I think what he means is why do you have [0] as your first argument
@SaintPeter
Aug 07 2015 01:53
@queenlizo I mean . . umm . . . `/^[^aeiou]+/` will match one or more constanants at the start of your word/string.
Liz Rezes
@queenlizo
Aug 07 2015 01:54
@gkt5015 because I want it to start at myArray[0], which is the first letter
@SaintPeter Hmm... Let me try that. It's definitely simpler than what's there.
Kolloom
@Kolloom
Aug 07 2015 01:54
the regex only gets the first letter if `globe` is not given
Gah Tang
@gkt5015
Aug 07 2015 01:55
@queenlizo the bracket notation isn't used in the splice argument
@SaintPeter
Aug 07 2015 01:55
@queenlizo Also, just a note: If a letter is not a vowel, it MUST be a constanant
Gah Tang
@gkt5015
Aug 07 2015 01:55
as a splice argument*
Liz Rezes
@queenlizo
Aug 07 2015 01:55
@gkt5015 but it's working
Kolloom
@Kolloom
Aug 07 2015 01:55
I really don't know what's the point of the else statement @queenlizo
Moisés Man
@moigithub
Aug 07 2015 01:55
@queenlizo but.. if u do splice.. u REMOVE and discard the element , piglatin require u RELOCATE part of the string to the end
Liz Rezes
@queenlizo
Aug 07 2015 01:56
@moigithub I'm removing the first letter/s, and then putting them at the end later. it was working
Moisés Man
@moigithub
Aug 07 2015 01:56
glove ===>>>> ovegl + ay
Liz Rezes
@queenlizo
Aug 07 2015 01:56
@moigithub @moigithub Right. That one is working now. but the others aren't
So, if you run this, it won't work.
``````function translate(str) {
var myArray = str.split("");
var newArray = [];

if ( /[aeiou]/i.test(myArray[0])){
myArray.push(myArray[0]);
myArray.splice([0], 1);
myArray.push("w", "a", "y");
newArray = myArray.join('');
} else if (/^[^aeiou]+/.test(myArray[0], myArray[1])) {
myArray.push(myArray[0], myArray[1]);
myArray.splice([0], 2);
myArray.push("a", "y");
newArray = myArray.join('');
} else {
myArray.push(myArray[0]);
myArray.splice([0], 1);
myArray.push("a", "y");
newArray = myArray.join('');
}

return newArray;

}

translate("consonant");``````
Moisés Man
@moigithub
Aug 07 2015 01:58
i think test function accept only 1 string.. not a list of comma separated strings
`if ((/^[^aeiou]+/.test(myArray[0]) and (/^[^aeiou]+/.test(myArray[1])) {`
Kolloom
@Kolloom
Aug 07 2015 02:00
reading other people's code is much harder than writing one...
Moisés Man
@moigithub
Aug 07 2015 02:00
probably...
Arianna
Aug 07 2015 02:00

Hi everyone! I hope you're having a great night / day. I just passed Bonfire: Confirm the Ending but I can't help feeling that I've cheated the system. The goal is: Check if a string (first argument) ends with the given target string (second argument). My code is: function end(str, target) {

``````var letter = str.substr(-1,1);
var four = str.substr(-4);

if(letter === target) {
return true;
} else if(four === target) {
return true;
} else {
return false;
}``````

}

end('He has to give me a new name', 'name');

Is there a better / more accurate way to do this? Any help greatly appreciated.
@SaintPeter
Aug 07 2015 02:01
@queenlizo There is actually not need to test for constanants - you know if it's not a vowel, that's what it is. What you CAN do is use the .match feature
Liz Rezes
@queenlizo
Aug 07 2015 02:02
@SaintPeter Hmm... I was looking at that .match. let me take another look
@SaintPeter
Aug 07 2015 02:02
@queenlizo Don't forget capture groups in regular expressions
@anaradanarad That does indeed seem like a cheat. A regular expression might be a more general solution. Do you recall the Regexp marker for "end of string"?
Moisés Man
@moigithub
Aug 07 2015 02:04
Liz Rezes
@queenlizo
Aug 07 2015 02:05
@moigithub Oooh. that's good too.
Moisés Man
@moigithub
Aug 07 2015 02:05
`var firstVowel = str.search(/[aeiou]/);`
Gah Tang
@gkt5015
Aug 07 2015 02:05
@anaradanarad it looks fine, maybe what you could do is declare only 1 variable as the substring starting from the length of the second argument
and just test that one variable
Liz Rezes
@queenlizo
Aug 07 2015 02:05
@gkt5015 I could use &&. That would be better. Thanks!
Arianna
Aug 07 2015 02:08
@SaintPeter I don't recall that, I'll read up; thank you for your feedback! @gkt5015 I think you're right. The ideal is slimmer, I'll give it a shot!
SojournerOctocat
@SojournerOctocat
Aug 07 2015 02:12
bf prime
CamperBot
@camperbot
Aug 07 2015 02:12

## :fire:Bonfire: Sum All Primes :link:

``````function sumPrimes(num) {
return num;
}

sumPrimes(10);``````

Sum all the prime numbers up to and including the provided number.
A prime number is defined as having only two divisors, 1 and itself. For example, 2 is a prime number because it's only divisible by 1 and 2. 1 isn't a prime number, because it's only divisible by itself.
The provided number may not be a prime.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

SojournerOctocat
@SojournerOctocat
Aug 07 2015 02:13
bf spoiler
CamperBot
@camperbot
Aug 07 2015 02:13
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
Kolloom
@Kolloom
Aug 07 2015 02:15
bonfire common
CamperBot
@camperbot
Aug 07 2015 02:15

## :fire:Bonfire: Smallest Common Multiple :link:

``````function smallestCommons(arr) {
return arr;
}

smallestCommons([1,5]);``````

Find the smallest number that is evenly divisible by all numbers in the provided range.
The range will be an array of two numbers that will not necessarily be in numerical order.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

SM
@nogo10
Aug 07 2015 02:15
how do i get gitter to stop popping notifications????
M Used
@mildused
Aug 07 2015 02:16
@nogo10 there is a wrench on the top right of this container
Kolloom
@Kolloom
Aug 07 2015 02:16
from what i understand the return value must be divisible by `[1, 2, 3, 4, 5]`?
Gah Tang
@gkt5015
Aug 07 2015 02:17
@kolloom yeah, so the smallest number that could
like for 1,2,3 it would be 6
SM
@nogo10
Aug 07 2015 02:18
@mildused thanks!!
Kolloom
@Kolloom
Aug 07 2015 02:19
im not sure if the formula for 2 numbers would work on more than 2 numbers?
`LCM(a,b) = (a*b)/GCD(a,b)` there are only 2 inputs
Gah Tang
@gkt5015
Aug 07 2015 02:19
Yeah that's not gonna work
Kolloom
@Kolloom
Aug 07 2015 02:20
then i don't know how to proceed
Gah Tang
@gkt5015
Aug 07 2015 02:22
Well it's not about turning a mathematical solution into code. For example:
with 1,2,3... you can start with 4 and see if that number can divide through 1,2,3 if not, check 5, if not check 6
Do you see what I mean? @Kolloom
Kolloom
@Kolloom
Aug 07 2015 02:23
well, i could take the largest number and have it divide by other 4 numbers, if reminder is not 0, multiple the largest number by 2 until all reminder is 0
oh right that might work @gkt5015
Gah Tang
@gkt5015
Aug 07 2015 02:25
But hey you have a great idea too @Kolloom. Prove to yourself that it works and that you're not going to miss any numbers in between
Tyler Haas
@tylerthehaas
Aug 07 2015 02:25
can someone tell me why myCountdown.seconds returns undefined? http://codepen.io/haasDev/pen/LVMmBL
Marc Davenport
@oneate7
Aug 07 2015 02:28
@haasDev - I'm definitely still learning but...you have seconds = options.seconds, but you haven't defined options .seconds that I can see.
D
@bergsman00
Aug 07 2015 02:32
Could anyone spot what I’m doing wrong here? Is this not the correct way to close “div"
<div class='row'>
<div class='col-xs-4'>
<a href='#'><img class='img-responsive thick-green-border' src='https://bit.ly/fcc-kittens'/></a>
</div>
Igor
@igorkovski
Aug 07 2015 02:32
you have two div's
Korina Jimenez
@kjcode25
Aug 07 2015 02:32
looks like you only closed one
@SaintPeter
Aug 07 2015 02:32
@bergsman00 You have two divs but only close one
HAha
Igor
@igorkovski
Aug 07 2015 02:33
;)
@SaintPeter
Aug 07 2015 02:33
In surround sound!
Igor
@igorkovski
Aug 07 2015 02:33
haha
D
@bergsman00
Aug 07 2015 02:33
I see the two divs…I can remove one and just end it all with </div>?
<div class='row' class='col-xs-4'>
<a href='#'><img class='img-responsive thick-green-border' src='https://bit.ly/fcc-kittens'/></a>
</div>
Like that?
Korina Jimenez
@kjcode25
Aug 07 2015 02:34
yes
@bergsman00
D
@bergsman00
Aug 07 2015 02:35
Thanks All! I’ll give that a try.
@SaintPeter
Aug 07 2015 02:35
@bergsman00 Yes, but that's not how you do two classes and I don't think it'll do what you expect
@bergsman00 Do two classes in one class statement seperated by a space
D
@bergsman00
Aug 07 2015 02:36
<div class=‘row', class='col-xs-4'>
<a href='#'><img class='img-responsive thick-green-border' src='https://bit.ly/fcc-kittens'/></a>
</div>
Like that?
Korina Jimenez
@kjcode25
Aug 07 2015 02:36
you dont have to put class 2 times
@SaintPeter
Aug 07 2015 02:36
@bergsman00 no comma either
Korina Jimenez
@kjcode25
Aug 07 2015 02:36
just put class once and no comma
D
@bergsman00
Aug 07 2015 02:36
OK Thanks again.
A little more help if possible…I’m in challenge 78 “Waypoint: Create a Custom Heading” for Free Code Camp…It’s still saying that I need to have a closing tag for my div elements….I have a closing tag like so: </div>. What do you think?
@SaintPeter
Aug 07 2015 02:41
@bergsman00 How many divs do you open?
D
@bergsman00
Aug 07 2015 02:42
<div class='row col-xs-8'</div>
<h2 class='text-primary text-center'>CatPhotoApp</h2><div/>
</div>
Oh…I have two div closed!
Nope…even with that change it won’t let me move on
@SaintPeter
Aug 07 2015 02:43
`<div/>` is not how to close a div
D
@bergsman00
Aug 07 2015 02:43
</div>?
@SaintPeter
Aug 07 2015 02:43
Correct. Also: `<div class='row col-xs-8'</div>`
You're missing a `>`
D
@bergsman00
Aug 07 2015 02:44
Man, these typos are really slowing me down. Thank you Saint Peter
SojournerOctocat
@SojournerOctocat
Aug 07 2015 02:44
Any hints for Sum All Primes? This is what I have so far…
``````function sumPrimes(num) {
var numPrimesSum = 0;
var numCounter = num;
var arrDivisors = [];

while (numCounter >= 2) {
for (var numIter = 2; numIter <= num; numIter++) {
if (num % numIter === 0) {
console.log(numIter);
arrDivisors.push(numIter);
}
}

if (arrDivisors.length == 1) {
numPrimesSum += arrDivisors[0];
}

numCounter--;
}

return numPrimesSum
}

sumPrimes(6);``````
Gah Tang
@gkt5015
Aug 07 2015 02:51
Can anyone help, I've hit a deadend.
``````var frequentOnline = ["freecodecamp", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "comster404", "brunofin", "thomasballinger", "noobs2ninjas", "beohoff", "TSM_theoddone"];
var status = [1,2,3];
var getStatus = function() {
frequentOnline.forEach(function(x) {
\$.getJSON('https://api.twitch.tv/kraken/streams/' + x, function(y) {
status.push("abc");

});

});
};
getStatus();
setTimeout(function() {
console.log(status);
}, 7000);``````
It's not letting me status.push -> says status.push is not a function
@SaintPeter
Aug 07 2015 02:53
@gkt5015 Step 1: Lets fix your callback problem. Do this:
``\$.getJSON('https://api.twitch.tv/kraken/streams/' + x + '?callback=?', function(y) {``
Gah Tang
@gkt5015
Aug 07 2015 02:54
@SaintPeter Okay
@SaintPeter
Aug 07 2015 02:55
@gkt5015 I just made that change to your code and it work.
Gah Tang
@gkt5015
Aug 07 2015 02:55
@SaintPeter It hasn't changed for me :(
It should theoretically push "abc" like 10 times into the array right
@SaintPeter
Aug 07 2015 02:55
@gkt5015 Are you waiting 7 seconds?
Gah Tang
@gkt5015
Aug 07 2015 02:56
@SaintPeter Yeah It's only spitting out the 1,2,3
@SaintPeter
Aug 07 2015 02:56
Do you have a codepen?
Gah Tang
@gkt5015
Aug 07 2015 02:56
@SaintPeter It's still telling me that that status.push isnt a function
@SaintPeter Yeah thats what im using
@SaintPeter for the record, if i replace status.push with console.log("blah blah blah"), it executes the callback just fine
I have no idea why it's giving me a hard time with pushing elements in the array
@SaintPeter
Aug 07 2015 02:59
@gkt5015 loking at it now
Robert
@rc242
Aug 07 2015 02:59
Heyo!
@SaintPeter
Aug 07 2015 02:59
Yo yo yo, Mr. Rc
@gkt5015 Ok, I'm getting that status error - looking into it
Gah Tang
@gkt5015
Aug 07 2015 03:01
@SaintPeter Thanks
Moisés Man
@moigithub
Aug 07 2015 03:03
seems "status" is a RESERVED keyword
rename ur variable
@gkt5015
@SaintPeter
Aug 07 2015 03:03
confirmed. When I changed `status` to another name everything worked just fine
IT may be being used by codepen
Shaklin
@ShaklinSyed
Aug 07 2015 03:04
@SaintPeter can you help me understanding the below code
``````function gcd(a,b) {

while (b !== 0) {
a = [b, b = a % b][0];
}
return a;

}``````
@SaintPeter
Aug 07 2015 03:04
@ShaklinSyed Wow, that's a bit tricky. . . . Lemme see
Gah Tang
@gkt5015
Aug 07 2015 03:05
@SaintPeter @moigithub all thanks. That did stop the error. But are you guys getting the actual array? I'm getting blank arrays
Shaklin
@ShaklinSyed
Aug 07 2015 03:05
or is there a simplified version of it
Moisés Man
@moigithub
Aug 07 2015 03:05
blank.. yes.. cuz async...
u should move all ur code inside the callback :)
@SaintPeter
Aug 07 2015 03:07
``````function gcd(a,b) {

while (b !== 0) {   // <-- Continue to loop until b === 0
a = [b, b = a % b][0];  // make a = b ( I think)
}
return a;
}``````
Man . . I'm not entirely sure. That is some funky stuff.
Gah Tang
@gkt5015
Aug 07 2015 03:07
@moigithub ohhh i fixed the non-sense thanks. Yeah I thought of moving it in the callback but i'm requesting different JSONs
@SaintPeter
Aug 07 2015 03:08
@gkt5015 Note that if you have a slow internet connection it make take more than 7 seconds to get your data back
Shaklin
@ShaklinSyed
Aug 07 2015 03:08
@SaintPeter thanks for giving it a try
Gah Tang
@gkt5015
Aug 07 2015 03:09
@SaintPeter is there a trick to work around this?
Robert
@rc242
Aug 07 2015 03:10
Really should finish this zipline.
@SaintPeter
Aug 07 2015 03:10
@gkt5015 Yes(ish). What I did was actually update my HTML inside the success callback. I added a new div with all of the images and stuff inside that loop.
@gkt5015 As long as you don't care about order, you can add your HTML whenever you'd like. Also, you can nest your \$.getJSON calls
@gkt5015 I bet you're thinking "Get all the results, then display them". Instead think "As soon as I have a result, display that result"
Gah Tang
@gkt5015
Aug 07 2015 03:12
@SaintPeter Ahh.. I'll look at that. The whole point of what I'm ttrying to do is to create an array that gives me the status of each twitch account. From there, I use conditional statements to place them to the appropriate place
Robert
@rc242
Aug 07 2015 03:13
10PM, and still 92F. jeezbus.
@SaintPeter
Aug 07 2015 03:14
@gkt5015 Yeah - you're going to have to rethink how that works. BTW, there ARE ways to wait until you're completely done. You can look up the jquery function called .when().
@gkt5015 But it's non-trivial.
Gah Tang
@gkt5015
Aug 07 2015 03:16
@SaintPeter thanks for the help
Ingrid
@voodoobettie
Aug 07 2015 03:27
This message was deleted
Can anyone help me with this? I can't seem to get my loop to run. I am having trouble with the for / in loop but whenever I use semi-colons I get a missing paren error, and when I don't I find that the loop won't iterate
``````function findLongestWord(str) {

// split the array using "" to get individual elements

var wordList = str.toLowerCase().split(" ");
console.log(wordList.length); // For testing
var longest = 0;  // number of characters in the current longest

for (i in wordList; i <= wordList.length; i=0 ) {
if (i.length >= longest) {
longest = wordList[i].length;
console.log(wordList[i].length, longest);
i++
return longest;
}
}

console.log(longest);

}

findLongestWord('The quick brown fox jumped over the lazy dog');``````
I seem to always get the result 'the' / and number 3
Ingrid
@voodoobettie
Aug 07 2015 03:33
The error I get is "SyntaxError: missing ) after for-loop control"
Kolloom
@Kolloom
Aug 07 2015 03:40
the `return` statement is inside the for loop?
not sure if you really want to do that as return statement would break the loop in first iteration
@voodoobettie
Ingrid
@voodoobettie
Aug 07 2015 03:42
@Kolloom You are right. I think I left that after changing things around. I will try that
@Kolloom Okay I moved it but the loop still doesn't iterate
I'm still getting a "missing paren" error when I run it, and it's returning 0
actually, it's not returning it, it's logging 0 (it doesn't have a => like a returned param)
so it's getting the value from when I initially set it

If I change line 9 to

``for (i in wordList) {``

then the loop runs and returns the first item in the array

Kolloom
@Kolloom
Aug 07 2015 03:47
what is it with `i=0` in the for loop condition?
Ingrid
@voodoobettie
Aug 07 2015 03:47
To set the initial value for i
which I am doing wrong it seems haha. Ok I changed that too
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 03:48
i need help with git
tryign to clone my wiki but i get errors
Ingrid
@voodoobettie
Aug 07 2015 03:49
What errors are you getting @Rafase282 ?
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 03:50
failed to create new commit after i tried to clone form teh shall
shell*
Tyler Haas
@tylerthehaas
Aug 07 2015 03:51
@oneate7 options is passed as an object and seconds is a property of that object
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 03:51
if i delete and try to clone then it send me to the log
@voodoobettie email says this StackTrace: at Octokit.Connection.HandleErrors(IResponse response)
at Octokit.Connection.
Sean
@seanr707
Aug 07 2015 03:52
Any one have a solution on how to solve this error?
``No 'Access-Control-Allow-Origin' header is present on the requested resource.``
Kolloom
@Kolloom
Aug 07 2015 03:53
`for (i in wordList; i <= wordList.length; i=0 )` i think this is the problem @voodoobettie
Ingrid
@voodoobettie
Aug 07 2015 03:53
@Rafase282 What's the command you're using to clone with?
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 03:54
that is the link generated from the wiki page
Kolloom
@Kolloom
Aug 07 2015 04:00
@voodoobettie your for loop is not valid
``````for ([initialization]; [condition]; [final-expression])
statement``````
`i in wordList` is not an initialization, instead it generates index from 0 to wordList.length -1
Kolloom
@Kolloom
Aug 07 2015 04:06
also `i.length` is the length of an number, which is always 1 in this case
Ingrid
@voodoobettie
Aug 07 2015 04:07

oh ok. Sorry, I'm used to python so I'm just confused. How can I run the for loop through the array that iterates over the indicies? I've been trying to figure it out. I tried

``````for (var i in wordList[i], i = 0, i++)
current = this.length;
if (current >= longest) {
var longest = current;
console.log(current);
return result;
//    console.log(longest);``````

but I couldn't get that one to work either :( @Kolloom

Kolloom
@Kolloom
Aug 07 2015 04:07
i came from python too
I kinda got your code fixed
Ingrid
@voodoobettie
Aug 07 2015 04:09
@Rafase282 Is it a private repo? I don't see it there. (I was trying to check your path)
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 04:09
@voodoobettie public
SM
@nogo10
Aug 07 2015 04:12
!!. how do you use multiplication of a string? ie. console.log(2* 'hello')
Kolloom
@Kolloom
Aug 07 2015 04:12
``````for (i = 0; i < 'hello'.length; i ++) {
console.log('hello'[i]);
} // that would be how you print char in word, unlike python, the i here is only a number``````
SM
@nogo10
Aug 07 2015 04:13
This message was deleted
Kolloom
@Kolloom
Aug 07 2015 04:14

you can do this though

``````for (var char in 'hello') {
console.log('hello'[char]); // print char in new line
}``````

that's the simplest way i know

Ingrid
@voodoobettie
Aug 07 2015 04:16
@Kolloom Ah! Okay, thank you! That makes total sense now that I see it.
Kolloom
@Kolloom
Aug 07 2015 04:17
This message was deleted
Ingrid
@voodoobettie
Aug 07 2015 04:18
That was my first thought. Haha. I think I've been looking at this for way too long!
Kolloom
@Kolloom
Aug 07 2015 04:20
i don't know what you trying to do with `this.length` though
Ingrid
@voodoobettie
Aug 07 2015 04:21
I think I put that in there to add some js magic late last night and then forgot it was there afterwards
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 04:21
and it turns out my code for arguments optional does not work for all test
Ingrid
@voodoobettie
Aug 07 2015 04:21
@Kolloom
oops
Kolloom
@Kolloom
Aug 07 2015 04:23
oh well gotta go , have fun with js :)
Ingrid
@voodoobettie
Aug 07 2015 04:23
I was going to ask if you're using a ruby gem for git called Octokit, that seems to be the source of the problem from what I can see (the stackTrace message is what I'm thinking of) - is that at all possible?
Thanks @Kolloom !
CamperBot
@camperbot
Aug 07 2015 04:23
voodoobettie sends brownie points to @kolloom :sparkles: :thumbsup: :sparkles:
Ingrid
@voodoobettie
Aug 07 2015 04:24
@Rafase282 - sorry, that last msg was for you
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 04:25
@voodoobettie I'm using their app, but I'm also runnign windows 10
Ingrid
@voodoobettie
Aug 07 2015 04:25
Ah ha! :P
Just kidding
@Rafase282 Can you stop the service and try it?
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 04:29
how do I do that? i even restarted the machine
Ingrid
@voodoobettie
Aug 07 2015 04:36
I'm not really all that ruby / rails savvy but I think you need to type 'spring stop' and that should stop the background gem preloader
that should stop the background services (I think)
Ingrid
@voodoobettie
Aug 07 2015 04:51
I just switched to linux because I was getting tired of everything in windows not working as easily as I'd like it to
Ozy Design & Software
@OzySky
Aug 07 2015 04:57
@nogo10 repeat (using new ES6 syntax)
bonfire unite
CamperBot
@camperbot
Aug 07 2015 04:58
Sorry, can't find a bonfire called unite. [ Check the map? ]
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 05:02
@voodoobettie I used ubuntu and when i got my new laptop I decided to keep windows 8.1 which now upgraded to windows 10
havent used linux since the last version came out
last versionof ubuntu
Ingrid
@voodoobettie
Aug 07 2015 05:08
@Rafase282 Same sort of thing for me, I had been using ubuntu a while back, then I got a windows laptop, but recently I got tired of battling with it, plus it was slow because it was a few years old. I just fixed my desktop with some new hardware and installed ubuntu but I haven't got around to installing windows yet
Rafael J. Rodriguez
@Rafase282
Aug 07 2015 05:09
I have virtualbox but havent installed ubuntu on it
I do have it on my older machine as dualboot
and my netbook
Ingrid
@voodoobettie
Aug 07 2015 05:12
Having a bunch of computers around is handy
David Sanchez
@wundertunge
Aug 07 2015 05:15
can anyone help me with a JQuery exercise?
Ingrid
@voodoobettie
Aug 07 2015 05:16
depends on what it is :)
David Sanchez
@wundertunge
Aug 07 2015 05:17
ok, so this is in the CodeAcademy intro to JQuery
and I can't tell if it's bugged because I appear to be doing it right
Ingrid
@voodoobettie
Aug 07 2015 05:17
oh ok. Then I might be able to
David Sanchez
@wundertunge
Aug 07 2015 05:17
``````\$(document).ready(function() {
\$('div').mouseenter(function() {
});
});``````
I am trying to get the button to go to full opacity when I hover over it
Ingrid
@voodoobettie
Aug 07 2015 05:18
I think it might be capitalization of "mouseEnter"
David Sanchez
@wundertunge
Aug 07 2015 05:18
no that's not right
it's all lower case
but I figured it out
Jason Healy
@jhealy86
Aug 07 2015 05:18
nope, it's all lowercase. jquery documentation
David Sanchez
@wundertunge
Aug 07 2015 05:18
Jason Healy
@jhealy86
Aug 07 2015 05:19
what was the problem?
David Sanchez
@wundertunge
Aug 07 2015 05:19
So the div selector starts with an opacity of .5 on the style sheet
Ingrid
@voodoobettie
Aug 07 2015 05:19
David Sanchez
@wundertunge
Aug 07 2015 05:19
and the instructions for the exercise say to create a jQuery function that makes the 'div' fadeTo full opacity 1 when you mouseenter it
when I changed it to 1 on the stylesheet, it made the exercise complete successfully even though those weren't the instructions

Using the examples above, make it so your 'div' fades to 1 (100%) opacity when your mouse enters the 'div'. Make the animation speed 'fast'. (Make sure to give fadeTo() its inputs in order—speed, then opacity.)

Click Save & Submit Code, then slowly mouse over your 'div' to see the effect!

doesn't that mean make it so the 'div' goes to full opacity? Not change it on the stylesheet?
yeah, that's even what they say in the hint
Jason Healy
@jhealy86
Aug 07 2015 05:22
David Sanchez
@wundertunge
Aug 07 2015 05:23
exercises 11 and 12
i would love for you to prove me incorrect :)
it would feel less frustrating
Jason Healy
@jhealy86
Aug 07 2015 05:25
``````\$(document).ready(function() {
\$('div').mouseenter(function() {
});
});``````
which looks identical to yours
``````\$(document).ready(function() {
\$('div').mouseenter(function() {
});
});``````
huh. weird.
David Sanchez
@wundertunge
Aug 07 2015 05:26
and it didn't work right?
Jason Healy
@jhealy86
Aug 07 2015 05:26
no, mine works fine
David Sanchez
@wundertunge
Aug 07 2015 05:26
oh
Jason Healy
@jhealy86
Aug 07 2015 05:26
you're typing it into the javascript tab, right?
David Sanchez
@wundertunge
Aug 07 2015 05:26
well I wonder too, did I not do the scripting correct on the html page?
yeah...it's called script.js
well that shouldn't actually matter because it auto-populates that
Jason Healy
@jhealy86
Aug 07 2015 05:28
yeah, in the html file you need to make sure you have
``````<head>
<!-- Stuff here-->
<script type='text/javascript' src='script.js'></script>
Muatasim Qazi
@muatasimqazi
Aug 07 2015 05:29
@wundertunge , I copied and pasted your code in CodeAcademy editor and it just works fine.
Jason Healy
@jhealy86
Aug 07 2015 05:29
@wundertunge shouldn't matter, but what browser and OS are you on?
David Sanchez
@wundertunge
Aug 07 2015 05:29
@jhealy ok, by moving my script into the 'head' section, it alleviated the issue and the coding worked
@jhealy86 at first I had it on line 1
but that's also where it autopopulated
browser: chrome // OS: ChromeOS (I'm using a Chromebook
Jason Healy
@jhealy86
Aug 07 2015 05:30
weird. yeah, script tags go in the `<head>`
David Sanchez
@wundertunge
Aug 07 2015 05:30
)
that's maybe where I messed up...but weirder still that for me, the script autopopulated on line 1 above <html>
and so is it important that it also go at the very bottom before the </html>
?
Oh, I just made sure it was before the endtag for </html>
anyways, it seems to have worked...but it's still a mystery. Thank you for your help!
Ozy Design & Software
@OzySky
Aug 07 2015 05:36
in bonfire pairwise, why does [1, 3, 2, 4], 4) equal 1?
Cristián Berríos
@crisberrios
Aug 07 2015 05:37
bf pairwise
CamperBot
@camperbot
Aug 07 2015 05:37
Sorry, can't find a bonfire called pairwise. [ Check the map? ]
Cristián Berríos
@crisberrios
Aug 07 2015 05:37
bf Pairwise
CamperBot
@camperbot
Aug 07 2015 05:37
Sorry, can't find a bonfire called pairwise. [ Check the map? ]
Cristián Berríos
@crisberrios
Aug 07 2015 05:38
Return the sum of all indices of elements of 'arr' that can be paired with one other element to form a sum that equals the value in the second argument 'arg'. If multiple sums are possible, return the smallest sum. Once an element has been used, it cannot be reused to pair with another.
Ozy Design & Software
@OzySky
Aug 07 2015 05:38
so?
Cristián Berríos
@crisberrios
Aug 07 2015 05:38
1+3 is the only combination possible
so index 0 + index 1 = 1
Jason Healy
@jhealy86
Aug 07 2015 05:39
@ozydesign you're adding the value of the indices. so 1 is at arr[0] and 3 is at arr[1]
0 + 1 = 1
Ozy Design & Software
@OzySky
Aug 07 2015 05:39
thanks!
Jason Healy
@jhealy86
Aug 07 2015 05:39
and one thing that frustrated me on this, you're adding the indices of all possible pairs, not just one pair
Ozy Design & Software
@OzySky
Aug 07 2015 05:40
didn't quite catch that till you explained it
Jason Healy
@jhealy86
Aug 07 2015 05:40
so if there were another 2 in that array, say at the end, you'd have your 1 from 1 and 3, then 2 + 4 from the 2's
so it would be 7
Ozy Design & Software
@OzySky
Aug 07 2015 05:40
thanks @jhealy86
CamperBot
@camperbot
Aug 07 2015 05:40
ozydesign sends brownie points to @jhealy86 :sparkles: :thumbsup: :sparkles:
:star: 2 | @jhealy86 | http://www.freecodecamp.com/jhealy86
Ozy Design & Software
@OzySky
Aug 07 2015 05:42
thanks @crisberrios
CamperBot
@camperbot
Aug 07 2015 05:42
ozydesign sends brownie points to @crisberrios :sparkles: :thumbsup: :sparkles:
:star: 109 | @crisberrios | http://www.freecodecamp.com/crisberrios
Cristián Berríos
@crisberrios
Aug 07 2015 05:42
my 1st brownie points :D
John Irle
@JohnIrle
Aug 07 2015 05:42
Could someone help me with the Convert HTML Entities bonfire?
Cristián Berríos
@crisberrios
Aug 07 2015 05:42
sure @doudeman
what's the matter?
John Irle
@JohnIrle
Aug 07 2015 05:42
Here is what I have so far.
``````function convert(str) {
str = str.split("");

for(i = 0; i < str.length; i++){
if(str[i] == /[^a-z]/){
switch(str[i]){
case "<":
str.replace(str[i], "&lt;");
break;

case ">":
str.replace(str[i], "&gt;");
break;

case "'":
str.replace(str[i], "&apos;");
break;

case "&":
str.replace(str[i], "&amp;");
break;

case '"':
str.replace(str[i], "&quot;");
break;
}
}
}

var repl = str.join("");

return repl;
}

convert('Dolce & Gabbana');``````
Cristián Berríos
@crisberrios
Aug 07 2015 05:44
hmm well in your case str.replace is kind of unneeded
as you are not replacing strings in a character
but actually characters/strings within an array
John Irle
@JohnIrle
Aug 07 2015 05:44
ah yeah that makes sense. I tried just making it equal to the entity
Cristián Berríos
@crisberrios
Aug 07 2015 05:44
so a simple str[i] = 'xxxx' would be enough
John Irle
@JohnIrle
Aug 07 2015 05:44
I tried that and it didn't work
Jason Healy
@jhealy86
Aug 07 2015 05:44
you could also tidy up that regex, just make it what you need to replace
so `/&<>'"/`
John Irle
@JohnIrle
Aug 07 2015 05:45
@jhealy86 ah thanks
Jason Healy
@jhealy86
Aug 07 2015 05:45
because what you have right now is going to catch whitespaces and other things that don't need replacement, like dashes
Cristián Berríos
@crisberrios
Aug 07 2015 05:45
now, you could just do all the replaces without iterating over the string
or breaking it into an array
but allegedly it would be a bit slower in memory as strings don't get modified but actually re-created on any modification
Jason Healy
@jhealy86
Aug 07 2015 05:46
also, strings are immutable in javascript, so if you're not catching the results of `str.replace()` when you call it you'll lose all your work and just have your original string at the end
Cristián Berríos
@crisberrios
Aug 07 2015 05:47
also ^
John Irle
@JohnIrle
Aug 07 2015 05:47
``````function convert(str) {
str = str.split("");

for(i = 0; i < str.length; i++){
if(str[i] == /&<>'"/){
switch(str[i]){
case "<":
str[i] = "&lt;";
break;

case ">":
str[i] = "&gt;";
break;

case "'":
str[i] = "&apos;";
break;

case "&":
str[i] = "&amp;";
break;

case '"':
str[i] = "&quot;";
break;
}
}
}

var repl = str.join("");

return repl;
}

convert('Dolce & Gabbana');``````
That is still not working
Jason Healy
@jhealy86
Aug 07 2015 05:47
because strings are immutable
... but i guess you're working with an array, aren't you
oh, make sure to triple equals all your conditionals unless you really know what you're doing. bad things will happen if you don't
so `str[i] === /regex/`
Cristián Berríos
@crisberrios
Aug 07 2015 05:49
nop
nope
John Irle
@JohnIrle
Aug 07 2015 05:49
?
Cristián Berríos
@crisberrios
Aug 07 2015 05:49
that will match a string against a regex
you need to do a regex.test
John Irle
@JohnIrle
Aug 07 2015 05:50
@crisberrios Oh really?
Cristián Berríos
@crisberrios
Aug 07 2015 05:51
DTing
@dting
Aug 07 2015 05:51
@doudeman all you need is `switch(str[i]) {`
get rid of the if statement and the regex completely
your switch is doing the matching for you since you are iterating each character
Jason Healy
@jhealy86
Aug 07 2015 05:51
^also true
John Irle
@JohnIrle
Aug 07 2015 05:51
@dting That did it
Cristián Berríos
@crisberrios
Aug 07 2015 05:52
@dting that's true but also it's good to know what you're trying to do
DTing
@dting
Aug 07 2015 05:59
@doudeman if you want to use str. replace you can use regex with a callback function, something like:
``````var escapeMap = Object.create(null);
escapeMap['<'] =  "&lt;";
escapeMap['>'] =  "&gt;";
escapeMap["'"] =  "&apos;";
escapeMap['&'] =  "&amp;";
escapeMap['"'] =  "&quot;";

function convert(str) {
return str.replace(/[<>'&"]/, function(match) {
return escapeMap[match];
});
}``````
Bill
@kirah1314
Aug 07 2015 06:00
what's going on here?
``````function fac(n) {
if (n == 0)
return 1;
else
return fac(n - 1) * n;
}``````
DTing
@dting
Aug 07 2015 06:00
@doudeman but your solution is equally valid
This message was deleted
This message was deleted
Bill
@kirah1314
Aug 07 2015 06:01
blew my mind that fac(8) gets 40,320
Cristián Berríos
@crisberrios
Aug 07 2015 06:02
@dting just missed the g flag in the regexp, but good solution
DTing
@dting
Aug 07 2015 06:03
oops thanks.
Jason Healy
@jhealy86
Aug 07 2015 06:09
@kirah1314 what do you mean? it's calculating a factorial. by using the most memory possible, apparently
Tyler Haas
@tylerthehaas
Aug 07 2015 06:11
I did it!!!!
sorry just had to share my excitement over my feat for the night
DTing
@dting
Aug 07 2015 06:12
@haasDev nice! not sure what it was but hopefully something good.
Luis Felipe López G.
@luishendrix92
Aug 07 2015 07:12

Help, this code works and passes all the tests in the Arguments optional bonfire but if I test `add([2])(3)` it returns an error in the developer tools console, but if I type `add(2)([3])` it returns undefined as it should in the first place. Also works if I type `add([2], 3)`:

``````function add(a, b) {
function argsNotNumber(args) {
for (var i in args)
if (typeof args[i] !== "number")
return true;
return false;
}

if (argsNotNumber(arguments))
return undefined;
else
return (arguments.length === 2) ? a + b : function () {
if (argsNotNumber(arguments))
return undefined;
else
return (a + arguments[0]);
};
}``````

What seems to be wrong for the code to fully work even after passing all FCC tests?

CamperBot
@camperbot
Aug 07 2015 07:12
no wiki entry for: `this code works and passes all the tests in the arguments optional bonfire but if i test add23 it returns an error in the developer tools console but if i type add23 it returns undefined as it should in the first place also works if i type add2 3function adda b function argsnotnumberargs for var i in args if typeof argsi number return true return false if argsnotnumberarguments return undefined else return argumentslength 2 a b function if argsnotnumberarguments return undefined else return a arguments0 what seems to be wrong for the code to fully work even after passing all fcc tests`
:pencil: click here to create one now!after creating your page type `update` to reload it here
Luis Felipe López G.
@luishendrix92
Aug 07 2015 07:12
bf arguments optional
CamperBot
@camperbot
Aug 07 2015 07:12

``````function add() {
return false;
}

Create a function that sums two arguments together. If only one argument is provided, return a function that expects one additional argument and will return the sum.
For example, add(2, 3) should return 5, and add(2) should return a function that is waiting for an argument so that <code>var sum2And = add(2); return sum2And(3); // 5</code>
If either argument isn't a valid number, return undefined.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Ozy Design & Software
@OzySky
Aug 07 2015 07:19
@luishendrix92 your putting the first argument in an array so type !=number but array
CamperBot
@camperbot
Aug 07 2015 07:19
ozydesign sends brownie points to @luishendrix92 :sparkles: :thumbsup: :sparkles:
:star: 1 | @luishendrix92 | http://www.freecodecamp.com/luishendrix92
Luis Felipe López G.
@luishendrix92
Aug 07 2015 07:21
Oh, thanks @ozydesign
Harvey
@harvey56
Aug 07 2015 07:23
hi! anyone willing to help ? i'm at bonfire 17. having a bit of a hard time understanding callbacks related stuff
Henry Erickson
@henryed86
Aug 07 2015 07:24
This message was deleted
Harvey
@harvey56
Aug 07 2015 07:25
I can filter the array with one arg, but can't figure out how to filter with 2 (or more)
Henry Erickson
@henryed86
Aug 07 2015 07:26
Hey guys! I can't seem to understand what they are asking for the Truncate a string Bonfire
Luis Felipe López G.
@luishendrix92
Aug 07 2015 07:31
@henryed86 Try searching for String.prototype.substr()
Ozy Design & Software
@OzySky
Aug 07 2015 07:32
@harvey56 care to paste your code?
Henry Erickson
@henryed86
Aug 07 2015 07:32
I'll try that @luishendrix92
Allan Armstrong
@allanarmstrong
Aug 07 2015 07:33
I'm doing Advanced Bonfire #6(No Repeats Please) and it seems like the tests are returning the expected value +2 (i.e. what the default test (permAlone('aab') returns)... Has anyone experienced this?
when I get rid of the permAlone('aab') at the bottom of the sandbox it passes the tests... weird
Luis Felipe López G.
@luishendrix92
Aug 07 2015 07:37
@henryed86 It's easier that way, you basically have to check if the length of the string is greater than the number given in the second parameter (num). If it's longer, return the result of triming the string from its beginning up to the given number (num) and add "..." to the end. Remember that Indices are 0-based and substr() is index based. If it's not, just return the string as it was.
Henry Erickson
@henryed86
Aug 07 2015 07:42
Ohh now I understand what the're asking for.. thanks @luishendrix92
I did it
Luis Felipe López G.
@luishendrix92
Aug 07 2015 07:51
@henryed86 Felicidades, ahora con los siguientes D:
Henry Erickson
@henryed86
Aug 07 2015 07:54
Por supuesto , pero sera mi ultimo... @luishendrix92
por hoy
Luis Felipe López G.
@luishendrix92
Aug 07 2015 07:54
De acuerdo entonces, descansa y otro día le sigues :)
Henry Erickson
@henryed86
Aug 07 2015 07:57
Hasta luego @luishendrix92
Matthew Barber
@Honno
Aug 07 2015 08:12
hey all, could I see a solution to bonfire sorted union?
I've spent an hour on it already, kinda wanna give up, would greatly appreciate some nudge in the right direction
Nepherius
@Nepherius
Aug 07 2015 08:18
``````function unite(arr1, arr2, arr3) {

arr1 = arr1.concat(arr2);
arr1 = arr1.concat(arr3);
arr1 = arr1.filter(function(item,position){
return arr1.indexOf(item) == position;
});
return arr1;
}``````
Randy Goldsmith
@Dueldrawer8
Aug 07 2015 08:21
```
``````var friends = {};
friends.bill: {
firstName: "Bill",
lastName: "Gates",
number: "(281) 655-9889",
};
friends.steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(879) 555-7980",
};``````
says syntax error I need a semicolon but my code seems fine..
nvm found it..
Matthew Barber
@Honno
Aug 07 2015 08:25

hey @Nepherius, thanks, did it like this in the end

``````function unite(arr1, arr2, arr3) {
var arr = [arr1, arr2, arr3].reduce(function(a, b) {
return a.concat(b);
});
arr = arr.filter(function(a, i) {
if(i === arr.indexOf(a)) {
return true;
} else {
return false;
}
});
return arr;
}

unite([1, 2, 3], [5, 2, 1, 4], [2, 1]);``````

and I don't know how it works exactly lol

but I get reduce and filte rproperly now
ah yes yes
everytime I finish a bonfire I always look at my code to see how I did it >.>
Nepherius
@Nepherius
Aug 07 2015 08:27
for concat you can also do arr1 = arr1.concat(arr2,arr3), its shorter :)
Matthew Barber
@Honno
Aug 07 2015 08:27
oh I didn't know it'd add more than one argument @Nepherius haha
Nepherius
@Nepherius
Aug 07 2015 08:28
neither did I when I did that bonfire :)))
Matthew Barber
@Honno
Aug 07 2015 08:28
I also should return i === arr.indexOf(a)
meh w/e had enough of this lol
one day I'll go through all my bonfires and do the optimal piece of code
Matthew Barber
@Honno
Aug 07 2015 08:35
Hey, is it best practice to declare a variable to use in a loop (going to be used every loop) outside of it?
Does it make the code run less effeciently if I keep on declaring it inside a loop?
or does it 'stay' declared on the first loop?
I dunno even what I'm talking about
Nepherius
@Nepherius
Aug 07 2015 08:37
if you declare it inside the loop wont it reset every itineration ?
Matthew Barber
@Honno
Aug 07 2015 08:39
That's what I don't quite get heh
Nepherius
@Nepherius
Aug 07 2015 08:40
well if you do something like var x = 2 inside a loop then every time the loop starts x will be set to 2 no matter what happens below
Matthew Barber
@Honno
Aug 07 2015 08:42
and that's not an assignment?
what if there was no var
Nepherius
@Nepherius
Aug 07 2015 08:42
for example if you owuld have something like
``````for () {
var x = 2;
x++
}``````
Matthew Barber
@Honno
Aug 07 2015 08:42
would it be an assignemnt or a declaration as a global var?
Nepherius
@Nepherius
Aug 07 2015 08:43
at the end of that loop x will be 3
no matter how many items it runs
if x would be declared outside the loop then x would grow every time
so it depends on what you are going for ...
no var would just mean it;s a global var instead of a local var .. or something like that :)
Matthew Barber
@Honno
Aug 07 2015 08:45
Nah was just wondering effeciency wise
I did some python and it's a bit different so I get confused haha
Nepherius
@Nepherius
Aug 07 2015 08:46
well if you only use x inside the loop then sure you should do var x; inside the loop
Matthew Barber
@Honno
Aug 07 2015 08:48
mhmk
Hey, kinda unsure what it's asking here
bonfire convert html
CamperBot
@camperbot
Aug 07 2015 08:50

## :fire:Bonfire: Convert HTML Entities :link:

``````function convert(str) {
// &colon;&rpar;
return str;
}

convert('Dolce & Gabbana');``````

Convert the characters "&", "<", ">", '"' (double quote), and "'" (apostrophe), in a string to their corresponding HTML entities.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Matthew Barber
@Honno
Aug 07 2015 08:50
so should it be "Dolce &amp Gabbana"?
Ozy Design & Software
@OzySky
Aug 07 2015 08:50
&
@vzamfirescu
Aug 07 2015 08:50
Dolce &
don't forget the ; after the amp
Ozy Design & Software
@OzySky
Aug 07 2015 08:51
yep
I fell there
@vzamfirescu
Aug 07 2015 08:51
I struggled on that one because I didn't put the ; at the end of the escape characters -.-
Matthew Barber
@Honno
Aug 07 2015 08:51
oo
thanks
Nepherius
@Nepherius
Aug 07 2015 08:52
took me like 15 minutes to understand what I had to do :)
Ozy Design & Software
@OzySky
Aug 07 2015 08:55
maybe we should add it to the hints?
seems most of us fell there :pensive:
Matthew Barber
@Honno
Aug 07 2015 08:57
Why doesn't this successfully add a semicolon?
``````function convert(str) {
// &colon;&rpar;
var arr = str.split("");
var arrCheck = arr;
for(i = 0; i < arr.length; i++) {
switch(arr[i]) {
case "&":
arr[i] = "&amp";
break;
case "<":
arr[i] = "&lt";
break;
case ">":
arr[i] = "&gt";
break;
case "\"":
arr[i] = "&amp";
break;
case "\'":
arr[i] = "&apos";
break;
default:
console.log("I'm so alooooone");
}
if(arr[i] !== arrCheck[i]) {
arr[i] = arr[i] + ";";
}
}
str = arr.join("");
return str;
}

convert('Dolce & Gabbana');``````
Ozy Design & Software
@OzySky
Aug 07 2015 08:57
apostrophe inside the quotes
Matthew Barber
@Honno
Aug 07 2015 08:58
?
I just did \', doesn't that cancel it?
cancel it as to be read like code
ffs
& is &amp when it wants to be
`console.log(arr[i] + " | " + arrCheck[i]);` prints `&amp | &amp`
I could add a semicolon manually but that's not hip
wtf
if I print arrCheck[6] it comes off as just & at the start
Matthew Barber
@Honno
Aug 07 2015 09:04
Once I change arr[6] into &amp it suddenly becomes &amp for arrCheck
Ozy Design & Software
@OzySky
Aug 07 2015 09:09
``&amp;<-- dont forget the apostrophe``
Nepherius
@Nepherius
Aug 07 2015 09:09
``````function convert(str) {
str.split('').map(function (i) {
if (str.match('<')) {
str = str.replace(/\</gm, '&lt;');
} else if (str.match('>')) {
str = str.replace(/\>/gm, '&gt;');
} else if (str.match('"')) {
str = str.replace(/"/gm, '&quot;');
} else if (str.match("'")) {
str = str.replace(/'/gm, '&apos;');
} else if (str.match(/\s&\s/gm)) {
str = str.replace('&', '&amp;');
}
});
return str;
}``````
Matthew Barber
@Honno
Aug 07 2015 09:13
yeah I get that lol
I just want to be hip
and do it for all cases in one fell swoop
techstonia
@techstonia
Aug 07 2015 09:14
does anyone know some online regex tool that gives same results as required in bonfire validate-us-telephone-numbers
?
Ozy Design & Software
@OzySky
Aug 07 2015 09:17
@techstonia regexr.com?
Nepherius
@Nepherius
Aug 07 2015 09:21
techstonia
@techstonia
Aug 07 2015 09:23
on regexr.com this (1 ?)?([0-9]{3}) ?([0-9]{3}-)[0-9]{4} matches the string "1 (555) 555-5555", but in nodejs and freecodecamp it doesn't
maybe i'm missing someting with whitespace
Ozy Design & Software
@OzySky
Aug 07 2015 09:24
look why it matched (by hovering over the match)
techstonia
@techstonia
Aug 07 2015 09:31
okay, i found out that if i remove some parenthesis, then it actually helps :)
Matthew Barber
@Honno
Aug 07 2015 09:39

Hey guys, how do I make this more effecient?

``````function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
var arr = str.split("");
if(arr.indexOf(" ") !== -1) {
str = str.toLowerCase().replace(/\s/g, "-");
} else if(arr.indexOf(" ") === -1) {
if(arr.indexOf("_") === -1) {
for(i = 1; i < arr.length - 1; i++) {
if(arr[i] === arr[i].toUpperCase()) {
arr[i] = "-" + arr[i].toLowerCase();
}
}
str = arr.join("");
}
else {
str = str.toLowerCase().replace(/_/g, "-");
}
}
return str;
}

spinalCase('This Is Spinal Tap');``````

for

bonfire spinal
CamperBot
@camperbot
Aug 07 2015 09:39

## :fire:Bonfire: Spinal Tap Case :link:

``````function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return str;
}

spinalCase('This Is Spinal Tap');``````

Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Ozy Design & Software
@OzySky
Aug 07 2015 09:41
regex
@Honno
Matthew Barber
@Honno
Aug 07 2015 09:42
How would I replace all capital letters with a hypen before them?
and make them lower case
Nepherius
@Nepherius
Aug 07 2015 09:46
``````function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return str.replace(/\s|_|([a-z](?=[A-Z]))/gm, '\$1-').toLowerCase();
}

spinalCase('This Is Spinal Tap');``````
Krzysztof Miąsko
Aug 07 2015 09:47
@Nepherius i don't think pasting solutions is the way to do it..
Nepherius
@Nepherius
Aug 07 2015 09:50
idk I like seeing solutions from other ppl, learn new ways to solve same bonfire ..
Matthew Barber
@Honno
Aug 07 2015 09:52
@kmiasko Yeah I agree, but once you spend an hour on a bonfire you know you're not learning anymore, and maybe that's because I don't research well but I really need a solution which pertains to the specific problem I'm doing
thanks @Nepherius and @ozydesign
CamperBot
@camperbot
Aug 07 2015 09:52
honno sends brownie points to @nepherius and @ozydesign :sparkles: :thumbsup: :sparkles:
:star: 1 | @ozydesign | http://www.freecodecamp.com/ozydesign
Matthew Barber
@Honno
Aug 07 2015 09:52
I do try and understand it before I move on, rewriting it essentially from memory first then reference
worried if I'm learning effectively heh
Nepherius
@Nepherius
Aug 07 2015 09:57
I always avoid reading other solutions before I solve it my way then I actually ask other ppl for solutions just to compare codes and see if I can improve mine
Matthew Barber
@Honno
Aug 07 2015 10:08
Hey @Nepherius I can't find this anywhere- what does \$1 exactly do?
does it identify a group from your regex?
Nepherius
@Nepherius
Aug 07 2015 10:09
it holds the captured group
Matthew Barber
@Honno
Aug 07 2015 10:09
It keeps it?
Nepherius
@Nepherius
Aug 07 2015 10:09
yes
Matthew Barber
@Honno
Aug 07 2015 10:09
How does _ turn into - then? shouldn't it be _-?
Nepherius
@Nepherius
Aug 07 2015 10:10
\$1 holds 'A' for example and I'm doing \$1- or A-
Matthew Barber
@Honno
Aug 07 2015 10:10
oh!
_ isn't captured
I see
thanks man
Nepherius
@Nepherius
Aug 07 2015 10:11
yw
Elizabeth Hatleli
@TheHighPriestess
Aug 07 2015 10:12
Question about the "Bonfires": How do you advance to the next one? My code runs fine in the console.
CamperBot
@camperbot
Aug 07 2015 10:12
type `bonfire name` to get some info on that bonfire. And check HelpBonfires chatroom
Elizabeth Hatleli
@TheHighPriestess
Aug 07 2015 10:13
..but I don't see anywhere to advance to the next "Bonfire"
Matthew Barber
@Honno
Aug 07 2015 10:13
Check below the run line, there may be errors
Also you need to return the value, not print it
YOU SAW NOTHING
I can't do this
Elizabeth Hatleli
@TheHighPriestess
Aug 07 2015 10:15
Perhaps I am not understanding the instructions.
My code works fine.
Matthew Barber
@Honno
Aug 07 2015 10:15
show it here and we can check it out
Elizabeth Hatleli
@TheHighPriestess
Aug 07 2015 10:15
but I'm getting error messages...

function reverseString(str) {
var res = str.split(" ");
var newArray = res.reverse();
var newString = newArray.toString();
console.log(newArray);
console.log(res);
console.log(newString);
return res;
}

reverseString('hello how are you?');

it gives me back a reversed string.
Matthew Barber
@Honno
Aug 07 2015 10:16
btw put that inbetween
```
<code here>
```
Krzysztof Miąsko
Aug 07 2015 10:17
@TheHighPriestess you need to return string, you're returning an array
take a look at .join
Matthew Barber
@Honno
Aug 07 2015 10:18
newArray to string? I joined it, what's the difference haha I dunno anymore
Krzysztof Miąsko
Aug 07 2015 10:19
@TheHighPriestess and you're returning res, so just splitted string, not reversed one
@TheHighPriestess console.log it's just for you, what mathers for test runner is what you're returning
Optmistic
@Optmistic
Aug 07 2015 10:55
why my factorial function returning 120??
why my factorial function returning 120??
http://prntscr.com/81v5i7
Omar
@oab00
Aug 07 2015 11:04
@Optmistic put `return fact;` outside the loop?
Optmistic
@Optmistic
Aug 07 2015 11:05
@oab00 thnkuu so muchh , Now its works
Omar
@oab00
Aug 07 2015 11:06
:)
Optmistic
@Optmistic
Aug 07 2015 11:29
how to check given string is pelindrom or not using replace() ????
George Tsoukatos
@Gts0uk
Aug 07 2015 11:32
hey guys how can I really learn how to use Apis ?
on the projects they ask to use Apis but there weren't any courses to teach this skill
Omar
@oab00
Aug 07 2015 11:36
@Gts0uk have you found an api ?
Joris Labie
@labiej
Aug 07 2015 11:36
the functional programming tutorial has a little info on that @Gts0uk
George Tsoukatos
@Gts0uk
Aug 07 2015 11:36
@oab00 the weather one
Joris Labie
@labiej
Aug 07 2015 11:37
Otherwise you are interested in the `\$.get`, `\$.getJSON` and `\$.ajax` functions of jQuery
vbobjee
@vbobjee
Aug 07 2015 11:38
Hello Coders,
George Tsoukatos
@Gts0uk
Aug 07 2015 11:39
@labiej ok I'll take a look. I just want for the beginning to be able to get data and represent them on my app. Nothing fancy
vbobjee
@vbobjee
Aug 07 2015 11:39

I am working on bonfire: steamroller. Can somebody help me with this.

``````function steamroller(arr) {
var bool = true;
var newArr = [];
function pusharr(val) {
newArr.push(val);
}
for (var i = 0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
arr[i].forEach(pusharr);
bool = false;
}
else
newArr.push(arr[i]);

}
if (bool)
return newArr;
else
steamroller(newArr);

}

steamroller([1, [2], [3, [[4]]]]);``````

The result is undefined when i run it.

It works fine when i run it on visual studio. But returns undefined when i run it on the website

Joris Labie
@labiej
Aug 07 2015 11:40
Than you are all set if you understand to use those functions
@vbobjee sure what is your problem?
help format
CamperBot
@camperbot
Aug 07 2015 11:40

## :point_right: pasting formatted code in gitter [wiki]

Use three ticks [ ` ] -- on American keyboards, that's the key in the corner between [1] and [Tab]. Then press [Enter]+[Shift]. Gitter will usually fill in the closing ticks for you, but if they aren't there remember to end your code with a line of three ticks. Ticks must always be on their own lines. When you are ready to send your message press [Ctrl]+[Enter].

You can edit your previously sent messages by hovering over the message and clicking the ...,
so if you accidentally paste unformatted code, just fix it.

If your code is long, you can create a Gist and paste the link in Gitter. This also allows fellow campers to collaborate with you more directly.
:pencil: read more about pasting formatted code in gitter on the FCC Wiki

Omar
@oab00
Aug 07 2015 11:40
@Gts0uk for example you can do this to request data from an api:
``````\$.getJSON('http://api.openweathermap.org/data/2.5/weather?q=London', gotData);

function gotData(data) {
console.log(data);
}``````
`?q=London` in the url being the city name requested to get weather data on
and `gotData` is a function to call after the data was sent back from the server
Joris Labie
@labiej
Aug 07 2015 11:47
@vbobjee You need recursion to process the (deeply) nested arrays if doing it this way
George Tsoukatos
@Gts0uk
Aug 07 2015 11:52
@oab00 I know that. I want to get the data from the geolocation of user
and if the user is from london then I'll present to him London's weather
so I guess I have to use two different APIS
Omar
@oab00
Aug 07 2015 11:53
you can use js to get geolocation object
George Tsoukatos
@Gts0uk
Aug 07 2015 11:53
@oab00 thx I take look at it
Joris Labie
@labiej
Aug 07 2015 11:54
@Gts0uk you can use ip-lookup apis like http://ipinfo.io
George Tsoukatos
@Gts0uk
Aug 07 2015 11:54
knowing how to use APIs is an important skill in my opinion
vbobjee
@vbobjee
Aug 07 2015 11:54
@labiej
For recursion I am calling the steamroller function again in the end.
George Tsoukatos
@Gts0uk
Aug 07 2015 11:55
thx again. c ya
Joris Labie
@labiej
Aug 07 2015 11:58
Ben
@benflinn
Aug 07 2015 11:58

bug i don't understand:

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

\$.getJSON('https://api.twitch.tv/kraken/streams/'+streamers[i] +'?callback=?', function(result) {
\$('#logo'+i).html("y");
});

};``````

i want it to alert once, with each time having a number zero through 9.
what's going on?

vbobjee
@vbobjee
Aug 07 2015 11:59
ok. will try thanks @labiej !
Joris Labie
@labiej
Aug 07 2015 12:00
I would refactor the code btw
whenever an element is an array, run it through steamroller and you are sure you get a flattened array in return, normally
Matthew Barber
@Honno
Aug 07 2015 12:09
``````function sumFibs(num) {
var fibsArr = [0, 1];
var i = 0;
var fib = 0;
var loop = true;
while(loop) {
fib = fibsArr[i] + fibsArr[i + 1];
if(fib <= num) {
fibsArr.push(fib);
} else {
loop = false;
}
i += 1;
}
var fibsOdd = fibsArr.filter(function(value) {
return value % 2 !== 0;
});
var fibsAcc = fibsOdd.reduce(function(a, b) {
return a + b;
});
return fibsAcc;
}

sumFibs(4);``````
Is there an easier way to do this?
bonfire sum fib
CamperBot
@camperbot
Aug 07 2015 12:09
Sorry, can't find a bonfire called sum fib. [ Check the map? ]
Matthew Barber
@Honno
Aug 07 2015 12:09
bonfire sum all
CamperBot
@camperbot
Aug 07 2015 12:09

## :fire:Bonfire: Sum All Numbers in a Range :link:

``````function sumAll(arr) {
return(1);
}

sumAll([1, 4]);``````

We'll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.
The lowest number will not always come first.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Matthew Barber
@Honno
Aug 07 2015 12:10
whoops
bonfire sum all fib
CamperBot
@camperbot
Aug 07 2015 12:10
Sorry, can't find a bonfire called sum all fib. [ Check the map? ]
Matthew Barber
@Honno
Aug 07 2015 12:10
I give up xD
it's bonfire sum of all fibonacci nums
Joris Labie
@labiej
Aug 07 2015 12:13
bonfire odd
CamperBot
@camperbot
Aug 07 2015 12:13

## :fire:Bonfire: Sum All Odd Fibonacci Numbers :link:

``````function sumFibs(num) {
return num;
}

sumFibs(4);``````

Return the sum of all odd Fibonacci numbers up to and including the passed number if it is a Fibonacci number.
The first few numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8, and each subsequent number is the sum of the previous two numbers.
As an example, passing 4 to the function should return 5 because all the odd Fibonacci numbers under 4 are 1, 1, and 3.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Joris Labie
@labiej
Aug 07 2015 12:15
@Honno it's possible to write it a little shorter.
Matthew Barber
@Honno
Aug 07 2015 12:15
yeah @labiej ozy design showed me a good solution
Joris Labie
@labiej
Aug 07 2015 12:15
``````function sumFibs(num) {
var sum = 1;
var fib = 1;
var prev = 1;

while(fib<=num){
var temp = fib;

if(fib%2 === 1)
sum += fib;

fib += prev;
prev = temp;
}
return sum;
}``````
Matthew Barber
@Honno
Aug 07 2015 12:16
yep, I did extra leg work, rather then clean it all up in the while loop
also am redundant a lot heh
Joris Labie
@labiej
Aug 07 2015 12:16
The only thing that would make it better would be to define `var temp` outside the loop
Not sure how good the garbage collection of javascript is. So a stack overflow is a possibility
Matthew Barber
@Honno
Aug 07 2015 12:17
oh we were having this discussion earlier @labiej, so it is better to declare variables outside loops yeah?
Joris Labie
@labiej
Aug 07 2015 12:17
Not sure myself
Matthew Barber
@Honno
Aug 07 2015 12:17
oh haha
whelp my pomodora break is a-go, time to uh, eat oranges
Ozy Design & Software
@OzySky
Aug 07 2015 12:18
lol
:laughing:
Matthew Barber
@Honno
Aug 07 2015 12:18
thanks @ozydesign & @labiej
CamperBot
@camperbot
Aug 07 2015 12:18
honno sends brownie points to @ozydesign and @labiej :sparkles: :thumbsup: :sparkles:
:star: 2 | @ozydesign | http://www.freecodecamp.com/ozydesign
Joris Labie
@labiej
Aug 07 2015 12:21
@Honno I confirmed it doesn't make any difference where you define the variable
Matthew Barber
@Honno
Aug 07 2015 12:22
oh cool, so it's better to stick to one convection and stick with it I guess
or is there a uniform best practice heh?
Stein Gee
@Stiino0
Aug 07 2015 12:22
bonfire seek and destroy
CamperBot
@camperbot
Aug 07 2015 12:22

## :fire:Bonfire: Seek and Destroy :link:

``````function destroyer(arr) {
// Remove all the values
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Raincode
@Raincode
Aug 07 2015 12:23
@camperbot nice
Stein Gee
@Stiino0
Aug 07 2015 12:23
am I on to something here for the bonfire?
``````function destroyer(arr) {

for (i=0;i<arguments[0].length;i++){
if (arguments[0] === arguments[1] || arguments[2]){
//arr.filter();
return true;
} else return false;
}
//return arguments[0];
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````
I don't know how to use this code and then use it to filter in the array :(
Matthew Barber
@Honno
Aug 07 2015 12:24
whenever someone posts their code I really want to help but I never actually understand it lol
Ozy Design & Software
@OzySky
Aug 07 2015 12:25
@Honno it's actually a pretty rare skill (and important btw) among coders
Joris Labie
@labiej
Aug 07 2015 12:25
@Stiino0 do a `console.log(arguments[0]);` inside the function
Raincode
@Raincode
Aug 07 2015 12:25
@Stiino0 What I did was create an array containing all numbers to me taken out, and check with arr.indexOf(num) if I had to take it out (your true or false for filter)
Ozy Design & Software
@OzySky
Aug 07 2015 12:25
being able to read other people's code
Stein Gee
@Stiino0
Aug 07 2015 12:26
is return also good @labiej ?
Joris Labie
@labiej
Aug 07 2015 12:26
you could but `console.log` is extremely useful for debugging purposes
Matthew Barber
@Honno
Aug 07 2015 12:26
@ozydesign maybe I need more experience before I try and help, because I just can't get it without wasting time reconstructing the code
Stein Gee
@Stiino0
Aug 07 2015 12:26
oh is it?
I've never used console.log
Raincode
@Raincode
Aug 07 2015 12:27
Then do the task from start to end lol
Stein Gee
@Stiino0
Aug 07 2015 12:27
anyway, I get the first element of the argument
[1,2,3,1,2,3]
Joris Labie
@labiej
Aug 07 2015 12:28
Now check out what the other arguments are
Stein Gee
@Stiino0
Aug 07 2015 12:28
In my if clause?
all the arguments are still the same
`arguments[0] = [1,2,3,1,2,3]`
Joris Labie
@labiej
Aug 07 2015 12:30
``````arguments.forEach( function( argument ){
console.log(argument);} );``````
Stein Gee
@Stiino0
Aug 07 2015 12:30
arguments[1] = 2
arguments[2] = 3
what's that @labiej :D
Joris Labie
@labiej
Aug 07 2015 12:31
It looks at each element of the arguments array and prints its value
So what can you tell from that if you look back at `destroyer([1, 2, 3, 1, 2, 3], 2, 3);`
Stein Gee
@Stiino0
Aug 07 2015 12:32
uhm it will print them separately?
1,2,3,1,2,3
2
and 3
Joris Labie
@labiej
Aug 07 2015 12:32
indeed, but how does that relate to `destroyer([1, 2, 3, 1, 2, 3], 2, 3);` ?
What would you expect from `destroyer([1, 2, 3, 1, 2, 3], 2, 3, a);` ?
Stein Gee
@Stiino0
Aug 07 2015 12:34
the a is also an argument
Joris Labie
@labiej
Aug 07 2015 12:34
which index?
Stein Gee
@Stiino0
Aug 07 2015 12:34
4
Joris Labie
@labiej
Aug 07 2015 12:34
3
Stein Gee
@Stiino0
Aug 07 2015 12:34
oh
starting from 0
0 1 2 3
Joris Labie
@labiej
Aug 07 2015 12:34
Indeed
Stein Gee
@Stiino0
Aug 07 2015 12:34
crap I always forget :D
Joris Labie
@labiej
Aug 07 2015 12:34
Now you understand the Arguments object
Stein Gee
@Stiino0
Aug 07 2015 12:35
Do I? :D
Joris Labie
@labiej
Aug 07 2015 12:35
I think you do at least
bonfire destroyer
CamperBot
@camperbot
Aug 07 2015 12:35
Sorry, can't find a bonfire called destroyer. [ Check the map? ]
Joris Labie
@labiej
Aug 07 2015 12:35
bonfire destroy
CamperBot
@camperbot
Aug 07 2015 12:35

## :fire:Bonfire: Seek and Destroy :link:

``````function destroyer(arr) {
// Remove all the values
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Stein Gee
@Stiino0
Aug 07 2015 12:36
so I should check index 0 with indexes larger than 0 (e.g 1, 2, 3, 4, 5,...)
or filter
Joris Labie
@labiej
Aug 07 2015 12:36
yep
filter is the most powerful
Stein Gee
@Stiino0
Aug 07 2015 12:37
is it definitely necessary to use the foreach you mentioned,
?
Joris Labie
@labiej
Aug 07 2015 12:37
you can use it but then you will use the array as well
Stein Gee
@Stiino0
Aug 07 2015 12:38
oh the code doesn't work
the foreach
arguments.forEach is not a function
Joris Labie
@labiej
Aug 07 2015 12:39
you have argument[0] from which you want to remove the following arguments
arguments
Stein Gee
@Stiino0
Aug 07 2015 12:39
yeah typo in chat
Joris Labie
@labiej
Aug 07 2015 12:40
but lets ignore foreach
Stein Gee
@Stiino0
Aug 07 2015 12:40
k
Joris Labie
@labiej
Aug 07 2015 12:40
you have arguments[0] as your array
Stein Gee
@Stiino0
Aug 07 2015 12:40
yeah
Joris Labie
@labiej
Aug 07 2015 12:40
and the following arguments are values you want to remove from array
Stein Gee
@Stiino0
Aug 07 2015 12:41
true
Joris Labie
@labiej
Aug 07 2015 12:43
so if you want to remove all 2's from `[1,2,3,1,2,3]` how would you use filter?
Stein Gee
@Stiino0
Aug 07 2015 12:44
`arguments[0].filter(arguments[1]);` ?
that won't work
Joris Labie
@labiej
Aug 07 2015 12:46
you need a callback in filter.
a callback is a function that does something
Stein Gee
@Stiino0
Aug 07 2015 12:46
filter works when true is found
Joris Labie
@labiej
Aug 07 2015 12:46
Check out MDN for an example
Stein Gee
@Stiino0
Aug 07 2015 12:47
sooo do I need to make a function in the filter
Joris Labie
@labiej
Aug 07 2015 12:47
Stein Gee
@Stiino0
Aug 07 2015 12:47
was reading yesterday, this morning, noon, now... :p
Joris Labie
@labiej
Aug 07 2015 12:49
``````function isBigEnough(value) {
return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]``````
this example should be enough to get you going
you want to check if the value is different from arguments[1]
Matthew Barber
@Honno
Aug 07 2015 13:00
Is this at all efficient
``````function sumPrimes(num) {
var divisors = [];
for(i = 2; i <= num; i++) {
divisors.push(i);
}
console.log(divisors);
var primes = [];
var check = false;
for(j = 0; j < divisors.length; j++) {
check = true;
for(k = 0; k < j - 1; k++) {
console.log(divisors[j] + " | " + divisors[k]);
if(divisors[j] % divisors[k] === 0) {
console.log("false");
check = false;
} else {console.log("true");}
}
if(check) {
primes.push(divisors[j]);
console.log("pushing " + divisors[j]);
}
}
console.log(primes);
var sum = primes.reduce(function(a, b) {
return a + b;
});
console.log(sum);
return sum;
}``````
Stein Gee
@Stiino0
Aug 07 2015 13:03
@labiej
``````function destroyer(arr) {
if (arguments[0] === arguments[1]){
return true;
} else if (arguments[0] === arguments[2]) return true;

var filtered = arguments[0].filter(destroyer);
return filtered;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````
Optmistic
@Optmistic
Aug 07 2015 13:04
@Stiino0 how to send screen shot of code ??
Joris Labie
@labiej
Aug 07 2015 13:04
help format
CamperBot
@camperbot
Aug 07 2015 13:04

## :point_right: pasting formatted code in gitter [wiki]

Use three ticks [ ` ] -- on American keyboards, that's the key in the corner between [1] and [Tab]. Then press [Enter]+[Shift]. Gitter will usually fill in the closing ticks for you, but if they aren't there remember to end your code with a line of three ticks. Ticks must always be on their own lines. When you are ready to send your message press [Ctrl]+[Enter].

You can edit your previously sent messages by hovering over the message and clicking the ...,
so if you accidentally paste unformatted code, just fix it.

If your code is long, you can create a Gist and paste the link in Gitter. This also allows fellow campers to collaborate with you more directly.
:pencil: read more about pasting formatted code in gitter on the FCC Wiki

Joris Labie
@labiej
Aug 07 2015 13:07
@Stiino0 have you tried debugging?
I also don't see any console.log's
The problem is that you attempt recursion but JS doesn't allow it (for some reason)
Stein Gee
@Stiino0
Aug 07 2015 13:11
I wouldn't know what to try to debug here :D
Joris Labie
@labiej
Aug 07 2015 13:12
The fact that the output was "undefined is not a function"?
Or the fact that not a single test was shown?
``````loop through the array
check if the element is different from both arguments[1] and arguments[1]
store the current element``````
Pseudo code, I have to go for a bit
Stein Gee
@Stiino0
Aug 07 2015 13:14
ok thx for the help so far :p
Jason Wood
@catapixel
Aug 07 2015 13:16
@Stiino0 I'm just coming on but are you looking for help with that one?
Stein Gee
@Stiino0
Aug 07 2015 13:16
Yes sir, labiej was helping me but he had to go for a bit!
Jason Wood
@catapixel
Aug 07 2015 13:17
I can try and help you. Can you repeat the issue you're having?
Stein Gee
@Stiino0
Aug 07 2015 13:18
bonfire destroy
CamperBot
@camperbot
Aug 07 2015 13:18

## :fire:Bonfire: Seek and Destroy :link:

``````function destroyer(arr) {
// Remove all the values
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Stein Gee
@Stiino0
Aug 07 2015 13:18
I'm just trying to figure this out :D but can't seem to
I need to .filter the second, third, ... argument
Jason Wood
@catapixel
Aug 07 2015 13:20
@Stiino0 ok. no problem. open a private chat and paste your current code in
Ozy Design & Software
@OzySky
Aug 07 2015 13:43
any ideas for bonfire Pairwise (reduce doesn't seem right to me for some reason)?
Ross Kaffenberger
@rossta
Aug 07 2015 14:01
@ozydesign filter, then reduce comes to mind
Ozy Design & Software
@OzySky
Aug 07 2015 14:04
@rossta how would you implement that?
Matthew Barber
@Honno
Aug 07 2015 14:06
Hey, does `if((num1 || num2) % x=== 0)` equal `if(num1 % x === 0 || num2 % x=== 0)`?
Ozy Design & Software
@OzySky
Aug 07 2015 14:07
@Honno I always wondered actually
Matthew Barber
@Honno
Aug 07 2015 14:07
in python it does iirc
Ross Kaffenberger
@rossta
Aug 07 2015 14:07
@ozydesign you can build up an array of indices that can be used as sum pairs
Matthew Barber
@Honno
Aug 07 2015 14:07
I could test it but...
Ross Kaffenberger
@rossta
Aug 07 2015 14:08
and then reduce that array with a sum function
Matthew Barber
@Honno
Aug 07 2015 14:09
FFFFFFFF
lost the work I spent 1hr on
because mint is all smart ass and takes a middle click as a delete
but I always accidently... ugh
rip tab
Ozy Design & Software
@OzySky
Aug 07 2015 14:10
@rossta could you pm me an example?
Alexander Schuneman
@AxSch
Aug 07 2015 14:10
Anyone on Introduction to Objects II?
Matthew Barber
@Honno
Aug 07 2015 14:10
@AxSch I've done it if you need help
Alexander Schuneman
@AxSch
Aug 07 2015 14:11
@Honno Thanks man, I’m stuck on 27/30
Matthew Barber
@Honno
Aug 07 2015 14:11
look for-in me?
Alexander Schuneman
@AxSch
Aug 07 2015 14:11
yeah
Matthew Barber
@Honno
Aug 07 2015 14:12
``````for(var property in languages) {
if(typeof languages[property] === "string") {
console.log(languages[property])
}
}``````
Basically, I check if the typeof every property in the object is a string
AJ Gibson
@gibsonio
Aug 07 2015 14:12
why isn't this code below letting me pass the "Falsey Bouncer" Bonfire? All of the check marks are showing that its correct!
``````arr = [7, 'ate', '', false, 9];

function bouncer(arr) {

var result = false;

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

if(arr[i] !== true) {

result = true;
}

return result;
}

}

var falsey = arr.filter(bouncer);

console.log(falsey);

bouncer([7, 'ate', '', false, 9]);``````
Matthew Barber
@Honno
Aug 07 2015 14:12
@AxSch If it isn't a string (like 4) then it has to go
Alexander Schuneman
@AxSch
Aug 07 2015 14:12
Oh is it not using a variable?
Matthew Barber
@Honno
Aug 07 2015 14:12
@AxSch It just checks the properties yeah
@AxSch Thats why the for is (var x in object), x being the property, object being the object name
Alexander Schuneman
@AxSch
Aug 07 2015 14:13
@Honno I understand it now
Matthew Barber
@Honno
Aug 07 2015 14:13
and goes through it systematically like any other for loop going x++
yay I kinda helped someone out
bonfire falsey
CamperBot
@camperbot
Aug 07 2015 14:14

``````function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr;
}

bouncer([7, 'ate', '', false, 9]);``````

Remove all falsey values from an array.
Falsey values in javascript are false, null, 0, "", undefined, and NaN.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.

type: `bf details` `bf links` `bf spoiler`

Alexander Schuneman
@AxSch
Aug 07 2015 14:14
@Honno I’d have to create a variable to store the property value in though right? else it would just return the variable name
Matthew Barber
@Honno
Aug 07 2015 14:14
@gibsonio the filter acts as a for loop
``````function bouncer(arr) {
// Don't show a false ID to this bouncer.
this.falseCheck = function (value) {
return Boolean(value);
};
var filtered = arr.filter(this.falseCheck);
return filtered;
}

bouncer([7, 'ate', '', false, 9]);``````
Like this
@AxSch Nah you `typeof` on the object's property item which is akin to `object[property]`
the item, not the prop
Alexander Schuneman
@AxSch
Aug 07 2015 14:16
ah ok i see
Matthew Barber
@Honno
Aug 07 2015 14:16
And you use that as a check, if it's yes a string then return true
@gibsonio So the function that goes in the `filter()` can pass the current value, then the function can check if the value meets a criteria, if it returns true then the item is kept in the array, if returned false the item goes
justindobbs
@justindobbs
Aug 07 2015 14:17
on the least common multiple one, the LC multiple of [1,5] is not 5?
Matthew Barber
@Honno
Aug 07 2015 14:18
@justindobbs It's the LC of 1, 2, 3, 4, 5
so it's 60
I'm doing it right now, fucked me up not knowing that xD
justindobbs
@justindobbs
Aug 07 2015 14:19
oh yes, it's the range, i missed that, thanks
arnie151
@arnie151
Aug 07 2015 14:25
Hey guys, for Waypoint: Line up Form Elements Responsively with Bootstrap, how do I Waypoint: Line up Form Elements Responsively with Bootstrap, and Wrap your form submission button in a div with the class "col-xs-5"? I just need some help!
Sophanarith Sok
@sok213
Aug 07 2015 14:28
May someone give me a hint for Advanced Bonfire: No Repeats Please? I understand how to calculate the number of possible permutations. I'm confused as to how I am supposed to determine how many times a consecutive pattern occurs within those possible permutations.
I have not slept. I have literally seen the sun rise up too many times this month. pls halp..
:3
Daniel Neumann
@NeuwDk
Aug 07 2015 14:29
I am at the same one as @sok213 - I'd like a little help as well :)
arnie151
@arnie151
Aug 07 2015 14:29
@sok213 sorry havent reached that yet.
Sophanarith Sok
@sok213
Aug 07 2015 14:29
@NeuwDk its hard right
Daniel Neumann
@NeuwDk
Aug 07 2015 14:30
@sok213 very much so. I'm getting the wrong outputs all the time.
Sophanarith Sok
@sok213
Aug 07 2015 14:30
@NeuwDk I have only been able to pass 3 of the tests so far, but I have a feeling I am going to have to scrap the entire code and start over
Daniel Neumann
@NeuwDk
Aug 07 2015 14:32
@sok213 me too. The first, third and last test
Peter Daily
@thepeted
Aug 07 2015 14:34
Sophanarith Sok
@sok213
Aug 07 2015 14:35
Thanks @thepeted
CamperBot
@camperbot
Aug 07 2015 14:35
sok213 sends brownie points to @thepeted :sparkles: :thumbsup: :sparkles:
:star: 157 | @thepeted | http://www.freecodecamp.com/thepeted
Peter Daily
@thepeted
Aug 07 2015 14:35
Ooh my first brownie points - thanks to you :-)
Sophanarith Sok
@sok213
Aug 07 2015 14:36
You missed an opportunity to return the favor there buddy
Peter Daily
@thepeted
Aug 07 2015 14:36
If you search around heaps algorithm there are some other useful links - would be interested to know if there is a simpler way of doing the permuations, but I couldn't find one.
Sophanarith Sok
@sok213
Aug 07 2015 14:36
jk
Alright, I'll check it out. Much appreciated!
Peter Daily
@thepeted
Aug 07 2015 14:37
:-)
Daniel Neumann
@NeuwDk
Aug 07 2015 14:39
@thepeted thanks, I'll take a look :)
Aug 07 2015 14:50
hi
Sophanarith Sok
@sok213
Aug 07 2015 14:50
Aug 07 2015 14:51
ANyone here who can help me with some simple js (codecademy)? :D
@sok213 hi :D
Sophanarith Sok
@sok213
Aug 07 2015 14:51
@SarthakAdhikari sure, what do you need help with
Aug 07 2015 14:51
this challenge
``````/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/
var compare = function(choice1, choice2) {
if (choice1===choice2) {
return "The result is a tie!";
}
else if(choice1==="rock");{
if (choice2==="scissors") {
return "rock wins";
}
else {
return "paper wins";
}
else if(choice1==="paper"){
if(choice2==="rock"){
return "paper wins";
}
else {
return "scissors wins";
}

}
};
compare()``````
here's my code :)
Matthew Barber
@Honno
Aug 07 2015 14:52
whats the problem?
Aug 07 2015 14:52
it gives a syntax error :3
SyntaxError: expected expression, got keyword 'else'
Daniel Neumann
@NeuwDk
Aug 07 2015 14:53
@SarthakAdhikari at choice1==="rock") no ; should be there.
if that makes sense
Aug 07 2015 14:54
ok ty ..i'll try
no its still now working
*not working
Sophanarith Sok
@sok213
Aug 07 2015 14:55
@SarthakAdhikari You have semi-colons on the wrong spot
Daniel Neumann
@NeuwDk
Aug 07 2015 14:55
@SarthakAdhikari you need to close your blocks. So you're in lack of }'s. After "paper" wins"; you need to add another }
Aug 07 2015 14:56
@sok213 ok ty but that didnt solve.. i must learn to program right though :)
@NeuwDk ty..let me try :D
@NeuwDk still didn't work :3
Paul Dynowski
@pdynowski
Aug 07 2015 14:57
good morning, all. or, y'know, good whatever-your-local-time-of-day is.
Sophanarith Sok
@sok213
Aug 07 2015 14:57
@SarthakAdhikari Also, you cannot have an else if statement after an else statement
``````/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/

var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return("The result is a tie!");
} else if (choice1 ==="rock") {
if (choice2 === "scissors") {
return("rock wins");
} else {
return("paper wins");
}
}
else if (choice1 === "paper") {
if (choice2 === "rock") {
return("paper wins");
} else {
return("scissors wins");
}
}
}``````
@SarthakAdhikari Here is to correct code, see how the else is nested within an else if and not after an else.
Aug 07 2015 15:00
ty...let me try :D
Paul Dynowski
@pdynowski
Aug 07 2015 15:01
can anyone help me with adding the silly twitter button to the first zipline? mine either loads nothing into the to-be-tweeted box, or it loads a link to the page instead of the quote
Daniel Neumann
@NeuwDk
Aug 07 2015 15:01
@sok213 Have you completed "No repeats please" yet? I'm still stuck :)
Sophanarith Sok
@sok213
Aug 07 2015 15:01
@NeuwDk no, I am sleep deprived, I think ill try it again in when I wake up this afternoon
Daniel Neumann
@NeuwDk
Aug 07 2015 15:02
@sok213 sleep tight! :)
Aug 07 2015 15:02
ty now i got it :D
Sophanarith Sok
@sok213
Aug 07 2015 15:03
@NeuwDk I'm thinking about forming all of the permutations and checking each one for consecutive matches and returning the amount of matches it finds.
@NeuwDk the hard part will be writing a function that will correctly form all the different permutations.
many many loops maybe
Daniel Neumann
@NeuwDk
Aug 07 2015 15:05
@sok213 That's exactly what I tried
@sok213 I did a loop of factorial length of the string, and then a nested loop of the string length to try and get all permutations
Paul Dynowski
@pdynowski
Aug 07 2015 15:06
@NeuwDk @sok213 simpler to actually calculate the permutations, no?
instead of looping over them all
Sophanarith Sok
@sok213
Aug 07 2015 15:08
@pdynowski calculating the amount of permutations is pretty easy
Daniel Neumann
@NeuwDk
Aug 07 2015 15:08
@pdynowski its easy to calculate the permutations, it's just factorial length of the string. But taking the repeats out is the hard part.
Sophanarith Sok
@sok213
Aug 07 2015 15:08
@pdynowski The hard part is returning the amount of consecutive matches
This helped me out a bit, however. http://giphy.com/gifs/instead-87xihBthJ1DkA
Paul Dynowski
@pdynowski
Aug 07 2015 15:09
@NeuwDk why? it's just calculating a different number of permutations. if the letter repeats, you can treat the whole thing as a different set of letters, in a set one shorter.
it gets trickier with multiple repeats, though
mostly because it's easy to double-count permutations with consecutive characters
am i making ANY sense?
Peter Daily
@thepeted
Aug 07 2015 15:13
Hey guys, if it helps with no repeats - my solution ivolved creating an array of all the perms and then filtering out the repeating ones using some regex
Sophanarith Sok
@sok213
Aug 07 2015 15:13
@pdynowski Sorry, I am still confused
Stein Gee
@Stiino0
Aug 07 2015 15:14
thanks @labiej
CamperBot
@camperbot
Aug 07 2015 15:14
stiino0 sends brownie points to @labiej :sparkles: :thumbsup: :sparkles:
Daniel Neumann
@NeuwDk
Aug 07 2015 15:14
@pdynowski @sok213 I'm also still confused.
Stein Gee
@Stiino0
Aug 07 2015 15:14
thanks @catapixel
CamperBot
@camperbot
Aug 07 2015 15:14
stiino0 sends brownie points to @catapixel :sparkles: :thumbsup: :sparkles:
:star: 1 | @catapixel | http://www.freecodecamp.com/catapixel
Sophanarith Sok
@sok213
Aug 07 2015 15:14
@thepeted So you did create a function that formed all the permutations, right?
I think that is the approach than @NeuwDk and I are trying to do
Peter Daily
@thepeted
Aug 07 2015 15:15
I did - I used Heap's Algorithm
Sophanarith Sok
@sok213
Aug 07 2015 15:15
Yes, the wiki page that you provided
Peter Daily
@thepeted
Aug 07 2015 15:16
the approach by @pdynowski is different to mine - I might have preffered to do that actually!
sounds like both will work :-)
Sophanarith Sok
@sok213
Aug 07 2015 15:16
I'll do both.
Paul Dynowski
@pdynowski
Aug 07 2015 15:16
@sok213 ok. so, you've got 'aab', say. if you're looking for permutations where 'aa' are next to each other in a 3-character array, you can treat 'aa' as a single character, say 'a'. then, you're looking for all the possible permutations of 'ab'. subtract those from the total permutations of the original.
with corrections for the a's actually being different, etc.
Sophanarith Sok
@sok213
Aug 07 2015 15:18
@pdynowski Ok, I think I understand
Give me a moment.
Matthew Barber
@Honno
Aug 07 2015 15:19
Why does arr also get shifted in
``````function drop(arr, func) {
console.log("---------------------------------");
// Drop them elements.
var arrDrop = arr;
for(i = 0; i < arr.length; i++) {
if(func(arr[i])) {
break;
} else {
arrDrop.shift();
}
}
return arrDrop;
}

drop([1, 2, 3, 4], function(n) {return n >= 3; });``````
Sophanarith Sok
@sok213
Aug 07 2015 15:20
@pdynowski Would that still not require me to generate all the permutations, though?
Henry Erickson
@henryed86
Aug 07 2015 15:20
Hello Pair Programmers!
Paul Dynowski
@pdynowski
Aug 07 2015 15:21
@sok213 it would require you to calculate them, not generate them.
you just need the number
Matthew Barber
@Honno
Aug 07 2015 15:21
this is killing me lol
Sophanarith Sok
@sok213
Aug 07 2015 15:21
ok
Matthew Barber
@Honno
Aug 07 2015 15:22
why would it I didn't reference arr AGGGHHH
Peter Daily
@thepeted
Aug 07 2015 15:23
@honno what do you mean by arr?
Matthew Barber
@Honno
Aug 07 2015 15:24
@thepeted the value `arr`, when `arrDrop.shift()` happens, `arr.shift()` happens as well
@je8896a
Aug 07 2015 15:25
hi, this is my second day coding and I'm having a bit of trouble with the anchor element, its probably something I am not seeing but its telling me I am not wrapping my a element in my p element correctly, would someone be able to help me with this?
Eric
@emaclean03
Aug 07 2015 15:25
post the code here, @je8896a
Aug 07 2015 15:25
@je8896a i may help with that :D
@je8896a can you post the code and the challenge :D
Matthew Barber
@Honno
Aug 07 2015 15:26
@thepeted try running
``````function drop(arr, func) {
var arrDrop = arr;
console.log(arrDrop);
for(i = 0; i < arr.length; i++) {
console.log("It's currently " + arr[i] + " at index " + i + " in array " + arr);
if(func(arr[i])) {
break;
} else {
arrDrop.shift();
console.log("after shift it's " + arrDrop);
}
}
console.log("returning " + arrDrop);
return arrDrop;
}

drop([1, 2, 3, 4], function(n) {return n >= 3; });``````
@je8896a
Aug 07 2015 15:26
I dont know how do the screenshots
Eric
@emaclean03
Aug 07 2015 15:26
put </a> after "now"
Peter Daily
@thepeted
Aug 07 2015 15:26
hang on
Sophanarith Sok
@sok213
Aug 07 2015 15:27
@thepeted ok, so the permutations of "aab" is 6. Permutations of "ab" is 2. 6 - 2 = 4. But the answer is supposed to be 2
ooops
@je8896a
Aug 07 2015 15:27
@emaclean03 i tried that it didnt work
Sophanarith Sok
@sok213
Aug 07 2015 15:27
I mean @pdynowski
Eric
@emaclean03
Aug 07 2015 15:27
Paul Dynowski
@pdynowski
Aug 07 2015 15:28
@sok213 ok. right. but the thing is silly, and counts the a's as different characters. so you've really got a1 and a2 around, and a1a2 is different than a2a1
Paul Dynowski
@pdynowski
Aug 07 2015 15:28
so, you'd be subtracting 2*2, not just 2
Eric
@emaclean03
Aug 07 2015 15:29
Peter Daily
@thepeted
Aug 07 2015 15:30
@honno I have to dart off I'm afraid, but I suppose my initial thought is - when would `func(arr[i])` ever not be true?
Eric
@emaclean03
Aug 07 2015 15:30
there is no "now" @je8896a
@je8896a
Aug 07 2015 15:31
@emaclean03 yea i know I added it in when I couldnt figure out anything else to do
nothing is workign
Eric
@emaclean03
Aug 07 2015 15:32
works for me - what do you have an x for?
@je8896a
Aug 07 2015 15:32
all of my elements are green except for the a element not being properly wrapped in the p element
Eric
@emaclean03
Aug 07 2015 15:32
`<p>Click here for<a href='http://www.catphotoapp.com'>cat photos</a></p>`
@je8896a
Aug 07 2015 15:32
its the fourth item on the list
Eric
@emaclean03
Aug 07 2015 15:32
that works for me, try refreshing browser
@je8896a
Aug 07 2015 15:33
ok ill refresh
Sophanarith Sok
@sok213
Aug 07 2015 15:33
@pdynowski Ok, I'm starting to get logic behind this
Matthew Barber
@Honno
Aug 07 2015 15:33
@thepeted yea
@je8896a
Aug 07 2015 15:34
Ha! it worked, thank you @emaclean03 this coding stuff is getting the best of me. I'm not sure if I'm cut out for it
Paul Dynowski
@pdynowski
Aug 07 2015 15:34
yeah. i did it this way because i really, really did not want to write a billion nested for loops
Omran Abazid
@OmranAbazid
Aug 07 2015 15:35
``````function drop(arr, func) {
for(var i in arr ){
if(func(arr[0])){
break;
}
arr.shift();
}
return arr;
}

drop([1, 2, 3], function(n) {return n < 3; });``````
what is wrong in my code Bonfire: Drop it
Eric
@emaclean03
Aug 07 2015 15:35
haha no problem. keep at it @je8896a, that wont be the first time something dumb like that happens :P
Omran Abazid
@OmranAbazid
Aug 07 2015 15:35
im getting this error
Sophanarith Sok
@sok213
Aug 07 2015 15:35
@pdynowski so all the permutations are "aab" "baa" "baa" "aab", so "ba" "ba" "ba" "ab" are the same thing. therefore the amount of consecutive matches are 4. am I right?
Omran Abazid
@OmranAbazid
Aug 07 2015 15:35
expect(drop([1, 2, 3, 4], function(n) {return n > 5; })).to.eqls([]);expected [ 3, 4 ] to deeply equal []
Sophanarith Sok
@sok213
Aug 07 2015 15:36
@pdynowski oops I put a extra "ba" in there
I get it
Paul Dynowski
@pdynowski
Aug 07 2015 15:36
@sok213 i think so, yeah
Sophanarith Sok
@sok213
Aug 07 2015 15:36
or 2
...
No wait, I explained it wrong, but I get it.
thanks @pdynowski
CamperBot
@camperbot
Aug 07 2015 15:38
sok213 sends brownie points to @pdynowski :sparkles: :thumbsup: :sparkles:
Sophanarith Sok
@sok213
Aug 07 2015 15:38
ima go sleep
Paul Dynowski
@pdynowski
Aug 07 2015 15:38
yeah. like i said, it gets tricky when there are multiple repeated characters.
Matthew Barber
@Honno
Aug 07 2015 15:42
``````function drop(arr, func) {
var arrDrop = arr;
for(i = 0; i < arr.length; i++) {
console.log("It's currently " + arr[i] + " at index " + i + " in array " + arr);
if(func(arr[i])) {
break;
} else {
arrDrop.shift();
}
}
return arrDrop;
}

drop([1, 2, 3, 4], function(n) {return n > 3; });``````
`console.log` prints `It's currently 1 at index 0 in array 1,2,3,4` then `It's currently 3 at index 1 in array 2,3,4` - why does arr changes as well?
Matthew Senko
@mpskierbg
Aug 07 2015 15:42
so so i want to use regex to do this (str[0] === a consant or cluster of consants) any thoghts?
Matthew Barber
@Honno
Aug 07 2015 15:43
@mpskierbg [aeiou]
I mean, the reverse
Omar
@oab00
Aug 07 2015 15:43
@OmranAbazid salam!
the problem is that the array gets smaller every time and the for loop gets confused with that
either copy `arr` to another array `var newArr = arr.slice();` and use that in the for loop
or make a variable that stores the length of `arr` and use a for loop with that length
Matthew Senko
@mpskierbg
Aug 07 2015 15:45
@Honno whats that?
Matthew Barber
@Honno
Aug 07 2015 15:45
@mpskierbg x === /[aeiou]/ will return true if x is a vowel
actually, I've never done it like that
Aug 07 2015 15:46
Hi!
Omran Abazid
@OmranAbazid
Aug 07 2015 15:46
@oab00 but im removing the first element only func(arr[0])
Matthew Barber
@Honno
Aug 07 2015 15:46
I did it lazily and did ["a", "e", "i", "o", "u"].indexOf(x) !== -1;
gah this one problem has stuck me for an hour, I'm out xD
Omar
@oab00
Aug 07 2015 15:49

@OmranAbazid yes that's why the for loop gets confused:

``````for(var i in newArr ){
arr.shift();
}``````

first iteration `i = 0` and `arr = [ 4 elements ]`
second iteration `i = 1` and `arr = [3 elements]`
third iteration `i = 2` and `arr = [2 elements]` <- this is where the problem is ..
`i = 2` is already bigger than the array because the array gets smaller every time

actually!
setting `i = 0` in the for loop works :smile:
Matthew Senko
@mpskierbg
Aug 07 2015 15:50
`(string.splice(0,1))` what does this do?
Michael Perkhofer
@mperkh
Aug 07 2015 15:50
at BF21 bonfire-roman-numeral-converter, why didnt they mention, what range of numbers schould be converted? https://en.wikipedia.org/wiki/Roman_numerals The system is really complex, when numbers become >99. The tests onyl test numbers <100..
Aug 07 2015 15:50
@mpskierbg This deletes the first character
Matthew Senko
@mpskierbg
Aug 07 2015 15:51
@HadiDev what does this `string.push(string.splice(0,1))` do?
Aug 07 2015 15:52
@mpskierbg It doesn't make much sense. What are you trying to do?
Mike Moss
@MMux
Aug 07 2015 15:52
local weather: I'm trying to capture a user ip address and store their city and country as variables. I'm getting an ajax error from a get request: http://codepen.io/MMux/pen/QbYMoP?editors=001
Has anyone had trouble w/ getting and saving user location as a variable?
I'm using http://ipinfo.io/ for the lookup.
Omar
@oab00
Aug 07 2015 15:53
that looks awesome!
Giorgio
Aug 07 2015 15:53

can anyone explain to me the difference between:

``````function MyObj(property) {
this.property = property;
this.aMethod = function() {
// some action
}
}``````

and

``MyObj.prototype.aMethod = function () {...}``
why would i declare a method one way over the other
Omar
@oab00
Aug 07 2015 15:54
@MMux looks like you're getting
`the server responded with a status of 429 (Too Many Requests)`
I recommend not getting user IP and use Javascripts Geolocation object to locate the person
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition
Mike Moss
@MMux
Aug 07 2015 15:56
@oab00 I see...thanks for that advice. Will look that up.
@oab00 where did you see that 429 status in dev tools? that would be very helpful.
rbunz
@rbunz08
Aug 07 2015 16:00
I know I have done this before, I think I am just over-thinking it... How do you split up all the elements of an array... for example I want [a, b, c, d] to be seen as four separate items.
Omar
@oab00
Aug 07 2015 16:01
@MMux yeah it logged that for me in the console when I opened the codepen
rbunz
@rbunz08
Aug 07 2015 16:03
Or better yet.. how do I get it to look at a specific element in an array of arrays. For example, ([a, b, c], [d, e, f]) How do I tell the computer to choose a?
Rafael Neubauer
@Scyles
Aug 07 2015 16:04
@rbunz08 you would probably want to look into the Array.slice() function https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Omar
@oab00
Aug 07 2015 16:05
@rbunz08
``````var arr = [11, 24, 35, 46];
console.log(arr[0]); // returns 11
console.log(arr[2]); // returns 35``````
Rafael Neubauer
@Scyles
Aug 07 2015 16:06
@rbunz08 Oh I see what you mean to access a specific element you just have to point to the index for your actual example it would be `array[0][0]`
Aug 07 2015 16:07
Can an expert tell me how to update the data-text of a tweet button in my zipline? Every way I try doesn't seem to work
Right now I'm destroying the button and recreating it every time to update the data-text property
rbunz
@rbunz08
Aug 07 2015 16:08
Thank-you @Scyles @oab00 , Ill try these!
Gwyn Murray
@gmurray327
Aug 07 2015 16:08
<div class= 'col-xs-6'>
<div class= 'col-xs-6'>
Rafael Neubauer
@Scyles
Aug 07 2015 16:08
@rbunz08 [a,b,c] is in array[0] and [d,e,f] is in array[1]. So the a in [a,b,c] is the 0th elementh making it array[0][0], b would be array [0][1], d would be array[1][0] etc.
Gwyn Murray
@gmurray327
Aug 07 2015 16:08
can't see what I'm doing wrong...
Omar
@oab00
Aug 07 2015 16:09

just wait for ECMA Script 6 to come out then you can do

``[a, b] = [1, 2];``

then you get a = 1 and b = 2 ;)

Colin Mason
@masonc15
Aug 07 2015 16:10
In HTML, when should you use single quotes and when should you use double quotes?
Sudeepto
@Sudeepto
Aug 07 2015 16:10

Good evening friends. I am on Steamroller bonfire.

I have solved it using recursion . This is the repl link.

But the bonfire considers it as wrong solution. Is it because I'm using the global array ans ??

If so, can someone tell me how can I solve the problem ??

Thank You.

Omar
@oab00
Aug 07 2015 16:13
@HadiDev I stumbled upon a similar problem then I found this and copied it
http://codepen.io/alistairtweedie/pen/JlFnq
you can then edit the URL instead of data-text ;)
@Sudeepto yes global variables aren't allowed
@Sudeepto what I've done is make another function and do the recursion on that
Aug 07 2015 16:18
@oab00 That does work but so does recreating the button every time. Web games do it for scores and such I really want to learn the right way.
DTing
@dting
Aug 07 2015 16:19
@HadiDev if you are going to use the twitter.widgets button i think you have to create a new one each time.
Rafael Neubauer
@Scyles
Aug 07 2015 16:22
@gmurray327 Do you have an ending `</div>` for you `<div class='row'>` ?
Aug 07 2015 16:22
@dting Wow my search tells me that's true. iframe elements cannot be modified after creation at all, and twitter doesn't provide an api to change it. here: http://slouchcou.ch/?p=318
I guess recreating or using that custom button is the correct way
Sudeepto
@Sudeepto
Aug 07 2015 16:24
@oab00 I also tried to do that. But I am not able to pass the empty array into which I want to push the numbers and in the end return it as the final flattened array.
Joe Smith
@joesmith100
Aug 07 2015 16:24
@oab00 Out of curiosity, why aren’t global variables allowed? I did something similar to @Sudeepto on the steamroller challenge using a global variable and my solution worked
rbunz
@rbunz08
Aug 07 2015 16:26
how do you get a for loop to print out all the values it does. Mine is only printing the first one.
Matthew Senko
@mpskierbg
Aug 07 2015 16:26
i have a string = 'GCG' how do i make that = [[g],[c],[g]]?
Paul Soper
@pdsoper
Aug 07 2015 16:26
@rbunz08 Could you post the loop?
Nathan Burkiewicz
@N8-B
Aug 07 2015 16:26
@rbunz08 Can you post your code?
Javed
@JayBee007
Aug 07 2015 16:27
@rbunz08 post the code plz
rbunz
@rbunz08
Aug 07 2015 16:28

function largestOfFour(arr) {

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

var largest = arr[i][0];

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

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Sudeepto
@Sudeepto
Aug 07 2015 16:28

@joesmith100 I never used global varibles in any bonfires but this one, as I wan't able to create an empty array only once. If I included that statement inside the function, it would be created on every invocation of `steamroller` function.

AFAIK, global variables are not encouraged in JS as they probably pollute the global namespace.

rbunz
@rbunz08
Aug 07 2015 16:28
@pdsoper @N8-B the idea is to print out the largest number in each array into a new array
right now it is printing out 5
Chris
@Shifthawke
Aug 07 2015 16:29
I dont understand what this way point wants from me.
Paul Soper
@pdsoper
Aug 07 2015 16:29
@rbunz08 Create an array for the answer, and `push` your answers onto it. If you actually want to print, use console.log
Chris
@Shifthawke
Aug 07 2015 16:29
I'm wrong in everything I do. I don't get it.
rbunz
@rbunz08
Aug 07 2015 16:31
@pdsoper I dont really know what you mean?? I'm okay with it just returning the answer.
Paul Soper
@pdsoper
Aug 07 2015 16:31
@Shifthawke You need to edit the <input> section at the end of the form.
Joe Smith
@joesmith100
Aug 07 2015 16:31
@Sudeepto That makes sense now you’ve said it. Also, the reason why your’re solution isn’t working is because you’re invoking the function in you’re solution. If you remove it the tests will pass
Chris
@Shifthawke
Aug 07 2015 16:32
........ I did it right.... Just... forgot to put the closing form tag at the end. -hangs head in shame-
Paul Soper
@pdsoper
Aug 07 2015 16:32
@rbunz08 All you are seeing now is the final value from your loop - `largest`. If you want to return more than that, you need to store them somewhere.
You can use an array to do that.
@Shifthawke Happens to everyone.
Sudeepto
@Sudeepto
Aug 07 2015 16:35
@joesmith100 Haha. Thanks. But I never removed the function invocation statement in previous bonfires :laughing:
Rafael Neubauer
@Scyles
Aug 07 2015 16:36
@rbunz08 The reason it is only returning 5 is because your return command is in your for loop, SO it runs once then jumps out of the function. Try placing the return command outside the first for loop
Also next time you paste code put 3 backticks ``` a line before and after the code to format it better
Joe Smith
@joesmith100
Aug 07 2015 16:37
@Sudeepto lol :P, its because of the global variable. If you look at the failed tests, you can see it duplicates the result. Its storing the result from both of the solution and the tests which is why it fails. So I suppose that is a perfect example to try and avoid global variables :D
rbunz
@rbunz08
Aug 07 2015 16:41
@Scyles @pdsoper it didn't work when I moved around the return command. I tried this, it is now returning a null array...

'''function largestOfFour(arr) {

var largestArray = largest;
for (i = 0; i < arr.length; i++) {

var largest = arr[i][0];

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

}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);'''

@Scyles sorry the ''' didnt work....
Nathan Burkiewicz
@N8-B
Aug 07 2015 16:44
@rbunz08 You need to push the 'largest' result from each iteration of the loop into an array.
Rafael Neubauer
@Scyles
Aug 07 2015 16:45
@rbunz08 it ` not ' its the symbol with the ~ key