These are chat archives for FreeCodeCamp/HelpJavaScript

24th
Mar 2016
Aleksander Gębicki
@Takumar
Mar 24 2016 00:00

@SuziexD && (prop == contacts[i].hasOwnProperty(prop) should be:

&& (contacts[i].hasOwnProperty(prop))

I think.
Also you cannot say "No such contact" before you check all items in your array, so move this after your loop!

Suzie
@SuziexD
Mar 24 2016 00:01
@Takumar Thanks! Let me take a look. :)
Matt Green
@mattxgreen
Mar 24 2016 00:01
@SuziexD your for statement doesn't loop. It tries the first contact, and returns a result for THAT contact only rather than trying the next one
alpox
@alpox
Mar 24 2016 00:02
@Takumar I am thinking about creating a template for your last "No such contact" sentence :D i see the same problem about 3-4 times a day
Brian van Vlymen
@arduino731
Mar 24 2016 00:02
@Takumar I see the FCC is required to pass intermediate algorithm to get front end certification. I think algorithm is hardest parts than using Angular's framework or jquery.
Aleksander Gębicki
@Takumar
Mar 24 2016 00:03
@alpox Yesterday you said tomorrow. Just do it ;-)
Brian van Vlymen
@arduino731
Mar 24 2016 00:03
I like to visual developer since I am deaf
alpox
@alpox
Mar 24 2016 00:03
@Takumar Here it is already tomorrow :D i should rather sleep ^^
Good night guys :D
Aleksander Gębicki
@Takumar
Mar 24 2016 00:03
Good night!
Matt Green
@mattxgreen
Mar 24 2016 00:04
@SuziexD Let me know if you need more direction
Suzie
@SuziexD
Mar 24 2016 00:04
@mattxgreen Thanks, I'm looking now. :D
CamperBot
@camperbot
Mar 24 2016 00:04
suziexd sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 343 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Matt Green
@mattxgreen
Mar 24 2016 00:05
@SuziexD You will also have to implement the change @Takumar suggested
Brandon
@Daxo
Mar 24 2016 00:06
Hey everyone, working on the Profile Lookup and I keep getting an undefined error for my code


  //iterate over array looking for firstName
  var i = 0;
  var firstNameFound = false;


  //stop once whole doc is scanned or if firstName is not found
 while(i < contacts.length || !firstNameFound ) {

    firstNameFound = (firstName === contacts[i].firstName);
    i++;

  }
gbbrambila
@gbbrambila
Mar 24 2016 00:06
@SuziexD look your last "else".
Suzie
@SuziexD
Mar 24 2016 00:06
@mattxgreen @Takumar Yep, implementing change and making sure it clicks in my head. :) Will keep posted.
Fernando Ramirez
@Gords
Mar 24 2016 00:06
having a bit of a trouble with symmetric difference, don't know what is wrong but it keep throwing me an typeError
function sym(args) {
  var newArray = [];
  var arr = [].slice.apply(arguments);
  for(i=0;i<arr.length;i++){
    for(j=0;j<arr[i].length;j++){
      if(arr[i][j]===arr[i+1][j]){
        newArray.push(arr[i][j]);
      }
    }
  }
  return newArray;
}

sym([1, 2, 3], [5, 2, 1, 4]);
swimrr
@swimrr
Mar 24 2016 00:08
where am I going wrong with Record Collection?
// Only change code below this line
function update(id, prop, value) {

  if ((value !=="") && (prop !== "tracks")) {
    collection[id][prop] = (value);
  } else if ((value !=="") && collection[id] == "tracks") {
    collection[id][3].push[value];
  } else {

  }




  return collection;
}
Brandon
@Daxo
Mar 24 2016 00:08
Here's the whole waypoint for context:
```
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];



function lookUp(firstName, prop){
// Only change code below this line




  //iterate over array looking for firstName
  var i = 0;
  var firstNameFound = false;


  //stop once whole doc is scanned or if firstName is found
 while(i < contacts.length || !firstNameFound ) {

    firstNameFound = (firstName === contacts[i].firstName);
    i++;

  }
Marc
@wumpafruits
Mar 24 2016 00:10
I'm trying to turn a string into unicode characters for Caesar's Cipher and it's proving difficult
Brandon
@Daxo
Mar 24 2016 00:10
@swimrr .push uses () not []
Matt Green
@mattxgreen
Mar 24 2016 00:11
@bleafman you're missing a closing }
scharla
@scharla
Mar 24 2016 00:12
@wumpafruits you need to move them to an array 1st and then assign the charcodes
Fernando Ramirez
@Gords
Mar 24 2016 00:12
@wumpafruits the string is an array too, you can do string[0] to obtain the first letter for example
@wumpafruits kind of like an array*
gbbrambila
@gbbrambila
Mar 24 2016 00:14
@SuziexD your last else will exit the "for" if dont execute your first and second if
Fernando Ramirez
@Gords
Mar 24 2016 00:14
@wumpafruits also check what is the charcode for whitespace
scharla
@scharla
Mar 24 2016 00:15
@wumpafruits oh and changing everything to lower case 1st really helps ;)
swimrr
@swimrr
Mar 24 2016 00:15
okay, I've fixed the push()
Suzie
@SuziexD
Mar 24 2016 00:16
@gbbrambila hmm, yeah thats why I should put the "No such contact", at the end of my for loop
Brian van Vlymen
@arduino731
Mar 24 2016 00:16
help pig latin
CamperBot
@camperbot
Mar 24 2016 00:16

:point_right: algorithm pig latin [wiki]

Problem Explanation:

  • You need to create a program that will translate from English to Pig Latin. Check the instructions for converting to Pig Latin from the initial description or the wiki page. It might not be obvious but you need to remove all the consonants up to the first vowel in the case there letter does not start with a vowel.
:pencil: read more about algorithm pig latin on the FCC Wiki
Fernando Ramirez
@Gords
Mar 24 2016 00:18
could somebody help me with this? have been stuck on symmetric difference for a good 4 hours :worried:
function sym(args) {
  var newArray = [];
  var arr = [].slice.apply(arguments);
  for(i=0;i<arr.length;i++){
    for(j=0;j<arr[i].length;j++){
      if(arr[i][j]!==arr[i+1][j]){
        newArray.push(arr[i][j]);
      }
    }
  }
  return newArray;
}

sym([1, 2, 3], [5, 2, 1, 4]);
Marc
@wumpafruits
Mar 24 2016 00:19
@Gords @scharla oh thanks! left chat for a bit
CamperBot
@camperbot
Mar 24 2016 00:19
wumpafruits sends brownie points to @gords and @scharla :sparkles: :thumbsup: :sparkles:
:star: 304 | @gords | http://www.freecodecamp.com/gords
:star: 303 | @scharla | http://www.freecodecamp.com/scharla
scharla
@scharla
Mar 24 2016 00:22
function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins

  var boo = /\s/g ;
  var boo2 = /\_/g;


  function replacer(str) {
   function upper(match) {
     return '-'+match.toLowerCase();
   }
   str = str.replace(/[A-Z]/g, upper);
str = str.replace(boo, "-");
  str = str.replace(boo2, "-");
    str = str.replace(/\-(?=\-)/g, "");
    if (str[0] =="-"){
      str = str.replace(/\-/, "");
    }
    return str;
     }
    return replacer(str);
}

spinalCase('This_Is spinalTap');
anyone got a better solution for spinal tap?
gbbrambila
@gbbrambila
Mar 24 2016 00:26
@SuziexD yes i saw, but if your first ou second "if" don't execute, your "for" will stop when i=0 i think
Damian
@an0o0nym
Mar 24 2016 00:30
Alright guys, I am at the "Mutations" challenge in Basic Algorithm Scripting. Can anyone let me now what do you think about my code? Can anyone suggest a better way to do this? I would be grateful for that
function mutation(arr) {
  var uniqArr = function(myArr) {
    return myArr.toLowerCase().split("").reduce(function(prev, curr) {
      if(prev.indexOf(curr) < 0)
        prev.push(curr);
      return prev;
    }, []);
  };
  var firstArr = uniqArr(arr[0]);
  var secondArr = uniqArr(arr[1]);
  var count = 0;
  for(var i = 0; i < firstArr.length; i++) {
    for(var j = 0; j < secondArr.length; j++) {
      if(firstArr[i].indexOf(secondArr[j]) !== -1)
        count++;
    }
  }
  if(count === secondArr.length)
    return true;
  return false;
}
scharla
@scharla
Mar 24 2016 00:31
@Gords I think I made the same mistake as you when I tried it by trying to compare the two arrays at once. This is not really necessary - you should be able to compare them one at a time. Thus is just from memory though
Peter
@xor4
Mar 24 2016 00:36
function truncateString(str, num) {
  if (str.length > num){
    str.slice(0, num).concat("...");
  } else {
    str.slice(0, num);
  }

  return str;
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Why isn't it working
bitgrower
@bitgrower
Mar 24 2016 00:36

um ... just take each element of the array, stick 'em into a separate variable (if you need to, not really necessary)

...then just iterate thru the second string and use indexOf to see if the character is found in the first array ... seems to me ...

@an0o0nym ^^^^
@xor4 -- are any of your tests passing ?
Damian
@an0o0nym
Mar 24 2016 00:40
@bitgrower well..seems you are right. just made it too complex
bitgrower
@bitgrower
Mar 24 2016 00:41
LOL ... I did it with a completely unneeded array ... somehow, once I found arrays, I forgot I can iterate thru a string the same way I can thru an array ... just can't modify the characters in the string ... but I don't need to ...
Peter
@xor4
Mar 24 2016 00:41
@bitgrower what do you mean
bitgrower
@bitgrower
Mar 24 2016 00:42
for your challenge, when you run it, are any of the assertion tests passing ?
the way I initially screwed up that challenge was by not reading the instructions carefully ...
there's kind of a gotcha ...
Peter
@xor4
Mar 24 2016 00:43
@bitgrower I changed the code and yes 4 out of 6 are passing
function truncateString(str, num) {
  var newStr = "";
  if (str.length > num){
    newStr = str.slice(0, num-3) + "...";
    return newStr;
  }
  return str;
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
With this string it passes
But when the string is A- and num equals 1 it doesn't
Matt Green
@mattxgreen
Mar 24 2016 00:44
@SuziexD no such contact should be the end of your if-else statements, and you should also qualify it to ensure i=contacts.length-1
scharla
@scharla
Mar 24 2016 00:44
@Gords yep, definitely do it one at a time, with indexOf
Matt Green
@mattxgreen
Mar 24 2016 00:44
(to make sure you have exhausted the table)
bitgrower
@bitgrower
Mar 24 2016 00:45
@xor4 -- yeah, because you end up with a negative number when you do num-3
scharla
@scharla
Mar 24 2016 00:46
@xor4 take out your first return newStr and replace your return str with return newStr
Peter
@xor4
Mar 24 2016 00:47
How to do it then
@scharla I did what you said
bitgrower
@bitgrower
Mar 24 2016 00:47
check for more different cases ...
and I think if you did what @scharla said, you will be returning an empty string instead of returning the original string ... when the num >= str.length
scharla
@scharla
Mar 24 2016 00:48
oh wait yeah
ignore me
bitgrower
@bitgrower
Mar 24 2016 00:50
basically, I set it up to look for these different cases, for separate handling
num >= str.length
num === 0
num <= 3
...and then if it wasn't caught by those cases, it did the str.slice(0,num-3) and returned the result ...
Peter
@xor4
Mar 24 2016 00:51
I cleaned it up a bit
function truncateString(str, num) {
  if (str.length > num){
    str = str.slice(0, num-3);
    str += "...";
  }
  return str;
}

truncateString("A-", 1);
But I still dunno how to deal with them negative numbers
bitgrower
@bitgrower
Mar 24 2016 00:51
check for num being less than 3... you can use more than 1 if statement :)
James Bond
@Dman89
Mar 24 2016 00:52
var tempatureF = 'love';
var tempatureC = 'le';
var something = tempatureF;

function toggle() {
  if (something === tempatureF) {
    $(".bob").html(tempatureF);
  }
  else if (something !== tempatureF) {
    $(".bob").html(tempatureC);
  }
}

making a button, but here is the function
to change the displayed text

what em i missing?

bitgrower
@bitgrower
Mar 24 2016 00:53
the displayed text ... where ?
$(document).ready() might help ...
Peter
@xor4
Mar 24 2016 00:54
thanks @bitgrower
CamperBot
@camperbot
Mar 24 2016 00:54
xor4 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 908 | @bitgrower | http://www.freecodecamp.com/bitgrower
Peter
@xor4
Mar 24 2016 00:54
Did it like this and works
function truncateString(str, num) {
  if (num < 3){
    str = str.slice(0, num);
    str += "...";
  } else if (str.length > num){
    str = str.slice(0, num-3);
    str += "...";
  }
  return str;
}

truncateString("A-", 1);
James Bond
@Dman89
Mar 24 2016 00:54
@bitgrower ok thanks, thats astart :D
CamperBot
@camperbot
Mar 24 2016 00:54
dman89 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
bitgrower
@bitgrower
Mar 24 2016 00:54
:)
CamperBot
@camperbot
Mar 24 2016 00:54
:star: 909 | @bitgrower | http://www.freecodecamp.com/bitgrower
scharla
@scharla
Mar 24 2016 00:54
@Dman89 something always equals tempatureF because you told the program it does?
James Bond
@Dman89
Mar 24 2016 00:55
yes
but later i want it to toggle on an off
right now its static
var tempatureF = 'love';
var tempatureC = 'le';
var something = tempatureF;
$(document).ready(function() {
function toggle() {
  if (something === tempatureF) {
    $(".bob").html(tempatureF);
  }
  else if (something !== tempatureF) {
    $(".bob").html(tempatureC);
  }
  else {
    $(".bob").html(tempatureC);
  }
}; });
else was to see if i messed up
scharla
@scharla
Mar 24 2016 00:57
@Dman89 yes but your condition no1 will always be true. maybe I'm missign something?
Greg D
@mosaic-greg
Mar 24 2016 00:57
@Gords merge the two arrays in to one then you can check if an element appears more than once
bitgrower
@bitgrower
Mar 24 2016 00:57
I think he's just testing for concept ...
scharla
@scharla
Mar 24 2016 00:57
ie it will never toggle
James Bond
@Dman89
Mar 24 2016 00:57
yes, but its still no disp[laying the item
scharla
@scharla
Mar 24 2016 00:57
oh I see, nvm
James Bond
@Dman89
Mar 24 2016 00:57
@bitgrower i am testing for concept, @scharla wont display my info
bitgrower
@bitgrower
Mar 24 2016 00:58
@Dman89 -- you have just defined the function toggle ... something has to CALL it in order for it to run ... ... and I think you need to stick an event listener onto the button to make things happen ...
James Bond
@Dman89
Mar 24 2016 00:58
ok, so a click event
bitgrower
@bitgrower
Mar 24 2016 00:59
yeah ... on.click or whatever the correct syntax is ...
James Bond
@Dman89
Mar 24 2016 00:59
@scharla @bitgrower thank you, double checking i gave you brownies
CamperBot
@camperbot
Mar 24 2016 00:59
dman89 sends brownie points to @scharla and @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: dman89 already gave bitgrower points
:star: 305 | @scharla | http://www.freecodecamp.com/scharla
bitgrower
@bitgrower
Mar 24 2016 00:59
yw !!!
James Bond
@Dman89
Mar 24 2016 01:00
just to double check, the onclick function should be my if else statments or i just need a onclick event?
bitgrower
@bitgrower
Mar 24 2016 01:00
@Dman89 -- go look in this room -- https://gitter.im/FreeCodeCamp/Help ... scroll up a little, someone posted similar code to what you are trying to accomplish ...
James Bond
@Dman89
Mar 24 2016 01:00
niice
i see it
scharla
@scharla
Mar 24 2016 01:01
@Dman89 I'd call it outside the function
James Bond
@Dman89
Mar 24 2016 01:01
@bitgrower <-- is grateful for your valuable time
bitgrower
@bitgrower
Mar 24 2016 01:01
:) ... appreciate it, @Dman89 ... :)
thanks @Dman89 :)
CamperBot
@camperbot
Mar 24 2016 01:01
bitgrower sends brownie points to @dman89 :sparkles: :thumbsup: :sparkles:
:star: 308 | @dman89 | http://www.freecodecamp.com/dman89
James Bond
@Dman89
Mar 24 2016 01:01
;)
bitgrower
@bitgrower
Mar 24 2016 01:02
especially since you posted code with syntax coloring ... my eyes SOOOOO appreciate that ...
James Bond
@Dman89
Mar 24 2016 01:03
haha anytime, i try to make helping me ez, lol
Jamin R. Dodson
@jaminandtaylor
Mar 24 2016 01:05
Okay so I'm in need of help.
var count = 0;

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


  return "Change Me";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Where would I start??
Help me please.
CamperBot
@camperbot
Mar 24 2016 01:05
no wiki entry for: me please
bitgrower
@bitgrower
Mar 24 2016 01:05
help count cards
CamperBot
@camperbot
Mar 24 2016 01:05
no wiki entry for: count cards
bitgrower
@bitgrower
Mar 24 2016 01:06
ugh ...
help counting cards
CamperBot
@camperbot
Mar 24 2016 01:06

:point_right: checkpoint counting cards [wiki]

Checkpoint: Counting Cards

About Blackjack

In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called Card Counting.

Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

Value Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K','A'

Instructions

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 the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.

Example Output:

:pencil: read more about checkpoint counting cards on the FCC Wiki

João Porfírio
@pixelparker
Mar 24 2016 01:07

guys i'm doing an exercise where i need to have this output:

12 1 = 12
12
2 = 24
12 3 = 36
...
12
11 = 132
12 * 12 = 144

and using this code, but i'm getting no results, what i'm doing wrong?

var timesTable = 12;
 var finalValue = (timesTable * loopCounter);

            for (var timesBy = 1; timesBy == 12; timesBy ++) {

                    document.write(timesTable + "*" + timesBy + "=" + finalValue + "<br />");
            }
bitgrower
@bitgrower
Mar 24 2016 01:07

based on the value of the "card" parameter, you adjust the global variable count ...

...based on the value of count, you return a number and a message ...

@jaminandtaylor

b1rd0fb3auty14
@b1rd0fb3auty14
Mar 24 2016 01:08
@notalkingplz @hnry I'm still confused
bitgrower
@bitgrower
Mar 24 2016 01:08
your loop test is messed up ... it will never run ... @RKellyd
Coy Sanders
@coymeetsworld
Mar 24 2016 01:09
yeah
the 2nd statement is the condition that checks whether or not the loop should run
João Porfírio
@pixelparker
Mar 24 2016 01:11
i had an error on my copy
sorry
its not loopCounter, but timesBy
Coy Sanders
@coymeetsworld
Mar 24 2016 01:11
there's still an issue in the for loop
bitgrower
@bitgrower
Mar 24 2016 01:12
you're still trying to use timesBy before it's defined ... (2nd line)
João Porfírio
@pixelparker
Mar 24 2016 01:12
im I supposed to use the comparison operator "==" or the assignment "="?
oh right
bitgrower
@bitgrower
Mar 24 2016 01:13
where, @RKellyd ?
in the loop test ?
João Porfírio
@pixelparker
Mar 24 2016 01:13
yeah
Eric Murta
@murtinha
Mar 24 2016 01:13

guys please help. I'm struggling the whole aftertnoon with wikipedia api trying to figure out how to use it.... can you guys give me the proper link teaching it? I've open so many different links and couldt get the proper api call, the closer I got was
// Using jQuery
$.ajax( {
url: remoteUrlWithOrigin,
data: queryData,
dataType: 'json',
type: 'POST',
headers: { 'Api-User-Agent': 'Example/1.0' },
success: function(data) {
// do something with data
}
} );

but what do i put on url??? this is making me crazy hahaa these api stuff

bitgrower
@bitgrower
Mar 24 2016 01:13
I wouldn't recommend using a strict equality test like that ... do something like timesBy <= 12
João Porfírio
@pixelparker
Mar 24 2016 01:13
for (var timesBy = 1; timesBy == 12; timesBy ++)
but its the correct operator right?
if i used simply the "=" i was just saying that timesBy was 12
or no?
Coy Sanders
@coymeetsworld
Mar 24 2016 01:15
you don't want to use one equals either @bitgrower is right
basically its your conditional statement in the for loop
so if that part is true the loop will run
once it finishes running the 3rd statement is done, so the timesBy variable gets incremented
bitgrower
@bitgrower
Mar 24 2016 01:15
if you did timesBy = 12 ... I'm not sure what the interpreter would do with that, tbh ... it's looking for a statement which evaluates to true or false ... since it's an expression expressions in and of themselves are true ... (if they don't evaluate to something meaningful) ... which means your loop would be endless, because it would always be true ...
and when you are using checking the condition of equality .. in js, because of dynamic typing, you want to use strict equality ===
Coy Sanders
@coymeetsworld
Mar 24 2016 01:17
yeah that sounds right, so don't do that
bitgrower
@bitgrower
Mar 24 2016 01:17
sorry @murtinha -- can't help you there ... api's are still at the periphery of my understanding ...
João Porfírio
@pixelparker
Mar 24 2016 01:18

yeah i get it. so i changed the 2nd statement to

```

b1rd0fb3auty14
@b1rd0fb3auty14
Mar 24 2016 01:18
@notalkingplz @hnry I figured out what I was doing wrong. Hint, you will need to create two booleans to keep track if the property and contact is found
João Porfírio
@pixelparker
Mar 24 2016 01:18
timesBy <= 12
bitgrower
@bitgrower
Mar 24 2016 01:18
bingo !
João Porfírio
@pixelparker
Mar 24 2016 01:18
and its giving me results
bitgrower
@bitgrower
Mar 24 2016 01:18
YAY !!!!
João Porfírio
@pixelparker
Mar 24 2016 01:18
but they're = to NaN
so my Var is wrong
Coy Sanders
@coymeetsworld
Mar 24 2016 01:19
yeah its not a number
because you're adding a break line tag at the end
bitgrower
@bitgrower
Mar 24 2016 01:19
what's your code look like now, @RKellyd
Coy Sanders
@coymeetsworld
Mar 24 2016 01:19
or wait what is giving you a NaN?
bitgrower
@bitgrower
Mar 24 2016 01:19
yeah, that's why I want to see his current code, @coymeetsworld
João Porfírio
@pixelparker
Mar 24 2016 01:19
wait a sec, let me copy
Coy Sanders
@coymeetsworld
Mar 24 2016 01:20
its probably the finalValue, that part doesn't look right
João Porfírio
@pixelparker
Mar 24 2016 01:20
var timesTable = 12;
 var timesBy;
 var finalValue = (timesTable * timesBy);

            for (var timesBy = 1; timesBy <= 12; timesBy ++) {

                    document.write(timesTable + "*" + timesBy + "=" + finalValue + "<br />");
            }
the finalValue is coming out as a string maybe?
Coy Sanders
@coymeetsworld
Mar 24 2016 01:20
yeah so that won't work either, because timesBy isn't defined yet
bitgrower
@bitgrower
Mar 24 2016 01:20
okay ... timesBy is declared, but not defined, so that's going to make finalValue either undefined/NaN ...
João Porfírio
@pixelparker
Mar 24 2016 01:21
oh i thought that i should assume that timesBy is 1
but if i define my timesBy value
Coy Sanders
@coymeetsworld
Mar 24 2016 01:22
you don't need to define it outside of the loop, also you shouldn't need a finalValue variable
bitgrower
@bitgrower
Mar 24 2016 01:22
@b1rd0fb3auty14 -- if you're talking about Profile LookUp ... it can be handled pretty much with if/else statements within the loop ... no booleans should be needed ...
João Porfírio
@pixelparker
Mar 24 2016 01:22
can i do something like
for (; timesBy <= 12;  timesBy++)
Matt Green
@mattxgreen
Mar 24 2016 01:22
@RKellyd you are defining timesBy globally AND locally in your for loop
Coy Sanders
@coymeetsworld
Mar 24 2016 01:22
maybe, but why? just declare timesBy in the for loop, you're not using it anywhere else
and cuts down a line in your code
bitgrower
@bitgrower
Mar 24 2016 01:23
^^^ what he said
no variable in js has a value unless you give it one ...
João Porfírio
@pixelparker
Mar 24 2016 01:24
ok
bitgrower
@bitgrower
Mar 24 2016 01:24
it's just "undefined"
João Porfírio
@pixelparker
Mar 24 2016 01:24
let me rewrite it
Coy Sanders
@coymeetsworld
Mar 24 2016 01:24
yeah also if you're keeping timesTable at 12, you don't really need that variable either
unless that value can change in a function or something and you're just testing it
bitgrower
@bitgrower
Mar 24 2016 01:25
until then, js doesn't even know what type your variable is ... until you "define" it (give it a value)
João Porfírio
@pixelparker
Mar 24 2016 01:25
            var timesTable = 12;
            var timesBy = 1;

            for (var timesBy = 1; timesBy <= 12; timesBy ++) {
                    var finalValue = timesTable * timesBy;
                    document.write(timesTable + "*" + timesBy + "=" + finalValue + "<br />");
            }
now its giving me the correct answers
Matt Green
@mattxgreen
Mar 24 2016 01:26
@RKellyd remove line 2
Coy Sanders
@coymeetsworld
Mar 24 2016 01:26
that line doesn't matter if he leaves it @mattxgreen
but it doesn't need to be there
Matt Green
@mattxgreen
Mar 24 2016 01:27
@coymeetsworld it's brittle, and bad practice to leave it
Coy Sanders
@coymeetsworld
Mar 24 2016 01:27
of course, just saying, there's other things that can be fixed here too but it is working
bitgrower
@bitgrower
Mar 24 2016 01:27
yeah, but it's good to not overwhelm folks ... one step at a time ...
João Porfírio
@pixelparker
Mar 24 2016 01:27
but in a if loop i can define that variable inside the loop right?
bitgrower
@bitgrower
Mar 24 2016 01:27
not only can you, you should
Coy Sanders
@coymeetsworld
Mar 24 2016 01:27
yes you can @RKellyd but you shouldn't
João Porfírio
@pixelparker
Mar 24 2016 01:28
and if i define that variable outside the loop i can leave it outside of the loop?
bitgrower
@bitgrower
Mar 24 2016 01:28
LOL ... opposing ideas !!!
WHICH variable ?
Coy Sanders
@coymeetsworld
Mar 24 2016 01:28
well which one? timesBy or finalValue?
finalValue no
João Porfírio
@pixelparker
Mar 24 2016 01:28
timesBy
Coy Sanders
@coymeetsworld
Mar 24 2016 01:28
yeah thats fine, that's how it's supposed to be
João Porfírio
@pixelparker
Mar 24 2016 01:28
if i declare outside the loop
that timesBy = 1
Coy Sanders
@coymeetsworld
Mar 24 2016 01:28
no you should keep it in the loop
bitgrower
@bitgrower
Mar 24 2016 01:28
the cool thing about for loops is you can initialize a BUNCH of variables, and even a bunch of different loop iterations, if you want ...
Coy Sanders
@coymeetsworld
Mar 24 2016 01:28
you're actually defining it twice
Matt Green
@mattxgreen
Mar 24 2016 01:28
@RKellyd Whatever variable you define will only exist in it's scope. If you ONLY need the variable in the codeblock you are in, then that is where it should be defined.
Coy Sanders
@coymeetsworld
Mar 24 2016 01:29
but the reason you're not getting an error is because the for loop has its own scope
bitgrower
@bitgrower
Mar 24 2016 01:29
it kinda depends, @mattxgreen -- in other languages, the loop variable becomes undefined after the loop exit ... but that's not true in js ... at least prior to ES6
João Porfírio
@pixelparker
Mar 24 2016 01:30
this is better ?
var timesTable = 12;

for (var timesBy = 1; timesBy < 13; timesBy++) { document.write(timesTable + " * " + timesBy + " = "                                                                   + timesBy * timesTable + "<br />");
}
Coy Sanders
@coymeetsworld
Mar 24 2016 01:30
yes
Matt Green
@mattxgreen
Mar 24 2016 01:30
yes
Coy Sanders
@coymeetsworld
Mar 24 2016 01:30
doesn't have to be all on one line though :)
bitgrower
@bitgrower
Mar 24 2016 01:31
well, a semicolon at the end of your statement would make me happier ... :)
João Porfírio
@pixelparker
Mar 24 2016 01:31
yeah, i'm bad at formating text on gitter :D
bitgrower
@bitgrower
Mar 24 2016 01:31
esp if you're going to the trouble of putting in brackets ...
Coy Sanders
@coymeetsworld
Mar 24 2016 01:31
there is a semicolon
bitgrower
@bitgrower
Mar 24 2016 01:31
really --? Dang, I thought I looked thrice ...
Coy Sanders
@coymeetsworld
Mar 24 2016 01:31
kind of hard to read, thats why you don't do it that way :)
bitgrower
@bitgrower
Mar 24 2016 01:31
oh ... oh ... oh ... what's that HUGE white space in there ... argh
João Porfírio
@pixelparker
Mar 24 2016 01:31
ahah i copied that all the way
sorry!
didn't notest ahah
Coy Sanders
@coymeetsworld
Mar 24 2016 01:32
still works but yeah better to keep things clean whenever you can
easier for others and you to read
bitgrower
@bitgrower
Mar 24 2016 01:32
readability !!!
João Porfírio
@pixelparker
Mar 24 2016 01:32
thanks guys! gonna dig deeper into the for loops
Coy Sanders
@coymeetsworld
Mar 24 2016 01:33
cool, gl with that @RKellyd :thumbsup:
bitgrower
@bitgrower
Mar 24 2016 01:33

you can do things like this ...

for (var i = 0; i < 13; i++) a=a+4

no brackets, no semicolons needed ... but it's not typically "popular" ... peeps will give you flack for not using brackets and semicolons at times...
João Porfírio
@pixelparker
Mar 24 2016 01:34
yeah i'm gonna pay attention to that. i try my best to practice clean code, but javascript its so new to me sometimes i don't know where i'm supposed to write certain things
bitgrower
@bitgrower
Mar 24 2016 01:34
...but if you read other people's code, know that if you only have 1 statement after a for, an if, an else, brackets & semicolons are not strictly needed ...
João Porfírio
@pixelparker
Mar 24 2016 01:34
the syntax its still confusing a bit
bitgrower
@bitgrower
Mar 24 2016 01:35
worked in any other languages ?
João Porfírio
@pixelparker
Mar 24 2016 01:35
na! just started messing with html and css a couple weeks ago, but thats easy compared to this ahah
i'm loving every second of it
bitgrower
@bitgrower
Mar 24 2016 01:36
there's a lot that's "portable" to other languages ... loops/ if/else's arrays etc ...
Joshua Jerrick
@JoshuaJerrick
Mar 24 2016 01:36
I need help on Using Objects for Lookups
Here is my code so far ```
````
João Porfírio
@pixelparker
Mar 24 2016 01:37
yeah, a couple people already told me that. im just trying to get a really good foundation on JS before moving to jquery.
Joshua Jerrick
@JoshuaJerrick
Mar 24 2016 01:37
What is the shortcut to paste in code?
scharla
@scharla
Mar 24 2016 01:38
function steamroller(arr) {
  // I'm a steamroller, baby

  function flatten(x) {
    x.reduce(function(a,b) {

    return a.concat(b); },
    []);
    }

  for (var i = 0; i<arr.length; i++) {
    if (Array.isArray(arr[i])) {
      arr[i] = flatten(arr[i]);

    }
 }
  return arr;
}

steamroller([1, [2], [3, [[4]]]]);
João Porfírio
@pixelparker
Mar 24 2016 01:38
you used one extra quote mark @JoshuaJerrick
scharla
@scharla
Mar 24 2016 01:38
what's wrong with this? I'm getting [1, null, null]
Joshua Jerrick
@JoshuaJerrick
Mar 24 2016 01:38
````
João Porfírio
@pixelparker
Mar 24 2016 01:38
just 3
not 4 ;)
well thanks @coymeetsworld , @bitgrower and @mattxgreen ! talk to you soon, back to study!
CamperBot
@camperbot
Mar 24 2016 01:39
rkellyd sends brownie points to @coymeetsworld and @bitgrower and @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 377 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
:star: 344 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
:star: 910 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Mar 24 2016 01:39
keep up the great work, @RKellyd ...
Matt Green
@mattxgreen
Mar 24 2016 01:39
@scharla your return is outside your function
Joshua Jerrick
@JoshuaJerrick
Mar 24 2016 01:39
// Setup
function phoneticLookup(val) {
  var result = "";

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

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

// Change this value to test
phoneticLookup("charlie");
scharla
@scharla
Mar 24 2016 01:40
@mattxgreen I don't think so?
bitgrower
@bitgrower
Mar 24 2016 01:41
@scharla .. this part looks odd to me?
   return a.concat(b); },
    []);
    }
Matt Green
@mattxgreen
Mar 24 2016 01:41
@scharla you're also not assignig your reduce to anything
bitgrower
@bitgrower
Mar 24 2016 01:42
lol @mattxgreen -- yeah, that's a bit problematic ...
scharla
@scharla
Mar 24 2016 01:42
@bitgrower I based it on this: (it should reduce an array of arrays)
Matt Green
@mattxgreen
Mar 24 2016 01:43
@scharla so in that example they:
var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
  return a.concat(b);
}, []);
// flattened is [0, 1, 2, 3, 4, 5]
bitgrower
@bitgrower
Mar 24 2016 01:43
@JoshuaJerrick -- you need to use the parameter val to "index" into the var "lookup" ...
objects are made up of key/value pairs, you can access the value of any key/value pair by using the key as an index into the object ...
Matt Green
@mattxgreen
Mar 24 2016 01:43
see how they assign the reduce to the var flattened?
your reduce isn't going anywhere
Guaca
@murkythunder
Mar 24 2016 01:44
hey can anyone tell me why I can't console log with this, link was really long bit.ly/1SisIXf
Matt Green
@mattxgreen
Mar 24 2016 01:45
@murkythunder
 var a = contacts[0].hasOwnProperty(prop) ;
  console.log(a);
if (a===true){ console.log(a);}
scharla
@scharla
Mar 24 2016 01:45
@mattxgreen Hm, yes but I want to be able to call it again rather than getting a one off. I think I'm way off though
Guaca
@murkythunder
Mar 24 2016 01:46
hmm I still can't see the console log
Matt Green
@mattxgreen
Mar 24 2016 01:47
@murkythunder perhaps you're not looking in the right spot... what browser?
Guaca
@murkythunder
Mar 24 2016 01:47
firefox
bitgrower
@bitgrower
Mar 24 2016 01:48
hey, if you can grab code from public sources like MDN ... definitely a GREAT place to start ... @scharla :)
Guaca
@murkythunder
Mar 24 2016 01:48
does it not log it in FCC's client on the left hand side?
bitgrower
@bitgrower
Mar 24 2016 01:48
no ... different things, @murkythunder
Matt Green
@mattxgreen
Mar 24 2016 01:48
@bitgrower no
Guaca
@murkythunder
Mar 24 2016 01:48
daaaaaaaaaaaaaaaaang rip
Darwin RC
@darwinrc
Mar 24 2016 01:48
@scharla you can try using recursion in the reduce function, that way you don't have to mess with loops, something like this
 return arr.reduce(function (a, b) {
    return a.concat(Array.isArray(b) ? flatten(b) : b);
  }
bitgrower
@bitgrower
Mar 24 2016 01:48
lol, no WHAT @mattxgreen
Matt Green
@mattxgreen
Mar 24 2016 01:49
@bitgrower that no was directed at @murkythunder ... screen moved as i clicked
:p
bitgrower
@bitgrower
Mar 24 2016 01:49
oh yeah ... gotta love gitter's auto-complete .. NOT
scharla
@scharla
Mar 24 2016 01:49
@bitgrower I take it you're not being serious?
Guaca
@murkythunder
Mar 24 2016 01:49
would contacts[0].hasOwnProperty(prop) print true btw?
this challenge really makes my head hurt
bitgrower
@bitgrower
Mar 24 2016 01:50
why shouldn't you start with code which is presumably already vetted, @scharla ? At least with the thousands of eyes which are on MDN ... any mistakes are probably caught quickly ...
Matt Green
@mattxgreen
Mar 24 2016 01:50
@murkythunder yes, you will get a true
Guaca
@murkythunder
Mar 24 2016 01:50
ok thank you
bitgrower
@bitgrower
Mar 24 2016 01:50
software re-use is a wonderful thing, @scharla
scharla
@scharla
Mar 24 2016 01:51
@bitgrower haha ok it just sounded a bit sarcastic :D
bitgrower
@bitgrower
Mar 24 2016 01:52
not at all ... dead serious ... as long as it's publicly available code & not copyrighted or patented ...
I'm applauding you -- I just wish I'd found that when I was doing steamroller ...
Matt Green
@mattxgreen
Mar 24 2016 01:53
@scharla I think you just need to return the x.reduce in your flatten function. ie:
scharla
@scharla
Mar 24 2016 01:53
@bitgrower the power of Google. Now just to actually figure out how the code I foudn actually works :D
Matt Green
@mattxgreen
Mar 24 2016 01:53
function flatten(x) {
    return x.reduce(function (a, b) {
            return a.concat(b);
        },
        []);
}
bitgrower
@bitgrower
Mar 24 2016 01:53
LOL .. yep, @scharla -- that, indeed, is the tricky part ...
scharla
@scharla
Mar 24 2016 01:55
@mattxgreen aaah I was missing an extra return. Thanks!
CamperBot
@camperbot
Mar 24 2016 01:55
scharla sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
bitgrower
@bitgrower
Mar 24 2016 01:55
I wish MDN was more like php.net ... on php.net they have people's comments on different php functions ... .AWESOME place to learn stuff ... because someone will post code on how to use the function to do this or that, then someone else will come along and say ... hey, but that doesn't work in this situation ... some of the banter gets quite interesting & informative ...
CamperBot
@camperbot
Mar 24 2016 01:55
:star: 345 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
bitgrower
@bitgrower
Mar 24 2016 01:56
awww ... that's pretty, @mattxgreen
scharla
@scharla
Mar 24 2016 01:56
seems I'm on the right track - now just to get it to loop
Tracy Pilcher
@motorcitycode
Mar 24 2016 01:57
array.sort(), what is the magic to get it to work? Looking at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort it says you need to do an array.join() first. That doesn't seem to work. Any clues appreciated.
bitgrower
@bitgrower
Mar 24 2016 01:58
what ?!? ... srsly? there must be some caveat to that ... I've never done that ...
Matt Green
@mattxgreen
Mar 24 2016 01:58
@motorcitycode how are you trying to sort?
Tracy Pilcher
@motorcitycode
Mar 24 2016 01:59
default no comparison, just array.sort(); array is a series of numbers
bitgrower
@bitgrower
Mar 24 2016 01:59
there's literally code on that page which shows how to do it ... I"m pretty sure ...
Matt Green
@mattxgreen
Mar 24 2016 01:59
do you want the numbers ascending or descending?
Tracy Pilcher
@motorcitycode
Mar 24 2016 02:00
ascending
bitgrower
@bitgrower
Mar 24 2016 02:00
like this ..
var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) {
  return a - b;
});
console.log(numbers);

// [1, 2, 3, 4, 5]
Matt Green
@mattxgreen
Mar 24 2016 02:01
@motorcitycode what @bitgrower said
Tracy Pilcher
@motorcitycode
Mar 24 2016 02:01
oh, thanks, I didn't understand that I needed the function thing
Matt Green
@mattxgreen
Mar 24 2016 02:01
@motorcitycode the function is a callback
if you wanted descending you''d just do b-a
Tracy Pilcher
@motorcitycode
Mar 24 2016 02:01
I see, makes sense now, thank you!
bitgrower
@bitgrower
Mar 24 2016 02:01
yeah ... the default sort is based on unicode ... great if you want to alphabetize something, but if you want numbers, you need a callback function ...
Tracy Pilcher
@motorcitycode
Mar 24 2016 02:02
missed the unicode bit ;)
Savvis
@Savvis
Mar 24 2016 02:03
Is there a reason my test function is not working as far as alerting the location.longitude from my getLocation() function? Here is the code: http://pastebin.com/rcPdG5a5
Rafael
@rafaelpdl
Mar 24 2016 02:03
Hi Everyone. I am having troubles understanding the .filter(). I have tried to read online on other sources, but I still dont get why the following code won't work. For example, I would like that the result in the next code was arr = ["ate","",false,9]. But why it doesn't?
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  arr.filter(7);
  return arr;
}

bouncer([7, "ate", "", false, 9]);
bitgrower
@bitgrower
Mar 24 2016 02:03
"The default sort order is according to string Unicode code points." .... 2nd sentence ...
Tracy Pilcher
@motorcitycode
Mar 24 2016 02:04
thanks @bitgrower
CamperBot
@camperbot
Mar 24 2016 02:04
motorcitycode sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 911 | @bitgrower | http://www.freecodecamp.com/bitgrower
Matt Green
@mattxgreen
Mar 24 2016 02:04
@rafaelpdl so you want filter to remove 7?
bitgrower
@bitgrower
Mar 24 2016 02:04
@rafaelpdl ... I spent hours on falsy bouncer ... until I read the recommended page on Booleans ...
Rafael
@rafaelpdl
Mar 24 2016 02:04
Yes
bitgrower
@bitgrower
Mar 24 2016 02:04
...then I solved it in a few minutes ...
Matt Green
@mattxgreen
Mar 24 2016 02:04
@rafaelpdl filter takes a callback function, so in that callback only return non-7 values
bitgrower
@bitgrower
Mar 24 2016 02:05
LOL ... I'm writing a book on javascript sanity ... I just added that javascript runs on callback functions the way an army runs on its stomach ...
Rafael
@rafaelpdl
Mar 24 2016 02:05
@bitgrower I read the page on Booleans. But I believe that my biggest problem now is not understanding how the filter() works. That is why I used "7" as an example.
scharla
@scharla
Mar 24 2016 02:05
@rafaelpdl filter needs a function
bitgrower
@bitgrower
Mar 24 2016 02:05
yeah ... get VERY VERY comfortable with callback functions ... they are everywhere in js
sooner you get comfortable with them, the sooner you will see your ease with js explode ...
Rafael
@rafaelpdl
Mar 24 2016 02:06
@mattxgreen @bitgrower @scharla Uhn.... okay.... I do not understand what are callback functions. I will try to read a bit about it.
Matt Green
@mattxgreen
Mar 24 2016 02:07
@rafaelpdl
arr.filter(function(val){
    return (val !=7) ? val : null;
});
scharla
@scharla
Mar 24 2016 02:07
function biggerThan7(x) {
return x>7;
array.filter(biggerThan7)
bitgrower
@bitgrower
Mar 24 2016 02:07
basically, it's a function you hand to a second function, returning values as expected by the outer function ...
in the case of filter, it's expecting you to return a true or false
Steve Stout
@jessebae
Mar 24 2016 02:07
Using Objects for Lookups -- Are these instructions and examples vague, or is it just me? I googled and found little regarding JavaScript Lookup tables. Removing the case, break, and not including if/else--those are easy instructions. But how am I supposed to extrapolate the correct structure for this table from this vague, overly simplified example? Please help with instructions, examples. Thanks!
bitgrower
@bitgrower
Mar 24 2016 02:08
code, please, @jessebae
Steve Stout
@jessebae
Mar 24 2016 02:08
The example has no key value pairs
bitgrower
@bitgrower
Mar 24 2016 02:08
@scharla -- sneak that missing bracket in there ...
you don't have any code, @jessebae ?
Steve Stout
@jessebae
Mar 24 2016 02:09

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

// Only change code below this line
var lookup = {
1: "alpha":
result = "Adams"}

 "bravo": 
  result = "Boston";
"charlie": 
  result = "Chicago";
  "delta": 
  result = "Denver";
  "echo": 
  result = "Easy";
  "foxtrot": 
  result = "Frank";

}

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

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

bitgrower
@bitgrower
Mar 24 2016 02:10
okay .. I'm not sure why you think the example doesn't have any key value pairs @jessebae -- I'm looking at the challenge and seeing them both in the instructions as well as the code provided ...
what do you think a key value pair should look like ?
scharla
@scharla
Mar 24 2016 02:10
```js
```js
function biggerThan7(x) {
return x>7;
}
array.filter(biggerThan7)
```
ARGH!

function biggerThan7(x) {
return x>7;
}
array.filter(biggerThan7)
Matt Green
@mattxgreen
Mar 24 2016 02:10
@jessebae switch statements fall-through
bitgrower
@bitgrower
Mar 24 2016 02:11
pesky brackets ...
Rafael
@rafaelpdl
Mar 24 2016 02:11
@mattxgreen In your example the "function(val)" is the callback function? The code between the {} is the code of this callback function?
scharla
@scharla
Mar 24 2016 02:11
hm, maybe I should filter my steamroller
Matt Green
@mattxgreen
Mar 24 2016 02:11
@rafaelpdl yep
Amé Wong
@wongstein
Mar 24 2016 02:11
@jessebae I think they want you too use something like a dictionary or whatever the JS implementation is of a hashmap
Steve Stout
@jessebae
Mar 24 2016 02:12

var alpha = {
1:"Z",
2:"Y",
3:"X",
4:"W",
...
24:"C",
25:"B",
26:"A"
};
alpha2; // "Y"
alpha[24]; // "C"

var value = 2;
alpha[value]; // "Y"

Key value 1:Z
bitgrower
@bitgrower
Mar 24 2016 02:12

right ... so
1:"Z"

that's a key value pair

"alpha":"Adams"

is a key value pair

you're providing the function with a parameter which contains a key ... and this is not at all complicated ... it's very sweet, simple and elegant ...

all you have to do is use the key to index into the variable alpha to get the value, and then you need to return it ...

Rafael
@rafaelpdl
Mar 24 2016 02:13
@mattxgreen So iI could define this function(val) outside of the array.filter and it would be the same? For example:
arr.filter(function(val){
    return (val !=7) ? val : null;
});
oops
I didnt change it . Just a sec
Matt Green
@mattxgreen
Mar 24 2016 02:14
@rafaelpdl you are right though
bitgrower
@bitgrower
Mar 24 2016 02:14
yeah, you got 3 descriptions of a callback function, @rafaelpdl -- and except for one missing a bracket, they were all correct ..
Rafael
@rafaelpdl
Mar 24 2016 02:15
function(val) { 
return (val !=7) ? val : null; }

arr.filter(function(val));
Is the same thing as you posted, then?
bitgrower
@bitgrower
Mar 24 2016 02:16
@rafaelpdl .. .almost ... you don't need to use function within the arr.filter line
Matt Green
@mattxgreen
Mar 24 2016 02:16
@rafaelpdl not quite...
Guaca
@murkythunder
Mar 24 2016 02:16
can anyone tell me what I have to use to solve https://www.freecodecamp.com/challenges/profile-lookup I've been stuck for 2 hours, I'm so confused.
Matt Green
@mattxgreen
Mar 24 2016 02:16
var noSevens = arr.filter(callback);
console.log(noSevens);

function callback(val){
    return val !=7 ? val : null;
}
@rafaelpdl
Guaca
@murkythunder
Mar 24 2016 02:16
I don't get the pseudocode
bitgrower
@bitgrower
Mar 24 2016 02:17
@murkythunder ... code ?
Rafael
@rafaelpdl
Mar 24 2016 02:17
@bitgrower Yes! I had understood (I think) you code and the code from @scharla . I was just having a hard understading the one from @mattxgreen , because it looked a bit odd for me. But thanks to all of you for helping ou! :)
CamperBot
@camperbot
Mar 24 2016 02:17
rafaelpdl sends brownie points to @bitgrower and @scharla and @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 346 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
:star: 306 | @scharla | http://www.freecodecamp.com/scharla
:star: 912 | @bitgrower | http://www.freecodecamp.com/bitgrower
Guaca
@murkythunder
Mar 24 2016 02:18
my problem is, if I run an if statement to check if there is a name and a value, I don't know how to tell it to check if it ran through the entire program before returning that it doesn't have a firstname, or a prop
I don't understand the thought process
bitgrower
@bitgrower
Mar 24 2016 02:18
@rafaelpdl -- you will probably see callback functions written like @mattxgreen did most of the time ...
well ... good thinking on your part, that's the part most folks miss, @murkythunder ...
if you look thru all of the elements in your array and you don't find it ... you haven't exited the function yet ... maybe you could return your message there ?
Guaca
@murkythunder
Mar 24 2016 02:19
am I missing something? I want to solve it with for loops and if statements. Do I need to use a while loop or switch ?
bitgrower
@bitgrower
Mar 24 2016 02:19
no ... for loop works great
Guaca
@murkythunder
Mar 24 2016 02:19
ok let me try it again
alright so far I have for (var i=0; i<contacts.length; i++){ if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)){ return contacts[a].prop;} }
for (var i=0; i<contacts.length; i++){        
  if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)){
    return contacts[a].prop;}   }
Matt Green
@mattxgreen
Mar 24 2016 02:22
@murkythunder that's a good start
Guaca
@murkythunder
Mar 24 2016 02:22
but I don't know how to tell it to return that it doesn't have a certain value, before the loop ends
scharla
@scharla
Mar 24 2016 02:23
@murkythunder it's all just about getting your if conditions in the right order
Guaca
@murkythunder
Mar 24 2016 02:23
if I add an else if statement that says it does not have a prop value, then it will return it for all the i values
Matt Green
@mattxgreen
Mar 24 2016 02:23
@murkythunder
for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)) {
        return contacts[a].prop;
    } else if(CONDITION){

    }
}
Micah Bales
@micahbales
Mar 24 2016 02:24
any idea why my div (.profile) isn't lining up right? (Also why does just one appear?) http://codepen.io/micahbales/pen/ONmXry?editors=1100
scharla
@scharla
Mar 24 2016 02:24
@murkythunder which is why your ifs need to be in the order that ensure that there is nothing more to do after your return
James Becker
@james-becker
Mar 24 2016 02:24
function rot13(str) {
  var arr = [];
  var newArr = [];
  var alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y'];
  for (i = 0; i < str.length; i++ ) {
    arr.push(str.charAt(i));
  }
  for (i = 0; i < arr.length ; i++ ) {
    if (arr[i].match(/[^A-Z]/i)) {newArr.push(arr[i]);}
    else newArr.push(alpha[alpha.indexOf(arr[i])+13]);
  }
  console.log(newArr.join(""));
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
rot13("GU*&# DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");
Any idea why this passes in JSBIN but not FCC?
Guaca
@murkythunder
Mar 24 2016 02:25
woooooow
James Becker
@james-becker
Mar 24 2016 02:25
(Caesar's Cipher bonfire)
Guaca
@murkythunder
Mar 24 2016 02:25
this entire time I had a huge brainfart. I forgot that it won't run the other else ifs if the first one is true. This is looks sooo much easier now. Thanks @scharla @mattxgreen @bitgrower
CamperBot
@camperbot
Mar 24 2016 02:25
murkythunder sends brownie points to @scharla and @mattxgreen and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 913 | @bitgrower | http://www.freecodecamp.com/bitgrower
:star: 307 | @scharla | http://www.freecodecamp.com/scharla
:star: 347 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Steve Stout
@jessebae
Mar 24 2016 02:26

@bitgrower sorry I'm so stupid to not get this "not at all complicated" solution I could only get this far, which doesn't meet any of the parameters of the problem // Setup
function phoneticLookup(val) {
var result = "";

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

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

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

Matt Green
@mattxgreen
Mar 24 2016 02:27
@micahbales
.profile
 background-color: green
 height: 50px
 margin: 10px 0
 width: 100%
bitgrower
@bitgrower
Mar 24 2016 02:27
@jessebae -- that comment was not intended as a putdown, but rather as a statement of hope & encouragement ...
scharla
@scharla
Mar 24 2016 02:28
@james-becker I greatly recommend making all your chars the same case 1st
bitgrower
@bitgrower
Mar 24 2016 02:28
@jessebae - do you know how to index into an object with a property ?
Steve Stout
@jessebae
Mar 24 2016 02:28
thank you. I have hope.
Micah Bales
@micahbales
Mar 24 2016 02:28
@mattxgreen Wow, so it was the position:absolute! Thanks! Any idea why that was fouling things up? I guess I don't quite understand the "position" property well enough yet....
CamperBot
@camperbot
Mar 24 2016 02:28
micahbales sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 348 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Matt Green
@mattxgreen
Mar 24 2016 02:29
@micahbales just read up on the position... it can be tricky
Steve Stout
@jessebae
Mar 24 2016 02:29
I did that in previous challenges
'
bitgrower
@bitgrower
Mar 24 2016 02:30
yeah, this feature of js is very very cool, and very powerful ... (and, as someone else alluded to, there is corresponding functionality in other languages ... )
Micah Bales
@micahbales
Mar 24 2016 02:30
@mattxgreen +1
bitgrower
@bitgrower
Mar 24 2016 02:30
@jessebae -- so, do it with this challenge ...
Steve Stout
@jessebae
Mar 24 2016 02:30
Wonderful! Though I've never seen it used in any simple web scripts
bitgrower
@bitgrower
Mar 24 2016 02:31
well I can't account for what you have or have not seen, @jessebae ... sorry about that ...
Steve Stout
@jessebae
Mar 24 2016 02:31
I'm looking for guidance, not puzzles.
bitgrower
@bitgrower
Mar 24 2016 02:32
I'm trying to guide you, @jessebae ... you said you've used indexing into objects with properties in other challenges, so why not use what you've learned in this one ... ?
Guaca
@murkythunder
Mar 24 2016 02:41
Heeeeeeeeeeeeeey guys, stuck again. bit.ly/1RmgaOy I think my first if statement has something wrong with it, but I can't figure it out...
bitgrower
@bitgrower
Mar 24 2016 02:42
which challenge, @murkythunder ... I have a lot of DNS issues, so linking thru link cloakers gives me a lot of pain ...
Eric Murta
@murtinha
Mar 24 2016 02:43
guys I have the following problem... I've a json that i'm getting from a site and I need to dynamically create a well for each element of the json. I put a for there but its only creating a well for the last element, ive tried with .each too and culdnt do it
bitgrower
@bitgrower
Mar 24 2016 02:44
got a link, @murtinha ?

have ~~~for (var i=0; i<contacts.length; i++){
if (contacts[i].firstName==1 && contacts[i].hasOwnProperty.prop){
return contacts[i][prop]; }

else if (contacts[i].firstName != firstName) {
return "No such contact";
}
else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty.prop!==true) {
return "No such property";}
}

~~~

```for (var i=0; i<contacts.length; i++){
if (contacts[i].firstName==1 && contacts[i].hasOwnProperty.prop){
return contacts[i][prop]; }

else if (contacts[i].firstName != firstName) {
return "No such contact";
}
else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty.prop!==true) {
return "No such property";}
}

```

for (var i=0; i<contacts.length; i++){        
  if (contacts[i].firstName==1 && contacts[i].hasOwnProperty.prop){
    return contacts[i][prop];  }

else if (contacts[i].firstName != firstName) {
  return "No such contact";
}
  else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty.prop!==true) {
  return "No such property";}
}
there we go
bitgrower
@bitgrower
Mar 24 2016 02:45
@murkythunder -- the 2 ways to index into an object are by brackets and by dot notation ... brackets is by FAR more flexible ... you can only use dot notation when you know the actual name of the property ...
your hasOwnProperty needs some help ...
Nicolas May
@hynso
Mar 24 2016 02:48
I'm looking for feedback on my "Drop It" algorithm but don't wanna post the solution here... Would someone be willing to take a quick peak on private chat?
bitgrower
@bitgrower
Mar 24 2016 02:52
@murtinha -- I'd have to see what the data structure you are getting in return looks like ...
Eric Murta
@murtinha
Mar 24 2016 02:52
@bitgrower ok
bitgrower
@bitgrower
Mar 24 2016 02:55
sent you a pm @hynso ...
Lisa Jordie
@lisajordie
Mar 24 2016 02:57
Good evening - I am stuck on challenge Escaping Literal Quotes in Strings. Can anyone please take a look at my code and see where I have an error? Thanks: var myStr = ("I am a \"double quoted\" string inside \"double quotes\"")
Nicolas May
@hynso
Mar 24 2016 02:58
Thanks in advance, @bitgrower !
CamperBot
@camperbot
Mar 24 2016 02:58
hynso sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 914 | @bitgrower | http://www.freecodecamp.com/bitgrower
Carole Anne Hannon
@CaroleAnneHannon
Mar 24 2016 03:00
@lisajordie works for me (as long as you have a ; at the end)
Lisa Jordie
@lisajordie
Mar 24 2016 03:00
@CaroleAnneHannon That was absolutely what was missing - thank you so much @CaroleAnneHannon !
CamperBot
@camperbot
Mar 24 2016 03:00
lisajordie sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 796 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
Guaca
@murkythunder
Mar 24 2016 03:01
still a bit confused, need help please bit.ly/21I4fxc
https://www.freecodecamp.com/challenges/profile-lookup
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].hasOwnProperty(prop)===true){
    return contacts[i][prop];  }

else if (contacts[i].firstName != firstName) {
  return "No such contact";
}
  else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop) !== true) {
  return "No such property";}
}
Eric Murta
@murtinha
Mar 24 2016 03:03
@bitgrower dude net down I'm sorry
eeflores
@eeflores
Mar 24 2016 03:04
@murkythunder put "No such contact" after the for loop
Pascal T.
@omegga
Mar 24 2016 03:05
@murkythunder you are returning "no such contact" at the first unfound contact , so the loop stops and does not check other contact
John Pyles
@japyles
Mar 24 2016 03:06
Thanks @renelis @abhisekp @Rafase282 for your help with Algorithm: Falsy Bouncer
CamperBot
@camperbot
Mar 24 2016 03:06
japyles sends brownie points to @renelis and @abhisekp and @rafase282 :sparkles: :thumbsup: :sparkles:
:star: 1099 | @rafase282 | http://www.freecodecamp.com/rafase282
:star: 2351 | @abhisekp | http://www.freecodecamp.com/abhisekp
:star: 380 | @renelis | http://www.freecodecamp.com/renelis
Guaca
@murkythunder
Mar 24 2016 03:07
oh.
Miguel T Rivera
@mtrivera
Mar 24 2016 03:11
wiki monkey
CamperBot
@camperbot
Mar 24 2016 03:11

:point_right: algorithm chunky monkey [wiki]

Explanation

Our goal for this Algorithm is to split arr (first argument) into smaller chunks of arrays with the length provided by size (second argument). There are 4 green checks (objectives) our code needs to pass in order to complete this Algorithm:

  1. (['a', 'b', 'c', 'd'], 2) is expected to be [['a', 'b'], ['c', 'd']]
  2. ([0, 1, 2, 3, 4, 5], 3) is expected to be [[0, 1, 2], [3, 4, 5]]
  3. ([0, 1, 2, 3, 4, 5], 2) is expected to be [[0, 1], [2, 3], [4, 5]]
  4. ([0, 1, 2, 3, 4, 5], 4) is expected to be [[0, 1, 2, 3], [4, 5]]

Click More information under the Algorithm title and read the helpful links if you haven't yet.

:pencil: read more about algorithm chunky monkey on the FCC Wiki

bitgrower
@bitgrower
Mar 24 2016 03:11
:) ... I like to see what you are actually getting, though ... it may not be what you expect, even from the documentation ...
Eric Murta
@murtinha
Mar 24 2016 03:13
@bitgrower thats for me?
bitgrower
@bitgrower
Mar 24 2016 03:13
yeah, @murtinha
Lisa Jordie
@lisajordie
Mar 24 2016 03:13
Hi again! I'm getting into JS and having issues with Escape Sequences in Strings - I'm way off, can take a look and reroute me in the right direction? http://bit.ly/1RAqwxE
Eric Murta
@murtinha
Mar 24 2016 03:14
@bitgrower my foor loop is only showing and creating a well for one parameter, I need it to create and show all parameters
hnry
@hnry
Mar 24 2016 03:16
@lisajordie don't put the extra space in the beginning, so it's
@lisajordie ok that messed up so it's "\\ \t \t \r \n"
bitgrower
@bitgrower
Mar 24 2016 03:16
yes ... so my suspicion is that that is due to a problem in the for loop definition ...
Lisa Jordie
@lisajordie
Mar 24 2016 03:17
Thank you both!!! @hnry thank you so much.
CamperBot
@camperbot
Mar 24 2016 03:17
lisajordie sends brownie points to @hnry :sparkles: :thumbsup: :sparkles:
:star: 186 | @hnry | http://www.freecodecamp.com/hnry
Eric Murta
@murtinha
Mar 24 2016 03:17
@bitgrower what do you mean?
bitgrower
@bitgrower
Mar 24 2016 03:19

the fact that it makes one, suggests that the code within the loop works ... and the fact that it's only one suggests that your loop test quits after one iteration ...

for(i=0;i<searchResults[1].length;i++)

searchResults[1].length is being seen as 1 ... so it exits after the first increment ...

your random button opens up in a new window, too ... :)
Eric Murta
@murtinha
Mar 24 2016 03:25
@bitgrower the random button is meant to open in a new window
@bitgrower i've tried to do i<10 but not with the append, let me see
@bitgrower same...
dkennell
@dkennell
Mar 24 2016 03:27
Hey, everyone. I'm working on the palindrome challenge, and my code keeps removing the character '1', and I'm not sure why. Is there something in my regex that's doing that?
function palindrome(str) {
  var downStr = str.toLowerCase();
  var cleanedUp = downStr.replace(/['`~!@$%^&*()_|+-=?;: '",.<>]/g, '');
  var firstArr = cleanedUp.split("");
  var scndArr = firstArr.reverse();
  var finalStr = scndArr.join("");
  if (cleanedUp !== finalStr) {
    return false;
  }
  // Good luck!
  return true;
}

palindrome("1 eye for of 1 eye.");
bitgrower
@bitgrower
Mar 24 2016 03:30
@murtinha -- try adding a <br> to your output string ...
Carole Anne Hannon
@CaroleAnneHannon
Mar 24 2016 03:31
@dkennell you should look into character classes
@dkennell it's not usually a good idea to list out characters like that. It's removing 1 because the - is making it freak out
Savvis
@Savvis
Mar 24 2016 03:32
Can someone help me with this Javascript code? http://pastebin.com/UcPNc8A1 - the latitude and longitude values in getLocation() are not carring over to the getWeather() function.
Carole Anne Hannon
@CaroleAnneHannon
Mar 24 2016 03:32
@dkennell or rather, the - is making it go into range mode (ex: a-z means all laters in a through z). Well +-= in regex means all characters between + and =
bitgrower
@bitgrower
Mar 24 2016 03:33
@murtinha -- is it printing the first or the last of your items... if the last .. then it's probably overwriting them ...
Carole Anne Hannon
@CaroleAnneHannon
Mar 24 2016 03:33
@dkennell and numbers are between those 2 symbols
Eric Murta
@murtinha
Mar 24 2016 03:34
@bitgrower the last...
Carole Anne Hannon
@CaroleAnneHannon
Mar 24 2016 03:34
@dkennell if you're gonna use special characters directly, you need to escape them via \ example \-
Matt Reynolds
@mareynolds
Mar 24 2016 03:34
in a 'for' loop, its telling me that 'myStrArr[i].join' is not a function:
words = myStrArr[i].join;
Eric Murta
@murtinha
Mar 24 2016 03:35
@bitgrower how to not overwrite then???
Matt Reynolds
@mareynolds
Mar 24 2016 03:37
function findLongestWord(str) {
  var myStrArr = [];
  var longestWord = 0;
  var words = "";
  myStrArr = str.split(" ");
  console.log("word count is " + myStrArr.length);

  for (var i = 0; i < myStrArr.length; i++)
  {
    words = myStrArr[i].join;
    if (words.length > longestWord)
      {
        longestWord = words.length;
      }
  }
  return str.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
and the debugger is giving me this error: TypeError {message: "myStrArr[i].join is not a function"}
Eric Murta
@murtinha
Mar 24 2016 03:39
@acctg4code I think its missing join()
Carole Anne Hannon
@CaroleAnneHannon
Mar 24 2016 03:39
That's because myStrArr[i] isn't an array, it's a string
DJ
@qualitymanifest
Mar 24 2016 03:39
@acctg4code you're splitting str at each space, so myStrArr is an array of words. you can't join() a word, since it's already a string
bitgrower
@bitgrower
Mar 24 2016 03:39
@murtinha -- add a <br> to your string ?
not sure ...
Eric Murta
@murtinha
Mar 24 2016 03:39
@bitgrower where exactly?
Matt Reynolds
@mareynolds
Mar 24 2016 03:41
well that was an easy fix, now that i removed the ".join" then it worked perfectly! Thanks @CaroleAnneHannon thanks @qualitymanifest !
CamperBot
@camperbot
Mar 24 2016 03:41
acctg4code sends brownie points to @caroleannehannon and @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 1103 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
:star: 797 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
bitgrower
@bitgrower
Mar 24 2016 03:42
@murtinha -- at the end of the string you are outputting, after the </div> ... or, you could try using something like nth child in your addressing ...
Matt Reynolds
@mareynolds
Mar 24 2016 03:42
In Chrome my console log is giving me this error when I go to a new Bonfire in FCC, before I do anything. Any ideas why?
Refused to load the script 'about:blank' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'unsafe-inline' .google-analytics.com .gstatic.com https://*.cloudflare.com .cloudflare.com https://.gitter.im https://*.cdnjs.com .cdnjs.com https://.jsdelivr.com .jsdelivr.com .twimg.com https://*.twimg.com vimeo.com 'self'".
bitgrower
@bitgrower
Mar 24 2016 03:42
sorry I can't be of more help today ... let me know how it goes, though, @murtinha
Matt Reynolds
@mareynolds
Mar 24 2016 03:43
maybe cause I'm logged into a public wifi?
bitgrower
@bitgrower
Mar 24 2016 03:43
quite possibly, @acctg4code
dkennell
@dkennell
Mar 24 2016 03:44
@CaroleAnneHannon Ooooooh, interesting! Thanks! I'm starting a JS regex tutorial on the side now, and I'll make sure to pay close attention to character classes. I appreciate the help. :smile:
CamperBot
@camperbot
Mar 24 2016 03:44
dkennell sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 798 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
bitgrower
@bitgrower
Mar 24 2016 03:46
@murtinha -- the OTHER thing you might try is just using the loop to generate the string ... then try outputting it after you exit the loop -- I think that's how the json/api challenges did it .. you might try looking at those for some ideas, too ...
Diwakar Serala
@diwpro007
Mar 24 2016 03:56
hello guys i'm currently doing intermediate algorithms and i'm stuck in Drop it. The part i'm confused is shouldn't
drop([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9, 2].
but instead
drop([1, 2, 3, 9, 2], function(n) {return n > 2;}) should return [3, 9].
Kevin Mulligan
@kmulligan
Mar 24 2016 03:57
@diwpro007 2 is not greater than 2
if it were return n >= 2, then it would return [3,9,2]
DJ
@qualitymanifest
Mar 24 2016 03:58

@diwpro007

Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.

the second argument is false for 1 and 2, but true when you reach 3, so 3 and everything after get returned.
Diwakar Serala
@diwpro007
Mar 24 2016 03:59
@qualitymanifest i don't understrand this part until the predicate (second argument) returns true.
Andrew Charlebois
@andrewchar
Mar 24 2016 04:00
This message was deleted
This message was deleted
This message was deleted
DJ
@qualitymanifest
Mar 24 2016 04:00
@diwpro007 here's your array. [1, 2, 3, 9, 2]. function(n) {return n > 2;}) gets run against each piece of the array, starting from the beginning. 1 returns false because it's not greater than 2, so you drop it and move on. 2 returns false for the same reason, so you drop it and move on. 3 returns true, you you return the remaining array
Eric Murta
@murtinha
Mar 24 2016 04:00
@bitgrower I wanted to be abble to do it auttomatically
Diwakar Serala
@diwpro007
Mar 24 2016 04:02
@qualitymanifest so we should not stop after getting false after getting the first true. hope i'm clear enough
DJ
@qualitymanifest
Mar 24 2016 04:03
@diwpro007 as soon as a you reach a number that returns true, you return the rest of the array
Jalon Dodson
@JEDodson
Mar 24 2016 04:05
// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber;       // Change this Line
var player = testObj;   // Change this Line
Can someone give me an example or help me out? Don't give me the answer please
Diwakar Serala
@diwpro007
Mar 24 2016 04:06
ok thanks @qualitymanifest understood now
CamperBot
@camperbot
Mar 24 2016 04:06
diwpro007 sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
Jalon Dodson
@JEDodson
Mar 24 2016 04:06
I'm supposed to use the playerNumber var to lookup player 16 in testObj
CamperBot
@camperbot
Mar 24 2016 04:06
:star: 1104 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
dkennell
@dkennell
Mar 24 2016 04:07
@JEDodson What's the name of this challenge, again?
Eric Murta
@murtinha
Mar 24 2016 04:09
guys please help me
http://codepen.io/murtinha/pen/ONmxqr
I need my while to print 10 wells on the screen, but its only printing/creating 1, the last on of the object
Jalon Dodson
@JEDodson
Mar 24 2016 04:13
@dkennell Accessing Objects Properties with Variables
dkennell
@dkennell
Mar 24 2016 04:21

@JEDodson Okay, so the exercise is just trying to show you that you can set a variable equal to a property, then use that variable in square brackets to access the value of said property.

So instead of using var player = testObj[16], you can use var player = testObj[Some other variable that's been set to 16]

Doug
@Spazcool
Mar 24 2016 04:25

I know it's gonna be a really simple solution but, I've been staring at this for half an hour. "Testing Objects for Properties." I can get the the 'true' values to return but, not the 'false' ones. What am I doing wrong? Thanks.// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
myObj.hasOwnProperty(checkProp);

if(false) {
return "Not Found";
}
else {
return myObj[checkProp];
}
}

// Test your code by modifying these values
checkObj("gift");

Andrew Charlebois
@andrewchar
Mar 24 2016 04:25
help format
CamperBot
@camperbot
Mar 24 2016 04:25

:point_right: code formatting [wiki]

Multi line Code

```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 ⏎]

Single line Code

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

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

:pencil: read more about code formatting on the FCC Wiki

Andrew Charlebois
@andrewchar
Mar 24 2016 04:25
@Spazcool ^^^
Doug
@Spazcool
Mar 24 2016 04:26
This message was deleted
This message was deleted
Andrew Charlebois
@andrewchar
Mar 24 2016 04:29
@Spazcool you're not looking for a true/false value. just checking if the obj has a value that is being passed in with checkObj("house");
Doug
@Spazcool
Mar 24 2016 04:30
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  myObj.hasOwnProperty(checkProp);

 if(false) {
   return "Not Found";
 }
  else {
    return myObj[checkProp];
  }
}

// Test your code by modifying these values
checkObj("gift");
Andrew Charlebois
@andrewchar
Mar 24 2016 04:31
so if you look in the example given, it shows me what they are looking for
David Alexis
@r0nind
Mar 24 2016 04:32
Greetings all! I've had some difficulty with the module "Check for Palindromes" This returns false. What am I missing?
function palindrome(str) {
  // Good luck!
  if ([str]) {
  str = str.toLowerCase().replace(/\s/, '');
  str = str.replace(/[^A-z\d]+/g, '');
  var drome = str.split('').reverse().join('');
  drome.replace(/[^\W\s]/gi, '');
  console.log(drome);

    if(str === drome) {
    return true;
  } else {
    return false;
  }
  }
}

palindrome("0_0 (: /-\ :) 0-0");
Andrew Charlebois
@andrewchar
Mar 24 2016 04:33
@Spazcool you want your if statement to look for the property in the same way they are checking for it in the example
Doug
@Spazcool
Mar 24 2016 04:34
@andrewchar I don't see it. I originally typed "if (true)" and that worked fine but, still wouldn't return on the "else"
@andrewchar They don't have an if statement in the example.
Andrew Charlebois
@andrewchar
Mar 24 2016 04:35
by only putting if (true). how do you expect it to search myObj
@Spazcool it doesnt know what to look at
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:38
function palindrome(str) {
  var strCleaned = str.replace(/\W/g,'').toLowerCase();
  var strCleanedRev = '';
  for (var i = strCleaned.length-1; i>=0; i--){
    strCleanedRev += strCleaned[i];
  }

  return (strCleaned === strCleanedRev);
}

palindrome("eye");
0_0 (: /-\ :) 0-0
it is not working for that string
what am I missing?
Miguel T Rivera
@mtrivera
Mar 24 2016 04:39
wiki mutations
CamperBot
@camperbot
Mar 24 2016 04:39

:point_right: algorithm mutations [wiki]

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..
:pencil: read more about algorithm mutations on the FCC Wiki
David Alexis
@r0nind
Mar 24 2016 04:39
@grfarshbaf I'm having the same issue. I've found something works for that but then I have issues with another point
Doug
@Spazcool
Mar 24 2016 04:40
@andrewchar I still don't understand it fully but, it works with "if(checkProp in myObj)". Thanks for the help.
CamperBot
@camperbot
Mar 24 2016 04:40
spazcool sends brownie points to @andrewchar :sparkles: :thumbsup: :sparkles:
Andrew Charlebois
@andrewchar
Mar 24 2016 04:40
@grfarshbaf look over your regexp to see how to also remove _
CamperBot
@camperbot
Mar 24 2016 04:40
:star: 389 | @andrewchar | http://www.freecodecamp.com/andrewchar
David Alexis
@r0nind
Mar 24 2016 04:40
@grfarshbaf The code that worked for that one but not another looked like this:
js
Andrew Charlebois
@andrewchar
Mar 24 2016 04:40
@Spazcool from the example myObj.hasOwnProperty("top") .... myObj is the object you tell it to search. .hasOwnProperty method search the object for a given property. and you want to, in this case search for checkProp which is just the argument of the function. function checkObj(checkProp)
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:41
@andrewchar the /\W/g should remove all the non-alphanumeric chars
David Alexis
@r0nind
Mar 24 2016 04:41

@grfarshbaf

function palindrome(str) {
  // Good luck!
  if ([str]) {
  str = str.toLowerCase().replace(/\s/, '');
  str = str.replace(/[^A-z]+/g, '');
  var drome = str.split('').reverse().join('');
  drome.replace(/[^\W\s]/gi, '');
  console.log(drome);

    if(str === drome) {
    return true;
  } else {
    return false;
  }
  }
}



palindrome("0_0 (: /-\ :) 0-0");

This works for the issue you had but it doesn't work for "1 eye for of 1 eye."

Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:41
but it looks like it is not working for _ character
Andrew Charlebois
@andrewchar
Mar 24 2016 04:42
@grfarshbaf yeah thats what i said
@grfarshbaf you need to add something to regexp to remove the underscore as well
dkennell
@dkennell
Mar 24 2016 04:43
This message was deleted
DJ
@qualitymanifest
Mar 24 2016 04:43
This message was deleted
This message was deleted
you could get rid of everything except for a-z, A-Z, and 0-9, or you could get rid of \W and underscores
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:49
/[^A-Za-z0-9]/g
This is the working regex!
DJ
@qualitymanifest
Mar 24 2016 04:49
that's one way, yeah
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:49
passed the challenge!
DJ
@qualitymanifest
Mar 24 2016 04:50
@grfarshbaf nice :+1:
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:50
@qualitymanifest do you know how to use\W to remove the underscore as well?
/\W/g
DJ
@qualitymanifest
Mar 24 2016 04:51
/\W|_/g or /[\W_]/g
David Alexis
@r0nind
Mar 24 2016 04:51
@qualitymanifest Thanks, I understand alot better. Still haven't gotten the regex to remove the underscore though. Have to play around with the ASCII a bit mroe
CamperBot
@camperbot
Mar 24 2016 04:51
r0nind sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
David Alexis
@r0nind
Mar 24 2016 04:51
Thanks
CamperBot
@camperbot
Mar 24 2016 04:51
:star: 1108 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
Mar 24 2016 04:51
the first one uses the or pipeline, the second one finds anything in betwen the brackets
David Alexis
@r0nind
Mar 24 2016 04:51
@grfarshbaf Thanks for that. Gotta get more practice with Regex
CamperBot
@camperbot
Mar 24 2016 04:51
r0nind sends brownie points to @grfarshbaf :sparkles: :thumbsup: :sparkles:
:star: 252 | @grfarshbaf | http://www.freecodecamp.com/grfarshbaf
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:52
@r0nind Thanks!
CamperBot
@camperbot
Mar 24 2016 04:52
grfarshbaf sends brownie points to @r0nind :sparkles: :thumbsup: :sparkles:
:star: 256 | @r0nind | http://www.freecodecamp.com/r0nind
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:52
DJ
@qualitymanifest
Mar 24 2016 04:52
@r0nind np. regexone.com has a pretty decent tutorial. between that and reading documentation on regex, you can learn a lot
ha. jinx @grfarshbaf
Reza Farshbaf
@grfarshbaf
Mar 24 2016 04:54
/\W|_/g or /[\W_]/gGreat! I didn't know about Pipe
function palindrome(str) {

  var strCleaned = str.replace(/\W|_/g,'').toLowerCase();
  return (strCleaned === strCleaned.split('').reverse().join(''));

}
Shorten the code!
dkennell
@dkennell
Mar 24 2016 04:59
@qualitymanifest Cool, I was just coming here to ask someone this! :+1:
@qualitymanifest Thanks!
CamperBot
@camperbot
Mar 24 2016 05:00
dkennell sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 1109 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
Mar 24 2016 05:00
@grfarshbaf nice - that's pretty much how my code ended up looking
@dkennell glad to hear
@grfarshbaf just so you know, you don't need the parens around the return
Sidharth Kriplani
@sidkrip
Mar 24 2016 05:04
I dont know if its a dumb question or not, but I have two concentric circles and I want to modify them as one, i.e change their position without affecting their characetreistics wrt each other. Can I group them together in CSS somehow?
*characteristics
In the question "Generate random whole numbers with javascript", I am getting errors. MY code is :

var randomNumberBetween0and19 = myFunction();

function myFunction() {

// Only change code below this line.

return Math.floor(Math.random() * 10);
}

Sidharth Kriplani
@sidkrip
Mar 24 2016 05:07
uhh someone please help?
DJ
@qualitymanifest
Mar 24 2016 05:08
@sidkrip just made this up for you http://codepen.io/qualitymanifest/pen/WwjyXL
naregkhodanian
@naregkhodanian
Mar 24 2016 05:08
I got every card sequence to work except this Cards Sequence 3, 7, Q, 8, A should return "-1 Hold"
nvm got it
Sidharth Kriplani
@sidkrip
Mar 24 2016 05:14
@qualitymanifest thanks! also, I need to shift this circle to a new position. Actually I am trying to make a thought cloud for the quote generator
CamperBot
@camperbot
Mar 24 2016 05:14
sidkrip sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 1110 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
Sidharth Kriplani
@sidkrip
Mar 24 2016 05:24
umm someone help?
Reza Jafar
@Reza7865
Mar 24 2016 05:28
Screen Shot 2016-03-23 at 10.28.00 PM.png
Screen Shot 2016-03-23 at 10.28.08 PM.png
can someone help plz^
Sidharth Kriplani
@sidkrip
Mar 24 2016 05:29
@Reza7865 challenge name and the problem you are having?
@qualitymanifest its done. figured it out. thank you :D
CamperBot
@camperbot
Mar 24 2016 05:31
sidkrip sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:warning: sidkrip already gave qualitymanifest points
Reza Farshbaf
@grfarshbaf
Mar 24 2016 05:31
function findLongestWord(str) {
  var arr = str.split(' ').map(function(words){
    return words.length;
  });
  arr.sort(function (a,b){
    return b-a;
  });
  return arr[0];
}
This is the code for finding the longest Word
How can I make it better?
cannelflow
@cannelflow
Mar 24 2016 05:35
@Reza7865 #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.
Reza Jafar
@Reza7865
Mar 24 2016 05:36
@sidkrip i posted a pic of the problem
its called "Stand in Line" in Front End > Basic JavaScript
cannelflow
@cannelflow
Mar 24 2016 05:37
@Reza7865 ^^
DJ
@qualitymanifest
Mar 24 2016 05:39

@grfarshbaf it can be done shorter:

function findLongestWord(str) {
  str = str.split(' ').sort(function (a,b){
    return b.length-a.length;
  });
  return str[0].length;
}

i think there's a more efficient way too, let me take a look

Reza Farshbaf
@grfarshbaf
Mar 24 2016 05:41
@qualitymanifest Cool!
Matt Green
@mattxgreen
Mar 24 2016 05:46
@qualitymanifest .reduce is more appropriate for that use-case
function findLongestWord(str) {
  return str.split(' ').reduce(function (a,b){
    return b.length>a.length ? b : a ;
  });
}
Reza Farshbaf
@grfarshbaf
Mar 24 2016 05:52
@mattxgreen Nice
I am learning lots of cool stuff here in FCC!
THank you guys
Matt Green
@mattxgreen
Mar 24 2016 05:53
sure thing
my example returns the actual word where @qualitymanifest 's returns the length of the longest word. not sure which you want, but you can just add .length to mine if it is wrong
DJ
@qualitymanifest
Mar 24 2016 05:58
This message was deleted
Nick Robson
@nickrobson
Mar 24 2016 05:59
function findLongestWord(str) {
   return str.split` `.reduce((p,c) => c.length > p.length ? c : p);
}
(if you want an even shorter solution without squishing everything)
var findLongestWord=s=>s.split` `.reduce((p,c)=>c.length>p.length?c:p);
Sidharth Kriplani
@sidkrip
Mar 24 2016 06:06
@Reza7865 so sorry for replying late. Was working on a problem myself. wait a second
Miguel T Rivera
@mtrivera
Mar 24 2016 06:09
function mutation(arr) {
var regExp = /[arr.length - 1]/i;
var isMutation = regExp.test(arr[0]);

  if(isMutation){
      return true;
  } else {
      return false;
  }
}
the only conditions that do not work are the first and last one for mutations, everything else works fine
Sidharth Kriplani
@sidkrip
Mar 24 2016 06:10
@Reza7865 this is your solution:
arr.push(item);
  var rem=arr.shift();
  return rem;  // Change this line
Jason Devloo
@JasonDevloo
Mar 24 2016 06:36
@Feralamillo Yes, thank you.
CamperBot
@camperbot
Mar 24 2016 06:36
jasondevloo sends brownie points to @feralamillo :sparkles: :thumbsup: :sparkles:
:star: 214 | @feralamillo | http://www.freecodecamp.com/feralamillo
kirill-2l
@kirill-2l
Mar 24 2016 06:44
when array1 .push(array2) can return number?
Matt Green
@mattxgreen
Mar 24 2016 06:47
@kirill-2l push adds onto the array. Do you mean pop() ?
kirill-2l
@kirill-2l
Mar 24 2016 06:48
@mattxgreen i mean push()
i solve the problem...
Matt Green
@mattxgreen
Mar 24 2016 06:49
great
Oliver Webb
@Ollie15
Mar 24 2016 07:03

// Initialize these three variables
var a;
var b;
var c;

a = 5 + 1;
b = 10 + 5;
c = "I am a String!";

// Do not change code below this line

cannelflow
@cannelflow
Mar 24 2016 07:05
@Boomybiscuit45 which exercise?
Oliver Webb
@Ollie15
Mar 24 2016 07:05
what is wrong here I have got it all ticked apart from do not change the code below this line
The lesson is Understanding Uninitialized Variables
@cannelflow
V Arun Kumar
@arunvkumr
Mar 24 2016 07:06
http://s.codepen.io/arunkumrv/debug/wGzgae
i have completed weather app, any feedback and suggestions? :grinning:
cannelflow
@cannelflow
Mar 24 2016 07:07
@arunkumrv
:+1:
V Arun Kumar
@arunvkumr
Mar 24 2016 07:08
@cannelflow thanks :smile: .
CamperBot
@camperbot
Mar 24 2016 07:08
arunkumrv sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 1001 | @cannelflow | http://www.freecodecamp.com/cannelflow
cannelflow
@cannelflow
Mar 24 2016 07:08
@Boomybiscuit45 a should be defined and have a value of 6
b should be defined and have a value of 15
c should not contain undefined and should have a value of "I am a String!"
Do not change code below the line
Oliver Webb
@Ollie15
Mar 24 2016 07:10
This message was deleted
This message was deleted
cannelflow
@cannelflow
Mar 24 2016 07:12
@Boomybiscuit45 c already have the value var c="I am a" now you need to do like c = c + " String!"; so that result will be I am a String!
Oliver Webb
@Ollie15
Mar 24 2016 07:13
thank you @cannelflow
CamperBot
@camperbot
Mar 24 2016 07:13
boomybiscuit45 sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 1002 | @cannelflow | http://www.freecodecamp.com/cannelflow
shameem fairooz
@sfshameem5
Mar 24 2016 07:38
guys I'm stuck in counting cards section in basic javascript

var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2, 3, 4, 5, 6:
return "5 Bet";
case 7, 8, 9:
return "0 Hold";
case 10, 'J', 'Q', 'K', 'A':
return "-5 Hold";
case 3, 7, "Q", 8, "A":
return "-1 Hold";
case 2, "J", 9, 2, 7:
return "1 Bet";
case 3, 2, "A", 10, "K":
return "-1 Hold";
}

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

anyone?
Shubhi Agrawal
@shubhiagr
Mar 24 2016 07:41
I am viewing this challenge
shameem fairooz
@sfshameem5
Mar 24 2016 07:41
@shubhiagr Thank you.
CamperBot
@camperbot
Mar 24 2016 07:41
sfshameem5 sends brownie points to @shubhiagr :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for shubhiagr
Miguel T Rivera
@mtrivera
Mar 24 2016 07:41
@sfshameem5 It looks like you have too many cases, reread the problem
shameem fairooz
@sfshameem5
Mar 24 2016 07:42
@migueltrivera But all the required conditions are met except for one
Marcus Nielsen
@marcusnielsen
Mar 24 2016 07:44
@sfshameem5 which one?
shameem fairooz
@sfshameem5
Mar 24 2016 07:44
@marcusnielsen this one. Cards Sequence 3, 7, Q, 8, A should return "-1 Hold"
rphares
@rphares
Mar 24 2016 07:46
@sfshameem5 , your approach is not quite what it is looking for, I'm think-- are those cases the test hands?
shameem fairooz
@sfshameem5
Mar 24 2016 07:46
@rphares I didn't get what you said.
rphares
@rphares
Mar 24 2016 07:46
What we are meant to do is write a function that doesn't return until the end... this function can update the count , with each card
we want a function that will tell us to bet or hold correctly no matter what cards we get...
it looks like you wrote the cases to match the tests... but those are just examples,
shameem fairooz
@sfshameem5
Mar 24 2016 07:47
@rphares oops
rphares
@rphares
Mar 24 2016 07:48
instead, you could have your first case increment the count, and second case decrement it
yep-- its no problem, just a different way of looking at it
using a switch is fine, as is an if/else,
shameem fairooz
@sfshameem5
Mar 24 2016 07:48
@rphares I'll try and let you know. Thanks..
CamperBot
@camperbot
Mar 24 2016 07:48
sfshameem5 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 3510 | @rphares | http://www.freecodecamp.com/rphares
shameem fairooz
@sfshameem5
Mar 24 2016 07:48
@rphares I'll try if/else
rphares
@rphares
Mar 24 2016 07:48
if you use a switch, just update your count and then finish with an if/else based on count (like if count is above zero return count and " Bet")
Cool-- give that a go and come back if you get stuck :blush: Happy coding, @sfshameem5 !
shameem fairooz
@sfshameem5
Mar 24 2016 07:51
This message was deleted
shameem fairooz
@sfshameem5
Mar 24 2016 07:57
Guys, I Still can't get it.
rphares
@rphares
Mar 24 2016 07:57
Could you paste what you are trying now, @sfshameem5 ?
shameem fairooz
@sfshameem5
Mar 24 2016 07:58
@rphares Nothing much but totally confused.

var count = 0;

function cc(card) {
// Only change code below this line
if (card == +1)
card++;

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

rphares
@rphares
Mar 24 2016 07:58
ohh, not quite the idea--
V Bhargav Chowdary
@bhargav4
Mar 24 2016 07:58
where can i find free beep sound source to use for pomodoro clock?
rphares
@rphares
Mar 24 2016 07:58
lets look at the first if together--
shameem fairooz
@sfshameem5
Mar 24 2016 07:58
@rphares okay..
rphares
@rphares
Mar 24 2016 08:00
so, the chart says for Cards 2, 3, 4, 5, 6 we will Count Changeby +1
shameem fairooz
@sfshameem5
Mar 24 2016 08:00
@rphares I think I got it.
rphares
@rphares
Mar 24 2016 08:00
cool, give it a go and lemme know if stuck :)
shameem fairooz
@sfshameem5
Mar 24 2016 08:00
@rphares I'll go with if/else.. and let you know
Srinivas
@sriducati
Mar 24 2016 08:02
anybody there?
Shubhi Agrawal
@shubhiagr
Mar 24 2016 08:03
@sfshameem5 I got this one
function cc(card) {
// Only change code below this line
if(card==2||card==3||card==4||card==5||card==6)
count++;
else if(card==10||card=='J'||card=='Q'||card=='K'||card=='A')
count--;
var decideBet="Hold";
if(count>0)
decideBet="Bet";
return(count+ " "+decideBet);
// Only change code above this line
}
shameem fairooz
@sfshameem5
Mar 24 2016 08:04
@shubhiagr I'm doing the same way.
@shubhiagr But you shouldn't have showed it.
Shubhi Agrawal
@shubhiagr
Mar 24 2016 08:04
@sfshameem5 My bad, sorry!
shameem fairooz
@sfshameem5
Mar 24 2016 08:05
@shubhiagr It's okay. Thanks ..
Shubhi Agrawal
@shubhiagr
Mar 24 2016 08:05
This is my first chat in here
CamperBot
@camperbot
Mar 24 2016 08:05
sfshameem5 sends brownie points to @shubhiagr :sparkles: :thumbsup: :sparkles:
:star: 130 | @shubhiagr | http://www.freecodecamp.com/shubhiagr
Jalon Dodson
@JEDodson
Mar 24 2016 08:07
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
     var Lookup = {
  }

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

// Change this value to test
phoneticLookup("charlie");
oops
anyway
am i starting out right?
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  switch(val) {
    case "alpha": 
      result = "Adams";
      break;
    case "bravo": 
      result = "Boston";
      break;
    case "charlie": 
      result = "Chicago";
      break;
    case "delta": 
      result = "Denver";
      break;
    case "echo": 
      result = "Easy";
      break;
    case "foxtrot": 
      result = "Frank";
  }

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

// Change this value to test
phoneticLookup("charlie");
shameem fairooz
@sfshameem5
Mar 24 2016 08:08
@rphares I've done until here.

var count = 0;

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

if (card == 2 || card == 4 || card == 5 || card == 6){
count ++;
}else if (card == 10 || card == "J" || card == 'Q' || card == 'K' || card == 'A'){
count --;
}

if (count > 0){
return count && "Bet";
}else if (count)

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Jalon Dodson
@JEDodson
Mar 24 2016 08:08
That's the original code, I need to convert it to a lookup table called lookup
shameem fairooz
@sfshameem5
Mar 24 2016 08:09
@JEDodson Can you mention the name of the exercise?
rphares
@rphares
Mar 24 2016 08:09
okay--, two things stand out-- @sfshameem5 ,
you will also need an if that says hold,
you DONT need a return change me (you can delete that)
and this will print countBet
you need a space in the string par to the return,
@JEDodson , thats using objects for lookups, right?
So, there are a few steps to that one,
you will want to make a table, like in the example--
shameem fairooz
@sfshameem5
Mar 24 2016 08:10
@rphares I still can't get it.
@JEDodson Will help you shortly.
Jalon Dodson
@JEDodson
Mar 24 2016 08:11
Using Objects for Lookups
@sfshameem5
rphares
@rphares
Mar 24 2016 08:11
@sfshameem5 , at the bottom, lets start with your returns-- your first one, you have &&
you want to concatenate
that means using +
AND
the output that you have right now would print 5Bet for example
there should be a space in between
Jalon Dodson
@JEDodson
Mar 24 2016 08:11
might wana use case @sfshameem5
easier
rphares
@rphares
Mar 24 2016 08:12
5 Bet
So, you will need to put a space at the beginning of the string part of the return
THEN
your else if... you also need a condition that tells you to hold
shameem fairooz
@sfshameem5
Mar 24 2016 08:13
@rphares still not getting it.
@rphares Now i'm here.

var count = 0;

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

if (card == 2 || card == 4 || card == 5 || card == 6){
count ++;
}else if (card == 10 || card == "J" || card == 'Q' || card == 'K' || card == 'A'){
count --;
}

if (count > 0){
return count + "Bet";
}

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Jalon Dodson
@JEDodson
Mar 24 2016 08:13
@rphares Yes it's wanting me to make a table, it's Using Objects for Lookups. How would I start though? In the example it shows
rphares
@rphares
Mar 24 2016 08:13
(when the count is less than zero) @sfshameem5
Jalon Dodson
@JEDodson
Mar 24 2016 08:14
var alpha = {
var alpha = {
1:"Z",
2:"Y",
3:"X",
4:"W",
...
24:"C",
25:"B",
26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"

var value = 2;
alpha[value]; // "Y"
shameem fairooz
@sfshameem5
Mar 24 2016 08:14
@rphares Okay, I did modify it.
rphares
@rphares
Mar 24 2016 08:14
@JEDodson , for that first step, here are the first two lines--
var lookup =  {
    "alpha": "Adams",
Jalon Dodson
@JEDodson
Mar 24 2016 08:14
Oh I forgot
rphares
@rphares
Mar 24 2016 08:14
see how it has the pairs, just like the example?
Jalon Dodson
@JEDodson
Mar 24 2016 08:14
You can use strings for the first part
Yeah lol..
rphares
@rphares
Mar 24 2016 08:14
yep :blush:
OKay, @sfshameem5 , can you paste again, please?
shameem fairooz
@sfshameem5
Mar 24 2016 08:15

var count = 0;

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

if (card == 2 || card == 4 || card == 5 || card == 6){
count ++;
}else if (card == 10 || card == "J" || card == 'Q' || card == 'K' || card == 'A'){
count --;
}

if (count < 0){
return count + "Bet";
}

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

rphares
@rphares
Mar 24 2016 08:15
right now, you have an if, @sfshameem5
let me paste you your code back, with comments :blush:
 var count = 0;

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

  if (card == 2 || card == 4 || card == 5 || card == 6){
    count ++;
  }else if (card == 10 || card == "J" || card == 'Q' || card == 'K' || card == 'A'){
    count --;
  }

  if (count < 0){ // This should be GREATER THAN zero
    return count + "Bet"; // You need a space at the beginning of this string
  }
  else {
   //Here you need to put in what to return IF count is LESS THAN zero
  }



  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
(sorry, didn't correct everything this time, just something to get you going again, @sfshameem5 :blush:
shameem fairooz
@sfshameem5
Mar 24 2016 08:18
@rphares Will try and let you know.
rphares
@rphares
Mar 24 2016 08:19
:plus1:
Jalon Dodson
@JEDodson
Mar 24 2016 08:19
@rphares it says 'Missing semicolon
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = { 
    "alpha": "Adams",
    "bravo": "Boston",

  }

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

// Change this value to test
phoneticLookup("charlie");
Where the curly bracket is underneath boston
rphares
@rphares
Mar 24 2016 08:20
Ah-- you have a ways to go... i'd ignore that for now,
shameem fairooz
@sfshameem5
Mar 24 2016 08:20
@rphares
rphares
@rphares
Mar 24 2016 08:20
you will not end your list there with a comma, though ;)
shameem fairooz
@sfshameem5
Mar 24 2016 08:20
@rphares I'm stuck here now.

var count = 0;

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

if (card == 2 || card == 4 || card == 5 || card == 6){
count ++;
}else if (card == 10 || card == "J" || card == 'Q' || card == 'K' || card == 'A'){
count --;
}

if (count > 0){
return count + "Bet";
}else if(count <= 0){
return count + "Hold";

}

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

rphares
@rphares
Mar 24 2016 08:20
you'll probably want to put a semicolon after the } @JEDodson , though :blush:
Jalon Dodson
@JEDodson
Mar 24 2016 08:20
Wouldn't it be var lookup(val) = { @rphares ?
rphares
@rphares
Mar 24 2016 08:21
@JEDodson , nope-- this is the var inside the function
Srinivas
@sriducati
Mar 24 2016 08:21
@sfshameem5 got solution?
rphares
@rphares
Mar 24 2016 08:21
@sfshameem5 , cool, but-- do you remember the exercise word blanks? (can't recall if it came first or not)
shameem fairooz
@sfshameem5
Mar 24 2016 08:21
@sriducati Still struggling.
rphares
@rphares
Mar 24 2016 08:21
you need the space...
Srinivas
@sriducati
Mar 24 2016 08:21
i will help u
rphares
@rphares
Mar 24 2016 08:21
Right now, say the 5 cards resulted in a count of 4
when you return 4 + "bet"
that will say
4Bet
all one word
thats not good
shameem fairooz
@sfshameem5
Mar 24 2016 08:22
@rphares so , all i need is a space
Jalon Dodson
@JEDodson
Mar 24 2016 08:22
@sfshameem5 markup your code so we could see it better
if (count > 0){
return count + " Bet";
} else {
return count + " Hold";
}
shameem fairooz
@sfshameem5
Mar 24 2016 08:22

var count = 0;

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

if (card == 2 || card == 4 || card == 5 || card == 6){
count ++;
}else if (card == 10 || card == "J" || card == 'Q' || card == 'K' || card == 'A'){
count --;
}

if (count > 0){
return count + " Bet";
}else if(count <= 0){
return count + " Hold";

}

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Jalon Dodson
@JEDodson
Mar 24 2016 08:22
use three ```'s
they're the button to the toplleft
shameem fairooz
@sfshameem5
Mar 24 2016 08:22
@JEDodson how can i markup my code?
rphares
@rphares
Mar 24 2016 08:22
explain format
CamperBot
@camperbot
Mar 24 2016 08:22

:point_right: code formatting [wiki]

Multi line Code

```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 ⏎]

Single line Code

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

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

:pencil: read more about code formatting on the FCC Wiki

Jalon Dodson
@JEDodson
Mar 24 2016 08:22
  if (count > 0){
    return count + " Bet";
  } else {
    return count + " Hold";
  }
Srinivas
@sriducati
Mar 24 2016 08:22

var count = 0;

function cc(card) {
// Only change code below this line
if(card>=2 && card<=6)
{
count++;
}else if(card>=7 && card<=9){
//count = 0;
}else if(card==10 || card=='J' || card=='Q' || card=='K' || card=='A'){
count--;
}
var send = "Bet";
if(count<=0)
{
send = "Hold";
}
return count+" "+send;
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(7);

thats working
can u test?
shameem fairooz
@sfshameem5
Mar 24 2016 08:23
@sriducati okay, I'll try
rphares
@rphares
Mar 24 2016 08:23
@sriducati , we usually try not to share answers, better if people can get it for themselves so they understand the solutions :blush:
Srinivas
@sriducati
Mar 24 2016 08:24
hmm but he was bit struck :worried:
Jalon Dodson
@JEDodson
Mar 24 2016 08:24
// Setup
function phoneticLookup(val) {
  var result = "";

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

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

// Change this value to test
phoneticLookup("charlie");
```
This is what I have right now.
rphares
@rphares
Mar 24 2016 08:24
okay, good start!
Bil
@thebiltheory
Mar 24 2016 08:24
Hiiii
rphares
@rphares
Mar 24 2016 08:24
so about 4 things left
first, you dont need that last line in the table, , "": undefined,
(everything from the comma after "Frank" until the } can go
i know it whines at you, but it will stop when the rest is right :) )
shameem fairooz
@sfshameem5
Mar 24 2016 08:25
@sriducati Thanks. But sad, that I didn't do it myself
CamperBot
@camperbot
Mar 24 2016 08:25
sfshameem5 sends brownie points to @sriducati :sparkles: :thumbsup: :sparkles:
:star: 236 | @sriducati | http://www.freecodecamp.com/sriducati
rphares
@rphares
Mar 24 2016 08:26
@sfshameem5 , can i make a suggestion? the part he gave you was the bottom, right?
shameem fairooz
@sfshameem5
Mar 24 2016 08:26
@rphares yeah.
Bil
@thebiltheory
Mar 24 2016 08:26
@JEDodson You need to lookup the object val, play with object notations
rphares
@rphares
Mar 24 2016 08:27
there is another way to write that part... look at it and see if you can think of a way to do it without using var send = "Bet"; and send = "Hold";
@sfshameem5
Srinivas
@sriducati
Mar 24 2016 08:27
@sfshameem5 u can try to find an alternate solution as well ;)
rphares
@rphares
Mar 24 2016 08:27
then the answer will be yours. You were very close
João Castanho
@joaocastanho
Mar 24 2016 08:28
hello
function slasher(arr, howMany) {
  // it doesn't always pay to be first

  var removed;
  var newArr = [];

  if (howMany > 0) {
    removed = arr.splice(0, howMany);

    newArr.push(arr.shift(removed));
  } else {
    newArr.push(arr);
  }

  return newArr;
}

slasher([1, 2, 3], 0);
rphares
@rphares
Mar 24 2016 08:28
@JEDodson , once you fix that part, then you have done the first part of the instructions, Convert the switch statement into a lookup table called lookup. As @thebiltheory is saying, you will need to follow the example to use bracket notation, to Use it to lookup val and assign the associated string to the result variable.
shameem fairooz
@sfshameem5
Mar 24 2016 08:28
@rphares Concentrating continuously for 1 and half hours. Gonna have a break and then I'll do it from scratch.
rphares
@rphares
Mar 24 2016 08:28
Perfect! Good luck and happy coding~
shameem fairooz
@sfshameem5
Mar 24 2016 08:29
@rphares @sriducati Thanks
CamperBot
@camperbot
Mar 24 2016 08:29
sfshameem5 sends brownie points to @rphares and @sriducati :sparkles: :thumbsup: :sparkles:
:warning: sfshameem5 already gave rphares points
:warning: sfshameem5 already gave sriducati points
Jalon Dodson
@JEDodson
Mar 24 2016 08:29
Ok so
Markus Kiili
@Masd925
Mar 24 2016 08:29
@joaocastanho You only need one slice to solve it.
Jalon Dodson
@JEDodson
Mar 24 2016 08:29
I have this
rphares
@rphares
Mar 24 2016 08:29
@JEDodson and example of this is in the instructions-- alpha[2]; // "Y" Look at how they got what is associated with 2 from var alpha
Jalon Dodson
@JEDodson
Mar 24 2016 08:29
// Setup
function phoneticLookup(val) {
  var result = "";

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

  result = lookup["charlie"];

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

// Change this value to test
phoneticLookup("charlie");
```
rphares
@rphares
Mar 24 2016 08:29
SUPER CLOSE
but... "charlie" is just the test...
João Castanho
@joaocastanho
Mar 24 2016 08:30
@Masd925 splice or slice?
rphares
@rphares
Mar 24 2016 08:30
you want to "Use it to lookup val" @JEDodson
Markus Kiili
@Masd925
Mar 24 2016 08:30
@joaocastanho Slice is better.
João Castanho
@joaocastanho
Mar 24 2016 08:30
ok
rphares
@rphares
Mar 24 2016 08:30
(from the instructions...) @JEDodson
Jalon Dodson
@JEDodson
Mar 24 2016 08:30
i had just changed it to result = lookup[val] as soon as you said that
lol
thanks @rphares
CamperBot
@camperbot
Mar 24 2016 08:30
jedodson sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 3512 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Mar 24 2016 08:31
Woohoo! Hiya @Masd925 , gonna pass the baton, i need a shower :blush:
Anytime~ Congrats and happy coding!
<