These are chat archives for FreeCodeCamp/HelpJavaScript

1st
May 2017
mira87
@mira87
May 01 2017 00:02

need help with global scope and functions
// Declare your variable here
var myGlobal;

function fun1() {
// Assign 5 to oopsGlobal Here

}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}

nvm got it
:)
:
:fire:
iandelible
@iandelible
May 01 2017 00:10
could someone help comment on my code? this is for the steamroller challenge:
function steamrollArray(arr) {
  var flattenedArray = [];
  arr.forEach(function(element) {
    if (Array.isArray(element)) {
      steamrollArray(element);
    }
    else {
      flattenedArray.push(element);
    }
  }); 

  return flattenedArray;
}
Tammzz
@Tammzz
May 01 2017 00:10

function nextInLine(arr, item) {
// Your code here

return item; // Change this line
}

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

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

iandelible
@iandelible
May 01 2017 00:10
it isn't working properly, so if someone could make suggestions that would be appreciated
Tammzz
@Tammzz
May 01 2017 00:11

function nextInLine(arr, item) {
  // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
how to do that ?
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Gulsvi
@gulsvi
May 01 2017 00:16
@Tammzz You'll want to use the array manipulation methods we learned earlier. .push() adds things to the end of an array, and .shift() removes things from the beginning of the array.
Tammzz
@Tammzz
May 01 2017 00:20
i did that not working
let me show
function nextInLine(arr, item) {
  // Your code here
  var x;
  arr.pop(item);
  x=arr[0];
   arr.shift(arr[0]);
  return x;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Gulsvi
@gulsvi
May 01 2017 00:21
Add the number to the end of the array, then remove the first element of array.
Tammzz
@Tammzz
May 01 2017 00:21
oh
sorry
i replaced push with pop
and worked
thanks XD
Gulsvi
@gulsvi
May 01 2017 00:21
:)
Tammzz
@Tammzz
May 01 2017 00:21
@SkyCoder01 thanks dude
CamperBot
@camperbot
May 01 2017 00:21
tammzz sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1231 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Gulsvi
@gulsvi
May 01 2017 00:21
You can also do x = arr.shift()
.shift() returns the item that it removed
Tammzz
@Tammzz
May 01 2017 00:22
mmm nice.
thnaks
btw
question
what is use of brownie ?
Stephen James
@sjames1958gm
May 01 2017 00:23
@iandelible When you call steamroller again it will return a flattened array you need to combine that with the answer
Gulsvi
@gulsvi
May 01 2017 00:29
@Tammzz Brownies just add up when you help people in chat or finish challenges
No use for them :cookie: :cookie:
iandelible
@iandelible
May 01 2017 00:35
@sjames1958gm I'm sorry I don't understand what you mean.
Stephen James
@sjames1958gm
May 01 2017 00:36
@iandelible steamrollArray(element); you call this function to steamroll a sub array - it returns that sub array flattened - you need to put that in the output
Gonçalo Pedro
@gpedro34
May 01 2017 00:41

can someone help me out understanding sort() ?
I have to sort an array from tthe largest t smallest but i don't seem to understand how i can do it... here is my code:

var array = [1, 12, 21, 2];

// Only change code below this line.

array.sort(function(a, b) {
return a + b;
});

my output is : [2, 21,12, 1];
don't make much sense o.O
iandelible
@iandelible
May 01 2017 00:42
@sjames1958gm so i could use the push() function to put the result into the array?
Manny
@Alloffices
May 01 2017 00:45
Having some trouble getting this to work:

function palindrome(str) {
  // Good luck!
  var res = str.split('').reverse().join('').replace(/\s|#|_|[^\w\s]/g,'').toLowerCase();
  if (str === res) {
    return true;
  } else if (str !== res) {
    return false;
  } else {
    return "Nothing!";
  }
//   return false;
}
palindrome("eye");
Gulsvi
@gulsvi
May 01 2017 00:46
@Alloffices Haven't tried running your code or anything, but if str is not all lowercase, it won't match res since you're making that all lowerCase. At least one thing to check out.
Gonçalo Pedro
@gpedro34
May 01 2017 00:47
@SkyCoder01
can you take a look at my sort() issue?
Gulsvi
@gulsvi
May 01 2017 00:49
@gpedro34 I'm not sure how adding a+b should work. Would need to console.log() it. The documentation for .sort() says to do this to sort ascending:
var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) {
  return a - b;
});
console.log(numbers);

// [1, 2, 3, 4, 5]
ascending*
Jor
@joreyesl
May 01 2017 00:51
@Alloffices you need to clean up and replace str first. Then you can get res. Otherwise you will be comparing res with the original str that still has special characters
Karol Gruszka
@Sniadekk
May 01 2017 00:51
function sprawdz(nr){

for (i=0; i>dlugosc; i++){
if (haslo.charAt(i)==literki.charAt(nr)){
  alert (i);
}
}
Hello, what is wrong with this code? It should compare two characters in two diffrent variables but it doesn't. Can you help me?
Eduar Tua
@eduartua
May 01 2017 00:53
Guys, it is good practice to put a for loop inside a callback of a .filter()?
Todd Abraham
@toddabraham
May 01 2017 00:53
Hello FCCers!
Karol Gruszka
@Sniadekk
May 01 2017 00:53
hello!
Todd Abraham
@toddabraham
May 01 2017 00:54
I could use some help here. I know this question will be foundational stuff, but I just need help getting my head straight…..
Gonçalo Pedro
@gpedro34
May 01 2017 00:54
i've tried it and that returns [1,2,12,21] also the example in the challenge is give from the smallest to the largest and is exactly what you put in there lol It's pretty confusing... i also had come to the mozilla documentation and didn't got it and they say in there that from the biggest to smallest is the way i am doing but it looks like the issue is beause the sort function converts the numbers into strings and as the numbers shown in the array are with 1 digit and 2, it causes this because to the sort function 10 is smallest than 2 wich doesn't make any sense lol
Jor
@joreyesl
May 01 2017 00:55
@gpedro34 sort expects a negative number if a should go before b, 0 if they are equal, and a positive number if b should go before a.
c0d0er2
@c0d0er2
May 01 2017 00:55

Can somebody please help me with Replacing If Else Chains with Switch in JavaScript? Here is my code:

function chainToSwitch(val) {
  var answer = "";
  // Only change code below this line

  switch (val === "bob") {
    case 1:
      answer = "Marley";
      break;
    case 2:
      answer = "The Answer";
      break;
    case 3:
      answer = "There is no #1";
      break;
    case 4:
      answer = "Missed me by this much!";
      break;
    default:
      answer = "Ate Nine";
      break;
  }

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

// Change this value to test
chainToSwitch(7);

Here is the link: https://www.freecodecamp.com/challenges/replacing-if-else-chains-with-switch

Gulsvi
@gulsvi
May 01 2017 00:56
@toddabraham Feel free to ask your question
Gonçalo Pedro
@gpedro34
May 01 2017 00:56
@joreyesl thanks... the answer was b-a then hahaha
CamperBot
@camperbot
May 01 2017 00:56
gpedro34 sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 813 | @joreyesl |http://www.freecodecamp.com/joreyesl
Karol Gruszka
@Sniadekk
May 01 2017 00:57
Can you help me please?
Todd Abraham
@toddabraham
May 01 2017 00:57
I’ve been working on the palindromes exercise. To test my learning of the RegExp syntax, I want to test a few different methods on CodePen JS console. The question is, how do I setup something like the palindromes exersise and have the result print to console in CodePen?
Jor
@joreyesl
May 01 2017 00:57
@gpedro34 yep, a-b sorts number ascending, b-a will sort descending. :thumbsup:
Todd Abraham
@toddabraham
May 01 2017 00:58

```function palindrome(str) {

var re = /[\W_]/g;

var lowRegStr = str.toLowerCase().replace(re, '');

var reverseString = lowRegStr.split('').reverse().join('');

// Good luck!
return reverseString === lowRegStr;
}

palindrome("A man, a plan, a canal. Panama");

Jor
@joreyesl
May 01 2017 00:58
@toddabraham I would suggest using https://repl.it/languages/javascript instead. You can copy the code from FCC
Gulsvi
@gulsvi
May 01 2017 00:59
The codepen console is fine...
Vamp
@the-vampiire
May 01 2017 01:00

how can this be condensed? it is very inefficient

// 1) alphabetize the items

        var items = [];
        var new_items = [];


        for(var i in arr1){
           items.push(arr1[i][1]);
           new_items.push(arr2[i][1]);
        }

        items.sort();
        new_items.sort();


        for(var j in arr1){
            arr1[j][1] = items[j];
            arr2[j][1] = new_items[j];
        }

with arrays

var arr1 = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var arr2 = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];
Gulsvi
@gulsvi
May 01 2017 01:00
@toddabraham Like this:
function palindrome(str) {

var re = /[\W_]/g;

var lowRegStr = str.toLowerCase().replace(re, '');

var reverseString = lowRegStr.split('').reverse().join('');

// Good luck!
return reverseString === lowRegStr;
}

var output = palindrome("A man, a plan, a canal. Panama");
console.log(output);
Csaba Balogh
@JasonCorp84
May 01 2017 01:05
blob
After 4 days :D and 5 people's help :D
Jor
@joreyesl
May 01 2017 01:06
@JasonCorp84 :thumbsup:
Todd Abraham
@toddabraham
May 01 2017 01:09
Awesome help, @SkyCoder01 and @joreyesl. I think I need to reframe my question somewhat though. I’m more interested in testing my understanding of RegExp, so I’d like to see in the console the effects of RegExp’s various modifiers on a string.
Gulsvi
@gulsvi
May 01 2017 01:10
@toddabraham http://www.regexpal.com/ may be better if it's for RegExp specifically
There's also: http://www.regexr.com/
Ian Arsenault
@ianarsenault
May 01 2017 01:12
There's also https://regex101.com/
Vamp
@the-vampiire
May 01 2017 01:14

in case anyone wanted an answer

// 1) alphabetize the items

        for(i in arguments){
            sort_arrs(arguments[i]);
        }

        function sort_arrs(arr){
            return arr.sort(sorting_hat);
        }


        function sorting_hat(a,b){
            return a[1].localeCompare(b[1]);
        }

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

Alfred Conlan
@AlfredConlan
May 01 2017 01:15
Hello everyone. If the Boolean() function returns the primitive value, why does this not pass the tests in the Boo Who challenge?
function booWho(bool) {
  var boolValue = Boolean(bool);
  return boolValue;
}

booWho(false);
khanvuthy88
@khanvuthy88
May 01 2017 01:17
(shift+enter for line break) var code = "formatted";
cchadwick75
@cchadwick75
May 01 2017 01:17
Im new to javascript but this is really getting me. I cannot get the lookupprofile to work for the life of me...can anyone provide insight

function lookUpProfile(firstName, prop) {
// Only change code below this line
var results = '';
for (var i = 0; i < contacts.length; i++){
//return contacts[i].prop ;
if (contacts[i].prop.hasOwnProperty()=== true){
console.log(contacts[i][prop]);
if (contacts[i][prop] === firstName){
results = contacts[i][prop];
} else {
results = 'No such contact';
}

} else {  

  results = 'No such property';

}
return results;
}

// Only change code above this line
}

Dan Couper
@DanCouper
May 01 2017 01:18
@AlfredConlan You're supposed to be checking if what goes in is a boolean value: if you use Boolean like that you convert every single value, regardless of what it actually was, to a boolean. Then you're returning the result of that conversion - so you return true or false every time. But, for example false is a boolean value
khanvuthy88
@khanvuthy88
May 01 2017 01:18
var code ="formatted"

ar 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');

Keon Samuel
@keonsam
May 01 2017 01:18
@AlfredConlan booWho is already passing false.
Jor
@joreyesl
May 01 2017 01:19
@AlfredConlan you should be checking if bool is a boolean primitive. try using typeof
Keon Samuel
@keonsam
May 01 2017 01:19
no I think there is a boolean function or something like that.
Dan Couper
@DanCouper
May 01 2017 01:20
no @keonsam, that's what he's already doing which won't work
Keon Samuel
@keonsam
May 01 2017 01:20
yh
basically passing false and boolean will give back false.
Alfred Conlan
@AlfredConlan
May 01 2017 01:21
So typeOf then?
khanvuthy88
@khanvuthy88
May 01 2017 01:21
'''
CamperBot
@camperbot
May 01 2017 01:21
:bulb: to format code use backticks! ``` more info
khanvuthy88
@khanvuthy88
May 01 2017 01:21
'''
var code='formatted'
'''
CamperBot
@camperbot
May 01 2017 01:21
:bulb: to format code use backticks! ``` more info
Jor
@joreyesl
May 01 2017 01:21
@AlfredConlan typeof
khanvuthy88
@khanvuthy88
May 01 2017 01:23
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');
kerafyrm02
@kerafyrm02
May 01 2017 01:24
What does the directions say for this exercise.
Alfred Conlan
@AlfredConlan
May 01 2017 01:24
@joreyesl Oh, ok. I see now. Thank you!
CamperBot
@camperbot
May 01 2017 01:24
alfredconlan sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 814 | @joreyesl |http://www.freecodecamp.com/joreyesl
Jor
@joreyesl
May 01 2017 01:25
@AlfredConlan np
khanvuthy88
@khanvuthy88
May 01 2017 01:25

Hello every one here please help me with this, I am really stuck with it.
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.

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');
Alfred Conlan
@AlfredConlan
May 01 2017 01:26
@DanCouper @keonsam Thanks for your help
CamperBot
@camperbot
May 01 2017 01:26
alfredconlan sends brownie points to @dancouper and @keonsam :sparkles: :thumbsup: :sparkles:
:cookie: 677 | @dancouper |http://www.freecodecamp.com/dancouper
:cookie: 351 | @keonsam |http://www.freecodecamp.com/keonsam
Eduar Tua
@eduartua
May 01 2017 01:26

guys, why

var args = [].slice.call(arguments, 1);

remove the first argument of the array created?

kerafyrm02
@kerafyrm02
May 01 2017 01:27
@khanvuthy88 Create an if statement that adds to count when card is 10, J, Q, K, A
Eduar Tua
@eduartua
May 01 2017 01:27
I mean the first value of the resulting array
kerafyrm02
@kerafyrm02
May 01 2017 01:27
just use shift() eduar
khanvuthy88
@khanvuthy88
May 01 2017 01:27
@kerafyrm02 OK, wait let me try frist
Jor
@joreyesl
May 01 2017 01:28
@eduartua slice() creates an array starting at the given index. You are passing in 1 so the new array does not contain the element at index 0
Vamp
@the-vampiire
May 01 2017 01:28
@kerafyrm02
kerafyrm02
@kerafyrm02
May 01 2017 01:28
yes?
Vamp
@the-vampiire
May 01 2017 01:28
hold me
kerafyrm02
@kerafyrm02
May 01 2017 01:28
Who needs help?!
Vamp
@the-vampiire
May 01 2017 01:28
<---
kerafyrm02
@kerafyrm02
May 01 2017 01:28
/holds Vamp
Vamp
@the-vampiire
May 01 2017 01:28
^^^
kerafyrm02
@kerafyrm02
May 01 2017 01:29
Next?
Vamp
@the-vampiire
May 01 2017 01:29
answer your pms
ya bastad
cchadwick75
@cchadwick75
May 01 2017 01:29
i do
kerafyrm02
@kerafyrm02
May 01 2017 01:29
sorry just saw it
Eduar Tua
@eduartua
May 01 2017 01:30
@joreyesl I was confused by the call() method, thank you
CamperBot
@camperbot
May 01 2017 01:30
eduartua sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 815 | @joreyesl |http://www.freecodecamp.com/joreyesl
Muhammed Moussa
@muhammedMoussa
May 01 2017 01:32
i'm need a help at Using Objects for Lookups
Ian Arsenault
@ianarsenault
May 01 2017 01:33
@eduartua Are you doing the Sorted Union problem?
CamperBot
@camperbot
May 01 2017 01:33
:bulb: to format code use backticks! ``` more info
Eduar Tua
@eduartua
May 01 2017 01:34
@GorgonsMaze I am doind the destroyer problem
doing
Ian Arsenault
@ianarsenault
May 01 2017 01:34
@eduartua Ah, ok.
Muhammed Moussa
@muhammedMoussa
May 01 2017 01:34

function phoneticLookup(val) {
  var result = lookup;
    var lookup = {
      alpha:"Adams",
      bravo:"Boston",
      charlie:"Chicago",
      delta:"Denver",
      echo:"Easy",
      foxtrot:"Frank",
    };
  return result;
}

phoneticLookup("charlie");
Ken Haduch
@khaduch
May 01 2017 01:35
@muhammedMoussa - note that you can go back and edit (or delete) old posts for a few minutes after you make them. Click the three dots near the timestamp on your post and it will pop up a menu. Just FYI...
Dan Couper
@DanCouper
May 01 2017 01:36
@eduartua also, is easier to understand if you use Array.from(arguments).slice(1) (and note that using slice.call to get function arguments is seriously discouraged now because JS engines can't optimise it)
Ken Haduch
@khaduch
May 01 2017 01:37
@muhammedMoussa - and for your exercise, what you have to do is assign a value to result using object lookup, with val containing the key, and you should use one of "dot" or "bracket" notation - just review those lessons, or try them both to see what works (only one of them will.) The line that you need to add should contain all three variables, result, lookup and val, along with = and either . or []... and it should be preceding the return result; line.
Corri Taylor
@corritaylor
May 01 2017 01:37
Hello All! I’m working on the "Quoting Strings with Single Quotes” excersice. and I’m so lost.
Eduar Tua
@eduartua
May 01 2017 01:37
@DanCouper I didn't know that thank you so much @DanCouper
CamperBot
@camperbot
May 01 2017 01:37
eduartua sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 678 | @dancouper |http://www.freecodecamp.com/dancouper
Dan Couper
@DanCouper
May 01 2017 01:39
@eduartua theslice.call... thing used to be the standard way of putting function args into an array, which is why most books/tutorials still use it. But you can use Array.from(arguments) everywhere now, just gives you the arguments in a nice array form if you need them that way
Muhammed Moussa
@muhammedMoussa
May 01 2017 01:39
@khaduch assign all objects vals to result variable or what
Eduar Tua
@eduartua
May 01 2017 01:40
thank you @DanCouper where can I read about those kinda of updates?
CamperBot
@camperbot
May 01 2017 01:40
eduartua sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: eduartua already gave dancouper points
Muhammed Moussa
@muhammedMoussa
May 01 2017 01:40
  var result = lookup.alpha;
i tried this but work for only one case
Ken Haduch
@khaduch
May 01 2017 01:41
@muhammedMoussa - the hint I put there - The line that you need to add should contain all three variables, result, lookup and val, along with = and either . or []... and it should be preceding the return result; line. It should not contain the keyword var because the variable is already defined. Using lookup.alpha is only access that one key and value. Using var in the appropriate manner will allow it to change with each invocation of the function.
J Tang
@jf4nathan
May 01 2017 01:42
Hey @khaduch , I'm working on that same problem right now and I have that part figured out. I'm still not able to pass all the tests though for some reason
can I PM you my code so i don't post the answer for anyone else
Ken Haduch
@khaduch
May 01 2017 01:43
@jf4nathan - can you post your code? I'll be happy to take a look...
Muhammed Moussa
@muhammedMoussa
May 01 2017 01:43
i cant understand what is val @khaduch
J Tang
@jf4nathan
May 01 2017 01:44

// 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
  };
  result = lookup.val;
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("alpha");
khanvuthy88
@khanvuthy88
May 01 2017 01:44
@kerafyrm02 what i tried is :
```
Ken Haduch
@khaduch
May 01 2017 01:45
@muhammedMoussa in the function definition, there is function phoneticLookup(val) { - val is the function argument, and it will be assigned the value that is in the parentheses when the function is invoked. So phoneticLookup("delta"); will have the string "delta" assigned to val so that you can use the variable val in the look-up from the object lookup.
khanvuthy88
@khanvuthy88
May 01 2017 01:45
@kerafyrm02 what i tried is :
ar count = 0;

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

  if(card=== '2' || card=== '3' || card=== '4' || card=== '5' || card=== '6' ){
    return '5 Bet';
  }else if(card === '7' || card === '8' || card === '9' ){
    return '0 Hold';
  }else if(card === '10' || card === 'J' || card === 'Q' || card ==='K' || card === 'A' ){
    return '-5 Hold';
  }else if(card === '3' || card === '7' || card === 'Q' || card === '8' || card === 'A' ){
    return "-1 Hold";
  }else if(card === '2' || card ==='J' || card==='9' || card==='2' || card==='7' ){
    return '1 Bet';
  }else if(card === '2' || card=== '2' || card=== '10' ){
    return '1 Bet';
  }else if(card=== '3' || card=== '2' || card=== 'A' || card=== '10' || card=== 'K' ){
    return '-1 Hold';
  }else{
    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');
Eduar Tua
@eduartua
May 01 2017 01:45

Guys in this code:
`
function destroyer(arr) {
var args = [].slice.call(arguments, 1);
console.log(args);
// Remove all the values
var ans = arguments[0].filter(function(val) {
for(var i = 0; i < args.length; i++){
if (args[i] !== val){
return val;
}
}
});
return ans;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
```
If I use == in the conditional it returns the array expected but if I change it for != it return the entire array and do not filter, Can anyone help me on this?

Dan Couper
@DanCouper
May 01 2017 01:45
@eduartua https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/arguments - there's a small section just above the little warning box, then there's just two lines under the heading Using the Spread Syntax with Arguments. Note you can also use a loop to get the other arguments as well - for (var i = 1; i < arguments.length; i++) { /* arguments[i] gets your other args */ }
Eduar Tua
@eduartua
May 01 2017 01:46

Guys in this code:
`
function destroyer(arr) {
var args = [].slice.call(arguments, 1);
console.log(args);
// Remove all the values
var ans = arguments[0].filter(function(val) {
for(var i = 0; i < args.length; i++){
if (args[i] !== val){
return val;
}
}
});
return ans;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
```
If I use == in the conditional it returns the array expected but if I change it for != it return the entire array and do not filter, Can anyone help me on this?

Dan Couper
@DanCouper
May 01 2017 01:46
Ah, right, problem is in your if
Eduar Tua
@eduartua
May 01 2017 01:46
The markdown is failing me Sorry about the message duplicated
khanvuthy88
@khanvuthy88
May 01 2017 01:46
@kerafyrm02 I got correct only one and another is not correct. please help
Ken Haduch
@khaduch
May 01 2017 01:47
@jf4nathan result = lookup.val; is not correct. val is a variable, and recall that there are two ways to access an object - dot notation and bracket notation. Only one of them is valid to use with the property name being held in a variable. You can review the lesson "Accessing Objects Properties with Variables" to see the proper technique.
Chris
@bestintown23
May 01 2017 01:47
where is a good place to start to learn javascript
J Tang
@jf4nathan
May 01 2017 01:47
@khaduch THANKS! that solved it for me :)
CamperBot
@camperbot
May 01 2017 01:47
jf4nathan sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2811 | @khaduch |http://www.freecodecamp.com/khaduch
Dan Couper
@DanCouper
May 01 2017 01:50
@eduartua the function in filter has to return true or false. If it's false, it will drop that value, if true, it'll keep it. So if the value is found in the loop you want to return false (not return the value as you are doing). Then right after the loop return true - the loop has finished, the value wasn't there, and fine to keep the array value
Ian Arsenault
@ianarsenault
May 01 2017 01:50
@bestintown23 Free Code Camp and https://www.codecademy.com/learn/javascript
Christopher McCormack
@cmccormack
May 01 2017 01:52
Just finished my React Leaderboard project - can anyone familiar take a look and provide a review? https://codepen.io/cmccormack/pen/vmmxWZ
Eduar Tua
@eduartua
May 01 2017 01:55
thank you @DanCouper it worked. So filter always work with boolean, right?
CamperBot
@camperbot
May 01 2017 01:55
eduartua sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: eduartua already gave dancouper points
Eduar Tua
@eduartua
May 01 2017 01:56
@DanCouper the true after the loop is to return the resulting array, right? because If I do not add that line it returns an empty array
Dan Couper
@DanCouper
May 01 2017 01:58

@eduartua Yes on the boolean. And the true after is basically saying "i want to keep this value", it's not returning the array - what filter does is go through and run that function for each value in the array in turn. So if the current value filter is looking at matches one of the values you want destroyed, you send back false (which drops it from the array), but if it doesn't you send back true (which says keep it)

(side issue, but do be aware that filter will try to convert anything to a boolean anyway, which can be an issue - like in your original code, you were returning the value - if the value was a 0, filter would see that as false, if it was any other number, filter would see it as true)

Ken Haduch
@khaduch
May 01 2017 02:00
@jf4nathan :+1:
Eduar Tua
@eduartua
May 01 2017 02:02
thank you so much @DanCouper
CamperBot
@camperbot
May 01 2017 02:02
eduartua sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: eduartua already gave dancouper points
Dan Couper
@DanCouper
May 01 2017 02:06

@eduartua might be helpful to see it written out imperatively:

function filter(arr, truthTestFunction) {
  var filteredArr = [];

  for (var i = 0; i < arr.length; i++) {
    if (truthTestFunction(arr[i]) === true) {
      filteredArr.push(arr[i]);
    }
  }

  return filteredArray;
}

so

> function smallerThan5(n) { return n < 5; }
> filter([1,2,3,4,5,6,7,8,9], smallerThan5)
[1,2,3,4]
Corri Taylor
@corritaylor
May 01 2017 02:07
I’m having trouble on this problem…
var myStr = 'FirstLine\n\\SecondLine\\rThirdLine'; // Change this line
Eduar Tua
@eduartua
May 01 2017 02:08
@DanCouper Nice solution, I did that way because they challenge suggests to use filter().
Ken Haduch
@khaduch
May 01 2017 02:09
@corritaylor - looks like you are missing a \ after the "SecondLine" - because you are inserting a backslash there. You have \\r and you need \\\r
Dan Couper
@DanCouper
May 01 2017 02:09
@eduartua yup, you'd always just use the filter method in practise - that above is just kinda how filter works under-the-hood
Corri Taylor
@corritaylor
May 01 2017 02:10
omgggg lol it was in my face rofl. Thank you very much @khaduch !
CamperBot
@camperbot
May 01 2017 02:10
corritaylor sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2812 | @khaduch |http://www.freecodecamp.com/khaduch
Eduar Tua
@eduartua
May 01 2017 02:10
@DanCouper That is awesome, how long it will take me to reach your level? You know a lot
Thank you @DanCouper
CamperBot
@camperbot
May 01 2017 02:10
eduartua sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: eduartua already gave dancouper points
Ken Haduch
@khaduch
May 01 2017 02:11
@corritaylor - sometimes those things are hard to spot - always good to have another set of eyes checking things!
Alan Saber
@Alan95
May 01 2017 02:11
hey guys, how can i remove this placeholder after a short of time, like 2 seconds? is there any delay option? after i created it: input.attr("placeholder", "Hello");
Corri Taylor
@corritaylor
May 01 2017 02:11
@khaduch you’ve got that right lol.
Dan Couper
@DanCouper
May 01 2017 02:12
takes a while, but after the initial pain and many thousands of google searches/MDN pages/stack overflow searches it all gets internalised, and your head gets full of useless JS knowledge ;)
Ken Haduch
@khaduch
May 01 2017 02:13
@corritaylor - and an example of how the tests report the problem - you have \\r - it reports an error that you should have \r, because it "sees" the \\ as the correctly escaped backslash in that part of the line. I was thinking that it should tell you that you didn't have "two correctly escaped backslash characters" instead... all depends on how you look at it, and the tests (this is the lesson) are very specific in what and how they examine results.
Christopher McCormack
@cmccormack
May 01 2017 02:14
@Alan95 checkout the setTimeout() method, takes a function and a timer as arguments, timer in milliseconds
Corri Taylor
@corritaylor
May 01 2017 02:15
@khaduch that makes total sense to me now that I realized I had to add another “\” to the string. I knew I was in the right place, just couldn’t figure it out at the time.
Ken Haduch
@khaduch
May 01 2017 02:15
@corritaylor - it's just a lesson to learn - the tests are helpful in guiding you to the answer if they find a failure, but they "see" things their own way - sometimes not the way you see it! :)
David Miller
@DavidMillerFL
May 01 2017 02:16

Variables which are used without the var keyword are automatically created in the global scope. This can create unintended consequences elsewhere in your code or when running a function again. You should always declare your variables with var

How do you even declare a variable without starting off with var ?

Keon Samuel
@keonsam
May 01 2017 02:18
lol
Ken Haduch
@khaduch
May 01 2017 02:18
@DavidMillerFL - just writing an equation (in javascript) as myStr = "this is a string"; will cause the creation of a global variable myStr if one has not been previous declared within the scope of where the equation is used.
Benji
@Benji-Leboe
May 01 2017 02:19

Hey guys! So I'm working through "Eloquent JavaScript" and just finished the "Deep Comparison" exercise. I wound up with a very different solution than is given in the book, and I feel like it's a lot more elegant and straightforward and it seems to do exactly the same thing. Thoughts?
My code:

function deepEqual(x,y){
    if(x === null||y === null){
        return undefined;
    }
    if(x === y){
        return true;
    }
    if(typeof x === 'object'&&typeof y === 'object'){
        for(var i in x){
            if(!y.hasOwnProperty(i)||!deepEqual(x[i],y[i])){
                return false;
            }
        }
        return true;
    }   
    return false;
}

VS. the answer given:

function deepEqual(a, b) {
  if (a === b) return true;

  if (a == null || typeof a != "object" ||
      b == null || typeof b != "object")
    return false;

  var propsInA = 0, propsInB = 0;

  for (var prop in a)
    propsInA += 1;

  for (var prop in b) {
    propsInB += 1;
    if (!(prop in a) || !deepEqual(a[prop], b[prop]))
      return false;
  }

  return propsInA == propsInB;
}
David Miller
@DavidMillerFL
May 01 2017 02:20
@khaduch Is it created globally even if I create it inside of a ‘'local’' block? I read that creating variables inside of other objects / functions makes it only locally accessible.
Benji
@Benji-Leboe
May 01 2017 02:21
@DavidMillerFL yes any variable created without var is global scope which is why it's bad practise
David Miller
@DavidMillerFL
May 01 2017 02:21
@Benji-Leboe Ah, I see. Thanks guys. @khaduch
CamperBot
@camperbot
May 01 2017 02:21
davidmillerfl sends brownie points to @benji-leboe and @khaduch :sparkles: :thumbsup: :sparkles:
:cookie: 263 | @benji-leboe |http://www.freecodecamp.com/benji-leboe
:star2: 2813 | @khaduch |http://www.freecodecamp.com/khaduch
Alan Saber
@Alan95
May 01 2017 02:22
http://codepen.io/BearCoding/pen/rmyQad?editors=1011 any tips or review for my current project?
Dan Couper
@DanCouper
May 01 2017 02:23
@Benji-Leboe do double equals for null checks, not triple. why undefined instead of false?
Ken Haduch
@khaduch
May 01 2017 02:24
@DavidMillerFL - that is what I meant by "within the scope" of the usage of that equation. If you have previous declared var myStr = ''; for example (sticking with my example) within a function's code block, then using myStr = "this is a string"; within that function will access the locally-declared and scoped variable. Also, within a function's code block, a function argument will be a "local" variable (for most practical purposes). It can be confusing if you declare a global variable and then a local variable and use them expecting one or the other thing to really - so as @Benji-Leboe said - bad practice to do that, and it can lead to buggy behavior if you happen to do it inadvertently.
Benji
@Benji-Leboe
May 01 2017 02:26
@DanCouper to differentiate an actual value from null so that it didn't pass false if one or more arguments were null. Why double and not triple? Is it because null is an object?
Todd Abraham
@toddabraham
May 01 2017 02:26
@SkyCoder01 Wow, thank you! Who knew RegEx was such a big deal?
CamperBot
@camperbot
May 01 2017 02:26
toddabraham sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1233 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Benji
@Benji-Leboe
May 01 2017 02:29
@DanCouper Nevermind I looked it up. That's exactly what it is, because null !== undefined, but null == undefined
Dan Couper
@DanCouper
May 01 2017 02:31
Sorry was a bit slow there. Yeah 99.9999% of the time you want to cover both for null checks, so it's basically the only situation where double equals is the best way to go
FlashHero
@FlashHero
May 01 2017 02:35

function translatePigLatin(str) {
  var current=[];
  var result=[];
  var arr=str.split('');
  var vowels=['a','e','i','o','u'];
  for(var i=0;i<arr.length;i++){
    if(vowels.includes(arr[0])){
      return str+'way';
    }
    else if(!vowels.includes(arr[i])){
      current.push(arr[i]);
    }else if(vowels.includes(arr[i])){
      var firstvowel=str.indexOf(arr[i]);
      var sliceup=arr.slice(firstvowel);
      result.push(sliceup);
    }
  }
  return result+current;
}

translatePigLatin("consonant");
what is wrong help please
Alan Saber
@Alan95
May 01 2017 02:35
@cmccormack thanks its worked
CamperBot
@camperbot
May 01 2017 02:35
alan95 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 471 | @cmccormack |http://www.freecodecamp.com/cmccormack
Jason Myers
@Jmyers1101
May 01 2017 02:41
Stuck again...
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");
khanvuthy88
@khanvuthy88
May 01 2017 02:41

Dear all members here.
please kindly help to resolve this one, i am really stuck with it.

var count = 0;

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

  if(card=== '2' || card=== '3' || card=== '4' || card=== '5' || card=== '6' ){
    return '5 Bet';
  }else if(card === '7' || card === '8' || card === '9' ){
    return '0 Hold';
  }else if(card === '10' || card === 'J' || card === 'Q' || card ==='K' || card === 'A' ){
    return '-5 Hold';
  }else if(card ==='3' || card === '7' || card === 'Q' || card === '8' || card === 'A' ){
    return "-1 Hold";
  }else if(card === '2' || card ==='J' || card==='9' || card==='2' || card==='7' ){
    return '1 Bet';
  }else if(card ==='2' || card=== '2' || card=== '10' ){
    return '1 Bet';
  }else if(card=== '3' || card=== '2' || card=== 'A' || card=== '10' || card=== 'K' ){
    return '-1 Hold';
  }else{
    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');

Cards Sequence 2, 3, 4, 5, 6 should return "5 Bet"
Cards Sequence 7, 8, 9 should return "0 Hold"
Cards Sequence 10, J, Q, K, A should return "-5 Hold"
Cards Sequence 3, 7, Q, 8, A should return "-1 Hold"
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
Cards Sequence 2, 2, 10 should return "1 Bet"
Cards Sequence 3, 2, A, 10, K should return "-1 Hold"

FlashHero
@FlashHero
May 01 2017 02:42
@Jmyers1101 you have to pass the checkProp in to .hasOwnProperty parenthesis
Christopher McCormack
@cmccormack
May 01 2017 02:42
@Jmyers1101 hasOwnProperty takes an argument
Ken Haduch
@khaduch
May 01 2017 02:42
@FlashHero - there are times when you are using result and the state of resultis that you have pushed a bunch of letters to it and haven't joined them together. So your cases with the vowels first are fine, the others aren't. For example the return for consonant looks like o,n,s,o,n,a,n,t, and goes on.
Christopher McCormack
@cmccormack
May 01 2017 02:43
@khanvuthy88 you need to modify count over time and you’re not doing that if you return immediatly
David Miller
@DavidMillerFL
May 01 2017 02:43
function fun1() {
  // Assign 5 to oopsGlobal Here
  oopsGlobal = 5;
}
So oopsGlobal is now… global?
Ken Haduch
@khaduch
May 01 2017 02:43
@DavidMillerFL - yes...
Jason Myers
@Jmyers1101
May 01 2017 02:43
@FlashHero If I put the checkProp into the .hasOwnProperty it still returns with nothing
Todd Abraham
@toddabraham
May 01 2017 02:44
How do I type the small uparrow in this regular expression? /[^A-Za-z0–9]/g
David Miller
@DavidMillerFL
May 01 2017 02:44
@khaduch Just double checking - Thanks again :)
CamperBot
@camperbot
May 01 2017 02:44
davidmillerfl sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: davidmillerfl already gave khaduch points
Christopher McCormack
@cmccormack
May 01 2017 02:44
@khanvuthy88 also why so much overlap with cards?? Are you supposed to use a switch for this project?
FlashHero
@FlashHero
May 01 2017 02:44
@Jmyers1101 you have to return that
Christopher McCormack
@cmccormack
May 01 2017 02:44
@toddabraham shift + 6 on US keyboard
Todd Abraham
@toddabraham
May 01 2017 02:45
@cmccormack Roger that! Works, thank you.
CamperBot
@camperbot
May 01 2017 02:45
toddabraham sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
Jason Myers
@Jmyers1101
May 01 2017 02:45
@cmccormack But what does it take?
CamperBot
@camperbot
May 01 2017 02:45
:cookie: 472 | @cmccormack |http://www.freecodecamp.com/cmccormack
Jason Myers
@Jmyers1101
May 01 2017 02:45
@FlashHero If i return the checkProp it does not give me the value just the property
checkObj("gift") should return "pony".
checkObj("pet") should return "kitten".
checkObj("house") should return "Not Found".
FlashHero
@FlashHero
May 01 2017 02:46
@khaduch so how do I join them I don't really understand what's going on
Christopher McCormack
@cmccormack
May 01 2017 02:46
@Jmyers1101 it takes a property variable, so if you want to see if an object has a property (remember: Object{property: value} you would pass that property variable to that function and it will return a value that tells you if it exists or not
FlashHero
@FlashHero
May 01 2017 02:46
@Jmyers1101 let me see your code
Jason Myers
@Jmyers1101
May 01 2017 02:47
```
Ken Haduch
@khaduch
May 01 2017 02:47
@FlashHero - I haven't analyzed the code - but if you have an array of individual letters, which you might have if you have done a .split('') on a word, or pushed individual letters on an array, you would use something like .join(''); to get them back into a string value. But it looks like you don't have the proper set of characters in there - many sub-strings of the word are being repeated.
Jason Myers
@Jmyers1101
May 01 2017 02:48

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");
Christopher McCormack
@cmccormack
May 01 2017 02:48
@Jmyers1101 Example:
> var a = {'hen': 'cluck'}
undefined
> a.hasOwnProperty('hen')
true
Jason Myers
@Jmyers1101
May 01 2017 02:48
@cmccormack The instructions want me to get the value out of it though, so I am confused
FlashHero
@FlashHero
May 01 2017 02:49
@Jmyers1101 it should be myObj.hasOwnProperty(checkProp)
Christopher McCormack
@cmccormack
May 01 2017 02:49
@Jmyers1101 that’s the next step
jonathanpuc
@jonathanpuc
May 01 2017 02:49
'''
'''
CamperBot
@camperbot
May 01 2017 02:49
:bulb: to format code use backticks! ``` more info
FlashHero
@FlashHero
May 01 2017 02:49
@khaduch I get a different output but can you tell me if the conditions are right though
Christopher McCormack
@cmccormack
May 01 2017 02:49
@Jmyers1101 to get a value, you can call using dot notation a.hen or bracket notation a[‘hen’] using my previous example
Ken Haduch
@khaduch
May 01 2017 02:50
@Jay33Canada - you are using a variable and dot notation to access your property values here: collection[i].key === source.key){ for one thing. And not initializing count in your for loop, for another.
Jason G
@Jay33Canada
May 01 2017 02:50

could someone tell me where i'm going wrong here?

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var sourceLength = Object.keys(source).length;

  for (var i = 0; i < collection.length; i++){
    var count;
        for (var key in source){
          if (collection[i].hasOwnProperty(key) && collection[i].key === source.key){
            count += 1;
          }
        }


    if (count === sourceLength){
      arr.push(collection[i]);
      console.log(arr);
      count = 0;
    }
  }
  // Only change code above this line
  return arr;
}

from the challenge https://www.freecodecamp.com/challenges/wherefore-art-thou

jonathanpuc
@jonathanpuc
May 01 2017 02:51
Hi guys, I'm doing the pig latin challenge. Though I cant figure out how to return the "pigged" into a string. I tried using the join method but no luck!
function translatePigLatin(str) {
  var pigged = '';
  var end;
  var vowels = ['a','e','i','o','u'];

  str = str.split('');

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

  if (str[0]=== vowels[i])
    {
      let end = 'way';
      pigged = str + end;

    }

  else {
    let end = 'ay';
    var y = str[0];
    var x = str.slice(1);     
    pigged = x + y + end;


  }

    }

  return pigged;
}

translatePigLatin("consonant");
khanvuthy88
@khanvuthy88
May 01 2017 02:51
@cmccormack , OK, let me try with switch.
Ken Haduch
@khaduch
May 01 2017 02:52
@Jay33Canada - also, you are using currentObjLength in your outer for loop, and not really using that for anything that makes sense. Things are a little twisted around in your code.
@jonathanpuc - sorry, I got confused on that last comment - working on two problems at the same time...
Christopher McCormack
@cmccormack
May 01 2017 02:54
@Jay33Canada just a brief review, you should initialize count with a number
@Jay33Canada you’ll get a NaN if you don’t initialize then try to do count += 1
Ken Haduch
@khaduch
May 01 2017 02:56
@Jay33Canada - with a couple simple modifications, I got your code working.
  • initialize count
  • remove the outer for loop in your nested for loops
  • use the key in your inner for loop with bracket notation to access the values, i.e. collection[i][key] === source[key]
Soumyaditya Choudhuri
@soum-c
May 01 2017 02:57
Hello, World!
I need help with the Random Quote Machine
Jason G
@Jay33Canada
May 01 2017 02:57
like this @khaduch ? it's still not working
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var sourceLength = Object.keys(source).length;

  for (var i = 0; i < collection.length; i++){
    var count;
        for (var key in source){
          if (collection[i].hasOwnProperty(key) && collection[i][key] === source[key]){
            count += 1;
          }
        }

    if (count === sourceLength){
      arr.push(collection[i]);
      console.log(arr);
      count = 0;
    }
  }
  // Only change code above this line
  return arr;
}
Ken Haduch
@khaduch
May 01 2017 02:58
@Jay33Canada - initialize count as invar count = 0; and try again. Oh, wait and get rid of the outer for loop - it's garbage! - Sorry - I"m just getting confused!
Jason G
@Jay33Canada
May 01 2017 02:58
MAGIC! thanks @khaduch
khanvuthy88
@khanvuthy88
May 01 2017 02:58
@cmccormack , Still can't , more detail please.
Jason G
@Jay33Canada
May 01 2017 02:59
why did it need to be initialized with a number? can't you define variables and give them values later? @khaduch
Soumyaditya Choudhuri
@soum-c
May 01 2017 02:59
I'm trying to use the following code, to edit the text in a <p> tag :
$(document).ready(function() {
    $("#refr").on("click", function(){
      $("#quote-text").html("Here is the message");
    });
  });
Christopher McCormack
@cmccormack
May 01 2017 03:00
@khanvuthy88 read through the problem carefully and make sure you’re fulfilling all the requirements. Often people don’t notice that you’re supposed to maintain a count as you go and only respond with how to play based on that count, not the current drawn card
Ken Haduch
@khaduch
May 01 2017 03:00
@Jay33Canada - an uninitialized variable started out as undefined, and that causes troubles if you try to add to it, etc. You can assign a value later on, but you have to make sure that it is a legit value afterward.
Christopher McCormack
@cmccormack
May 01 2017 03:01
@soum-c what’s your error?
Jason G
@Jay33Canada
May 01 2017 03:01
what happens with var undefined = undefined; and then undefined += 1;? what does java do?
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:01
@cmccormack It doesn't seem to update the text.
Ken Haduch
@khaduch
May 01 2017 03:02
@Jay33Canada - I don't know what java would do, I don't know what javascript would do, either. I think that you'd blow up the world with that! :)
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:02
@cmccormack I have a <p> tag with an id of quote-text, and a button with an id of refr
Christopher McCormack
@cmccormack
May 01 2017 03:02
@Jay33Canada did you ensure you have both of those IDs defined in your html? Do you have a pen?
Jason G
@Jay33Canada
May 01 2017 03:02
i just tried it @khaduch it just says NaN
Interesting
@cmccormack i think you meant that for someone else. my problem is solved.
Christopher McCormack
@cmccormack
May 01 2017 03:03
yup sorry
jonathanpuc
@jonathanpuc
May 01 2017 03:03
@khaduch thats okay, ill be patient! what I mean is that my code only takes me up to the point where the string thats meant to be in pig latin returns "o,n,s,o,n,a,n,tcay" instead of onsonantcay.
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:04
@cmccormack Here is my CodePen: http://codepen.io/soum-c/pen/pPPjBZ
Ben Carp
@carpben
May 01 2017 03:04

Hi, in the tic tac toe project, I'm trying to control some of the data in an object. Take a look at the last property:

    game: {
      _gameBoard: [
        ["", "", ""],
        ["", "", ""],
        ["", "", ""]
      ],
      player1starts: Boolean(Math.round(Math.random())),
      nextMove: 1, //between 1 and 9
      player1Move: this.player1starts
    },

for some reason my assignment of the last property doesn't work, and it is left undefined.
Any idea why, and which solution can I implement?

Jason G
@Jay33Canada
May 01 2017 03:05
thanks for the help guys. have a good night
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:06
@cmccormack Anything wrong with my code?
Christopher McCormack
@cmccormack
May 01 2017 03:06
@soum-c did you actually load jQuery in your settings?
Ken Haduch
@khaduch
May 01 2017 03:06

@jonathanpuc - then what you need to do is take that final string that was concatenated together, then do :

    pigged = x + y + end;
    pigged = pigged.join('');

If you have the correct sequence of letters in pigged before the join. Oh, wait, I don't know if pigged is an array at that point. I have to study the code... If you had it as an array of characters, then the last line there would join it...

Soumyaditya Choudhuri
@soum-c
May 01 2017 03:07
@cmccormack Thanks! Sorry for the trouble.
CamperBot
@camperbot
May 01 2017 03:07
soum-c sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 473 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
May 01 2017 03:07
@soum-c no trouble at all!
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:07
@cmccormack And how do brownie points work?
Christopher McCormack
@cmccormack
May 01 2017 03:08
@soum-c just a gesture to encrouage people to help others and finish projects
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:08
@cmccormack Alright, and how are they sent?
Ken Haduch
@khaduch
May 01 2017 03:08
@jonathanpuc - so this: pigged = x.join('') + y + end; gets the first two tests to pass, with the code that you posted above. The last three do not pass, the "starts with a vowel" cases are broken, and the "starts with two consonants" case is broken.
Christopher McCormack
@cmccormack
May 01 2017 03:09
@soum-c saying thanks or ty or other strings that are matched while @mentioning someone’s name
jonathanpuc
@jonathanpuc
May 01 2017 03:10
@khaduch hmm, okay thanks Ken! Ill keep cracking at it
CamperBot
@camperbot
May 01 2017 03:10
jonathanpuc sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2814 | @khaduch |http://www.freecodecamp.com/khaduch
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:10
@cmccormack Alright, thanks again!
CamperBot
@camperbot
May 01 2017 03:10
soum-c sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: soum-c already gave cmccormack points
Christopher McCormack
@cmccormack
May 01 2017 03:10
@soum-c :thumbsup:
Eduar Tua
@eduartua
May 01 2017 03:11
I've never done a pairing code session, Does anyone here want to pair to do the Caesar cipher?
Christopher McCormack
@cmccormack
May 01 2017 03:16
@eduartua you may have better luck a bit earlier in the day, there aren’t as many people on right now
Eduar Tua
@eduartua
May 01 2017 03:16
I see that, What about people from others continents?
Christopher McCormack
@cmccormack
May 01 2017 03:16
@eduartua there is also a LetsPair room on Gitter
not sure but my experience is the most active times are a few hours earlier than now
Eduar Tua
@eduartua
May 01 2017 03:17
No one in the letspair room
Ken Haduch
@khaduch
May 01 2017 03:18
@jonathanpuc - one thing that could cause you some problems is this: if (str[0] === vowels[i]) because you are looping using str.length as the loop control, so you are possibly getting an error accessing something outside the bounds of your vowels array. Your previous test for that was better.
Jason Myers
@Jmyers1101
May 01 2017 03:22
With the help of the forums I was able to get here, but I'm still stuck.

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("house");|
khanvuthy88
@khanvuthy88
May 01 2017 03:24
@cmccormack please help me with this one, if i can't pass this step, i can't continue to next step.
Eduar Tua
@eduartua
May 01 2017 03:25
@Jmyers1101 look carefully at the first return.
Jason Myers
@Jmyers1101
May 01 2017 03:25
I used to have the first return as myObj.checkProp
Christopher McCormack
@cmccormack
May 01 2017 03:25
@khanvuthy88 you’d have to post your code again so I can see your progress, and it would be good for you to describe what your specific issue is
Ogundele Olumide
@Lumexralph
May 01 2017 03:25
@Jmyers1101 you need to return the value stored in the checkProp parameter holding the property name
khanvuthy88
@khanvuthy88
May 01 2017 03:26
@cmccormack well, here it is.
jhobotuck
@jhobotuck
May 01 2017 03:26
Hey team. Struggling with Chucky Monkey. It's just not looping!
function chunkArrayInGroups(arr, size) {

  var array = [];
  var finalArray = [];

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

    array = arr.slice(i, i + 2);
    finalArray.push(array);
  }

  return finalArray;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Jason Myers
@Jmyers1101
May 01 2017 03:26
Okay, I changed it back to return myObj.checkProp;
Eduar Tua
@eduartua
May 01 2017 03:26
Check the condition of the for @jhobotuck
jhobotuck
@jhobotuck
May 01 2017 03:27
Ohh array.length!
Thanks @eduartua
CamperBot
@camperbot
May 01 2017 03:27
jhobotuck sends brownie points to @eduartua :sparkles: :thumbsup: :sparkles:
:cookie: 256 | @eduartua |http://www.freecodecamp.com/eduartua
khanvuthy88
@khanvuthy88
May 01 2017 03:27

@cmccormack

var count = 0;

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

  if(card=== '2' || card=== '3' || card=== '4' || card=== '5' || card=== '6' ){
    return '5 Bet';
  }else if(card === '7' || card === '8' || card === '9' ){
    return '0 Hold';
  }else if(card === '10' || card === 'J' || card === 'Q' || card ==='K' || card === 'A' ){
    return '-5 Hold';
  }else if(card ==='3' || card === '7' || card === 'Q' || card === '8' || card === 'A' ){
    return "-1 Hold";
  }else if(card === '2' || card ==='J' || card==='9' || card==='2' || card==='7' ){
    return '1 Bet';
  }else if(card ==='2' || card=== '2' || card=== '10' ){
    return '1 Bet';
  }else if(card=== '3' || card=== '2' || card=== 'A' || card=== '10' || card=== 'K' ){
    return '-1 Hold';
  }else{
    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');

Cards Sequence 2, 3, 4, 5, 6 should return "5 Bet"
Cards Sequence 7, 8, 9 should return "0 Hold"
Cards Sequence 10, J, Q, K, A should return "-5 Hold"
Cards Sequence 3, 7, Q, 8, A should return "-1 Hold"
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
Cards Sequence 2, 2, 10 should return "1 Bet"
Cards Sequence 3, 2, A, 10, K should return "-1 Hold"

Ken Haduch
@khaduch
May 01 2017 03:27
@jhobotuck - also - you are using i + 2 in your slice - you should really be using size in there somewhere...
khanvuthy88
@khanvuthy88
May 01 2017 03:28
Christopher McCormack
@cmccormack
May 01 2017 03:28
@khanvuthy88 this code doesn’t take into account anything that was said earlier - you’re still not using count at all
you also have the same cards in serveral different scenarios, why?
Ogundele Olumide
@Lumexralph
May 01 2017 03:28
@jhobotuck check your for loop increment and your slice ending index
Christopher McCormack
@cmccormack
May 01 2017 03:29
@khanvuthy88 You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value(see table). The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
Ogundele Olumide
@Lumexralph
May 01 2017 03:29
@jhobotuck your for loop should increment with size your slice end index should be i + size
jhobotuck
@jhobotuck
May 01 2017 03:34
Nailed it! The increment was the problem. Thanks @Lumexralph
CamperBot
@camperbot
May 01 2017 03:34
jhobotuck sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1613 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
May 01 2017 03:35
@jhobotuck :+1:
jonathanpuc
@jonathanpuc
May 01 2017 03:41
Hey guys, I cant seem to fulfill the third case. Where "Glove" should return "Oveglay"

function translatePigLatin(str) {

var vowelRegex = /[aeiou]/;

var letters = str.split('');


  if (vowelRegex.test(letters[0])) {

      str = letters.join('') + "way";

    }

  else {

    var y = letters[0];
    str = letters.join('');
    str = letters.slice(1);
    str = str.join('');
    str = str + y + "ay";

  }


  return str;
}

translatePigLatin("consonant");
Christopher McCormack
@cmccormack
May 01 2017 03:46
@jonathanpuc sequences of consonants at the beginning of the word should be combined then appended to the string before the ay
if I’m remembering the requirement correctly
Ken Haduch
@khaduch
May 01 2017 03:46
@jonathanpuc - you have to get the consonants from the beginning - all of them, to the end...
Christopher McCormack
@cmccormack
May 01 2017 03:46

@jonathanpuc

Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay".

jonathanpuc
@jonathanpuc
May 01 2017 03:47
Right, my fault. I didnt know what a consonant meant haha
any pointers on how I would test that?
would it just be a matter of doing an else if and using reg exp?
Ken Haduch
@khaduch
May 01 2017 03:47
@jonathanpuc - with the technique you've been using, you could use a for loop and your vowels array and loop to test for non-vowels at the beginning of the string, then manipulate the results accordingly.
Vamp
@the-vampiire
May 01 2017 03:47

anyone know of a way to filter a 2D array?

working on the inventory algorithm problem. merged the lists now want to filter out duplicates. the problem is unlike a normal filter the “items” being filtered are arrays themselves. as far as I know arrays cant be compared to each other

Ken Haduch
@khaduch
May 01 2017 03:48
@jonathanpuc - regular expressions help a lot.
jonathanpuc
@jonathanpuc
May 01 2017 03:48
oookie, thanks Ken
Vamp
@the-vampiire
May 01 2017 03:48
got 12 minutes before I break my streak! ahhh
khanvuthy88
@khanvuthy88
May 01 2017 03:48
@cmccormack , more idea please, this is what i achieve :
var count = 0;

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


  if(card=== '2' || card=== '3' || card=== '4' || card=== '5' || card=== '6' ){
    count=+1;
  }else if(card === '7' || card === '8' || card === '9' ){
    count=0;
  }else if(card === '10' || card === 'J' || card === 'Q' || card ==='K' || card === 'A' ){
    count=-1;
  }
  if(count>0){
    return count+' Bet';
  }else{
    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');
Ken Haduch
@khaduch
May 01 2017 03:49
@the-vampiire - hint - go to the bottom of the lesson map and watch one of the videos about javascript or something, if you haven't done that already... you get a point for each one you complete. ;)
Vamp
@the-vampiire
May 01 2017 03:49
!
hell ya
I mean I am trying. i log in every day but this is hte longest streak I’ve had. I know its meaningless but it is a nice motivator
@khaduch thanks
CamperBot
@camperbot
May 01 2017 03:50
the-vampiire sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2815 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
May 01 2017 03:50
save the videos for dire emergencies... :)
of this type...
Christopher McCormack
@cmccormack
May 01 2017 03:50

@khanvuthy88

Hint
Do NOT reset count to 0 when value is 7, 8, or 9.

Vamp
@the-vampiire
May 01 2017 03:50
hah
Christopher McCormack
@cmccormack
May 01 2017 03:51
@khanvuthy88 you’re getting very close though!
khanvuthy88
@khanvuthy88
May 01 2017 03:51
@cmccormack , so when 7,8,9 should count=count ?
Christopher McCormack
@cmccormack
May 01 2017 03:51
@khanvuthy88 just do nothing :D
Ken Haduch
@khaduch
May 01 2017 03:52
@the-vampiire - every little motivator helps! :space_invader:
Christopher McCormack
@cmccormack
May 01 2017 03:52
Streaks will get broken once you get to the projects most likely anyhow - if they’re important save the videos like Ken suggests :D
Ken Haduch
@khaduch
May 01 2017 03:53
@cmccormack @the-vampiire - or you can try to help a fellow camper and get a brownie point or two, which you've probably done. Just another way to keep the streak going. Although it can be all-consuming of your time.
Vamp
@the-vampiire
May 01 2017 03:54
wait that works for the streak?
I help in here every day
Christopher McCormack
@cmccormack
May 01 2017 03:54
@khaduch Didn’t realize cookies counted in streaks. Thanks! Thank you! ty :)
CamperBot
@camperbot
May 01 2017 03:54
cmccormack sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2816 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
May 01 2017 03:55
@the-vampiire - yes it does. The more thank yous you get (with time limits in between from the same camper) they count...
Joseph
@revisualize
May 01 2017 03:55
@khanvuthy88 I see that you're doing this: count=+1; ... That is setting the value of count to +1 that isn't adding one to the value of count.
Vamp
@the-vampiire
May 01 2017 03:55
damn good to know
often I am stuck on a problem and my procrastination is to com ehere and help others
Ken Haduch
@khaduch
May 01 2017 03:56
@the-vampiire - brownie points explained (if you didn't know?)
Joseph
@revisualize
May 01 2017 03:56
Do you know what brownie points actually get you?
Ken Haduch
@khaduch
May 01 2017 03:57
@revisualize - a bigger number in the upper right corner of your page... that's about it. ;)
Bryan Reese
@breese8009
May 01 2017 03:57
@revisualize lol nothing?
Joseph
@revisualize
May 01 2017 03:57
@khaduch Yeah.
They get you jack shit.
Vamp
@the-vampiire
May 01 2017 03:57
ahh
Christopher McCormack
@cmccormack
May 01 2017 03:57
And recognition when people work on the Leaderboard project :D
Vamp
@the-vampiire
May 01 2017 03:57
someone ask a question quick
Joseph
@revisualize
May 01 2017 03:58
You can't go to an employer and say.. Look at all my brownie points.
Bryan Reese
@breese8009
May 01 2017 03:58
if u like jack shit tho...its a great deal
Vamp
@the-vampiire
May 01 2017 03:58
anything below advanced algorithms ill help you with in the next 3 minutes
Bryan Reese
@breese8009
May 01 2017 03:58
lol jk
Vamp
@the-vampiire
May 01 2017 03:58
lol
Bryan Reese
@breese8009
May 01 2017 03:58
jk
Christopher McCormack
@cmccormack
May 01 2017 03:58
@the-vampiire what’s the best practice way to implement promises in ES6?
Joseph
@revisualize
May 01 2017 03:58
Hey, Employer.. Check out all these points that I have on some website.
Vamp
@the-vampiire
May 01 2017 03:58
idc about the brownie points I just like the streak
Soumyaditya Choudhuri
@soum-c
May 01 2017 03:58
Hello! I'm trying to redirect to a page. What can I use? I've built a URL for it, but using window.current.href gives me a blank page on CodePen.
Vamp
@the-vampiire
May 01 2017 03:58
I promise to get back to you in 2 minutes with an answer…?
hah
no idea man I havent touched es6
Joseph
@revisualize
May 01 2017 03:59
@the-vampiire Thanks.
CamperBot
@camperbot
May 01 2017 03:59
revisualize sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 332 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Christopher McCormack
@cmccormack
May 01 2017 03:59
@the-vampiire ok thanks
Bryan Reese
@breese8009
May 01 2017 03:59
@cmccormack @revisualize @the-vampiire @soum-c ty brownies for u all
CamperBot
@camperbot
May 01 2017 03:59
breese8009 sends brownie points to @cmccormack and @revisualize and @the-vampiire and @soum-c :sparkles: :thumbsup: :sparkles:
:cookie: 262 | @soum-c |http://www.freecodecamp.com/soum-c
:cookie: 333 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
:cookie: 474 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 3856 | @revisualize |http://www.freecodecamp.com/revisualize
Vamp
@the-vampiire
May 01 2017 03:59
aww yee
thanks guys
Joseph
@revisualize
May 01 2017 03:59
@the-vampiire Look at that.. Now you're half evil.
Bryan Reese
@breese8009
May 01 2017 04:00
lol
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:00
@cmccormack How can I redirect to a page, please?
Bryan Reese
@breese8009
May 01 2017 04:00
333*2
Christopher McCormack
@cmccormack
May 01 2017 04:00
@soum-c window.location = "http://www.yoururl.com”;
taken straight from Stackoverflow fyi :D
(hope it works…)
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:01
@cmccormack I've tried that. Doesn't seem to work. Takes me to a blank page on CodePen.
Eduar Tua
@eduartua
May 01 2017 04:01
Guys, this Caesar Cipher program works fine, I passed, but i want you to advice me how can I improve it?
function rot13(str) { // LBH QVQ VG!
  var ans = "";
  for(var i = 0; i < str.length; i++) {
    if(/\W/.test(str[i])){
      ans += str[i];
    }
    else{
      if(str[i].charCodeAt() <= 77){
        ans += String.fromCharCode(str[i].charCodeAt() + 13);
      }
      else{
        ans += String.fromCharCode(str[i].charCodeAt() - 13);
      }
    }
  }
  return ans;
}
Vamp
@the-vampiire
May 01 2017 04:01
codepen does weird things with links
I think you need to add target blank or something
let me see if I can find the page I remember reading that on
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:02
@the-vampiire Alright. How can I add target blanks?
Screen Shot 2017-05-01 at 12.02.39 AM.png
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:03
@the-vampiire How can I use this directly in JavaScript?
Christopher McCormack
@cmccormack
May 01 2017 04:03
@the-vampiire don’t think they’re looking for a link though
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:04
@cmccormack I looked at a site with a ton of different methods to do it, but none of them work on CodePen: https://appendto.com/2016/04/javascript-redirect-how-to-redirect-a-web-page-with-javascript/
khanvuthy88
@khanvuthy88
May 01 2017 04:04
@cmccormack , what about this ? But it's show the same result as before :
var count = 0;

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


  if(card=== '2' || card=== '3' || card=== '4' || card=== '5' || card=== '6' ){
    count+=1;
  }else if(card === '7' || card === '8' || card === '9' ){

  }else if(card === '10' || card === 'J' || card === 'Q' || card ==='K' || card === 'A' ){
    count=-1;
  }
  if(count>0){
    return count+' Bet';
  }else{
    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');
Ogundele Olumide
@Lumexralph
May 01 2017 04:04
@khanvuthy88 check your decrement
@khanvuthy88 count -= 1 not count =-1
Christopher McCormack
@cmccormack
May 01 2017 04:07
@soum-c so it does work in my testing just now, but you may be running into CORS issues. Check your javascript console. If you’re https in codepen, try redirecting to an https site
khanvuthy88
@khanvuthy88
May 01 2017 04:08
@Lumexralph after I changed to " count -=1 " it's show more incorrect.
Christopher McCormack
@cmccormack
May 01 2017 04:08

@soum-c

<script>
  window.location.href = "https://www.example.com";
</script>

Placing this in the HTML section worked fine, but I was currently in https://codepen.io

Soumyaditya Choudhuri
@soum-c
May 01 2017 04:09
@cmccormack How can I put this in my Javascript and have the target attribute?
Bryan Reese
@breese8009
May 01 2017 04:09
@khanvuthy88 why not use switch statement for this?
Ogundele Olumide
@Lumexralph
May 01 2017 04:09
@khanvuthy88 you should check the number value 2, 3, 4...... not string
Christopher McCormack
@cmccormack
May 01 2017 04:10
@soum-c you shouldn’t need the target attribute, that’s if you’re using an a element. You can copy the code above minus the script tags and put it in your js, should work
Ogundele Olumide
@Lumexralph
May 01 2017 04:10
@breese8009 if statement is also fine..... he's comparing strings instead of numbers
Bryan Reese
@breese8009
May 01 2017 04:10
@Lumexralph oh i kno, just alot easier with a switch lol
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:10
@cmccormack I'm not using an a-element. I'm only using a button, of which I change the href attribute, after generating a custom link.
Ogundele Olumide
@Lumexralph
May 01 2017 04:11

@khanvuthy88

if(card=== 2 || card=== 3 || card=== 4 || card=== 5 || card=== 6)

apply that to numbers in your code

Christopher McCormack
@cmccormack
May 01 2017 04:11
@soum-c I’m not suggesting you use an aelement
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:11
@cmccormack So I shouldn't use an a element? What should I use then?
Christopher McCormack
@cmccormack
May 01 2017 04:11
@soum-c however, a redirect is not something you would associate with a button, so I wonder what you’re trying to do here
Vamp
@the-vampiire
May 01 2017 04:11
@soum-c this would be easier if you just explain what you want to accomplish
you may not even need a redirect
Christopher McCormack
@cmccormack
May 01 2017 04:11
@soum-c are you just trying to link to something?
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:11
@cmccormack Yes.
Vamp
@the-vampiire
May 01 2017 04:12
if you want a button to link to someting that doesnt require a redirect
wrap your button in <a> and set the href there
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:12
@the-vampiire Alright, let me try that.
Vamp
@the-vampiire
May 01 2017 04:12
<a href=“your link here”><button>your button text here</button></a>
Christopher McCormack
@cmccormack
May 01 2017 04:12
<a href=“https://www.example.comtarget=“_blank”><button>Click Me!</button></a>
Vamp
@the-vampiire
May 01 2017 04:13
in fact anything (?) can be wrapped in a it doesnt have to be a button. you can wrap a picture with it, a whole div element, a line in text anything I can think of at least
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:13
@cmccormack @the-vampiire If I did that, wouldn't it take me to a set link? I'm trying to generate a custom twitter link everytime.
Bryan Reese
@breese8009
May 01 2017 04:13
anytime theres a bunch of || in my if else's,,, usually makes for good switch :)
Vamp
@the-vampiire
May 01 2017 04:14
ah
@soum-c explain what you are tyring to do and you will get more direct help
Christopher McCormack
@cmccormack
May 01 2017 04:14
@soum-c probably need to tell us what youre doing earlier haha
Vamp
@the-vampiire
May 01 2017 04:14
sounds like you are on twitter challenge
lol
so here’s somethings to check out
are you using jquery?
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:14
@the-vampiire Yes, I am.
Vamp
@the-vampiire
May 01 2017 04:14
ok
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:15
@cmccormack Sorry.
Christopher McCormack
@cmccormack
May 01 2017 04:15
now I feel like I’m parroting @the-vampiire haha
Vamp
@the-vampiire
May 01 2017 04:15
so you can use something called .attr in jquery
so .attr(‘href’, ‘your link here’)
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:15
@the-vampiire Yes, to set an attribute.
Vamp
@the-vampiire
May 01 2017 04:15
so you would use select your button
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:15
an id

tw-link

Christopher McCormack
@cmccormack
May 01 2017 04:15
and make sure you’re elements have loaded in the DOM first as well
Vamp
@the-vampiire
May 01 2017 04:15
$(‘#button_id’).attr(‘href’, ‘url’+variable_with_text_you_want_to_append_to_url);
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:15
@cmccormack What's DOM?
Christopher McCormack
@cmccormack
May 01 2017 04:16
Document Object Model
@soum-c basically a big tree structure that contains all the nodes in your page
Vamp
@the-vampiire
May 01 2017 04:16
This message was deleted
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:16
Yes. I basically .split() the quote
and then .join("%20")
the quote
Christopher McCormack
@cmccormack
May 01 2017 04:17
@soum-c if your dom isn’t loaded and you tried to use an element in a jquery selector it won’t work, that’s why we use $(document).ready(function() { })}
Vamp
@the-vampiire
May 01 2017 04:17
so
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:17
@cmccormack Oh. It's that! Yes, I did that. Everything I wrote is in that whole function.
@cmccormack All the JS, I mean.
Vamp
@the-vampiire
May 01 2017 04:18
1) make your ajax call
2) store your quote in a variable from ajax call
3) set the href of your button with that variable appended to the url
Christopher McCormack
@cmccormack
May 01 2017 04:18
@soum-c that’s good, should mean less troubleshooting later :)
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:18
@the-vampiire I've done #1, #2.
Vamp
@the-vampiire
May 01 2017 04:18
now the question is where does all of this take place? separate function? success callback function from ajax?
whooo knowwwwss
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:18
@the-vampiire In a refresh function.
when refresh is pressed.
Vamp
@the-vampiire
May 01 2017 04:19
refresh or get new quote
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:19
$("#refr").on("click", {here})
get new quote. I just called it refresh.
Vamp
@the-vampiire
May 01 2017 04:19
you should make a button that pulls a new quote, dont make the user refresh the page from the browser
Christopher McCormack
@cmccormack
May 01 2017 04:19
which twitter project is this anyhow?
Vamp
@the-vampiire
May 01 2017 04:19
ok
Christopher McCormack
@cmccormack
May 01 2017 04:19
ah quote
Christopher McCormack
@cmccormack
May 01 2017 04:19
404
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:20
@the-vampiire No, it's a button for the new quote. Not a refresh button.
Vamp
@the-vampiire
May 01 2017 04:20
whoops
lol
forgot my own urls
Branden Ng
@BrandenDaniel
May 01 2017 04:20
Hello. Kinda stuck with this challenge

//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 lookUpProfile(firstName, prop){
if (contacts.hasOwnProperty) {
}

  else {
    return "No such contact";
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");
David Miller
@DavidMillerFL
May 01 2017 04:20
I’m doing “Basic JavaScript: Assignment with a Returned Value” and I don’t really understand the point of the last line, would there be a way to make the var processed more dynamic?
// Setup
var processed = 0;

function processArg(num) {
  return (num + 3) / 5;
}

// Only change code below this line
var processed = processArg(7);
Christopher McCormack
@cmccormack
May 01 2017 04:21
@BrandenDaniel hasOwnProperty is a method, you need to pass an argument to it
Vamp
@the-vampiire
May 01 2017 04:21
@soum-c okay sounds lke youre pretty close then
David Miller
@DavidMillerFL
May 01 2017 04:21
I understand what’s happening, it’s creating a variable and assigning the function call to it, but the (7) arguement seems kind of… static?
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:22
@the-vampiire @cmccormack Oh. I think I can reload the <a> href every refresh click. That may work.
Vamp
@the-vampiire
May 01 2017 04:22
@DavidMillerFL 7 is the ‘num’ being passed to your function
Christopher McCormack
@cmccormack
May 01 2017 04:22
@DavidMillerFL 7 is a number literal, just to give you an example
David Miller
@DavidMillerFL
May 01 2017 04:22
I’m an idiot. For a second I thought 7 was the result of the calculation not the
nevermind
Vamp
@the-vampiire
May 01 2017 04:22
lol
David Miller
@DavidMillerFL
May 01 2017 04:22
I hit enter on my message too soon
Vamp
@the-vampiire
May 01 2017 04:22
function(argument)
David Miller
@DavidMillerFL
May 01 2017 04:23
right
Vamp
@the-vampiire
May 01 2017 04:23
you got it man
Christopher McCormack
@cmccormack
May 01 2017 04:23
you’d rarely pass actual literals in your code unless it’s state information
Vamp
@the-vampiire
May 01 2017 04:23
@soum-c yes like I said what you want to do is change the href dynamically. every time a new call is made you should be setting the href attr to a url + quote text
David Miller
@DavidMillerFL
May 01 2017 04:23
@cmccormack ?
Soumyaditya Choudhuri
@soum-c
May 01 2017 04:24
@the-vampiire @cmccormack It's working!!! Thanks a lot!
CamperBot
@camperbot
May 01 2017 04:24
soum-c sends brownie points to @the-vampiire and @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 475 | @cmccormack |http://www.freecodecamp.com/cmccormack
:cookie: 334 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Christopher McCormack
@cmccormack
May 01 2017 04:24
@the-vampiire your quote page wallpaper makes me want to make mine look prettier haha
Vamp
@the-vampiire
May 01 2017 04:25
@soum-c welcome!
@cmccormack check out the source on my quote page
I use that site to get great images
they have some unbelievable ones on there. all free to use
used it for the dynamic background images on my weather app too
although dont forget to shrink them first. they are HUGE images
Christopher McCormack
@cmccormack
May 01 2017 04:28
Yeah I was going to get a bunch for my weather api from a site that has pretty decent keyword search but I decided it was easier to just have one pretty background and move on haha
khanvuthy88
@khanvuthy88
May 01 2017 04:28
@Lumexralph , @revisualize @cmccormack yes it's work, thanks you very much for help me.
CamperBot
@camperbot
May 01 2017 04:28
khanvuthy88 sends brownie points to @lumexralph and @revisualize and @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 476 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 3857 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 1614 | @lumexralph |http://www.freecodecamp.com/lumexralph
Christopher McCormack
@cmccormack
May 01 2017 04:28
@khanvuthy88 great job!
David Miller
@DavidMillerFL
May 01 2017 04:29

Write a function nextInLine which takes an array (arr) and a number (item) as arguments.
Add the number to the end of the array, then remove the first element of the array.

I’m guessing I need to use.unshift() and .push() ?

Vamp
@the-vampiire
May 01 2017 04:30
what does unshift() do?
@DavidMillerFL
Ken Haduch
@khaduch
May 01 2017 04:31
@DavidMillerFL - you definitely need .push(), and then the one that removes an element from the beginning of the array...
David Miller
@DavidMillerFL
May 01 2017 04:31
If I’m recalling correctly it removes the first item from the array
Or that might have been shift.
Vamp
@the-vampiire
May 01 2017 04:31
you are recalling incorrectly
might be...
(it is)
push is to unshift as pop is to shift
David Miller
@DavidMillerFL
May 01 2017 04:32
Hah, ok. thanks @the-vampiire Just wanted to make sure my thinking was somewhere on the right track. (I disagree with the naming of shift and unshift, they should be switched around)
CamperBot
@camperbot
May 01 2017 04:32
davidmillerfl sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 335 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
May 01 2017 04:33
well if it helps to remember
shift is like shifting everything over and leaving that fellow behind
pop is popping one off the top
Branden Ng
@BrandenDaniel
May 01 2017 04:33
yeah still stuck with profile lookup
Vamp
@the-vampiire
May 01 2017 04:33
might be easier if push was called unpop lol
Branden Ng
@BrandenDaniel
May 01 2017 04:33
any hints from anyone?
Ogundele Olumide
@Lumexralph
May 01 2017 04:33
@BrandenDaniel where ?
Vamp
@the-vampiire
May 01 2017 04:34
I have a hint
Branden Ng
@BrandenDaniel
May 01 2017 04:34

//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 lookUpProfile(firstName, prop){
if (contacts.hasOwnProperty(firstName)) {
  return contacts[firstName];
}

  else {
    return "No such contact";
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Vamp
@the-vampiire
May 01 2017 04:34
a return statement that is reached in a loop will instantly break the loop
Ogundele Olumide
@Lumexralph
May 01 2017 04:34
@BrandenDaniel
Here's an outline, if you follow it step-wise it'll help a great deal in telling you what to do or step you missed
1. you need a loop to pick each objects in the contacts array
    1.1  in the loop you need to 
         1.1.1  check if the objects picked has the firstName property equal to the firstName parameter
                  1.1.1.1 you need to check if it has a property prop
                                  return the value of prop in the object
                 1.1.1.2  return no such property if  1.1.1.1 is false
2.  when your loop is done looking through  contacts return no such contact
Vamp
@the-vampiire
May 01 2017 04:34
@Lumexralph lol at having a noutline
Christopher McCormack
@cmccormack
May 01 2017 04:35
@BrandenDaniel the value passed into firstName will never be a property of contacts
Vamp
@the-vampiire
May 01 2017 04:35
very helpful. laughing because this question is where literally every single FCC user gets stuck
Branden Ng
@BrandenDaniel
May 01 2017 04:35
lol
cheers @Lumexralph
Vamp
@the-vampiire
May 01 2017 04:35
(we were all there, not laughing at you, with you)
diegoxro
@diegoxro
May 01 2017 04:35
@the-vampiire trueeeee XD
Ogundele Olumide
@Lumexralph
May 01 2017 04:36
@the-vampiire easier that way, :smile: .... especially when i'm held up with stuffs and you have to spend minutes explaining
Vamp
@the-vampiire
May 01 2017 04:36
how did you get that out so fast?
Ogundele Olumide
@Lumexralph
May 01 2017 04:36
@BrandenDaniel all the best man
Vamp
@the-vampiire
May 01 2017 04:36
you have it on a notepad thats never closed? lol
Ogundele Olumide
@Lumexralph
May 01 2017 04:37
@the-vampiire my laptop hates me
Vamp
@the-vampiire
May 01 2017 04:37
I vote to have it added to the FCC bot himself. cbot “lookup"
cbot
CamperBot
@camperbot
May 01 2017 04:37
you called?
Vamp
@the-vampiire
May 01 2017 04:37
I did
make yourself useful and add @Lumexralph notes to your stash of answers
Ogundele Olumide
@Lumexralph
May 01 2017 04:38
@the-vampiire :joy:
@the-vampiire cbot will never grow, so just let it be
Vamp
@the-vampiire
May 01 2017 04:38
I believe in cbot
cbot do you believe in yourself?
CamperBot
@camperbot
May 01 2017 04:38
you called?
Vamp
@the-vampiire
May 01 2017 04:38
I DID DAMN IT
cbot if you believe in yourself ask me if I called you
CamperBot
@camperbot
May 01 2017 04:39
you called?
Vamp
@the-vampiire
May 01 2017 04:39
;)
Branden Ng
@BrandenDaniel
May 01 2017 04:41
@Lumexralph regarding the loop, how exactly would i construct the loop?
for (contacts = 0; contacts == firstName;) {

}
Ogundele Olumide
@Lumexralph
May 01 2017 04:42
@BrandenDaniel just think of it as you're using a loop to pick each elements in an array
Branden Ng
@BrandenDaniel
May 01 2017 04:44
would i initialize contracts to 0?
Ogundele Olumide
@Lumexralph
May 01 2017 04:46
@BrandenDaniel an array starts at index what?
Branden Ng
@BrandenDaniel
May 01 2017 04:46
righttt, so its the index
i keep thinking its like giving it a value of 0 z
Joseph
@revisualize
May 01 2017 04:46
@BrandenDaniel Which lesson are you working on?
Branden Ng
@BrandenDaniel
May 01 2017 04:47
Profile LookUp
NaveenRathor
@NaveenRathor
May 01 2017 04:47
hey guys what's wrong in my code?

function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
if(str.substr(length-1) == target.substr(length-1)){
return true;
}else if (str.substr(length-1) != target.substr(length-1)){
return false;
}

}

confirmEnding("Bastian", "n");

Joseph
@revisualize
May 01 2017 04:48

@BrandenDaniel Okay, I have a question...

var contacts = ["a", "b"];
var firstName = "Sam";
for (contacts = 0; contacts == firstName;) {
     console.log(contacts);
}

What is the value logged to the console?

Ogundele Olumide
@Lumexralph
May 01 2017 04:49
@NaveenRathor you don't need to compare substring of target just use the string as it is
Branden Ng
@BrandenDaniel
May 01 2017 04:49
Sam
Joseph
@revisualize
May 01 2017 04:49
@BrandenDaniel That is incorrect.
Branden Ng
@BrandenDaniel
May 01 2017 04:50
hmm
would it be nothing
Joseph
@revisualize
May 01 2017 04:51
@BrandenDaniel Actually, that's correct.
@BrandenDaniel Why is nothing logged to the console?
NaveenRathor
@NaveenRathor
May 01 2017 04:52
@Lumexralph when i'm using just string it's throw an error unexpected token
Ogundele Olumide
@Lumexralph
May 01 2017 04:53
@NaveenRathor show your updated code
Branden Ng
@BrandenDaniel
May 01 2017 04:53
because @revisualize you're asking whether the var contacts is equating to the var firstName
since they dont
NaveenRathor
@NaveenRathor
May 01 2017 04:53
@Lumexralph

function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
if(str.substr(length-1) == target()){
return true;
}else if (str.substr(length-1) != target(){
return false;
}

}

confirmEnding("Bastian", "n");

Branden Ng
@BrandenDaniel
May 01 2017 04:53
the console logs an error or blank? am i right or @revisualize
Joseph
@revisualize
May 01 2017 04:54
@BrandenDaniel The for loop doesn't run.
Branden Ng
@BrandenDaniel
May 01 2017 04:54
@revisualize also i have a question, is adding an equation not always necessary?
Joseph
@revisualize
May 01 2017 04:55
@BrandenDaniel An evaluation is required for a for loop to run.
Ogundele Olumide
@Lumexralph
May 01 2017 04:55
@NaveenRathor remove the parenthesis () with target
Branden Ng
@BrandenDaniel
May 01 2017 04:55
@revisualize i mean the final expression **
Ogundele Olumide
@Lumexralph
May 01 2017 04:55
@NaveenRathor target is not a method or function in JS
Joseph
@revisualize
May 01 2017 04:55
@BrandenDaniel What?
Branden Ng
@BrandenDaniel
May 01 2017 04:55
for ([initialization]; [condition]; [final-expression])
Vamp
@the-vampiire
May 01 2017 04:56
no
Branden Ng
@BrandenDaniel
May 01 2017 04:56
it seems that your code didnt include the final expression @revisualize
Ogundele Olumide
@Lumexralph
May 01 2017 04:56
@NaveenRathor if(str.substr(length-1) == target )
Branden Ng
@BrandenDaniel
May 01 2017 04:56
is it not always necessary
Joseph
@revisualize
May 01 2017 04:56
@BrandenDaniel But, I copied your code.
Vamp
@the-vampiire
May 01 2017 04:56
for(incrementer; conditon; increment)
NaveenRathor
@NaveenRathor
May 01 2017 04:56
@Lumexralph it should also return this
"He has to give me a new name", "name"
Vamp
@the-vampiire
May 01 2017 04:56
lol
calls you out on his own code
Joseph
@revisualize
May 01 2017 04:57
@BrandenDaniel What you're calling "my code" ... Is actually YOUR code.
Branden Ng
@BrandenDaniel
May 01 2017 04:57
lol i didnt know that
either way i want to learn from it
Joseph
@revisualize
May 01 2017 04:58

@BrandenDaniel

for ([initialization]; [condition]; [final-expression])
   statement

REQUIRED for a for loop.

NaveenRathor
@NaveenRathor
May 01 2017 04:58
@Lumexralph but it's not compare a word
Branden Ng
@BrandenDaniel
May 01 2017 04:58
so all 3 is a must to require a for loop to work
NaveenRathor
@NaveenRathor
May 01 2017 04:58
it's compare a letter
Joseph
@revisualize
May 01 2017 04:58
@BrandenDaniel yes.
Branden Ng
@BrandenDaniel
May 01 2017 04:58
got cha
Joseph
@revisualize
May 01 2017 04:59
@BrandenDaniel Now, any part could be BLANK.
@BrandenDaniel but, the ; is required.
Branden Ng
@BrandenDaniel
May 01 2017 05:00
@revisualize ooohhh
i see.
Joseph
@revisualize
May 01 2017 05:00
@BrandenDaniel You can also omit all three blocks. Again, make sure to use a break statement to end the loop and also modify (increase) a variable, so that the condition for the break statement is true at some point.
var i = 0;

for (;;) {
  if (i > 3) break;
  console.log(i);
  i++;
}
Ogundele Olumide
@Lumexralph
May 01 2017 05:00
@NaveenRathor show your code
NaveenRathor
@NaveenRathor
May 01 2017 05:00

@Lumexralph
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
if(str.substr(length-1) == target){
return true;
}else if (str.substr(length-1) != target){
return false;
}

}

confirmEnding("Bastian", "n");

Joseph
@revisualize
May 01 2017 05:01
@BrandenDaniel But, the space for the value needs to still be there.
@BrandenDaniel And if you don't have a way for your loop to terminate.. It will run forever.
Blara02
@Blara02
May 01 2017 05:01

im really struggling with "Manipulating Complex Objects."

my added code is this:
myMusic[1] = [
{
"artist": "Kendrick",
"title": "DAMN",
"release_year": 2017,
"formats": [
"CS",
"TT",
"LP" ],
"gold": true
}
];

Branden Ng
@BrandenDaniel
May 01 2017 05:02
@revisualize right
Joseph
@revisualize
May 01 2017 05:02
@Blara02 You just need to manually add the object as an element for your array.
@Blara02 Example myMusic = [ { ... } , { ... } ]
Branden Ng
@BrandenDaniel
May 01 2017 05:02
@revisualize this profile lookup challenge still confuses the hell outta me
Joseph
@revisualize
May 01 2017 05:03
@BrandenDaniel You're working on a challenge that is taking all of your previous knowledge and slamming it into one problem.
Ogundele Olumide
@Lumexralph
May 01 2017 05:03
@NaveenRathor you should use the length of target as starting index in the substr of str
Vamp
@the-vampiire
May 01 2017 05:03
@BrandenDaniel I think you need to look up how for loops work first. that is the beginning of this challenge
Branden Ng
@BrandenDaniel
May 01 2017 05:03
well this is what i got so far, in terms of looping
Vamp
@the-vampiire
May 01 2017 05:03
once you have your loop working then start looking at how to add in your different checks (conditional statements)
Branden Ng
@BrandenDaniel
May 01 2017 05:03

function lookUpProfile(firstName, prop){

for (contacts = 0; contacts == firstName;) {
  for (contracts = 0; contracts == prop;) {
  }
}
Joseph
@revisualize
May 01 2017 05:04
@BrandenDaniel Except none of that is correct.
Vamp
@the-vampiire
May 01 2017 05:04
yes that is incorrect
Branden Ng
@BrandenDaniel
May 01 2017 05:04
yep
Vamp
@the-vampiire
May 01 2017 05:04
if what @revisualize is explaining to you isn’t helping you correct your for loop then you need to spend more time learning them on your own
we can help you if you listen but nobody here will write the code for you
Branden Ng
@BrandenDaniel
May 01 2017 05:05
but am i supposed to loop within a loop
Vamp
@the-vampiire
May 01 2017 05:05
nobody said that
listen man
Joseph
@revisualize
May 01 2017 05:05
Part of the problem is by doing contacts = 0 is OVERWRITING the data.
Vamp
@the-vampiire
May 01 2017 05:05
you need to learn how to loop correctly first
just write a few simple loops soyou understand that concept
then work on the rest of the problem
Ogundele Olumide
@Lumexralph
May 01 2017 05:05
@BrandenDaniel you only have an array to loop through, so you don't need 2 loops
Joseph
@revisualize
May 01 2017 05:06
@BrandenDaniel Let me write an example for you.
Vamp
@the-vampiire
May 01 2017 05:06
no part of that loop as it stands is correct. im not saying this to be mean to you im saying it so you can go look up how they work and then return to the challenge
Joseph
@revisualize
May 01 2017 05:07

@BrandenDaniel

var myArrayOfData = ["a" , "b" , "c" , "d"];
for (myArrayOfData = 0; myArrayOfData < 4; myArrayOfData++) {
       console.log(myArrayOfData);
}

What gets output to the console?

Blara02
@Blara02
May 01 2017 05:08
@revisualize Im not really sure what you mean i thought i had that accomplished, but now im shuffling around syntax and cant get it to work
Vamp
@the-vampiire
May 01 2017 05:08
for(starting value declaration; condition to stop the loop; increment of starting value)
Branden Ng
@BrandenDaniel
May 01 2017 05:08
@the-vampiire you think i dont go back to previous challenges to further evaluate loops? lol Ofcourse i do. But i'm ALSO asking questions to get a deeper perspective from others. Because not everything is detailed, and for a new comer, it aint so easy is it?
Vamp
@the-vampiire
May 01 2017 05:08
no I think you are not listening to what he is telling you
Joseph
@revisualize
May 01 2017 05:08
@Blara02 You just need to manually add the object as an element to the array.
Vamp
@the-vampiire
May 01 2017 05:09
if you were your loop would not look the exact same as it did before he began explaining to you..
Branden Ng
@BrandenDaniel
May 01 2017 05:09
@the-vampiire not everyone learns the same good sir
Blara02
@Blara02
May 01 2017 05:09
@revisualize okay ill read up on those terms thanks
CamperBot
@camperbot
May 01 2017 05:09
blara02 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3858 | @revisualize |http://www.freecodecamp.com/revisualize
Vamp
@the-vampiire
May 01 2017 05:09
you posted an incorrect loop. revis explained to you how loops work and why yours was incorrect. you then posted the exact same loop you started with. that is the sign of somoene not listening.
you cant learn if you dont listen
Joseph
@revisualize
May 01 2017 05:10
@Blara02 By doing myMusic[1] = [ { .... } ]; You're adding an array with an object to the myMusic array. So, myMusic looks something like this [ { ... } , [ { ... } ] ]
Vamp
@the-vampiire
May 01 2017 05:10
thats true for everyone
Branden Ng
@BrandenDaniel
May 01 2017 05:10
LOL
Blara02
@Blara02
May 01 2017 05:10
@revisualize oooooooooooooooooooooooo okay i see
Branden Ng
@BrandenDaniel
May 01 2017 05:10
@revisualize thanks for the example btw
CamperBot
@camperbot
May 01 2017 05:10
brandendaniel sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3859 | @revisualize |http://www.freecodecamp.com/revisualize
Vamp
@the-vampiire
May 01 2017 05:11

@BrandenDaniel

var myArrayOfData = ["a" , "b" , "c" , "d"];
for (myArrayOfData = 0; myArrayOfData < 4; myArrayOfData++) {
       console.log(myArrayOfData);
}

What gets output to the console?

Branden Ng
@BrandenDaniel
May 01 2017 05:11
d lol
Vamp
@the-vampiire
May 01 2017 05:12
nope
Joseph
@revisualize
May 01 2017 05:12
@Blara02 You just have to manually add the object to the array myMusic ... So, that it looks something like this: [ { ... } , { ... } ]
David Miller
@DavidMillerFL
May 01 2017 05:13
function nextInLine(arr, item) {
  // Your code here

 testArr.push(item);
 return testArr.shift();  // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
Add the number to the end of the array, then remove the first element of the array.
The nextInLine function should then return the element that was removed.
Branden Ng
@BrandenDaniel
May 01 2017 05:13
or rather a b c and d
Vamp
@the-vampiire
May 01 2017 05:13
no
loganTharbin
@loganTharbin
May 01 2017 05:13
hey im new and im stuck on the convert Celsius to Fahrenheit challenge. I dont really know where to start can someone help please
Joseph
@revisualize
May 01 2017 05:13
@BrandenDaniel Incorrect. myArrayOfData = 0; OVERWRITES the previous value of myArrayOfData
Ogundele Olumide
@Lumexralph
May 01 2017 05:13
@loganTharbin you know the formula, right?
Joseph
@revisualize
May 01 2017 05:14
@DavidMillerFL You're using testArr when you should be using arr
David Miller
@DavidMillerFL
May 01 2017 05:14
doh
loganTharbin
@loganTharbin
May 01 2017 05:14
it says The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.
David Miller
@DavidMillerFL
May 01 2017 05:14
let me try that then
Joseph
@revisualize
May 01 2017 05:14
@DavidMillerFL arr is the parameter for the function that represents the value of the Array.
Ogundele Olumide
@Lumexralph
May 01 2017 05:14
@loganTharbin C * 9 / 5 + 32
Vamp
@the-vampiire
May 01 2017 05:14
@DavidMillerFL and you have combined them. should be arr = [1, 2, 3, 4] item = 5
Ogundele Olumide
@Lumexralph
May 01 2017 05:15
@loganTharbin replace C in the formula with the celsius parameter
loganTharbin
@loganTharbin
May 01 2017 05:15
ohhh thank you that helps alot
Vamp
@the-vampiire
May 01 2017 05:15
nextInLine([1, 2, 3, 4], 5);
David Miller
@DavidMillerFL
May 01 2017 05:15
@the-vampiire Sec, reading everything
Ogundele Olumide
@Lumexralph
May 01 2017 05:15
@loganTharbin cool
Vamp
@the-vampiire
May 01 2017 05:16
@DavidMillerFL I think you changed some things that shouldnt have been changed. ONLY change inside the function
David Miller
@DavidMillerFL
May 01 2017 05:16
Okay, I’ll reset because none of this makes any sense
Branden Ng
@BrandenDaniel
May 01 2017 05:16
@revisualize the 0 in myArrayOfData = 0 is the index is it not
Joseph
@revisualize
May 01 2017 05:16
@BrandenDaniel No.
Vamp
@the-vampiire
May 01 2017 05:16
no
Joseph
@revisualize
May 01 2017 05:16
@BrandenDaniel = is assignment.
Vamp
@the-vampiire
May 01 2017 05:17
@DavidMillerFL post the original unedited code here
David Miller
@DavidMillerFL
May 01 2017 05:17
function nextInLine(arr, item) {
  // Your code here

  return item;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Here’s unedited.
...
Joseph
@revisualize
May 01 2017 05:17
@BrandenDaniel if I do something like this.
var name = "Joseph"
name = 10;
name = [1,2,3];
name = { p: 10 };
name = "happy feet";
David Miller
@DavidMillerFL
May 01 2017 05:17
There’s more stuff at the bottom though
Vamp
@the-vampiire
May 01 2017 05:17
you were really close
remember inside your funtion you ONLY use the arguments that are passed to it
Joseph
@revisualize
May 01 2017 05:18
@BrandenDaniel WHat is the value of name if I was to do a console.log(name); at the end of all of that?
David Miller
@DavidMillerFL
May 01 2017 05:18
Hmm
Vamp
@the-vampiire
May 01 2017 05:18
testArr is outside your function
Branden Ng
@BrandenDaniel
May 01 2017 05:18
@revisualize happy feet
Joseph
@revisualize
May 01 2017 05:18
@BrandenDaniel Why?
Branden Ng
@BrandenDaniel
May 01 2017 05:18
its the last assign
Vamp
@the-vampiire
May 01 2017 05:18
so what do you have to work with in your function? the 2 parameters ‘arr’ and ‘item’
Ogundele Olumide
@Lumexralph
May 01 2017 05:19
@DavidMillerFL you're to add item to the end of arr array, what array method will help you achieve that?
Branden Ng
@BrandenDaniel
May 01 2017 05:19
or most recent rather
Vamp
@the-vampiire
May 01 2017 05:19
@Lumexralph he had it already just used the wrong array
This message was deleted
Ogundele Olumide
@Lumexralph
May 01 2017 05:19
@the-vampiire okay
David Miller
@DavidMillerFL
May 01 2017 05:19
But if I just write arr.push, and not testArr.push… how does that manipulate testArr ?
Vamp
@the-vampiire
May 01 2017 05:19
function nextInLine(arr, item) {
  // Your code here

 testArr.push(item);
 return testArr.shift();  // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
Joseph
@revisualize
May 01 2017 05:20
@BrandenDaniel So,
var arr = ["a", "b", "c", "d", "e"];
for (var arr = 0; ...
Inside of the for loop what is the value of arr?
Vamp
@the-vampiire
May 01 2017 05:20
because look below
testarr is the arr being passed int oyour function
Joseph
@revisualize
May 01 2017 05:20
@DavidMillerFL Because testArr is being passed to your function as an argument.
Vamp
@the-vampiire
May 01 2017 05:20
but in your function you can only write in terms of the parameters for that function
David Miller
@DavidMillerFL
May 01 2017 05:20
Hmm… but you wrote testArr too @the-vampiire ?
Joseph
@revisualize
May 01 2017 05:20
@DavidMillerFL arr is the parameter that holds the value of the argument passed to the function during the function call.
Vamp
@the-vampiire
May 01 2017 05:21
function nextInLine(arr, item) {
  // Your code here

 testArr.push(item);
 return testArr.shift();  // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
var anyNameIWant = [1, 2, 3]

// now I call you function twice
nextInLine(testArr, 5); 
nextInLine(anyNameIWant, 7);
Joseph
@revisualize
May 01 2017 05:21
function addThree (num) {
    var result;
    result = num + 3;
    return result;
}

So, when we make the function call of:

addThree(10);

You're calling the function addThree You're also passing a value 10 as an argument.
In the function declaration of function addThree (num) { You see that there is a parameter defined of num
When we do addThree(10) then the value of the parameter num is passed the argument value of ... 10
Then if you follow the code through.. result = num + 3; ... and we know the value of num is 10.
Therefore, if we follow through the function we end up with ... result = 10 + 3; then result = 13; then we return the result.
...
If you then make another function call..

addThree(39);

You can use the same function to follow the operation:
When we do addThree(39) then the value of the parameter num is passed the argument value of ... 39
Then if you follow the code through.. result = num + 3; ... and we know the value of num is now 39.
Therefore, if we follow through the function we end up with ... result = 39 + 3; then result = 42; then we return the result.

David Miller
@DavidMillerFL
May 01 2017 05:21
ugh
woah
Branden Ng
@BrandenDaniel
May 01 2017 05:21
@revisualize var arr would be 0
@BrandenDaniel does that mean it is essential to use i or j in loops
David Miller
@DavidMillerFL
May 01 2017 05:22
Ok… let me try again with this in mind.
Joseph
@revisualize
May 01 2017 05:22
@BrandenDaniel See... So, doing for (contacts = 0;.... ... that makes the value of contacts equal 0. Essentially, Overwriting any previous value.
@BrandenDaniel Hint: You should NOT be overwriting the value of the large contacts array of objects.
Branden Ng
@BrandenDaniel
May 01 2017 05:23
okay i understand that now. So in this case instead of contacts i can use i?
Joseph
@revisualize
May 01 2017 05:24
@BrandenDaniel i is a value you could use. You could use anything you want really. Just don't overwrite contacts because you need to use and get data out of contacts
Vamp
@the-vampiire
May 01 2017 05:24
@DavidMillerFL see how when I pass ‘anyNameIWant’ into your function it will fail. because inside your function you have defined everything in terms of testArr which is not the paramter your function is using
Branden Ng
@BrandenDaniel
May 01 2017 05:24
@revisualize got it, thanks for that
CamperBot
@camperbot
May 01 2017 05:24
brandendaniel sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: brandendaniel already gave revisualize points
Branden Ng
@BrandenDaniel
May 01 2017 05:24
@the-vampiire also, sorry about before. Cheers for the help
Vamp
@the-vampiire
May 01 2017 05:24
everything in your code is correct except for the array you are using
David Miller
@DavidMillerFL
May 01 2017 05:25
I reset my code so I don’t even remember what I typed lol, I’m going to start over
Vamp
@the-vampiire
May 01 2017 05:25
@BrandenDaniel nothing to apologize for man. I wasnt calling you out I was just saying it imortant to understand loops before continuing with the challenge
Todd Abraham
@toddabraham
May 01 2017 05:25
Hi
Vamp
@the-vampiire
May 01 2017 05:25
function nextInLine(arr, item) {
  // Your code here

 testArr.push(item);
 return testArr.shift();  // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
Todd Abraham
@toddabraham
May 01 2017 05:25
```
Vamp
@the-vampiire
May 01 2017 05:25
this is what you had
Todd Abraham
@toddabraham
May 01 2017 05:26
function findLongestWord(str) {

  var strSplit = str.split(' ');
}

findLongestWord("The quick brown fox jumped over the lazy dog");

console.log();
Ogundele Olumide
@Lumexralph
May 01 2017 05:26
@toddabraham hallo
Branden Ng
@BrandenDaniel
May 01 2017 05:26
@the-vampiire good lad :)
Vamp
@the-vampiire
May 01 2017 05:26
@DavidMillerFL see how you wrote ‘item’ instead of ‘6’? why did you do that?
Todd Abraham
@toddabraham
May 01 2017 05:26
What’s wrong with my code?
Joseph
@revisualize
May 01 2017 05:26

@BrandenDaniel Look, I got to go to bed. Good luck with your challenge.
I wrote this a while ago: Gist by revisualize / FreeCodeCamp - Profile Lookup.js

We have an array of objects representing different people in our contacts lists.
Example: var contacts = [ { ... } , { ... } , { ... } , { ... } ];
Hopefully it helps.

David Miller
@DavidMillerFL
May 01 2017 05:26
I have no idea :D @the-vampiire
Vamp
@the-vampiire
May 01 2017 05:26
@DavidMillerFL because item is the parameter your function uses and when it is called OUTSIDE the function to test it they pass ‘6’ for ‘item’. do the same for the array
Todd Abraham
@toddabraham
May 01 2017 05:26
I want to out put the results of var strSplit to console.
Ogundele Olumide
@Lumexralph
May 01 2017 05:26
@toddabraham nothing, question I think you should be asking is what are you to do next
Christopher McCormack
@cmccormack
May 01 2017 05:27
@toddabraham you need to return something from your function
Joseph
@revisualize
May 01 2017 05:27
@toddabraham console.log(strSplit); inside of your function.
@toddabraham The information will be output to your browsers console.
Ogundele Olumide
@Lumexralph
May 01 2017 05:27
@toddabraham on FCC ? or you're on a browser console or other types
Vamp
@the-vampiire
May 01 2017 05:28

thats the point of functions. you give it arbitrary parameters that you deal with internal to the function. then when you want to call the function you pass in values for those parameters. like basic algebra

f(x) = x + 5
f(10) = 10 + 5
f(15) = 15 + 5

you can pass anythin you want in for x but in the generic equation it is f(x) = x + 5 see how x is used inside the function?

Todd Abraham
@toddabraham
May 01 2017 05:28
@Lumexralph On FCC
@Lumexralph Wanting to test as I go through the exercise.
David Miller
@DavidMillerFL
May 01 2017 05:28
I don’t see a function call anywhere in this code, so where am I passing arguements into?
Vamp
@the-vampiire
May 01 2017 05:28
@DavidMillerFL where
f(x) is the same as saying function of x
Joseph
@revisualize
May 01 2017 05:29
@DavidMillerFL The function call is on line....
Vamp
@the-vampiire
May 01 2017 05:29
FCC is passing arguments into your function
to test if you did it correctly
David Miller
@DavidMillerFL
May 01 2017 05:29
Is this it ?
console.log(nextInLine(testArr, 6)); // Modify this line to test
Vamp
@the-vampiire
May 01 2017 05:29
yep
Joseph
@revisualize
May 01 2017 05:29
@DavidMillerFL That's it.
Ogundele Olumide
@Lumexralph
May 01 2017 05:29
@toddabraham FCC is more like an editor..... and doesn't behave like a true console...... use your browser console or repl.it/languages/JavaScript and do what @revisualize suggested
Vamp
@the-vampiire
May 01 2017 05:29
see how they passed in testArr for arr and 6 for item
now when they run your code they can pass in any array they want for arr and any item they want for item and see if it worked
David Miller
@DavidMillerFL
May 01 2017 05:30
Ok the “console log” stuff completely threw me off, I didn’t realize a function call can be..that.
Vamp
@the-vampiire
May 01 2017 05:30
they have predetermined what array and item to pass based on the results they expect. thats how they test the challenges. passing known values in with known results expected to come out
David Miller
@DavidMillerFL
May 01 2017 05:30
Got it.. gonna try again from square one now.