19th
Feb 2016
Gabriel
@Zera99
Feb 19 2016 00:00
@n3rdvana are you doing the Palindrome challenge?
@n3rdvana
Feb 19 2016 00:02

@Zera99 Yep! I've been trying to figure it out what seems like forever and I think I almost have it but I can't seem to figure out what I'm doing wrong. This is what I have so far:

``````function palindrome(str) {

var removeChar = str.replace(/[A-Za-z0-9]/gi,"").toLowerCase();
var checkPalindrome = removeChar.split('').reverse().join('');

if (removeChar && checkPalindrome){
return true;
}else{
return false;
}
return palindrome;
}

palindrome("eye");``````

I was thinking that perhaps I'm missing taking out symbols and punctuation?

Gabriel
@Zera99
Feb 19 2016 00:02
Someone linked this to me today: http://regexr.com/
Also, you only need
`` str = str.replace(/[\W_]/gi, "").toLowerCase();``
That's what worked for me
``````function palindrome(str) {
var pivot;
str = str.replace(/[\W_]/gi, "").toLowerCase();

if(str.length % 2 === 0) {
for(var i = 0; i < str.length/2; i++) {
if(str[i] !== str[str.length-(i+1)]) {
return false;
}
}
return true;
} else {
pivot = Math.floor(str.length/2);
for(var j = 0; j < pivot; j++){
if(str[j] !== str[str.length-(j+1)]) {
return false;
}
}
return true;

}

}

palindrome("0_0 (: /-\ :) 0-0");``````
That's what I did.. A bit.. hands-on xD The days of C and Pascal still haunt me
@n3rdvana
Feb 19 2016 00:05
@Zera99 what does the [\W_] mean?
Livia Alexandra Stancu
@LivStar
Feb 19 2016 00:05
Thanks @tvotyakov
CamperBot
@camperbot
Feb 19 2016 00:05
lstro sends brownie points to @tvotyakov :sparkles: :thumbsup: :sparkles:
:star: 108 | @tvotyakov | http://www.freecodecamp.com/tvotyakov
Gabriel
@Zera99
Feb 19 2016 00:06
\W means not alpha-numeric characters, and the is to add the '', because for some reason it doesn't get added. Check the link I gave you, you can hover over the regex, and it'll explain what it does ^^
_
Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:10
any help????????????????????
Timofey Votyakov
@tvotyakov
Feb 19 2016 00:11
@khaledxmahmoud what help do you need?
@n3rdvana
Feb 19 2016 00:12
Wow, awesome! Thanks!!! Some parts look confusing but I'll look into it. I checked out a couple of books on javascript so I can better understand what I'm writing but it's so overwhelming, there's so many ways to execute something it's just a manner of figuring out which way is best and simpler
@Zera99
Gabriel
@Zera99
Feb 19 2016 00:12
What I did there is well, my first try at solving the Palindrome issue thing.. I've tried in C before but blergh, never got to finish it..
Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:13
@tvotyakov i posted the problem above,
Gabriel
@Zera99
Feb 19 2016 00:13
I need to go AFK, but do send me a message here if you need any help with programming logic, or need some help. I'm a newb, but I'll try to help
Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:14

I have a problem in javascript in Testing Objects for Properties : // Setup
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(myObj) {
if (myObj.hasOwnProperty() === true){
return myObj;
}else{
}
}

// Test your code by modifying these values

DJ
@qualitymanifest
Feb 19 2016 00:14
@Zera99 no need to have two loops there, it doesn't matter if str's length is even or odd. your first loop would get the job done.
Timofey Votyakov
@tvotyakov
Feb 19 2016 00:15
@khaledxmahmoud I see. Could you past formatted code, because it is unreadable now?
E
@efhjones
Feb 19 2016 00:15
Hi all, can anyone help me with Seek and Destroy? http://www.freecodecamp.com/challenges/seek-and-destroy
Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:15
how ?
@tvotyakov
@n3rdvana
Feb 19 2016 00:15
Thanks! I appreciate the help! @Zera99
CamperBot
@camperbot
Feb 19 2016 00:15
n3rdvana sends brownie points to @zera99 :sparkles: :thumbsup: :sparkles:
:star: 265 | @zera99 | http://www.freecodecamp.com/zera99
Timofey Votyakov
@tvotyakov
Feb 19 2016 00:17
@khaledxmahmoud try to use three backtiks before and after your code.
explain format
CamperBot
@camperbot
Feb 19 2016 00:17

## :point_right: code formatting [wiki]

### Inline code

This an inline ``<paste code here>`` code formatting with a single backtick(`) at start and end around the `code`.

### Code Block

```js ⇦ Type 3 backticks and then press `[shift + enter ⏎]` (type js or html or css)

``````<paste your code here>,
then press [shift + enter ⏎]``````

``` ⇦ Type 3 backticks, then press `[enter ⏎]`

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:19
``````// Setup
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(myObj){
if (myObj.hasOwnProperty("checkProp")){
return myobj;
}else{
}

}

// Test your code by modifying these values
@tvotyakov
Timofey Votyakov
@tvotyakov
Feb 19 2016 00:21
@khaledxmahmoud ok. your problem is in checkObj function. First of all you need to pass `checkProp` not `myObj` as you can see it in original code
``````function checkObj(checkProp) {

return "Change Me!";
}``````
Richard Gottleber
@rgottleber
Feb 19 2016 00:22
Hey, can someone explain this to me?
Alex
@Jeckstex
Feb 19 2016 00:22
help hasOwnProperty
CamperBot
@camperbot
Feb 19 2016 00:22
no wiki entry for: `hasownproperty`
Richard Gottleber
@rgottleber
Feb 19 2016 00:22
var logo = data.logo != null ? data.logo : "http://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F",
Norman Dela Cruz
@dcnr
Feb 19 2016 00:22
@khaledxmahmoud also quoting `checkProp` will turn your variable into a string. so you should remove `""` on `.hasOwnProperty("checkProp")`
Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:22
ok @tvotyakov
Timofey Votyakov
@tvotyakov
Feb 19 2016 00:23
@rgottleber it will set logo to data.logo if data.logo is not null and "http://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F" if data.logo is null
Richard Gottleber
@rgottleber
Feb 19 2016 00:23
so syntax is
set data.logo to that string if it’s null
then assign that to logo?
Timofey Votyakov
@tvotyakov
Feb 19 2016 00:24
@rgottleber it is similar to
``````var logo;
if (data.logo != null) {
logo = data.logo;
} else {
logo = "http://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F";
}``````
Richard Gottleber
@rgottleber
Feb 19 2016 00:25
right
but it’s actually doing
Norman Dela Cruz
@dcnr
Feb 19 2016 00:25
@rgottleber yeah it's
`(check condition) ? (do this if true) : (do this if false);`
Richard Gottleber
@rgottleber
Feb 19 2016 00:25
ok
thanks tvotyakov and dcnr
.. errr thanks @tvotyakov and @dcnr *brownie points must be given!
CamperBot
@camperbot
Feb 19 2016 00:25
rgottleber sends brownie points to @tvotyakov and @dcnr :sparkles: :thumbsup: :sparkles:
arifsyed88
@arifsyed88
Feb 19 2016 00:25
Any help on "Accessing Nested Arrays in JSON"?
CamperBot
@camperbot
Feb 19 2016 00:25
:star: 658 | @dcnr | http://www.freecodecamp.com/dcnr
:star: 109 | @tvotyakov | http://www.freecodecamp.com/tvotyakov
Norman Dela Cruz
@dcnr
Feb 19 2016 00:27
lol you're welcome and thanks too @rgottleber sometimes the conditional operator makes the code hard to read though, especially if it's a long one, might as well just do an if-else or make line breaks
CamperBot
@camperbot
Feb 19 2016 00:27
dcnr sends brownie points to @rgottleber :sparkles: :thumbsup: :sparkles:
:star: 351 | @rgottleber | http://www.freecodecamp.com/rgottleber
Norman Dela Cruz
@dcnr
Feb 19 2016 00:27
@rgottleber but that's just personal coding style
Timofey Votyakov
@tvotyakov
Feb 19 2016 00:30
@khaledxmahmoud In short, you need to
• replace your myObj parameter name by checkProp here `function checkObj(myObj)`
• remove quotes here `if (myObj.hasOwnProperty("checkProp")){`
• and return `myObj[checkProp]` here `return myobj;`
Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:32
Thanks alot, @tvotyakov
CamperBot
@camperbot
Feb 19 2016 00:32
khaledxmahmoud sends brownie points to @tvotyakov :sparkles: :thumbsup: :sparkles:
:star: 110 | @tvotyakov | http://www.freecodecamp.com/tvotyakov
Khaled M. Mahmoud Khamis
@khaledxmahmoud
Feb 19 2016 00:34
Thanks alot @dcnr
CamperBot
@camperbot
Feb 19 2016 00:34
khaledxmahmoud sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 659 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 19 2016 00:35
@khaledxmahmoud I didn't do much :P it's all thanks to @tvotyakov
CamperBot
@camperbot
Feb 19 2016 00:35
dcnr sends brownie points to @khaledxmahmoud and @tvotyakov :sparkles: :thumbsup: :sparkles:
:star: 111 | @tvotyakov | http://www.freecodecamp.com/tvotyakov
:star: 218 | @khaledxmahmoud | http://www.freecodecamp.com/khaledxmahmoud
Alex
@Jeckstex
Feb 19 2016 00:36
Hello campers! I am working on the " Where art thou" challenge in the intermediate Algorithm section. I have to use hasOwnProperty but I don't really understand how to use it. This is what I have done so far: ``` ```
Moisés Man
@moigithub
Feb 19 2016 00:37
`myObj.hasOwnProperty( myPropToCheck )` @Jeckstex
Alex
@Jeckstex
Feb 19 2016 00:37
``````
function where(collection, source) {
var arr1 = [];
var arr2=[];
var stock=[];

arr2=Object.keys(source);
size=collection.length;

for(var i=0; i<size; i++)
{
arr1=Object.keys(collection[0]);
if(arr1.hasOwnProperty(arr2))
{
stock.concat(arr1);
}
}

return  stock;
}

where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });``````
Moisés Man
@moigithub
Feb 19 2016 00:38
@Jeckstex it do not check for array..but each object.. for specific properties
Alex
@Jeckstex
Feb 19 2016 00:39
@moigithub but myPropToCheck is it a string? For example, I want to check if the last name is "Capulet" Is it what I am suppost to put as myPropToCheck?
I really have a hard time with this object notion
Moisés Man
@moigithub
Feb 19 2016 00:40
u use keys ... not values
`myobj={ key: value} ;`
`var source = { last: "Capulet" }`
if u wanna check if source have the property named `last`
u do
`if (source.hasOwnProperty("last"))`
Alex
@Jeckstex
Feb 19 2016 00:42
haaa! So "the text in green in the object" are the properties, okay got it.
Moisés Man
@moigithub
Feb 19 2016 00:42
if u wanna work with variables.. u can do.. soemthing like...
``````var myPropToCheck="last";
if (source.hasOwnProperty(myPropToCheck)) {...}``````
Alex
@Jeckstex
Feb 19 2016 00:44
so hasOwnProperty will just tell you if such property exists in your object?
Moisés Man
@moigithub
Feb 19 2016 00:44
yes.. it will return true or false if exist or not
Alex
@Jeckstex
Feb 19 2016 00:45
Okay It is much more clear now! Thanks @moigithub
CamperBot
@camperbot
Feb 19 2016 00:45
jeckstex sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 644 | @moigithub | http://www.freecodecamp.com/moigithub
Conflict
@prusso
Feb 19 2016 00:53
function repeat(str, num) {
if (num < 0) {
return null;
} else {
for (var i = 0; i < num; i++) {
console.log(str);
}
}
}
repeat("abc", 3);
anyone know why this isnt printing anything?
Afaaq Alam
@afaaqalam
Feb 19 2016 01:00
@prusso which waypoint is this?
Elijah
Feb 19 2016 01:03
Ok so I'm having issues with the "Iterating over Arrays with .map method"
Afaaq Alam
@afaaqalam
Feb 19 2016 01:03
@prusso it'll log abc three times
Elijah
Feb 19 2016 01:03
The example used isn't executing, let alone my usage of it
Afaaq Alam
@afaaqalam
Feb 19 2016 01:04
Elijah
Feb 19 2016 01:07
I take it back lol I've been doing it right, the site just had a bug!
Moisés Man
@moigithub
Feb 19 2016 01:07
@prusso u need to make a string variable.. and on each iteration build a "bigger string"
doin `repeat("abc", 3);` should return abcabcabc
console.log() is used for debuggin purposes only...
Aleksander Gębicki
@Takumar
Feb 19 2016 01:09

@tvotyakov

@lstro @Takumar first of all it is not if/else-if or switch problem. You should return "Bet" if the count is positive and "Hold" if it is zero or negative. But you @lstro returns "Bet" when you increase count and "Hold" in other situations. That is wrong.

You are right, I was writing about that @lstro should check `count` variable if it is positive or negative also earlier :point_up: 19 lutego 2016 00:28
but it looks like @lstro haven't noticed that.

Ram
@rambaldoz
Feb 19 2016 01:17
hi..
im having trouble with javascript right and i just want to know how queue work
Aleksander Gębicki
@Takumar
Feb 19 2016 01:19
@rambaldoz you want to add one element to the array and remove first element from your array?
@rambaldoz for sure you have learnt about `push()` and `shift()` methods working on arrays.
Ram
@rambaldoz
Feb 19 2016 01:19
@Takumar yes thats right
Aleksander Gębicki
@Takumar
Feb 19 2016 01:20
@rambaldoz try to use methods which I mentioned above.
Ram
@rambaldoz
Feb 19 2016 01:20
@Takumar oh. that should help. Thanks a lot!
CamperBot
@camperbot
Feb 19 2016 01:20
rambaldoz sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2336 | @takumar | http://www.freecodecamp.com/takumar
E
@efhjones
Feb 19 2016 01:22
Could someone help me with .filter? I'm being crushed under a mountain of confusion
Aleksander Gębicki
@Takumar
Feb 19 2016 01:24
@rambaldoz you are welcome :-)
E
@efhjones
Feb 19 2016 01:25

I keep getting this error:

``TypeError: Array.prototype.filter callback must be a function``

when I run this:

``````var returnedArr = [];
function destroyer(arr, x, y) {
// Remove all the values

return arr.filter(x,y);

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

But then in a previous challenge this worked just fine:

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

return arr.filter(Boolean);
}

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

I don't see the difference X_X

Norman Dela Cruz
@dcnr
Feb 19 2016 01:29
@efhjones filter needs a callback function for it to call on your array elements, `Boolean` is a function (well used as a function) while `x` and `y` are not
E
@efhjones
Feb 19 2016 01:30
@dcnr could you help me out with callback function? Whenever I hear that term my brain looks in another direction...
Norman Dela Cruz
@dcnr
Feb 19 2016 01:31
@efhjones to put it simply, a callback function is just a function used as an argument to another function, and that callback is then used by that function however/whenever it needs to
@efhjones so with `.filter` it takes in a (callback) function, that it uses on your array elements

@efhjones

``````var numbers = [1, 2, -3, 0, -5];

var positive = numbers.filter(function(number) {
return number > 0;
});
// [1, 2]``````

here, the function inside filter is the callback

@efhjones
it can also be written like this
``````var numbers = [1, 2, -3, 0, -5];

function positiveOnly(number) {
return number > 0;
}

var positive = numbers.filter(positiveOnly);
// [1, 2]``````
that's why `arr.filter(Boolean)` works, it's like the second example, with the function passed instead of written inline
Bakari Holmes
@bakarih
Feb 19 2016 01:36
Having trouble with smallest common multiple in the intermediate algorithm challenges. Getting an infinite loop message but I can't see it. Can anyone help? Code is here:

function smallestCommons(arr) {
var maxElement = Math.max(arr[0], arr[1]);
var minElement = Math.min(arr[1], arr[0]);
var scm = maxElement;
for (var i = 0; i < maxElement-1; i++)
{
if (scm % arr[i] === 0)
{
continue;
}
while (scm % arr[i] !== 0)
{
scm *= 2;
}
}
return scm;
}

smallestCommons([1,5]);

E
@efhjones
Feb 19 2016 01:39

@dcnr Thanks, something like this?

``````function filter(arr, x, y){

return arr !== x || != yy ;
}``````

It won't compile obviously but I'm still trying to wrap my head around this...

CamperBot
@camperbot
Feb 19 2016 01:39
efhjones sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 660 | @dcnr | http://www.freecodecamp.com/dcnr
Aleksander Gębicki
@Takumar
Feb 19 2016 01:40
@efhjones you cannot make shortcuts in conditions.
Try:
`` return arr !== x || arr !== yy ;``
Norman Dela Cruz
@dcnr
Feb 19 2016 01:41
@efhjones each built-in function is documented, and if you don't know the signature you should look it up. For example, Filter on MDN
@bakarih it's just warning you that you may have a potential infinite loop, if you are sure it will not be an infinite loop, you can disable the protection, go here https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Loop-Protect
Aleksander Gębicki
@Takumar
Feb 19 2016 01:44
@efhjones also you should run your filter on an array:
``````myArray.filter(function(arr, x, y) {
// code of your callback function
});``````
E
@efhjones
Feb 19 2016 01:46
@dcnr I've read that page, I just can't understand it :worried: The example they use have too many things in them I don't understand
Norman Dela Cruz
@dcnr
Feb 19 2016 01:48
you will have to learn how to understand these documents though, a lot of your time as a coder would be reading API documentation :(
Aleksander Gębicki
@Takumar
Feb 19 2016 01:49

@efhjones look at such example:

``````var arr = [-1, 1];
var newArr = arr.filter(function(value) {
if (value > 0) return true;  // value will go to newArr
else return false;  // this value will be omited
});``````

such code will put only positive values to `newArr` array, is it more clear?

Norman Dela Cruz
@dcnr
Feb 19 2016 01:49
oh hello @Takumar :D
Aleksander Gębicki
@Takumar
Feb 19 2016 01:50
Hello @dcnr :-)
I have to work a little to save my streak :-)
Norman Dela Cruz
@dcnr
Feb 19 2016 01:51
ahah :D
@Takumar how do you even prolong streaks? does revisiting a problem count?
Aleksander Gębicki
@Takumar
Feb 19 2016 01:53
@dcnr by helping others and getting brownies, or solving challenges on FCC.
Norman Dela Cruz
@dcnr
Feb 19 2016 01:54
@Takumar aah I see, I was wondering why I have 11 days when I've stopped doing challenges :D thank you!
CamperBot
@camperbot
Feb 19 2016 01:54
dcnr sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2340 | @takumar | http://www.freecodecamp.com/takumar
Aleksander Gębicki
@Takumar
Feb 19 2016 01:54
@dcnr you are welcome :-)
Gabriel
@Zera99
Feb 19 2016 01:58
I'm back!
E
@efhjones
Feb 19 2016 02:02

@Takumar @dcnr Thanks for your patience, am I going down the right path here? I don't see how to make it compare the arr[1] and arr[2] to the values in arr[0]

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

var newArr = arr.filter(function(value) {
if (value == arguments[1] || value == arguments[2]) return false; // this value will be omited
else return true;  // value will go to newArr
});
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````

I guess I don't know what to put in 'value' in function(value)

CamperBot
@camperbot
Feb 19 2016 02:02
efhjones sends brownie points to @takumar and @dcnr :sparkles: :thumbsup: :sparkles:
:warning: efhjones already gave dcnr points
:star: 2342 | @takumar | http://www.freecodecamp.com/takumar
Aleksander Gębicki
@Takumar
Feb 19 2016 02:06
@efhjones I think it is almost good, but inside your internal (callback) function you don't have access to `destroyer()` arguments, your internal function has its own arguments. You have to store arguments from `destroyer()` function to some variable to access them later.
Gabriel
@Zera99
Feb 19 2016 02:07
@qualitymanifest Are you online?
Aleksander Gębicki
@Takumar
Feb 19 2016 02:07

@efhjones add such line at the beginning of your `destroyer()` function:

``  var args = Array.prototype.slice.call(arguments, 1);``

this comes from documentation, and work on `args` array in your filter, instead of `arguments`.

DJ
@qualitymanifest
Feb 19 2016 02:08
@Zera99 whats up?
budimanfix
@budimanfix
Feb 19 2016 02:08

@Takumar Hello which to correct here: function lookUp(firstName, prop){
// Only change code below this line

for (var i = 0;i < contacts.length; i++) {
if (contacts[i].firstName === firstName && contacts[i][prop])
{
if (contacts[i][prop]) {
return contacts[i][prop];
}
else {
return "no such contact";
}
}
}
return "no such property";

}

Gabriel
@Zera99
Feb 19 2016 02:09
When I posted my solution for the palindrome thing, you said the 2 loops weren't necessary.. I took out the second loop, and it doesn't pass the test, but I can't see what I'm missing. Would you take a look at the code again? (I'll repost it, with the loop I'm talking about commented out)
DJ
@qualitymanifest
Feb 19 2016 02:09
@Zera99 sure paste it again
Gabriel
@Zera99
Feb 19 2016 02:10
Thanks @qualitymanifest
CamperBot
@camperbot
Feb 19 2016 02:10
zera99 sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 980 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
Gabriel
@Zera99
Feb 19 2016 02:10
``````function palindrome(str) {
var pivot;
str = str.replace(/[\W_]/gi, "").toLowerCase();

if(str.length % 2 === 0) {
for(var i = 0; i < str.length/2; i++) {
if(str[i] !== str[str.length-(i+1)]) {
return false;
}
}
return true;
} /*else {
pivot = Math.floor(str.length/2);
for(var j = 0; j < pivot; j++){
if(str[j] !== str[str.length-(j+1)]) {
return false;
}
}*/
return true;
}

palindrome("1 eye for of 1 eye.");``````
Norman Dela Cruz
@dcnr
Feb 19 2016 02:10
@efhjones hi, I'm sorry I stepped away for a bit, but I see Takumar answered you already :D
Gabriel
@Zera99
Feb 19 2016 02:10
(That test in particular is the one that fails, the 1 eye for of 1 eye.)
DJ
@qualitymanifest
Feb 19 2016 02:10
@Zera99 you'll need to get rid of your if statement
@Zera99 what i was saying is, your first loop will work regardless of if str's length is even or odd. but with that if statement, the loop only happens if str's length is even
the last return true is unnecessary at that point also
Aleksander Gębicki
@Takumar
Feb 19 2016 02:11
@budimanfix for sure you have to correct your strings: `"No such contact"` and `"No such property"`
Gabriel
@Zera99
Feb 19 2016 02:12
Hm, let me see
Ah, it works! thanks again!
I over-thought that one..
Aleksander Gębicki
@Takumar
Feb 19 2016 02:13
@budimanfix you can say that you haven't found your contact after you check every record in the contacts, that means after your loop completes! So remove `return "No such contact";` line after your for loop, but include "No such property" in the conditions inside the loop :-)
DJ
@qualitymanifest
Feb 19 2016 02:16
@Zera99 np :+1:
Arafat Hossain
@hossain1993
Feb 19 2016 02:16

// Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup = {
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank"
};
result = lookup.val;
// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("charlie");

Hey guys, have no idea how to fix this!
Aleksander Gębicki
@Takumar
Feb 19 2016 02:17
@hossain1993 `val` is not name of property but variable containing name of property, you cannot use period to get access to such property from your object you have to use bracket notation.
Check this line: `result = lookup.val;`
Gabriel
@Zera99
Feb 19 2016 02:17
When you check container using variables, you have to use the bracket notation, not the dot @hossain1993 , I think that's the issue there
lookup[val] instead of lookup.val ? Correct me if I'm wrong campers x.x
Arafat Hossain
@hossain1993
Feb 19 2016 02:18
@Zera99 yes! that worked, thanks!
CamperBot
@camperbot
Feb 19 2016 02:18
hossain1993 sends brownie points to @zera99 :sparkles: :thumbsup: :sparkles:
Aleksander Gębicki
@Takumar
Feb 19 2016 02:18
@Zera99 no, you are right. :-)
CamperBot
@camperbot
Feb 19 2016 02:18
:star: 266 | @zera99 | http://www.freecodecamp.com/zera99
budimanfix
@budimanfix
Feb 19 2016 02:18
@Takumar like this one?? : for (var i = 0;i < contacts.length; i++) {
if (contacts[i].firstName === firstName && contacts[i][prop])
{
if (contacts[i][prop]) {
return contacts[i][prop];
}
else {
return "No such property ";
}
}
}
Gabriel
@Zera99
Feb 19 2016 02:19
Yay ^^
Aleksander Gębicki
@Takumar
Feb 19 2016 02:19
@budimanfix `&& contacts[i][prop]` is not needed, because you are checking it in lower line.
@budimanfix also you have space in the string: `return "No such property ";` after "property" remove it.
aeroengz
@aeroengz
Feb 19 2016 02:23
Hey relative noob here. I'm trying to add a record for the first JSON tutorial and have ran into a wall.
budimanfix
@budimanfix
Feb 19 2016 02:25
@Takumar yep still left one task now : "Bob", "number" should return "No such contact"
@Takumar for (var i = 0;i < contacts.length; i++) {
if (contacts[i].firstName === firstName)
{
if (contacts[i][prop]) {
return contacts[i][prop]; }
else {
return "No such property";
}
}
}
}
JackeL
@jackel27
Feb 19 2016 02:28
@aeroengz whats the issue? Can u paste your code?
Gabriel
@Zera99
Feb 19 2016 02:28
@budimanfix one thing I did that my life much easier, is input the "test" text that fails, into the test they present there, and see what it returns, and why
Return random info (if you don't want to open the developer console) to check what's going on ^^
aeroengz
@aeroengz
Feb 19 2016 02:30
Hey sorry var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
];
I'm trying to just add to this object. I've tried the push() function to avail
JackeL
@jackel27
Feb 19 2016 02:32
Object in an array
Bakari Holmes
@bakarih
Feb 19 2016 02:33
This is my updated solution for smallest common multiple. Working for every case except the last. Hmm.... Here's my updated code:

function smallestCommons(arr) {
var maxElement = Math.max(arr[0], arr[1]);
console.log("The maxElement is " + maxElement);
var minElement = Math.min(arr[1], arr[0]);
console.log("The minElement is " + minElement);
var scm = maxElement;
for (var i = minElement; i <= maxElement; i++)
{
console.log("Started for loop. The value of i is " + i);
if (scm % i === 0)
{
console.log(i + " divides evenly into " + scm);
continue;
}
while (scm % i !== 0)
{
console.log(i + " does NOT divide evenly into " + scm);
if (i % 2 === 0)
{
scm = scm 2;
}
else scm
= i;
console.log("The new scm is " + scm);
}
}
console.log("Returning a value of " + scm);
return scm;
}

smallestCommons([1,5]);

aeroengz
@aeroengz
Feb 19 2016 02:34
JackeL
@jackel27
Feb 19 2016 02:34
@aeroengz so you want to add after the object
@aeroengz object beteen {} array is [] . You could try arrayname.push (whattopush);
@aeroengz research more on push method :) it may give u answer your looking for.
aeroengz
@aeroengz
Feb 19 2016 02:37
@jackel27 yes the instructions are to add a new album (artist,title,release_year, formats). I think it's my syntax. Thanks for the feedback!
CamperBot
@camperbot
Feb 19 2016 02:37
aeroengz sends brownie points to @jackel27 :sparkles: :thumbsup: :sparkles:
:star: 321 | @jackel27 | http://www.freecodecamp.com/jackel27
JackeL
@jackel27
Feb 19 2016 02:38
No prob! Keep going, it will get easier and harder :)
aeroengz
@aeroengz
Feb 19 2016 02:48
@jackel27 that was way too easy. I was being complicated. Just had to literally add another {}. Thanks again
CamperBot
@camperbot
Feb 19 2016 02:48
aeroengz sends brownie points to @jackel27 :sparkles: :thumbsup: :sparkles:
:warning: aeroengz already gave jackel27 points
teingram
@teingram
Feb 19 2016 02:51
Hello Super Groovy Folks, working on Filter Arrays with .filter. Isn't this sentence false?: The filter method is used to iterate through an array and filter out elements where a given condition is not true.
Shouldn't it be: Return true to keep the element, false otherwise.
Norman Dela Cruz
@dcnr
Feb 19 2016 02:53

@teingram

filter out elements where a given condition is not true

that's what it is, it's said in a roundabout way though

JackeL
@jackel27
Feb 19 2016 02:53
@teingram explain falsy
Explain falsy
CamperBot
@camperbot
Feb 19 2016 02:53

# Problem Explanation:

Remove all falsy values from an array.

teingram
@teingram
Feb 19 2016 02:54
Ah, you know, dang, that's correct. I must have read that 5 times and still didn't understand.
JackeL
@jackel27
Feb 19 2016 02:54
albyh
@albyh
Feb 19 2016 02:54
In "Check for Palindromes" anyone know why
`palindrome("1 eye for of 1 eye.") should return false.`
isn't considered a palindrome given the directions that say to remove all non-alphanumeric characters? My code seems to work correctly but this looks like it should be a palindrome to me.
teingram
@teingram
Feb 19 2016 02:54
thanks dcnr
thanks @dcnr
CamperBot
@camperbot
Feb 19 2016 02:55
teingram sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 661 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 19 2016 02:55
you're welcome, thank you too @teingram
CamperBot
@camperbot
Feb 19 2016 02:55
dcnr sends brownie points to @teingram :sparkles: :thumbsup: :sparkles:
:star: 246 | @teingram | http://www.freecodecamp.com/teingram
JackeL
@jackel27
Feb 19 2016 02:58
Nicely done @aeroengz :)
DJ
@qualitymanifest
Feb 19 2016 02:58
@albyh the 1s make it not a palindrome
yoni chanowitz
@yonichanowitz
Feb 19 2016 02:59
help me!
in "seek and destroy"
i cant figure out how t o check for more than one variable
``````function destroyer(arr) {
// Remove all the value
for(var i = 0; i < arguments[i].length +1;i++){

}
function c(ary){
if( ary === i){return ary;}
} var d = arr.filter(c);
return d;
}

destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3);``````
CamperBot
@camperbot
Feb 19 2016 02:59
no wiki entry for: `mein seek and destroy i cant figure out how t o check for more than one variablefunction destroyerarr remove all the value forvar i 0 i argumentsilength 1i function cary if ary ireturn ary var d arrfilterc return ddestroyer1 2 3 5 1 2 3 2 3`
albyh
@albyh
Feb 19 2016 03:00
ok. Thanks @qualitymanifest. I was thinking just letters... doh
CamperBot
@camperbot
Feb 19 2016 03:00
albyh sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 981 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
JackeL
@jackel27
Feb 19 2016 03:02
@yonichanowitz i belived i used arguments function on this one..
Ivan Perez
@joannesalfa
Feb 19 2016 03:02
@yonichanowitz you need to apply brackets for condition
then do return true, otherwise return false
@yonichanowitz I think you should use loop inside of this function
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:03
@jackel27 , what do you mean?
Ivan Perez
@joannesalfa
Feb 19 2016 03:04
@yonichanowitz
``````  function yourFunction (s) {
//Get index of argument.length
for( ... ){
//If parameter is same as index, should return false
if(s == arguments[i]){
return false;
}
}
//If not, it can pass destroyed values from argument
return true;
}``````
this is for filter
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:06
@joannesalfa , but i need to return the value (a number or string) not true or false?
Ivan Perez
@joannesalfa
Feb 19 2016 03:07
you can create var to assign array.filter(function); and call var for return

``````var d = arr.filter(c);
return d;``````

it's fine, but the rest is wrong

Manuel Pinto
@P1N2O
Feb 19 2016 03:10

Hello there..

http://www.freecodecamp.com/challenges/word-blanks

Ivan Perez
@joannesalfa
Feb 19 2016 03:10
filter function can mutate arrays if you pick arguments and compare, then return. after all
@StaticBlaze it's easy, you are supposed to build your own sentence between strings and arguments
for example
``"Hello my name is " + myName + "and my age is " + myAge;``
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:13
thanks @joannesalfa
CamperBot
@camperbot
Feb 19 2016 03:13
yonichanowitz sends brownie points to @joannesalfa :sparkles: :thumbsup: :sparkles:
:star: 415 | @joannesalfa | http://www.freecodecamp.com/joannesalfa
knnonah
@knnonah
Feb 19 2016 03:13
``````function mutation(arr) {
var str;
var doesContain;
arr = arr.toString().toLowerCase();
arr = arr.includes(arr[1]);
if(arr !== true){
return false;
}

return arr;
}

mutation(["hello", "HEll"]);``````
Manuel Pinto
@P1N2O
Feb 19 2016 03:14
Okay. Now I understand! Thanks @joannesalfa
CamperBot
@camperbot
Feb 19 2016 03:14
staticblaze sends brownie points to @joannesalfa :sparkles: :thumbsup: :sparkles:
:star: 416 | @joannesalfa | http://www.freecodecamp.com/joannesalfa
knnonah
@knnonah
Feb 19 2016 03:14
Hey all, can anyone help me understand why this function is not passing false.
I think it has something to do with my "if" statement, but I am not seeing what the root is. Thanks.
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:15
@knnonah , you can't re-assign `arr` without changing it back
knnonah
@knnonah
Feb 19 2016 03:16
@yonichanowitz What do you mean changing it back? Back to an array?
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:19
@knnonah , the other issue is your if statement doesn't have anything clear to compare.
knnonah
@knnonah
Feb 19 2016 03:22
@yonichanowitz Anything clear to compare? I can't think of anything else to compare it to. I don't understand. Will you please elaborate.
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:24

@knnonah try making two variables that reference different partsof the array
example

``````var dude = arr[0];
var sweet = arr[1];``````

then you need to use `.indexOf()` to be sure that theparts of each word are the same, or not

Ivan Perez
@joannesalfa
Feb 19 2016 03:25
@knnonah funny why did you use array.includes(); this api is not ready for all browsers
however it's experimental api, it's working in some browsers
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:26
@knnonah , one hint that took me 3 excruciatingly painful days to realise, dont use an `else` , the `return` statement will end the loop after checking one item (part of array, or letter)
knnonah
@knnonah
Feb 19 2016 03:27
@yonichanowitz Awesome, yonichanowitz. Thanks for the insight and info.
CamperBot
@camperbot
Feb 19 2016 03:27
knnonah sends brownie points to @yonichanowitz :sparkles: :thumbsup: :sparkles:
:star: 269 | @yonichanowitz | http://www.freecodecamp.com/yonichanowitz
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:27
@knnonah thanks
CamperBot
@camperbot
Feb 19 2016 03:27
yonichanowitz sends brownie points to @knnonah :sparkles: :thumbsup: :sparkles:
:star: 260 | @knnonah | http://www.freecodecamp.com/knnonah
yoni chanowitz
@yonichanowitz
Feb 19 2016 03:27
first earned brownie points WOOO HOOO!
rphares
@rphares
Feb 19 2016 03:28
Have another, @yonichanowitz
CamperBot
@camperbot
Feb 19 2016 03:28
rphares sends brownie points to @yonichanowitz :sparkles: :thumbsup: :sparkles:
:star: 270 | @yonichanowitz | http://www.freecodecamp.com/yonichanowitz
knnonah
@knnonah
Feb 19 2016 03:28
@joannesalfa I changed the array into a string and then used string.include();
Ivan Perez
@joannesalfa
Feb 19 2016 03:29
@knnonah oh youre right
Michelle
@Michelle2016
Feb 19 2016 03:51
EEK! I am on the Using Objects for Lookups challenge!!
rphares
@rphares
Feb 19 2016 03:52
heh, that one gets a lot of people,
Michelle
@Michelle2016
Feb 19 2016 03:53
@rphares To be honest, I would rather not. I am all over the place with this one....
rphares
@rphares
Feb 19 2016 03:54
hmm, kinda hard to help without--
you need to a) make a table,
b) build the part that gets `val`
Michelle
@Michelle2016
Feb 19 2016 03:54
var lookUp?
rphares
@rphares
Feb 19 2016 03:54
(following the example, `alpha[2]` will help)
thats the table, yup :)
c) make sure to set result to what you want to return
(after the table, dont change it at the top)
Michelle
@Michelle2016
Feb 19 2016 03:55
So var lookUp{
rphares
@rphares
Feb 19 2016 03:55
yup
well,
with an =
(`var Name = {something}`format :blush: )
but the rest is fine~
Michelle
@Michelle2016
Feb 19 2016 03:56
var lookUp ={
rphares
@rphares
Feb 19 2016 03:56
yep
oh,
no camel case either, heh
Michelle
@Michelle2016
Feb 19 2016 03:58
then, under the curly bracket, result=
rphares
@rphares
Feb 19 2016 03:58
(dunno if it matters-- it wouldn't in real life, as long as you were consistent, but sometimes the tests are built to check for what the directions said, so better to be safe :) )
yep
Michelle
@Michelle2016
Feb 19 2016 03:58
No camel case for lookUp?
rphares
@rphares
Feb 19 2016 03:59
yeah,, the directions said `"into a lookup table called lookup. "`
so not sure if it will test for `lookup` exactly
Michelle
@Michelle2016
Feb 19 2016 03:59
Ah!
rphares
@rphares
Feb 19 2016 03:59
camelcase in that sitch would work normally, as long as you used the same standards throughout.
just not sure what the FCC tests might be shrug
James Minkler
@Hook1169
Feb 19 2016 04:00
I am really struggling to understand this, i don't think I quite understand what they are expecting... "Write a function queue which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The queue function should then return the element that was removed."

function queue(arr, item) {

return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

rphares
@rphares
Feb 19 2016 04:00
@Hook1169 , im not great at helping this one, but--
review push and shift,
i suggest reading the MDNs carefully, not just the FCC lessons :blush:
bitgrower
@bitgrower
Feb 19 2016 04:01
that pretty quickly narrows it down, @rphares ... :)
James Minkler
@Hook1169
Feb 19 2016 04:01
ok, was tryingt o use pop() maybe i got them mixed up
MDNs?
rphares
@rphares
Feb 19 2016 04:01
lol @bitgrower , i know, its a biggie, BUT
bitgrower
@bitgrower
Feb 19 2016 04:01
Mozilla Developer Network ...
rphares
@rphares
Feb 19 2016 04:01
google that-- its quite important going forward--
James Minkler
@Hook1169
Feb 19 2016 04:01
Oh i have not checked that out..
rphares
@rphares
Feb 19 2016 04:02
they are a great resource which you'll wanna be really familiar with,
bitgrower
@bitgrower
Feb 19 2016 04:02
@rphares is understanding it's importance, actually ...
James Minkler
@Hook1169
Feb 19 2016 04:02
will do. thanks again @rphares and @bitgrower
CamperBot
@camperbot
Feb 19 2016 04:02
hook1169 sends brownie points to @rphares and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 2878 | @rphares | http://www.freecodecamp.com/rphares
:star: 569 | @bitgrower | http://www.freecodecamp.com/bitgrower
rphares
@rphares
Feb 19 2016 04:02
its pretty much standard reading for all the algorithms and a few other challenges :)
Sure thing~
( @bitgrower , you know I'm not a fan of giving answers--
in that one, i feel people can't use them properly, even once they have read that,
let alone figure ut the logic,
its usually their first exposure, and a big jump,
bitgrower
@bitgrower
Feb 19 2016 04:03
I like to just send 'em to the MDN Array page and look at the different functions available ... :)
rphares
@rphares
Feb 19 2016 04:03
so i think its actually a far removed hint most the time, based on what I've seen here,,,,)
ah, thats a good call
bitgrower
@bitgrower
Feb 19 2016 04:04
who knows what they might learn ?!?
rphares
@rphares
Feb 19 2016 04:04
heh, i need to get more familiar myself-
bitgrower
@bitgrower
Feb 19 2016 04:04
they might stumble over slice ... or splice ...
me too, @rphares ...
rphares
@rphares
Feb 19 2016 04:04
when i did all the BFs, etc, i found them incomprehensible most of the time. I either read it and used it,
or googled things i found on that page till i could just hack something together with no comp
bitgrower
@bitgrower
Feb 19 2016 04:04
I guess I was lucky that when I first visited mdn, my browser page was wide enough to have the list of functions along the left side ...
rphares
@rphares
Feb 19 2016 04:05
so I'm just starting to find it useful...
Bryan Gilbraith
@bryantheastronaut
Feb 19 2016 04:05
help caesars cipher
CamperBot
@camperbot
Feb 19 2016 04:05

# Problem Explanation:

• You need to write a function, which will take string encoded with
Caesar cipher as a parameter and decode it.
• The one used here is ROT13 where the value of the letter is
shifted by 13 places.
e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
• You have to shift it back 13 positions, such that 'N' ↔ 'A'.
bitgrower
@bitgrower
Feb 19 2016 04:05
you.did.that.with.exact.change ?!?
rphares
@rphares
Feb 19 2016 04:06
lol, i dont think I'm that far, i stopped a few from the end of intermediate, and went back to redo everything until i can comment everything I'm doing,
focusing more on outside reading atm, to be honest,
got asked about solutions of mine when my profile was still open.... couldn't even remember what id done,
bitgrower
@bitgrower
Feb 19 2016 04:06

@bryantheastronaut -- think of it as 3 things you need to do ..

1. convert character to character code
2. uncipher it
3. return it to character code ...

you have to do some string to array & back stuff as well ... but those 3 steps are the guts

James Minkler
@Hook1169
Feb 19 2016 04:06
so are you recommending reading more about arrays? I would assume to start at functions. I guess any reading in general is probably best. Just looking for a good jumping in point.. and BTW thanks for the reference to MDN this looks like a TON of info...
rphares
@rphares
Feb 19 2016 04:06
felt like people thought id copied, even though i just saw where the instructions were pointing and put pieces together, so ... shrug
Bryan Gilbraith
@bryantheastronaut
Feb 19 2016 04:07
@bitgrower thanks! im so close to finishing the algorithms!
CamperBot
@camperbot
Feb 19 2016 04:07
bryantheastronaut sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
rphares
@rphares
Feb 19 2016 04:07
Its @Hook1169 , definitely-- they are gonna be a huge part going forward :) You're gonna end up wanting that tab open alot :) :)
CamperBot
@camperbot
Feb 19 2016 04:07
:star: 570 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 19 2016 04:07
I suspect @rphares and I recommend more reading altogether !!!
eh @bryantheastronaut -- I think you have a few more ahead of you -- you mean, this section of algos ... but ... don't let me rain on your parade ... CONGRATS!!!!
anyone have the chrome MDN extension installed & know how to use it ?
rphares
@rphares
Feb 19 2016 04:09
Yep-- makes a huge difference!! I like eloquent JS and YDKJS (you dont know javascript) as well, helpful for putting things more into place and explaining the things you've banged your head against till then :blush: @Hook1169 . But go ahead and start with the MDNs-- they are the most consistent resources, and some of the books kinda expect you to be familiar with stuff you'll learn there~
bitgrower
@bitgrower
Feb 19 2016 04:10
@Hook1169 -- I would DEFINITELY recommend reading the helpful hints ... sometimes you'll find the exact thing you need to pass the challenge ...
rphares
@rphares
Feb 19 2016 04:13
( @Michelle2016 , how you doing on that last bit? :blush: )
Michelle
@Michelle2016
Feb 19 2016 04:20
@rphares Well....
rphares
@rphares
Feb 19 2016 04:21
okay, for the `result=` line,
lests loks at the example
their table is called `var alpha` and they wanna get `2`, so they write `alpha[2]`
your table is called `var lookup` and you wanna get `val`, so you can write...? @Michelle2016
Michelle
@Michelle2016
Feb 19 2016 04:22
So my table is called lookup and I want to get val
lookup[val]
rphares
@rphares
Feb 19 2016 04:22
Yep,
now just put that in result...
and if its not running, id like to ask you to paste, because it appears all three major pieces (the table, the way to get val, and how to return it) are correct... so its a silly little error somewhere, and we can help look~
Michelle
@Michelle2016
Feb 19 2016 04:24
Ok...
rphares
@rphares
Feb 19 2016 04:25
really-- you are doing great :)
Michelle
@Michelle2016
Feb 19 2016 04:25
Thank you :)
This is where I am getting hung up now for some reason : Use it to lookup val and assign the associated string to the result variable.
rphares
@rphares
Feb 19 2016 04:26
thats the `result =` line,
using it to lookup val is what you did when you wrote `lookup[val]`
Michelle
@Michelle2016
Feb 19 2016 04:26
The one at the top?
rphares
@rphares
Feb 19 2016 04:26
but you are going to return result,
no,
the one after the table
at top, they have already introduced and set result,
but they set it to `var result = " "`
Michelle
@Michelle2016
Feb 19 2016 04:27
Yes, thank you I have the lookup[val] part
rphares
@rphares
Feb 19 2016 04:27
so when, at the bottom, they say `return result`
if you dont change it with the `result =` you mentioned,
all you will get is `" "`
so, after the table, before you return,
you need to reset `result=`
and put the nice part you made in there,
so that when you return, `result = what you want`
and it will give you `what you want`
(not literally setting it to those words. use what you just built to get `val`)
Michelle
@Michelle2016
Feb 19 2016 04:29
So use lookup[val]?
rphares
@rphares
Feb 19 2016 04:29
:)
thats what you want, right?
Michelle
@Michelle2016
Feb 19 2016 04:30
Yes :)
result = lookup[val];
rphares
@rphares
Feb 19 2016 04:30
:)
Michelle
@Michelle2016
Feb 19 2016 04:31

// Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup= {
"bravo": "Boston";
"charlie":"Chicago",
"delta": "Denver",
"echo" : "Easy",
"foxtrot" :"Frank"
}

lookup[val];
result = lookup[val];

// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("charlie");

rphares
@rphares
Feb 19 2016 04:32
oh,
Michelle
@Michelle2016
Feb 19 2016 04:32
oh?
rphares
@rphares
Feb 19 2016 04:32
delete the one above `result = lookup[val]`
Michelle
@Michelle2016
Feb 19 2016 04:32
Ok yes sorry
rphares
@rphares
Feb 19 2016 04:32
hes extra, yu dont need him separately :)
Michelle
@Michelle2016
Feb 19 2016 04:32
I forgot to take that out. :)
rphares
@rphares
Feb 19 2016 04:32
also, thow a semicolon after that table,
(wow, thats twice in three days that I've typed the wrong homonym... good honk :| )
``````"foxtrot" :"Frank"
}// give me a semicolon, please :)
lookup[val];// im extra, you can take me out~
result = lookup[val];``````
Michelle
@Michelle2016
Feb 19 2016 04:35

// Only change code below this line
var lookup= {
"bravo": "Boston";
"charlie":"Chicago",
"delta": "Denver",
"echo" : "Easy",
"foxtrot" :"Frank"
};

result = lookup[val];

// Only change code above this line
return result;
}

rphares
@rphares
Feb 19 2016 04:36
hmm, what am i missing, that should work...
can you refresh your page and run tests again, before we call in the big guns?
Michelle
@Michelle2016
Feb 19 2016 04:36
Yes :)
rphares
@rphares
Feb 19 2016 04:38
OH
no it shouldn't,
the bravo line,
Michelle
@Michelle2016
Feb 19 2016 04:38
Why?
rphares
@rphares
Feb 19 2016 04:38
you see whats different about the punctuation at the end, to the others?
Michelle
@Michelle2016
Feb 19 2016 04:38
AHA!!!
High Five!!!
Thank you @rphares !!!!
CamperBot
@camperbot
Feb 19 2016 04:38
michelle2016 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2879 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 19 2016 04:39
yay!! congrats :) :)
Anytime~
Michelle
@Michelle2016
Feb 19 2016 04:39
Yea!!!
rphares
@rphares
Feb 19 2016 04:39
(big take aways on this, it'll come up again--
the link to what you want and the return is super important,
Michelle
@Michelle2016
Feb 19 2016 04:39
Now I am going to study the heck out of this!!!
rphares
@rphares
Feb 19 2016 04:39
thats always one of the first things to check when you think you've done it right,
and
we used `val`, not "alpha" "charlie" etc,
so that its reusable and can get lots of stuff, not one specific string,
that'll be big from now on :)
Congrats again and enjoy your studies! :blush:
Michelle
@Michelle2016
Feb 19 2016 04:40
To make sure that it is reusable?
rphares
@rphares
Feb 19 2016 04:40
yes--
we dont wanna write things that work for specific words or values,
thats kinda wasteful, and
they may change--
Michelle
@Michelle2016
Feb 19 2016 04:41
Thank you so much for all of your help @rphares :)
CamperBot
@camperbot
Feb 19 2016 04:41
michelle2016 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: michelle2016 already gave rphares points
rphares
@rphares
Feb 19 2016 04:41
so we want to use variable s and properties and parameters and all that good stuff,
so we dont have to write a million functions, specific to every scenario
going forward, you will see this a lot (like in the very next exercise, i think :blush:) You dont wanna code strings and values specifically, its not very efficient~
anytime!
OmMinky
@OmMinky
Feb 19 2016 05:02
Hi all, I'm working on the counting cards puzzle, would an array function help? here's my code
``````var count = 0;

function cc(card) {
// Only change code below this line

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
break;
case 7:
case 8:
case 9:
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
break;
}
{ if ((card) > count)
return "bet";
} else if ((card))"hold"

return "Change Me";
var code = "formatted";``````
bitgrower
@bitgrower
Feb 19 2016 05:04
well, you could do it with an array ... kind of a matter of style ... but I think the lesson's intent is to help you become more familiar with switch statements...
you need to re-read the requirements of the challenge, though, I think ...
eeflores
@eeflores
Feb 19 2016 05:05
instead of `answer` you may want to modify `count`
bitgrower
@bitgrower
Feb 19 2016 05:06
:) @eeflores -- sometimes it's hard to know where to start ... :)
eeflores
@eeflores
Feb 19 2016 05:06
yeah ... that's one place ...
OmMinky
@OmMinky
Feb 19 2016 05:10
thx @bitgrower does that mean I could do without array?
@eeflores was your comment for me?
rphares
@rphares
Feb 19 2016 05:11
@OmMinky , yeah, it was :blush:
(you are returning `count`, not `answer`, so you need to update `count`, not `answer`...)
(You also want to increment and decrement it, not set it...)
(Maybe review the lessons on increment and decrement :blush: )
OmMinky
@OmMinky
Feb 19 2016 05:13
@rphares , will do, hmm, havent use increment, decrement much, will do thx. BRB
CamperBot
@camperbot
Feb 19 2016 05:13
omminky sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2883 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 19 2016 05:14
sure thing! there are others things to change, but step by step :)
James Minkler
@Hook1169
Feb 19 2016 05:16
This message was deleted
Blake Lieberman
@blakel11
Feb 19 2016 05:28
Has anyone completed local scope challenge in javascript? I think it is broken.
Brock
@brockwei
Feb 19 2016 05:28
where do you usually put the <script></script> in a code? whats the difference in putting it in the <body></body> or <head></head> ?
rphares
@rphares
Feb 19 2016 05:29
Collin
@collinferry
Feb 19 2016 05:35
@brockwei I believe it's better to put it <script> in the <head> tag for reasons of loading order and user experience. I'm not familiar with the technical details though.
Nikolajs Korolkovs
@NickEU
Feb 19 2016 05:44
@Dahuolong
Feb 19 2016 05:55
Ankit
@ankitrn
Feb 19 2016 05:56
Hey has anyone solved the where art thou exercise?
ichirped
@ichirped
Feb 19 2016 05:57
Does javascript have a data structure similar to hashmap where you can store <key, value>
Jon Grant
@jong649
Feb 19 2016 05:58
Hey there everyone, I'm doing the Validate Telephone Numbers exercise, and am wondering what I'm doing wrong with my RegEx test? I thought it would return false with the example I have, but it's true
``````function telephoneCheck(str) {
// Good luck!
var len = str.length;
var reg = /[)(-\d]/g;
var test = (reg.test(str));
if(len<9||len>14){
return false;
}
else
return test;
}

telephoneCheck("a555a555-5555");``````
ichirped
@ichirped
Feb 19 2016 06:00
@jong649 I haven't reached that problem yet but regex /[)(-\d]/g doesn't seem right.
Jon Grant
@jong649
Feb 19 2016 06:02
@ichirped I thought I was testing the string for 0-9, (), and -, then when found it would return true
ichirped
@ichirped
Feb 19 2016 06:02
@jong649 specially this part )(- what does it stand for ? hyphens are usually used to define a range when used within []
Jon Grant
@jong649
Feb 19 2016 06:03
@ichirped looking for the hyphen itself and parentheses
ichirped
@ichirped
Feb 19 2016 06:03
you can test your regex here : https://regex101.com/ before you apply to your code. @jong649
Jon Grant
@jong649
Feb 19 2016 06:03
I used that, and it found those characters with what I have
but it doesn't seem to be working here
ichirped
@ichirped
Feb 19 2016 06:07
Jon Grant
@jong649
Feb 19 2016 06:09
@ichirped nope, same result
bitgrower
@bitgrower
Feb 19 2016 06:09
you need to escape a - if it's within brackets
be sure to click the right regex tester ...
Jon Grant
@jong649
Feb 19 2016 06:10
@bitgrower I was using RegExr
OmMinky
@OmMinky
Feb 19 2016 06:11
``````var count = 0;

function cc(card) {
// Only change code below this line

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count = 1;
break;
case 7:
case 8:
case 9:
count = 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count= -1;
break;
}
count++;

{ if (count >0)
return "bet";
} if (count <=0)
return "hold";

return "Change Me"``````
bitgrower
@bitgrower
Feb 19 2016 06:11
not familiar with it ... but the advice still stands ... make sure the regex tester is one which is testing regexes in javascript ...
ichirped
@ichirped
Feb 19 2016 06:11
@jong649 I think @bitgrower meant the language you test the regex for
Jon Grant
@jong649
Feb 19 2016 06:12
I've tried just testing for [\d] and it still returns true, even if str is all letters
From what I've read \d is numbers 0-9
rphares
@rphares
Feb 19 2016 06:12
@OmMinky , closer!
still need to increment and decrement,
bitgrower
@bitgrower
Feb 19 2016 06:12
@jong649 -- IT DEPENDS
rphares
@rphares
Feb 19 2016 06:13
can do that using `count++` or `count += 1` @OmMinky
not count = 1
ichirped
@ichirped
Feb 19 2016 06:13
@jong649 [()\d-] matches each of them literally
rphares
@rphares
Feb 19 2016 06:13
when you do count = 1, you are setting it every time, not increasing it... @OmMinky
bitgrower
@bitgrower
Feb 19 2016 06:13
^^^^ what @ichirped said ...
Catalin Scripcariu
@CatalinScr
Feb 19 2016 06:13
@jong649 you can try this site for testing the combination of RegExp http://regexr.com/
ichirped
@ichirped
Feb 19 2016 06:13
geez why does my escape chars escape lol
bitgrower
@bitgrower
Feb 19 2016 06:13
add g to match 'em all ...
rphares
@rphares
Feb 19 2016 06:13
then, we can jump to you return-- check the string parts, @OmMinky
bitgrower
@bitgrower
Feb 19 2016 06:14
@CatalinScr -- he has been using that site ...
Jon Grant
@jong649
Feb 19 2016 06:14
So switching it to [0-9] is also returning true for letters
rphares
@rphares
Feb 19 2016 06:14
they should be capitalized, for one
OmMinky
@OmMinky
Feb 19 2016 06:14
@rphares will try, thank you, are you refering to the switch statement part?
CamperBot
@camperbot
Feb 19 2016 06:14
omminky sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
rphares
@rphares
Feb 19 2016 06:14
@OmMinky , and
CamperBot
@camperbot
Feb 19 2016 06:14
:star: 2884 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 19 2016 06:14
yep :)
Catalin Scripcariu
@CatalinScr
Feb 19 2016 06:14
@bitgrower ok. i haven't read all the messages
Jon Grant
@jong649
Feb 19 2016 06:14
``var reg = /[0-9]/g;``
rphares
@rphares
Feb 19 2016 06:14
you dont want the output to be `5Bet` for example, @OmMinky , so you will want to include a space in those returns...
scottmike0
@scottmike0
Feb 19 2016 06:15
SENPAI
@rphares
bitgrower
@bitgrower
Feb 19 2016 06:15
np @CatalinScr ... just letting you know ... :)
Jon Grant
@jong649
Feb 19 2016 06:15
Just trying to get it one step at a time, but it returns true with letters in my str
ichirped
@ichirped
Feb 19 2016 06:16
@jong649 what's your test string ?
Jon Grant
@jong649
Feb 19 2016 06:16
``````function telephoneCheck(str) {
// Good luck!
var len = str.length;
var reg = /[0-9]/g;
var test = reg.test(str);
/*if(len<9||len>14){
return false;
}
else*/
return test;
}

telephoneCheck("a5555555555");``````
bitgrower
@bitgrower
Feb 19 2016 06:16
yeah, it matches a bunch of 555555s ... :)
Jon Grant
@jong649
Feb 19 2016 06:16
I'm trying to get it to see that first a, and return false
ichirped
@ichirped
Feb 19 2016 06:17
@jong649 if you are writing a regex for telephone numbers think more about how they are formatted, what don't you want in them etc.
bitgrower
@bitgrower
Feb 19 2016 06:18
"Use test() whenever you want to know whether a pattern is found in a string" ... it finds a match, returns true
"
ichirped
@ichirped
Feb 19 2016 06:18
[0-9] matches all digits but your doesn't restrict alphabets @jong649
bitgrower
@bitgrower
Feb 19 2016 06:18
^^^ ding ding ding!!!
Jon Grant
@jong649
Feb 19 2016 06:21
@ichirped @bitgrower thanks guys, I will figure it out; I had the wrong approach
CamperBot
@camperbot
Feb 19 2016 06:21
jong649 sends brownie points to @ichirped and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 271 | @ichirped | http://www.freecodecamp.com/ichirped
:star: 577 | @bitgrower | http://www.freecodecamp.com/bitgrower
ichirped
@ichirped
Feb 19 2016 06:22
@jong649 regex are really fun. Try doing this write each thing you want to match and don't want in your pattern in words, then try to solve it one by one 1) you want to match digits, 2) allow hyphens (wherein the string) , 3) allow parenthesis (again where in the string), 4) don't allow alphabets... and so on
scottmike0
@scottmike0
Feb 19 2016 06:24
i got no idea what regex is
rphares
@rphares
Feb 19 2016 06:25
help regex
CamperBot
@camperbot
Feb 19 2016 06:25

## :point_right: js regex resources [wiki]

See also: :clipboard: Tutorials | :syringe: Testing | :soccer: Games | :newspaper: Blogs | :package: Software

scottmike0
@scottmike0
Feb 19 2016 06:25
i've been doing some ethical hacking*
rphares
@rphares
Feb 19 2016 06:25
@scottmike0 , check out the recommended links for regex, they are super helpful,
bitgrower @bitgrower did that challenge in 3 steps ... just seemed more comprehensible that way ... :)
bitgrower
@bitgrower
Feb 19 2016 06:26
reggae ? for ethical hacking ?
scottmike0
@scottmike0
Feb 19 2016 06:26
@rphares i see
@bitgrower no
bitgrower
@bitgrower
Feb 19 2016 06:26
oh, for the actual music ...
rphares
@rphares
Feb 19 2016 06:26
bitgrower @bitgrower likes reggae, too ...
scottmike0
@scottmike0
Feb 19 2016 06:26
@bitgrower actual network stuff and penetration for websites :P
rphares
@rphares
Feb 19 2016 06:27
(whoopsies, edited it. auto corrupted again... @bitgrower )
OmMinky
@OmMinky
Feb 19 2016 06:27
@rphares , feeling closer, for example, I'm actually not getting an error sign. Here's the new version
``````
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
count = 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--;
break;
}

{ if (count >0)
return ((count) + "bet");
} if (count <=0)
return ((count) + "hold");

return "Change Me";``````
bitgrower @bitgrower loves networks ... spent years doing assy language on a world wide data comm network ... :)
ichirped
@ichirped
Feb 19 2016 06:27
back to my own problem universe, which I came to solve here ! Roman Numeral Converter !!! I want to use a hashmap like data structure but not able to
Ian Barker
@IanBarkerDev
Feb 19 2016 06:27
github
Well.
That was a google search that failed.
rphares
@rphares
Feb 19 2016 06:28
much closer!
bitgrower
@bitgrower
Feb 19 2016 06:28
so what is reggae, in this context ?
@ichirped -- hashmap == associative array -- 'tis possible, me thinks ...
rphares
@rphares
Feb 19 2016 06:28
now, next is the return, @OmMinky :point_up: February 19, 2016 1:13 PM :point_up: February 19, 2016 1:14 PM :point_up: February 19, 2016 1:14 PM
bitgrower
@bitgrower
Feb 19 2016 06:29
I just used arrays ... :)
ichirped
@ichirped
Feb 19 2016 06:29
hmm @bitgrower
rphares
@rphares
Feb 19 2016 06:29
(and, also, be sure to delete the extra change me return, @OmMinky )
bitgrower
@bitgrower
Feb 19 2016 06:30
but ... a regular old hashmap/assoc array would be welcome ... LOL ... trying to do someting like that with Exact Change ... taint workin'
ichirped
@ichirped
Feb 19 2016 06:30
@bitgrower how did you match it with correct roman number ?
bitgrower
@bitgrower
Feb 19 2016 06:30
if statements ... not an associative array ...
ichirped
@ichirped
Feb 19 2016 06:30
@bitgrower the only thing I can think of is like bunch of if conditions, which doesn't seem right :(
bitgrower
@bitgrower
Feb 19 2016 06:31
let me go look ... think I just used if statements (I was a little sick of the problem at the time, tbh ... )
especially since I don't know how to create V's with bars on top ... :) ... so it felt incomplete ... :)
ichirped
@ichirped
Feb 19 2016 06:32
so if condition for 1, 4, 5, 9, 10, 49, 50, 99, 100, ....1000
Markus Kiili
@Masd925
Feb 19 2016 06:32
@ichirped Why not just use two arrays. One with numbers and the other with corresponding roman numerals.
bitgrower
@bitgrower
Feb 19 2016 06:32
yeah ... that's kinda what I did, @Masd925 -- I seem to recall having 2 arrays ... LOL ...
ichirped
@ichirped
Feb 19 2016 06:32
@bitgrower I'm not even thinking of huge numbers just yet... pretty sick of this problem already !! pulls hair, screams
Markus Kiili
@Masd925
Feb 19 2016 06:33
@bitgrower I even did a one-liner on Roman but it was not pretty.
ichirped
@ichirped
Feb 19 2016 06:33
@Masd925 and then indexOf() I believe ... sounds good, let me go try it out, thanks
CamperBot
@camperbot
Feb 19 2016 06:33
ichirped sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 996 | @masd925 | http://www.freecodecamp.com/masd925
bitgrower
@bitgrower
Feb 19 2016 06:33
3 arrays, 4 if statements ... <<-- bitgrower's solution
ichirped
@ichirped
Feb 19 2016 06:34
@bitgrower hmm... let me try ! thanks !!
CamperBot
@camperbot
Feb 19 2016 06:34
ichirped sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 578 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 19 2016 06:35
lol ... it's late enough I don't even understand my own solution atm ... guess I'll have to go back and comment it ...
zhouxh
@zhouxh
Feb 19 2016 06:35
``````function convert(num) {
var arr =String(num).split('');
var re = "";
console.log(arr);
if(arr.length>0){
var g = arr.splice(arr.length-1);
switch(Number(g)){
case 1:
re = 'I';
break;
case 2:
re = 'II';
break;
case 3:
re = 'III';
break;
case 4:
re = 'IV';
break;
case 5:
re = 'V';
break;
case 6:
re = 'VI';
break;
case 7:
re = 'VII';
break;
case 8:
re = 'VIII';
break;
case 9:
re = 'IX';
break;
}
}
if(arr.length>0){
var s = arr.splice(arr.length-1);
switch(Number(s)){
case 1:
re = 'X'+re;
break;
case 2:
re = 'XX'+re;
break;
case 3:
re = 'XXX'+re;
break;
case 4:
re = 'XL'+re;
break;
case 5:
re = 'L'+ re;
break;
case 6:
re = 'LX'+re;
break;
case 7:
re = 'LXX'+re;
break;
case 8:
re = 'LXXX'+re;
break;
case 9:
re = 'XC'+re;
break;
}
}
if(arr.length>0){
var b = arr.splice(arr.length-1);
switch(Number(b)){
case 1:
re = 'C'+re;
break;
case 2:
re = 'CC'+re;
break;
case 3:
re = 'CCC'+re;
break;
case 4:
re = 'CD'+re;
break;
case 5:
re = 'D'+ re;
break;
case 6:
re = 'DC'+re;
break;
case 7:
re = 'DCC'+re;
break;
case 8:
re = 'DCCC'+re;
break;
case 9:
re = 'CM'+re;
break;
}
}
if(arr.length>0){
var q = arr.splice(0);
if(Number(q)>0){
for (var i=0;i<Number(q) ;i++)
{
re ='M'+re;
}
}
}

return re;

}

convert(36);``````
this is for "Roman Numeral Converter"
are there other simple way?
bitgrower
@bitgrower
Feb 19 2016 06:36
@zhouxh -- as we were discussing ... use arrays
@Masd925 -- I can imagine a 1 liner for that one would look pretty ugly ...
there are some problems that I just create arrays and they become easy ... but I always feel like I'm cheating ... :)
ichirped
@ichirped
Feb 19 2016 06:37
@zhouxh that seems like a brute force approach. I'm sure there are better solutions out there
Markus Kiili
@Masd925
Feb 19 2016 06:37
@bitgrower Solution is quite simple with .reduce(), but stuffing it on one line makes it bad.
@ichirped Iterating over the array of numbers is a better idea than indexOf.
zhouxh
@zhouxh
Feb 19 2016 06:39
thanks @bitgrower @ichirped
CamperBot
@camperbot
Feb 19 2016 06:39
zhouxh sends brownie points to @bitgrower and @ichirped :sparkles: :thumbsup: :sparkles:
:star: 272 | @ichirped | http://www.freecodecamp.com/ichirped
:star: 579 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 19 2016 06:41

ah ... I am far from a reduce master ... I've tried taking working things and putting them into reduce without much luck .. :)

My reading assignment is to read ch 5 in eloquent js ... I think I heard one of the FCC team say it helped them a lot (after reading it 5 times ... LOL.)

ichirped
@ichirped
Feb 19 2016 06:41
@Masd925 ahh ok. Will use that, thanks!
bitgrower
@bitgrower
Feb 19 2016 06:41
@ichirped -- think "number systems"
Markus Kiili
@Masd925
Feb 19 2016 06:42
@ichirped Just start the iteration with the largest number etc.
Bryce Turner
@AbryceT
Feb 19 2016 06:43
nesting loops help
ichirped
@ichirped
Feb 19 2016 06:43
@bitgrower yeah i tried to do this test = num % 10 in regards to that, getting the number from right to left
bitgrower
@bitgrower
Feb 19 2016 06:43
actually, now as I look at my solution ... it's pretty patterned ... I think all my if statements could be put into a function and then just call the function 4 times ... :)
or 3 ... probably 3 ... 1 for each array ...
Bryce Turner
@AbryceT
Feb 19 2016 06:45
``````function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++)
console.log(arr[i][j]);
}
// Only change code above this line
return product;

}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);``````
bitgrower
@bitgrower
Feb 19 2016 06:45
or maybe not ... I think it would look a little ugly that way, tbh ...
too many exceptions ...
zhouxh
@zhouxh
Feb 19 2016 06:45
``````function convert(num) {
var arr =String(num).split('');
var garr = ['','I','II','III','IV','V','VI','VII','VIII','IX'];
var sarr = ['','X','XX','XXX','XL','L','LX','LXX','LXXX','XC'];
var barr = ['','C','CC','CCC','CD','D','DC','DCC','DCCC','CM'];
var re = "";
if(arr.length>0){
var g = arr.splice(arr.length-1);
re =  garr[Number(g)] + re;
}
if(arr.length>0){
var s = arr.splice(arr.length-1);
re =  sarr[Number(s)] + re ;
}
if(arr.length>0){
var b = arr.splice(arr.length-1);
re =  barr[Number(b)] + re ;
}
if(arr.length>0){
var q = arr.splice(0);
if(Number(q)>0){
for (var i=0;i<Number(q) ;i++)
{
re ='M'+re;
}
}
}

return re;

}

convert(36);``````
bitgrower
@bitgrower
Feb 19 2016 06:46
does that get you the right answer, @zhouxh ?
Markus Kiili
@Masd925
Feb 19 2016 06:46
@zhouxh It is enough to consider the basis of roman numerals 1000,900,500,...
zhouxh
@zhouxh
Feb 19 2016 06:47
yes @bitgrower
bitgrower
@bitgrower
Feb 19 2016 06:48
yeah, the String(num) would have been something I thought about doing, but I didn't know how to do it that cleanly ... so I opted for a different solution ... nice job!
zhouxh
@zhouxh
Feb 19 2016 06:49
:smile:
ichirped
@ichirped
Feb 19 2016 06:49
does String(num) vs. var arr = num.toString().split(''); make any difference
that's what I'm doing.
@zhouxh
bitgrower
@bitgrower
Feb 19 2016 06:50
@ichirped -- I think @zhouxh 's is a bit cleaner ...
zhouxh
@zhouxh
Feb 19 2016 06:51
yeah,i will try @ichirped
ichirped
@ichirped
Feb 19 2016 06:52
@bitgrower @zhouxh now I remember ... performance wise casting an int to string is much faster than .toString
zhouxh
@zhouxh
Feb 19 2016 06:53
:smile:
bitgrower
@bitgrower
Feb 19 2016 06:53
that part I don't remember, @ichirped -- it just was 1 fewer function calls ...
@AbryceT -- okay, so you've pulled up the numbers and you need a product ... what to you need to do, then ?
ichirped
@ichirped
Feb 19 2016 06:54
1 fewer function calls === better performance @bitgrower lol
Bryce Turner
@AbryceT
Feb 19 2016 06:55
@bitgrower Multiply the product by the numbers?
bitgrower
@bitgrower
Feb 19 2016 06:55
okay ... these 2 things sounds like 1 function a piece: "performance wise casting an int to string is much faster than .toString"
@Abryce -- why not try it out and see ?
Markus Kiili
@Masd925
Feb 19 2016 06:56
@bitgrower @ichirped I can post my .reduce() solution if you like. Probably won't spoil your work because you used other techniques.
bitgrower
@bitgrower
Feb 19 2016 06:56
should I shield my eyes ? :)
is this programming pornography ?
ichirped
@ichirped
Feb 19 2016 06:56
@Masd925 noooo
Eduardo Garcia
@eagarcia8
Feb 19 2016 06:56
Can I get a clue on why the following doesn't work for Seek and Destroy? I keep getting the first argument as the result:
``````function destroyer(arr) {

var mainArray = arguments[0];
var filteredArray = [];

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

for (e=1; e < (arguments.length); e++) {

filteredArray = mainArray.filter(function(val) {

if (val == arguments[e]) {
return false;
}
return true;

});
}
}

return filteredArray;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````
ichirped
@ichirped
Feb 19 2016 06:57
@Masd925 please don't, I haven't completed yet !!!!
bitgrower
@bitgrower
Feb 19 2016 06:57
I think that means @ichirped hasn't been passed to "where are thou"
Markus Kiili
@Masd925
Feb 19 2016 06:57
@ichirped Ok. Later... :)
bitgrower
@bitgrower
Feb 19 2016 06:57
This message was deleted
bitgrower This message was deleted
ichirped
@ichirped
Feb 19 2016 06:58
@bitgrower yes ! I haven't... I just talk a lot... should get back to it and reach there
Markus Kiili
@Masd925
Feb 19 2016 06:58
@eagarcia8 The filter callback function has its own arguments object (arguments[e] is not accessing destroyers arguments). Also it is better to filter only once and put the logic inside the callback function.
bitgrower @bitgrower realizes she is too tired to not jump to conclusions ... :)
OmMinky
@OmMinky
Feb 19 2016 07:00
@rphares , are you saying I should use another phrase instead of return? I'm looking at the alternatives to "return" since this exits the function, when maybe want to continue on a loop, and am coming up empty, would "replace" be useful?
bitgrower
@bitgrower
Feb 19 2016 07:01
@eagarcia8 -- it makes it a bit harder to read your code when you don't use the named argument in your function ... just sayin'
Markus Kiili
@Masd925
Feb 19 2016 07:02
@eagarcia8 You don't need to loop through the array arr. Just return arr.filter(...); Filter will do the iterating over the arr elements.
bitgrower @bitgrower just realized a month ago she wouldn't have had a clue to understanding what she just said ...
Bryce Turner
@AbryceT
Feb 19 2016 07:04
@bitgrower
```
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++)
product = [i][j] * 1;
}
It's not quite right
coming up null
bitgrower
@bitgrower
Feb 19 2016 07:05
what is the number you just had ?
Bryce Turner
@AbryceT
Feb 19 2016 07:06
1
bitgrower
@bitgrower
Feb 19 2016 07:06
console.log(arr[i][j]); <---- that thing ...
Bryce Turner
@AbryceT
Feb 19 2016 07:06
Ah yeah
bitgrower
@bitgrower
Feb 19 2016 07:07
[i][j] are indexes ... they gotta index into sumthin' ...
(unless you're doing one of the later challenges, where you have to add up the indexes ... but that's not the challenge here ...
put a js after your backticks,, and 3 backticks after your code & you'll be golden @AbryceT
Bryce Turner
@AbryceT
Feb 19 2016 07:08
No I'm doing the Nesting Loops
``````function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++)
console.log (product = [i][j] * 1);
}

// Only change code above this line
return product;

}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);``````
bitgrower
@bitgrower
Feb 19 2016 07:08
right -- 99%of the time (in my experience) -- you index into an array to get the the values in the array ...
[i] & [j] are not indexing into anything @AbryceT
here, they are ... ===> console.log(arr[i][j]); <---- that thing ... the thing in the parentheses ...
Bryce Turner
@AbryceT
Feb 19 2016 07:10
Ok
bitgrower
@bitgrower
Feb 19 2016 07:11
but you also have to create a cumulative multiple ... that is, you have to multiply all the numbers together ...
Dulshani Gunawardhana
@dshgna
Feb 19 2016 07:11
``````function every(collection, pre) {
var falsy =[0, null, undefined, "", NaN];
for(var i=0; i<collection.length; i++){
if (!collection[i].hasOwnProperty(pre)||falsy.indexOf(collection[i][pre])>-1){
return false;
}
}
return true;
}``````
This passes all test cases other than the NaN case and I can't figure out why. The NaN case is `every([{"single": "double"}, {"single": NaN}], "single");`
bitgrower
@bitgrower
Feb 19 2016 07:11
and what you are doing right now won't do that, even if you use "that' thing ...
Bryce Turner
@AbryceT
Feb 19 2016 07:12
@bitgrower Ok let me work on it a bit then...
bitgrower
@bitgrower
Feb 19 2016 07:12
@dshgna -- want a perfect legitimate shortcut to this challenge ...
bitgrower @bitgrower can't help herself ... go read the "helpful hints" pages ...
Markus Kiili
@Masd925
Feb 19 2016 07:13
@dshgna NaN is special because NaN===NaN is false. Spoils your solution.
bitgrower
@bitgrower
Feb 19 2016 07:13
you will find a golden nugget among them
...but reading the docs is good for him, @Masd925 ... :)
Dulshani Gunawardhana
@dshgna
Feb 19 2016 07:14
@Masd925 oh! So I'll have to use a special case for NaN
Markus Kiili
@Masd925
Feb 19 2016 07:14
@bitgrower Fix their solution first and then spoil it...
bitgrower @bitgrower learned the hard way that reading the docs -- especially the "helpful hints" docs are, indeed helpful ...
Bryce Turner
@AbryceT
Feb 19 2016 07:16
@bitgrower Thank you sir! Got it!
CamperBot
@camperbot
Feb 19 2016 07:16
abrycet sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 580 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 19 2016 07:17
YAY !!!! Now .. do you understand it ?
array are your friends ... as are regexes ... love them, treat them well, and you will be a js jedi knight
well, a bit of objects & functional programming would help, too ... so, let me re-phrase -- well on your way to becoming a js jedi knight .
Markus Kiili
@Masd925
Feb 19 2016 07:19
@dshgna You can add a condition to your if that checks for NaN and it works then. You can use value!==value to check for NaN, because NaN is the only value that is not equal to itself.
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:21

Here is an updated version of my solution for Seek and Destroy:

``````function destroyer(arr) {

var args = (arguments.length === 1?[arguments[0]]:Array.apply(null, arguments));
var mainArray = args[0];

args.shift();

return mainArray.filter(function(val) {

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

if (val == args[i]) {
return false;
}

return true;
}
});
}

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

I have a feeling im using filter incorrectly.

Markus Kiili
@Masd925
Feb 19 2016 07:22
@eagarcia8 That is a truly terrible way to turn arguments into an array :)
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:22
I copied it from the arguments page
The part I get stuck on is the evaluation of filter, it returns [1,3,1,3]
Markus Kiili
@Masd925
Feb 19 2016 07:23
``````var args = [];
for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);``````
Dulshani Gunawardhana
@dshgna
Feb 19 2016 07:24
@Masd925 I went the value!==value way simply because it was new :D
@Masd925 Thanks!
CamperBot
@camperbot
Feb 19 2016 07:24
dshgna sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 997 | @masd925 | http://www.freecodecamp.com/masd925
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:24
I'll look at it later, I don't even know what it does but it does convert it to an array which I need for evaluating in the filter.
The problem I have is val == args[i]
It seems correct, but it returns an array with [1,3,1,3] which I don't get.
budimanfix
@budimanfix
Feb 19 2016 07:27

@Masd925 Hello.. What decimal meaning here bro? : function myFunction() {

// Only change code below this line.
Math.random();
return 10;

/

Markus Kiili
@Masd925
Feb 19 2016 07:27
@eagarcia8 Yeah. I am not blaming you. Apply doesn't really work when turning arguments into an array and the flaw is fixed with crappy ternary trick. Really bad code when there is a simple for loop that does it.
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:30
Markus Kiili
@Masd925
Feb 19 2016 07:30
@eagarcia8 The loop logic inside is a bit wrong. One return is out of place.
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:30
@Gerhard29046 ?
Leonel Tejeda
@devbuilt
Feb 19 2016 07:31
nesting for loops
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:32
@eagarcia8 i am at Counting Cards but got stuck look at my code:
``````var count = 0;

function cc(card) {
// Only change code below this line
switch(cc)
{
case 2: count++; console.log(cc+" Bet");
break;

case 3: count++;
break;

case 4: count++;
break;

case 5: count++;
break;

case 6: count++;
break;
//-----------
case 7:count=0;
break;
case 8: count=0;
break;
case 9: count++;
break;
}

// Only change code above this line
}

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');``````
Ivan Perez
@joannesalfa
Feb 19 2016 07:33
@Gerhard29046 don't use count=0 because it resets to 0
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:35
@Gerhard29046 Each card has a value of 0, 1, or +1, you need to add to or remove count, not just by ++.
*0, 1, -1
OmMinky
@OmMinky
Feb 19 2016 07:36
@rphares thx! saved me some zzz, you're everything + a 'lil sparkle.
CamperBot
@camperbot
Feb 19 2016 07:36
omminky sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2886 | @rphares | http://www.freecodecamp.com/rphares
OmMinky
@OmMinky
Feb 19 2016 07:36
got it
budimanfix
@budimanfix
Feb 19 2016 07:37

Any one can correct what i missing here : function myFunction() {

// Only change code below this line.
Math.random(1);
return 10;

Afaaq Alam
@afaaqalam
Feb 19 2016 07:38
@budimanfix your function here always returns 10
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:38
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:38
@Masd925 I don't see the missplaced return, I even did if-else but ends the same:
``````for (i=0; i < args.length; i++) {

if (val == args[i]) {
return false;
}else {
return true;
}
}``````
Markus Kiili
@Masd925
Feb 19 2016 07:39
@eagarcia8 Your code is returning true based on one argument.
It must come after checking all the arguments.
Afaaq Alam
@afaaqalam
Feb 19 2016 07:39
@budimanfix
```function myFunction() { // Only change code below this line. return Math.random(1)*10;```
@budimanfix
``````function myFunction(){
return Math.random(1) * 10;
}``````
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:40
@Masd925 hi what is the code to add something if not count++
budimanfix
@budimanfix
Feb 19 2016 07:41
@afaaqalam Thank you :+1:
CamperBot
@camperbot
Feb 19 2016 07:41
budimanfix sends brownie points to @afaaqalam :sparkles: :thumbsup: :sparkles:
:star: 277 | @afaaqalam | http://www.freecodecamp.com/afaaqalam
Ivan Perez
@joannesalfa
Feb 19 2016 07:41
@Gerhard29046 I think he means you shouldn't use count++ for all cases, count++ works fine
you should try count+=1 count+=0 and count-=1
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:42
@joannesalfa thanks but how do you add something
CamperBot
@camperbot
Feb 19 2016 07:42
gerhard29046 sends brownie points to @joannesalfa :sparkles: :thumbsup: :sparkles:
:star: 417 | @joannesalfa | http://www.freecodecamp.com/joannesalfa
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:42
@joannesalfa thanks
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:43
@Masd925 Wait are you telling me the first return ends the for loop?
Ivan Perez
@joannesalfa
Feb 19 2016 07:43
@Gerhard29046 optionally you can use count++ and count--
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:43
``````You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.

Example Output
"-3 Hold"
"5 Bet"

Hint
Do NOT reset count to 0 when value is 7, 8, or 9.``````
Ivan Perez
@joannesalfa
Feb 19 2016 07:43
@Gerhard29046 in case of 0, you can skip cases or just add count+=0;
Markus Kiili
@Masd925
Feb 19 2016 07:43
@eagarcia8 You return false if you find a match and if no match, return true. Basic loop logic.
Ivan Perez
@joannesalfa
Feb 19 2016 07:44
@Gerhard29046 yes, you need to add if/else to compare count if is less than 0, it should display "hold", otherwise, more than 0 of count, then "bet"
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:45
@joannesalfa so i mustn't use switch/case statement
Ivan Perez
@joannesalfa
Feb 19 2016 07:45
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:45
``````function cc(card) {
// Only change code below this line
switch(cc)
{
case 2: count+=1; console.log(cc+" Bet");
break;

case 3: count+=1; console.log(cc+" Bet");
break;

case 4: count+=1; console.log(cc+" Bet");
break;

case 5: count+=1; console.log(cc+" Bet");
break;

case 6: count+=1; console.log(cc+" Bet");
break;
//-----------
case 7:count=0;
break;
case 8: count=0;
break;
case 9: count++;
break;
}``````
is this right
Ivan Perez
@joannesalfa
Feb 19 2016 07:46
@Gerhard29046 don't repeat yourself
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:47
@joannesalfa if i run this i dont get any correct marks
Ivan Perez
@joannesalfa
Feb 19 2016 07:47
I would use
``````if (count < 0){
return count + " hold";
}
else{
return count + " bet";
}``````
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:48
i shall see if it works
@joannesalfa you are confusing me, must i still use switch and case or must i rather use if/else statement
or both of them
Ivan Perez
@joannesalfa
Feb 19 2016 07:50
if/else is just for return
not inside of cases
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:51
@joannesalfa if else must come after the closing bracket of switch statement
Ivan Perez
@joannesalfa
Feb 19 2016 07:51
I have go to now, anyway I leave my code, but do not try to copy and paste, try to understand it
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:51
Ivan Perez
@joannesalfa
Feb 19 2016 07:52
``````function cc(card) {
switch (card){
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count--;
break;
}

if ( count > 0){
return count+" Bet";
}
else{
return count+" Hold";
}
}``````
Gerhard van Wijk
@Gerhard29046
Feb 19 2016 07:53
oh ok thanks i understand what you mean with the if and else thanks @joannesalfa
CamperBot
@camperbot
Feb 19 2016 07:53
gerhard29046 sends brownie points to @joannesalfa :sparkles: :thumbsup: :sparkles:
:warning: gerhard29046 already gave joannesalfa points
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:54
@Masd925 Thanks Masd925, figured out that the logic was only checking the first argument. Appreciate just giving me clues and not spoiling it =)
CamperBot
@camperbot
Feb 19 2016 07:54
eagarcia8 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 998 | @masd925 | http://www.freecodecamp.com/masd925
Heidi Gay
@heidigay
Feb 19 2016 07:54
hey guys... i'm currently stuck on the profile lookup challenge
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:55
@heidigay What does your code look like?
Heidi Gay
@heidigay
Feb 19 2016 07:55
Markus Kiili
@Masd925
Feb 19 2016 07:56
@eagarcia8 You can also use indexOf inside the callback instead of looping.
Heidi Gay
@heidigay
Feb 19 2016 07:57
right sorry, i was trying something that didn't work, last lines should be
else {
return "No such contact";
}}
@Masd925 what's indexOf ?
Eduardo Garcia
@eagarcia8
Feb 19 2016 07:59
@Masd925 How would you use indexOf if there is a different amount of arguments every time?
Eduardo Garcia
@eagarcia8
Feb 19 2016 08:04
@heidigay I don't know what contacts[i].length returns
@Masd925 But you can try to check if it exists instead of looping through each property and matching it to the argument.
Heidi Gay
@heidigay
Feb 19 2016 08:11
@eagarcia8 right thanks
CamperBot
@camperbot
Feb 19 2016 08:11
heidigay sends brownie points to @eagarcia8 :sparkles: :thumbsup: :sparkles:
:star: 276 | @eagarcia8 | http://www.freecodecamp.com/eagarcia8
Manan Kalra
@manankalra
Feb 19 2016 08:11
'''
CamperBot
@camperbot
Feb 19 2016 08:11
Manan Kalra
@manankalra
Feb 19 2016 08:11

'''
function titleCase(str) {
var array = str.split(" ");
var random = [];
var randomUpper = [];
for(var i=0;i<array.length;i++){
random.push(array[i].split(""));
}
for(var j=0;j<random.length;j++){
random[j][0].toUpperCase();
}
return random;
}

titleCase("abcd efgh ijkl");
'''

CamperBot
@camperbot
Feb 19 2016 08:11
Manan Kalra
@manankalra
Feb 19 2016 08:11
Can anyone tell me why my second for loop isn;t working?
``````function titleCase(str) {
var array = str.split(" ");
var random = [];
var randomUpper = [];
for(var i=0;i<array.length;i++){
random.push(array[i].split(""));
}
for(var j=0;j<random.length;j++){
random[j][0].toUpperCase();
}
return random;
}

titleCase("abcd efgh ijkl");``````
Dulshani Gunawardhana
@dshgna
Feb 19 2016 08:14

suppose I want to reference a local variable declared inside a for loop in the ajax callback.
For example,

``````  for(var i=0; i<channels.length; i++){
var url = "https://api.twitch.tv/kraken/streams/" + channels[i] + "?callback=?";
\$.getJSON(url, function(data) {
console.log(channels[i]);
});
}``````

here `console.log(channels[i]);` returns as undefined. I understand that this issue is because AJAX is making asyn calls, but anyway to get around it?

Nikunj Keswani
@stirpot
Feb 19 2016 08:15
why doesn't it work?
i even added var val = charlie
Eduardo Garcia
@eagarcia8
Feb 19 2016 08:17
@stirpot Try lookup["charlie"]
@stirpot Also the keys need to be in quotes: "charlie" : "Adams"
Ashley
@asberrie
Feb 19 2016 08:20
@mananKalra i'll check that out, thx
CamperBot
@camperbot
Feb 19 2016 08:20
asberrie sends brownie points to @manankalra :sparkles: :thumbsup: :sparkles:
:star: 256 | @manankalra | http://www.freecodecamp.com/manankalra
scottmike0
@scottmike0
Feb 19 2016 08:21
you can easily reduce arrays by simply making a new array
greg
@wearenotgroot
Feb 19 2016 08:23
@mananKalra
``````unction titleCase(str) {
var array = str.split(" ");
var random = [];
var randomUpper = [];
for(var i=0;i<array.length;i++){
random.push(array[i].split(""));
}
for(var j=0;j<random.length;j++){
random[j][0].toUpperCase(); //<-----------you forgot to set the value------->random[j][0]=random[j][0].toUpperCase();
}
return random;
}

titleCase("abcd efgh ijkl");``````
@Chichavl
Feb 19 2016 08:25
Hi, can anyone help me with callback function in TwitchTV, I want to use it for a delay for api call. But It doesnt stops and I recieve empty `streamersObj`
``````var streamers = ["freecodecamp", "storbeck", "terakilobyte", "habathcx","RobotCaleb","thomasballinger","noobs2ninjas","beohoff","brunofin","comster404", "esl_sc2"];

function apiCall(callback) {
var streamersObj = [];
streamers.forEach(function(element, index, array) {
var obj = {};
obj.name = element;
\$.getJSON('https://api.twitch.tv/kraken/streams/'+ element +'?callback=?', function(data) {
//console.log(data);
if (data.status == "422") {
obj.status = "Closed";
}
else if (data.stream == null) {
obj.status = "Offline";
obj.url = "http://twitch.tv/"+ element;
}
else if (data.stream.channel.status) {
obj.status = "Online";
obj.channelStatus = data.stream.channel.status;
obj.url = data.stream.channel.url;
}
//console.log(obj);
streamersObj.push(obj);
});
});
callback(streamersObj);
}

apiCall(function(streamersObj) {
console.log(streamersObj);
var html = "";
html = "<ul>";
streamersObj.forEach(function(obj) {
html += "<a href=" + obj.url + ' target="_blank"><li><b>' + obj.name + "</b>"+obj.status+"<br>" + obj.channelStatus + "</li></a>";
});
html += "<ul>";
\$("#result").html(html);
});
});``````
Manan Kalra
@manankalra
Feb 19 2016 08:28
@wearenotgroot Got it! Thanks! :)
CamperBot
@camperbot
Feb 19 2016 08:28
manankalra sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 894 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
scottmike0
@scottmike0
Feb 19 2016 08:30
@Chichavl it most likely is because you are having a += for html twice, there probably is a more easier way of going about doing that
@Chichavl
Feb 19 2016 08:32
@scottmike0 I tried making `streamersObj` global and then pasted code with `html` in console - it worked fine
@scottmike0 I stuck in pause and waiting data to retrive - wanted to use callback for it, maybe you can advice another way
Timofey Votyakov
@tvotyakov
Feb 19 2016 08:37

@dshgna you can do it something like this

``````  for(var i=0; i<channels.length; i++){
var url = "https://api.twitch.tv/kraken/streams/" + channels[i] + "?callback=?";
var j = i;
\$.getJSON(url, function(data) {
console.log(channels[j]);
});
}``````

or

``````  for(var i=0; i<channels.length; i++){
var url = "https://api.twitch.tv/kraken/streams/" + channels[i] + "?callback=?";
var curChannel = channels[i];
\$.getJSON(url, function(data) {
console.log(curChannel);
});
}``````
budimanfix
@budimanfix
Feb 19 2016 08:41

Hi folksvar car = {
"wheels":4,
"engines":1,
"seats":5
};

var motorBike = {
, how to do this code:

Hello folks, how to do this challenge : var car = {
"wheels":4,
"engines":1,
"seats":5
};

var motorBike = {

Ashley
@asberrie
Feb 19 2016 08:43
what's a callback function? is it just a function that is called inside of another function?
i've looked it up and read some things about it, but am still generally confused :S
scottmike0
@scottmike0
Feb 19 2016 08:47
@asberrie its exactly how you would think it is, a function that is used to a variable or something similar to this example http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/
Timofey Votyakov
@tvotyakov
Feb 19 2016 08:48
@dshgna sorry, my previous suggestions were not right. This will work
``````  for(var i=0; i<channels.length; i++){
var url = "https://api.twitch.tv/kraken/streams/" + channels[i] + "?callback=?";
\$.getJSON(url, function(i) {
return function (data) {
console.log(channels[i]);
}
}(i));
}``````
Ashley
@asberrie
Feb 19 2016 08:49
thanks, i'll see if those help.... I was reading the javascriptissexy.com one, but I have a hard time understanding something when the thing in question is being used to describe itself... :S
Timofey Votyakov
@tvotyakov
Feb 19 2016 08:52

@asberrie

what's a callback function? is it just a function that is called inside of another function?

yes, you're right. callback function is just a function that will called someway later: inside of another function, or as an event handler, or then some data will be ready (in ajax calls, for example).

Ashley
@asberrie
Feb 19 2016 08:56
Thanks all! I found this page (http://stackoverflow.com/questions/9596276/how-to-explain-callbacks-in-plain-english-how-are-they-different-from-calling-o) [answers 2 & 3] and @tvotyakov's explanation the easiest to understand.
CamperBot
@camperbot
Feb 19 2016 08:56
asberrie sends brownie points to @tvotyakov :sparkles: :thumbsup: :sparkles:
:star: 116 | @tvotyakov | http://www.freecodecamp.com/tvotyakov
@Chichavl
Feb 19 2016 08:56
I made pause through setTimeout. It is dump, but works. If any one know better solution please advice me.
``````var streamers = ["freecodecamp", "storbeck", "terakilobyte", "habathcx","RobotCaleb","thomasballinger","noobs2ninjas","beohoff","brunofin","comster404", "esl_sc2"];
var streamersObj = [];

function display() {
console.log(streamersObj);
var html = "";
html = "<ul>";
streamersObj.forEach(function(obj) {
html += "<a href=" + obj.url + ' target="_blank"><li><b>' + obj.name + "</b>"+obj.status+"<br>" + obj.channelStatus + "</li></a>";
});
html += "<ul>";
\$("#result").html(html);
}

streamers.forEach(function(element, index, array) {
var obj = {};
obj.name = element;
\$.getJSON('https://api.twitch.tv/kraken/streams/'+ element +'?callback=?', function(data) {
//console.log(data);
if (data.status == "422") {
obj.status = "Closed";
}
else if (data.stream == null) {
obj.status = "Offline";
obj.url = "http://twitch.tv/"+ element;
}
else if (data.stream.channel.status) {
obj.status = "Online";
obj.channelStatus = data.stream.channel.status;
obj.url = data.stream.channel.url;
}
//console.log(obj);
streamersObj.push(obj);
});
});
timer = setTimeout("display()", 1000);

});``````
Dulshani Gunawardhana
@dshgna
Feb 19 2016 08:58
@tvotyakov: Thank you. Do you mind explaining why the final way works? I'm confused there :(
CamperBot
@camperbot
Feb 19 2016 08:58
dshgna sends brownie points to @tvotyakov :sparkles: :thumbsup: :sparkles:
:star: 117 | @tvotyakov | http://www.freecodecamp.com/tvotyakov
Alessandro Giordo
@bovas85
Feb 19 2016 09:05
find seek and destroy
CamperBot
@camperbot
Feb 19 2016 09:05

find seek and destroy

Timofey Votyakov
@tvotyakov
Feb 19 2016 09:05
@dshgna amm, it will be a little tricky to me, because English is not my native language, and closures are not an easy theme :) Try to read this http://javascriptissexy.com/understand-javascript-closures-with-ease/ Especially, this part: "Closures’ Rules and Side Effects: Closures store references to the outer function’s variables". I think it is better way to understand
Dulshani Gunawardhana
@dshgna
Feb 19 2016 09:08
@tvotyakov Thanks again! I'll go through it. I've never worked with closures before.
CamperBot
@camperbot
Feb 19 2016 09:08
dshgna sends brownie points to @tvotyakov :sparkles: :thumbsup: :sparkles:
:warning: dshgna already gave tvotyakov points
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:09
@dshgna hope it will help
zhouxh
@zhouxh
Feb 19 2016 09:12
``````function fearNotLetter(str) {
var result = "";
var found = false;
for(i=0;i<str.length;i++){
if(i+1<str.length){
if(str.charCodeAt(i+1)>str.charCodeAt(i)+1){
for(var j =str.charCodeAt(i)+1;j<str.charCodeAt(i+1);j++){
result += String.fromCharCode(j);
found =true;
}
}
}
}
if(Boolean(found)){
return result;
} else return undefined;
}
fearNotLetter("abce");``````
this is for "Missing letters".
are there a better way?
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:14
@Chichavl sorry, but why did you want to pause something? why don't you just display your links inside your getJson callback?
@Chichavl The main problem of your solution is that if \$.getJson will work more than 1 second (1000 ms), you will loose some data to display.
@Chichavl
Feb 19 2016 09:19
@tvotyakov Idea was to try to cache api results, but transformed to split retrieve and display. I understand about 1000 ms losing some data
@tvotyakov thats why i wanted callback but failed with code
Alessandro Giordo
@bovas85
Feb 19 2016 09:21
Thanks @Rafase282 for your help with Algorithm: Seek and Destroy
CamperBot
@camperbot
Feb 19 2016 09:21
bovas85 sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star: 987 | @rafase282 | http://www.freecodecamp.com/rafase282
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:26

@Chichavl

to try to cache api results

why? are you using them somewhere else?

Markus Kiili
@Masd925
Feb 19 2016 09:28
@asberrie Callback functions just mean that functions in JS are objects like all other objects are. They can be given as arguments on function calls, returned from functions, assigned to variables, stored on data structures and created with literals. Invoking with () is just one special property of a function object.
@Chichavl
Feb 19 2016 09:29
@tvotyakov You persuade me. I will rewrite to display at api callback :smile:
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:29
@Chichavl I think it is better (and more userfriendly) to display data by portions when the portion will recieve. If your user will wait for one second or more to see all data, he or she will be confused.
Dulshani Gunawardhana
@dshgna
Feb 19 2016 09:31

@tvotyakov
So I was trying to understand my way through your example. It's a bit confusing so could you clarify on my thinking process please?

``````  for(var i=0; i<channels.length; i++){
var url = "https://api.twitch.tv/kraken/streams/" + channels[i] + "?callback=?";
\$.getJSON(url, function(i) {
return function (data) {
console.log(channels[i]);
}
}(i));
}``````

So here, function(i) is the outer function and function(data) is the inner function. function(data) gets i as soon as function(i)(i.e. ajax call) is called?

Am I understanding it right? Also another question, I though the callback function in get Json took the result as its parameter?
@Chichavl
Feb 19 2016 09:34
@tvotyakov My thoughts is that we should big in production project I will not display data to user at retrieve. One function for one task
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:35
@Chichavl you may create a function to display data (one function for one task), and than call it from your callback
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:42
@dshgna yes, in this scope function(i) is the outer function and function(data) is the inner function. Unlike of function(data) which will be called when getJson will receive data , function(i) will be called immediate when getJson will be called.
Dulshani Gunawardhana
@dshgna
Feb 19 2016 09:44
I see...so stupid question. What stops i being interpreted as the output of the json call?
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:47
@dshgna you can rewrite my code like this (may be it will be easier to understand)
``````  var callbackFactory = function(j) {
return function(data) {
console.log(channels[j]);
};
);
for(var i=0; i<channels.length; i++){
var url = "https://api.twitch.tv/kraken/streams/" + channels[i] + "?callback=?";
var callbackFunc = callbackFactory(i); // here callbackFunc is almost equal to function(data) { console.log(channels[i]); }
\$.getJSON(url, callbackFunc);
}``````
Dulshani Gunawardhana
@dshgna
Feb 19 2016 09:49
Thank you very much @tvotyakov.
CamperBot
@camperbot
Feb 19 2016 09:49
dshgna sends brownie points to @tvotyakov :sparkles: :thumbsup: :sparkles:
:warning: dshgna already gave tvotyakov points
Dulshani Gunawardhana
@dshgna
Feb 19 2016 09:52
@tvotyakov: So to put it in, when the json function is called, function(i) is executed simultaneously(we already know value of i). Then when data is returned function(data) is called.
Timofey Votyakov
@tvotyakov
Feb 19 2016 09:52
@dshgna yes, exactly.
greg
@wearenotgroot
Feb 19 2016 09:53
Dulshani Gunawardhana
@dshgna
Feb 19 2016 09:55
@tvotyakov thank you again! that explanation deserved more than one brownie point :)!
CamperBot
@camperbot
Feb 19 2016 09:55
dshgna sends brownie points to @tvotyakov :sparkles: :thumbsup: :sparkles:
:warning: dshgna already gave tvotyakov points
Alessandro Giordo
@bovas85
Feb 19 2016 09:57
find where do
CamperBot
@camperbot
Feb 19 2016 09:57

find where do

Timofey Votyakov
@tvotyakov
Feb 19 2016 10:04
Alessandro Giordo
@bovas85
Feb 19 2016 10:22
find cesar
CamperBot
@camperbot
Feb 19 2016 10:22
find cesar
nothing found
Alessandro Giordo
@bovas85
Feb 19 2016 10:22
find caesars
CamperBot
@camperbot
Feb 19 2016 10:22

find caesars

:zero: algorithm caesars cipher

T N Surender
@tnsurender
Feb 19 2016 10:30
Hi Guys ... Not able to solve the exercise 243 -
Make Object Properties Private
Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.

var Car = function() {
// this is a private variable
var speed = 10;

// these are public methods
this.accelerate = function(change) {
speed += change;
};

this.decelerate = function() {
speed -= 5;
};

this.getSpeed = function() {
return speed;
};
};

var Bike = function() {

// Only change code below this line.
var gear=1;

// following are the public methods

this.setGear = function() {
gear += change;
};

this.getGear = function(change){
return gear;
};

};

var myCar = new Car();

var myBike = new Bike();

any help would be appreciated
Alessandro Giordo
@bovas85
Feb 19 2016 10:36
Thanks @anuragaryan and @SaintPeter for your help with Algorithm: Caesar's Cipher
CamperBot
@camperbot
Feb 19 2016 10:36
bovas85 sends brownie points to @anuragaryan and @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2513 | @saintpeter | http://www.freecodecamp.com/saintpeter
:star: 296 | @anuragaryan | http://www.freecodecamp.com/anuragaryan
Codemzy
@codemzy
Feb 19 2016 10:40
@tnsurender for this.setGear you need to pass in a param and so if its to set the gear as something totally new it would be...
``````this.setGear = function(change) {
gear = change;
};``````
so in your setGear function in the above example, you are setting gear to whatever the new value is that you pass into the function
T N Surender
@tnsurender
Feb 19 2016 10:43
@codemzy - Thanks alot ..
CamperBot
@camperbot
Feb 19 2016 10:43
tnsurender sends brownie points to @codemzy :sparkles: :thumbsup: :sparkles:
:star: 620 | @codemzy | http://www.freecodecamp.com/codemzy
Codemzy
@codemzy
Feb 19 2016 10:51
@tnsurender :thumbsup:
Jeremy
@JeremyAntonoff
Feb 19 2016 10:59
can someone help me with nested loops
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
product = arr([i][j]) * product;
}
}
T N Surender
@tnsurender
Feb 19 2016 11:00
@JAntonoff - Whats the question ?
Jeremy
@JeremyAntonoff
Feb 19 2016 11:00
it doesn't work
I get function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
product = arr([i][j]) * product;
}
}
oops
canntot read property length of undefined
Markus Kiili
@Masd925
Feb 19 2016 11:03
@JAntonoff Use arr[i][j] without parens.
Timofey Votyakov
@tvotyakov
Feb 19 2016 11:04
@JAntonoff don't use parentheses here `product = arr([i][j]) * product;`
Jeremy
@JeremyAntonoff
Feb 19 2016 11:06
wow that was it huh
lol
thank you so much!
T N Surender
@tnsurender
Feb 19 2016 11:06
@JAntonoff did you try ?
Jeremy
@JeremyAntonoff
Feb 19 2016 11:07
yep it passed
T N Surender
@tnsurender
Feb 19 2016 11:07
:)
Jeremy
@JeremyAntonoff
Feb 19 2016 11:07
:)\
Diederik Craps
@diederikcraps
Feb 19 2016 11:11
wiki mutations
CamperBot
@camperbot
Feb 19 2016 11:11

# Problem Explanation:

• Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array..
Ankit Panwar
@coderNoob
Feb 19 2016 11:11

I added a click trigger and now the draw message appears twice ! Can anyone tell me why?

``````if (boardFull(movesSign)) { // Show draw game message
\$(".winner").append("<p>Draw Game!</p>");
setTimeout(function() {
\$('#reset').trigger('click');
}, 2000);
}``````

http://codepen.io/coderNoob/pen/vLmyWN?editors=1010

Alessandro Giordo
@bovas85
Feb 19 2016 11:22
Hi everyone, I'm stuck at the first test Build Random Quote generator
How am I supposed to find quotes and generate them?
Moon Man
@CEREBR4L
Feb 19 2016 11:24
@bovas85 can always just find some quotes or make them up and put the in an array.. that's be the easiest way
Alessandro Giordo
@bovas85
Feb 19 2016 11:24
@CEREBR4L yes but I'd like to learn ajax and json as that's probably what it points me to
Ankit Panwar
@coderNoob
Feb 19 2016 11:24
@bovas85 You can either put them in an array or if you know how to use an API, then you can use some website such as They said so
Moon Man
@CEREBR4L
Feb 19 2016 11:25
@bovas85 if you want to do so do as coderNoob suggested but make sure you do the api section on FCC first to help you :)