These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
May 2017
Wisdom Peters
@blackcytographer
May 22 2017 00:12
good day guys please i am stuck dont know what seems to be wrong with my codes.

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch(val) {
case 1:
val = "alpha";
break;
case 2:
val = "beta";
break;
case 3:
val = "gamma";
break;
case 4:
val = "delta";
break;
default:
return answer;
}

// Only change code above this line

}

// Change this value to test
caseInSwitch(1);

Christopher McCormack
@cmccormack
May 22 2017 00:12
@mahmudulhasanjhoony review the two different ways of accessing values of a property in an object
@blackcytographer you're assigning your values to val instead of answer
Wisdom Peters
@blackcytographer
May 22 2017 00:13
@cmccormack thanks my man didnt see that earlier
CamperBot
@camperbot
May 22 2017 00:13
blackcytographer sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 626 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
May 22 2017 00:20
@blackcytographer np
Wisdom Peters
@blackcytographer
May 22 2017 00:28
@cmccormack pls what will be in my switch statement val or caseInSwitvh
Christopher McCormack
@cmccormack
May 22 2017 00:29
@blackcytographer have you tried replacing all val= in your switch statement with answer=?
@blackcytographer remember the value in the parenthesis of your switch ( switch(val) ) is what each of your case statements are compared against. After the comparison, if there is a match, you're going to do some work. In this case your work is to assign a string to your answer variable so you can later return that variable at the end of your function
Wisdom Peters
@blackcytographer
May 22 2017 00:32
@cmccormack Roger that sir
@cmccormack

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch(val) {
case 1:
answer= "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;

default:
  return  answer;  

}

// Only change code above this line

}

// Change this value to test
caseInSwitch(1);

Christopher McCormack
@cmccormack
May 22 2017 00:36
@blackcytographer I don't remember the problem 100% but I believe your return should be outside of your default. If it's only in your default, then the function will only return answer when none of the case conditionals match. If any do match, it will return undefined because functions return undefined by default if not specified otherwise
Wisdom Peters
@blackcytographer
May 22 2017 00:37
@cmccormack still having errors dont know what seems to be the problem
Xarri Jorge
@xarrijorge
May 22 2017 00:37
@blackcytographer try resetting the challenge
Wisdom Peters
@blackcytographer
May 22 2017 00:45
@kodinglife yea thanks it is working perfectly now.
CamperBot
@camperbot
May 22 2017 00:45
blackcytographer sends brownie points to @kodinglife :sparkles: :thumbsup: :sparkles:
:cookie: 403 | @kodinglife |http://www.freecodecamp.com/kodinglife
Stephen James
@sjames1958gm
May 22 2017 00:55
@mahmudulhasanjhoony contacts is an array - so you will need a loop to access each individual contact
Jessica Bensch
@lilithlotus
May 22 2017 00:58

I am having trouble with the Card Counting problem, it is only working for some of the test cases and not all and I cannot figure out why, here is the next of the problem:
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.

Count Change Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K', 'A'
You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.

Example Output
"-3 Hold"
"5 Bet"

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

var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
     count = count + 1;
     break;
    case 7:
    case 8:
    case 9:
      count = count + 0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count = count - 1;

      if(count <= 0) {
        return count + " Hold";
      } else if(count > 0) {
        return count + " Bet";
      }
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);
Stephen James
@sjames1958gm
May 22 2017 00:58
@lilithlotus Your final if is inside the last case and not after the switch
Jessica Bensch
@lilithlotus
May 22 2017 01:00
@sjames1958gm thank you! I had been staring at it for like 20 minutes and didn't catch that!
CamperBot
@camperbot
May 22 2017 01:00
lilithlotus sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7414 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 22 2017 01:00
@lilithlotus :checkered_flag:
Mohamed Derhalli
@derhallim
May 22 2017 01:02
hala madrid
Jessica Bensch
@lilithlotus
May 22 2017 01:04
I made the comment earlier that it is a good thing I am learning at home because I spend half the day making exclamations such as "oh", "duh", "why" and the like out loud and to no one in general. At least the only "person" I am startling this way is the dog haha
Mohamed Derhalli
@derhallim
May 22 2017 01:08
@HeebieGeeBee where r u :O
Christopher McCormack
@cmccormack
May 22 2017 01:16
@lilithlotus I hear that fairly often when I'm in the office as well :D
Jessica Bensch
@lilithlotus
May 22 2017 01:21
@cmccormack lol, that makes me feel better about my outbursts
Ngas Wakefield
@ngas-wakefield
May 22 2017 01:31
what am i doing wrong var a;
var b = 7;
var a = b = 7;
Christopher McCormack
@cmccormack
May 22 2017 01:35
@ngas-wakefield chaining assignments like that isn't going to work, at least not the way the exercise may require. b is already assigned the value 7, if your goal is to assign b to a, you don't need to included b=7 in your statement a = b = 7
@ngas-wakefield what error are you getting?
Ngas Wakefield
@ngas-wakefield
May 22 2017 01:38
TypeError: 7 is not a function
i need to Do not change code above the line
a should have a value of 7
b should have a value of 7
a should be assigned to b with =
Christopher McCormack
@cmccormack
May 22 2017 01:40
@ngas-wakefield try splitting your assignments into different lines and see what you get.
Ngas Wakefield
@ngas-wakefield
May 22 2017 01:47
i got it

// Setup
var a;
var b = 2;

// Only change code below this line
a = 7;
b = a;

Johanes
@jokusuma
May 22 2017 01:50
Hello, I need help on this :
https://www.freecodecamp.com/challenges/make-instances-of-objects-with-a-constructor-function
What does this mean :
"Then give myCar a nickname property with a string value." ?
Thank you
Mohamed Derhalli
@derhallim
May 22 2017 01:53
myCar.nickname = "value";
@jokusuma
Jake R.
@theaquacadet
May 22 2017 02:02
Hey guys, I'm trying to complete the "Profile Lookup" challenge. I can't figure out what I'm doing wrong.
function lookUpProfile(firstName, prop){
// Only change code below this line
  if (contacts.hasOwnProperty(firstName)) {
  if (contacts.hasOwnProperty(prop)) {
    return contacts[prop];
  }  else {
    return "No such property";
  }
} else {
  return "No such contact";
}

  // Only change code above this line
}
Johanes
@jokusuma
May 22 2017 02:05
@derhallim Thank you
CamperBot
@camperbot
May 22 2017 02:05
jokusuma sends brownie points to @derhallim :sparkles: :thumbsup: :sparkles:
:cookie: 381 | @derhallim |http://www.freecodecamp.com/derhallim
patrickjbritton
@patrickjbritton
May 22 2017 02:07
// Setup
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = myPlants[1].trees[1]; // Change this line
Feel like this should be simple but I'm obviously missing something here
Retrieve the second tree from the variable myPlants using object dot and array bracket notation.
Garrett
@mastersmedia11
May 22 2017 02:11
@patrickjbritton myPlants[1] is your "trees" .list[1] would give you fir
Christopher McCormack
@cmccormack
May 22 2017 02:12
@patrickjbritton trees is not a property of the object
Garrett
@mastersmedia11
May 22 2017 02:12
actually it would give you pine. .list[0] would give you fir. I have to start counting from 0 now
Mohamed Derhalli
@derhallim
May 22 2017 02:16
@cmccormack hey man, wassup
Christopher McCormack
@cmccormack
May 22 2017 02:17
@derhallim heya nm trying to finish this React recipe app - yourself?
Mohamed Derhalli
@derhallim
May 22 2017 02:17
playing AOE
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:18
can someone help me with this code?

function PriorityQueue () {
    this.collection = [];
    this.printCollection = function() {
      console.log(this.collection);
    };
    // Only change code below this line
    this.enqueue = function(element) {
      if(this.size() !== 0) {
        var pos = collection.findIndex(function(val) {
          return val[1] >= element[1];
        });
        collection.splice(pos,0,element);
      }
      else
        collection.push(element);
    };
    this.dequeue = function() {
      return collection.length !== 0 ? collection.shift()[0] : "Queue already empty";
    };
    this.size = function() {
      return this.size();
    };
    this.front = function() {
      return this.size() === 0 ? "No front exists, queue empty" : collection[0];
    };
    this.isEmpty = function() {
      return this.size() === 0 ? true : false;
    };
    // Only change code above this line
}
Christopher McCormack
@cmccormack
May 22 2017 02:18
@derhallim sounds like a nice night :D
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:18
this is the error that i get:
"maximum call stack size exceeded"
Mohamed Derhalli
@derhallim
May 22 2017 02:19
@cmccormack no it sucks, am actually playing to change mood
patrickjbritton
@patrickjbritton
May 22 2017 02:19
Awesome thank you @cmccormack and @mastersmedia11
CamperBot
@camperbot
May 22 2017 02:19
patrickjbritton sends brownie points to @cmccormack and @mastersmedia11 :sparkles: :thumbsup: :sparkles:
:cookie: 214 | @mastersmedia11 |http://www.freecodecamp.com/mastersmedia11
:cookie: 627 | @cmccormack |http://www.freecodecamp.com/cmccormack
patrickjbritton
@patrickjbritton
May 22 2017 02:20
Did not remember learning about list, I did see it elsewhere while trying to Google for help tho.
Christopher McCormack
@cmccormack
May 22 2017 02:21
@sinharaksh1t you can't return this.size() in a function called this.size() :) maybe return collection.length or whatever you're supposed to be getting the length for instead
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:22
@cmccormack thank you
CamperBot
@camperbot
May 22 2017 02:22
sinharaksh1t sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 628 | @cmccormack |http://www.freecodecamp.com/cmccormack
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:22
Screen Shot 2017-05-21 at 10.22.09 PM.png
I wonder what do they really want
getting the same error as I did earlier
Christopher McCormack
@cmccormack
May 22 2017 02:23
@derhallim cheer up buddy :D
Christopher McCormack
@cmccormack
May 22 2017 02:30
@sinharaksh1t also not quite sure you want to reference the first letter of the item you're shifting in your dequeue, try removing [0], although I don't know what your inputs look like
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:34
[[‘human’, 1], [’kitten’, 2], [‘dog’, 2], [‘rabbit’, 2]] this is how the queue looks like and the input is in this fashion: ['human', 1] @cmccormack
Jessica Bensch
@lilithlotus
May 22 2017 02:34
Can someone help me with this, I am stuck.
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found".

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

function checkObj(checkProp) {
  var check = myObj.hasOwnProperty(checkProp);
  if(check === true) {
    return myObj.checkProp;
  } else {
    return "Not Found";
  }

}

// Test your code by modifying these values
checkObj("gift");
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:35
since checkProp is a variable, you should use myObj[checkProp] @lilithlotus
Jessica Bensch
@lilithlotus
May 22 2017 02:36
@sinharaksh1t thank you, that made it work. Just to follow up, checkProp is considered a variable because it is being fed into the function? I was looking at it as a property because it represented a property.
CamperBot
@camperbot
May 22 2017 02:36
:cookie: 285 | @sinharaksh1t |http://www.freecodecamp.com/sinharaksh1t
lilithlotus sends brownie points to @sinharaksh1t :sparkles: :thumbsup: :sparkles:
Joseph
@revisualize
May 22 2017 02:37
hello.
Christopher McCormack
@cmccormack
May 22 2017 02:37
@revisualize heya
Joseph
@revisualize
May 22 2017 02:38
@lilithlotus Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:38
@lilithlotus Yes it is a variable because when checkObj("gift"); calls this function, the property "gift" is stored in checkProp variable.
Joseph
@revisualize
May 22 2017 02:39
@sinharaksh1t It technically isn't a variable.

So you have a function declaration of function checkObj(checkProp) { } .. With that function declaration you have a function name of checkObj and you have a parameter of checkProp.
Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).
So, when you make a function call:
checkObj("pet") ... the parameter checkProp gets the value of the arguement "pet".
checkObj("horse") ... the parameter checkProp gets the value of the arguement "horse".
As mentioned above, you can then use the parameter inside of the function just like you'd use any other variable that holds a value.
Now, the lesson is trying to teach you about the object method .hasOwnProperty()

The hasOwnProperty() method returns a boolean (true/false) indicating whether the object has the specified property as own (not inherited) property.

@lilithlotus ---^^
Jessica Bensch
@lilithlotus
May 22 2017 02:40
@revisualize thank you, I had tried it as myObj["checkProp"], but I was still thinking of it as a property and putting the quotes. @sinharaksh1t thank you as well. Knowing to treat the parameter like a a variable helps.
CamperBot
@camperbot
May 22 2017 02:40
:warning: lilithlotus already gave sinharaksh1t points
lilithlotus sends brownie points to @revisualize and @sinharaksh1t :sparkles: :thumbsup: :sparkles:
:star2: 3991 | @revisualize |http://www.freecodecamp.com/revisualize
Rid Amsal
@RidAmsal
May 22 2017 02:41

@ngas-wakefield ,after
a = 7;
b = a;

then a should be assigned to b with =
how to write that code?

Joseph
@revisualize
May 22 2017 02:42
@RidAmsal that is how you write it.
Jessica Bensch
@lilithlotus
May 22 2017 02:42
@revisualize the one thing that made sense off the at was the .hasOwnProperty()
I think I've hit my learning wall for the day! lol
Rid Amsal
@RidAmsal
May 22 2017 02:43
@revisualize

@revisualize

// Setup
var a;
var b = 2;

// Only change code below this line
var a = 7;
var b = 7;
a = b
like that?

Joseph
@revisualize
May 22 2017 02:44
@RidAmsal No.
@RidAmsal Delete this:
var b = 7;
a = b
@RidAmsal the variable a should be assigned to b with the assignment operator =
@RidAmsal How do you assign the value 7 to a variable num?
num = 7;
@RidAmsal How do you assign the value of the variable a to the variable b ... ... b = a;
Rid Amsal
@RidAmsal
May 22 2017 02:46

It works:
var a = 7;
var b = a;

Thanks a bunch @revisualize

CamperBot
@camperbot
May 22 2017 02:46
ridamsal sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3992 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
May 22 2017 02:46
How do you assign the value of 7 to a variable num? ... var num = 7;
Now if you want you can use a variable to store values.
Like in mathmatics. num + 3 = 10 What is the value of num?
var x = num + 3; ... That outputs 10
So, you can do several things with variables. But, you need to understand that variables hold values and variables can be used with other variables.
So, how do you assign the value of 5 to a variable x? ... x = 5; (Which is also overwriting the previous value of 10 from above.
How do you assign the value of x to a variable y?
Look at the way things are written. var y = x;
How do you assign the value of 42 to a variable answer? ... What is the answer?
Variables hold values. Just understand that.
Rid Amsal
@RidAmsal
May 22 2017 02:47
Ok @revisualize , im trying to read your explanation slowly now.
Netrunner21
@Netrunner21
May 22 2017 02:49
Can someone help me with Smallest Common Multiple?
Rakshit Sinha
@sinharaksh1t
May 22 2017 02:54
@revisualize can you explain what you meant by saying that function parameters are not technically variables?
I know they are not declared with the var keyword, but they are invariably variables right, lol
Long Nguyen
@longnt80
May 22 2017 02:59
@Netrunner21 where are you stuck?
Netrunner21
@Netrunner21
May 22 2017 03:01
I've made the array with all the sequential numbers. I can't loop to find a number that divides evenly with all of them, it's too big. I need a different way to do it. I'm not sure where to start.
Joseph
@revisualize
May 22 2017 03:01
@sinharaksh1t Look, they're basically the same thing.
@sinharaksh1t But, calling them a variable can confuse where the declaration context is placed.
Long Nguyen
@longnt80
May 22 2017 03:02
@Netrunner21 it has to get big for some cases
Joseph
@revisualize
May 22 2017 03:02
@sinharaksh1t If I say, You have a function addThree with a parameter of num. ... You know exactly how to make that function declaration.
@sinharaksh1t Whereas, if I say you have a function hello with the variable name... You don't really know how to make that function.
Long Nguyen
@longnt80
May 22 2017 03:03
@Netrunner21 but once it finds the common multiple, it will stop
@Netrunner21 can you post the code
Joseph
@revisualize
May 22 2017 03:03
@sinharaksh1t function addThree (num) {}
@sinharaksh1t vs...
Netrunner21
@Netrunner21
May 22 2017 03:03
function smallestCommons(arr) {
  var arr2 = []; 
  arr.sort();
  for (var i = arr[0]; i <= arr[1]; i++) {
    arr2.push(i);
  } 
  return arr2;
}

smallestCommons([1, 13]);
Joseph
@revisualize
May 22 2017 03:04
@sinharaksh1t
function hello () {
    var name;
}
Netrunner21
@Netrunner21
May 22 2017 03:04
@longnt80 I had previously the big loop, but it never got to 6056820. My loops can't handle much more than i < 10,000.
Joseph
@revisualize
May 22 2017 03:04
@sinharaksh1t Calling a parameter a parameter and not a variable allows you to know the context of where the value is derived.
@sinharaksh1t Make sense?
Long Nguyen
@longnt80
May 22 2017 03:05
@Netrunner21 did you set the limit for i?
Netrunner21
@Netrunner21
May 22 2017 03:05
@longnt80 basically I was looping through every number to 6056820 to check if one of them was divisible by all of the numbers
Yes I set it to 6056821, because one of the answers was 6056820.
Munkhmanlai
@munkhmanlai
May 22 2017 03:06
please help me to solve this

In JavaScript, you can store a value in a variable with the assignment operator.

myVariable = 5;

Assigns the Number value 5 to myVariable.

Assignment always goes from right to left. Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator.

myVar = 5;
myNum = myVar;
Assigns 5 to myVar and then resolves myVar to 5 again and assigns it to myNum.

Instructions
Assign the value 7 to variable a.

Assign the contents of a to variable b.

Rakshit Sinha
@sinharaksh1t
May 22 2017 03:07
@revisualize Gotcha! I understand what you're trying to say! I was just wondering if there is any deeper difference between them on the computational level that I am missing!
But I completely understand and agree with the point that you are trying to make about how it should be represented theoretically! So i will remember it next time to draw a distinguishing line between variables and parameters.
Thanks :D
CamperBot
@camperbot
May 22 2017 03:07
sinharaksh1t sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3993 | @revisualize |http://www.freecodecamp.com/revisualize
Long Nguyen
@longnt80
May 22 2017 03:07
@Netrunner21 no you should not set the limit because you never know how big the common multiple
Netrunner21
@Netrunner21
May 22 2017 03:08
ok
Mohamad Adel Mekkawy
@madoococa
May 22 2017 03:08
var a = 7;
var b = a;
try this @munkhmanlai
Netrunner21
@Netrunner21
May 22 2017 03:09
I'm more concerned about the structure of whats in the loop
obviously if it has to loop through 6056819 numbers to get the asnwer, it will never get there
I need a different approach
Long Nguyen
@longnt80
May 22 2017 03:10
@Netrunner21 post your code
Rakshit Sinha
@sinharaksh1t
May 22 2017 03:10
@munkhmanlai what help are you asking for? :point_up: May 21, 2017 11:06 PM
Netrunner21
@Netrunner21
May 22 2017 03:11
I don't know how to make the loop. Right now I have just the new array with all the numbers the LCM has to be divisible by
Munkhmanlai
@munkhmanlai
May 22 2017 03:11

In JavaScript, you can store a value in a variable with the assignment operator.

myVariable = 5;

Assigns the Number value 5 to myVariable.

Assignment always goes from right to left. Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator.

myVar = 5;
myNum = myVar;
Assigns 5 to myVar and then resolves myVar to 5 again and assigns it to myNum.

Instructions
Assign the value 7 to variable a.

Assign the contents of a to variable b.

Netrunner21
@Netrunner21
May 22 2017 03:11
function smallestCommons(arr) {
  var arr2 = []; 
  arr.sort();
  for (var i = arr[0]; i <= arr[1]; i++) {
    arr2.push(i);
  } 
  return arr2;
}

smallestCommons([1, 13]);
Munkhmanlai
@munkhmanlai
May 22 2017 03:11

var a=7;
var b=a;
// Setup
var a;
var b = 2;

// Only change code below this line

it says b should have value of 7
how do you print screen this
Mihir Shanishchara
@MihirNS
May 22 2017 03:14
@munkhmanlai use console.log(your content)
Joseph
@revisualize
May 22 2017 03:15
@sinharaksh1t Note.. On a JS level... Variables and Parameters are different. But, that's also getting to the core of JS.
Mihir Shanishchara
@MihirNS
May 22 2017 03:15
@Netrunner21 you need to specify length in your for loop condition part (i.e i < arr.length)
Joseph
@revisualize
May 22 2017 03:15
@munkhmanlai How do you assign the value of 7 to a variable num? ... var num = 7;
Now if you want you can use a variable to store values.
Like in mathmatics. num + 3 = 10 What is the value of num?
var x = num + 3; ... That outputs 10
So, you can do several things with variables. But, you need to understand that variables hold values and variables can be used with other variables.
So, how do you assign the value of 5 to a variable x? ... x = 5; (Which is also overwriting the previous value of 10 from above.
How do you assign the value of x to a variable y?
Look at the way things are written. var y = x;
How do you assign the value of 42 to a variable answer? ... What is the answer?
Variables hold values. Just understand that.
Long Nguyen
@longnt80
May 22 2017 03:15
@Netrunner21 ok, you should loop through all the multiples of one number first. Then, at each multiple, you divides by each of the other numbers
so you need 2 loops
Joseph
@revisualize
May 22 2017 03:15
@munkhmanlai You're doing things out of order.
Netrunner21
@Netrunner21
May 22 2017 03:16
@longnt80 alright. I'll give that a shot. Thanks.
CamperBot
@camperbot
May 22 2017 03:16
netrunner21 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 288 | @longnt80 |http://www.freecodecamp.com/longnt80
Long Nguyen
@longnt80
May 22 2017 03:19
@Netrunner21 ok, in the first loop where you loop through all multiples of one number, you can omit the limit for i because you don't know how big the multiple can get
Rakshit Sinha
@sinharaksh1t
May 22 2017 03:20
@revisualize oh that's really good to know! Thanks again man! I will refer the documentation later to find out the nuances.
CamperBot
@camperbot
May 22 2017 03:20
sinharaksh1t sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: sinharaksh1t already gave revisualize points
Rakshit Sinha
@sinharaksh1t
May 22 2017 03:20
:D
Netrunner21
@Netrunner21
May 22 2017 03:22
@longnt80 I think I understand
Long Nguyen
@longnt80
May 22 2017 03:22
@Netrunner21 ok give it a try
john g
@jgwould
May 22 2017 03:33

function reusableFunction(){
  console.log("Hi World");
}
Can someone explain to me why you have to call the function in order for it to work
ie

function reusableFunction(){
  console.log("Hi World");
}

reusableFunction();
Joseph
@revisualize
May 22 2017 03:34
@jgwould because functions are reusable.
john g
@jgwould
May 22 2017 03:34
What does that mean
Joseph
@revisualize
May 22 2017 03:34
@jgwould If you have a function "breakfast" .. You don't want it to run every time you walk into the kitchen.
Because at 8pm you don't want "breakfast".
john g
@jgwould
May 22 2017 03:35
ok..
Daniel Zeff
@Diesirae9
May 22 2017 03:35
Who is up for helping a poor schleub.
john g
@jgwould
May 22 2017 03:36
hmm nice analogy, I am still falling short on my understanding
Joseph
@revisualize
May 22 2017 03:36
@jgwould Functions are reusable code blocks that allow you to do things when you want them to.

@jgwould If I have a function

function addThree (num) {
    var result;
    result = num + 3;
    return result;
}

So, when we make the function call of:

addThree(10);

....
I don't want the function addThree to just run without me telling it when / where to run.

Daniel Zeff
@Diesirae9
May 22 2017 03:37
I am working on the Confirm the Ending Algorithm and have hit a snag.
john g
@jgwould
May 22 2017 03:37
So you're letting it know to run when you have 10 as num
Joseph
@revisualize
May 22 2017 03:37
Also, what if I don't want to addThree to the value 10. But, I want to change the number to 18?
@jgwould No.
Daniel Zeff
@Diesirae9
May 22 2017 03:38
it works for like half the problem and not the other half.
Joseph
@revisualize
May 22 2017 03:38
@jgwould You can do addThree(1)
@jgwould You can do addThree(3330)
john g
@jgwould
May 22 2017 03:38
ok so youre letting know to run when you have addThree(num)
Joseph
@revisualize
May 22 2017 03:38
@jgwould Ummm.. Change your context please. It is misleading.
john g
@jgwould
May 22 2017 03:39
addThree(x);
Joseph
@revisualize
May 22 2017 03:39

@jgwould

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.

Daniel Zeff
@Diesirae9
May 22 2017 03:40
function confirmEnding(str, target) {
  var sTA= str.split(" "); // varible holds string into a array
  for (i = 0; i < sTA.length; i++){
    str = sTA[i];
  }
  // run through string. assign the last section of the array to str
  if (str==target){
    return true;
  } else {return false;}
}
// if str
confirmEnding("Bastian", "n");
john g
@jgwould
May 22 2017 03:40
OK THAT MAKES SENSE! I see now.
Joseph
@revisualize
May 22 2017 03:40
@jgwould I use that pretyped text to explain something else. But, it can show how functions are reusable.
john g
@jgwould
May 22 2017 03:40
So, essentially it gives you the ability to change the paramaters
Joseph
@revisualize
May 22 2017 03:41
@jgwould Sure, but, you don't need to have function parameters or function arguments.
Daniel Zeff
@Diesirae9
May 22 2017 03:42
any thoughts? :)
Joseph
@revisualize
May 22 2017 03:42
@Diesirae9 THat's a lot of code.
john g
@jgwould
May 22 2017 03:42
thanks for helping me out. I am still unsure of what you mean by the above. Are you saying I could do it more simply
Daniel Zeff
@Diesirae9
May 22 2017 03:42
I have some notes in there for myself as well.
want me to remove my notes?
john g
@jgwould
May 22 2017 03:43
also is this recursive?
thank you @revisualize
CamperBot
@camperbot
May 22 2017 03:44
jgwould sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3994 | @revisualize |http://www.freecodecamp.com/revisualize
Masaki
@masaki1223
May 22 2017 03:44
.toString(2) convert num into binary, but .toString(10) doesn't change num into decimal. WHy is that?
Daniel Zeff
@Diesirae9
May 22 2017 03:45
function confirmEnding(str, target) {
  var sTA= str.split(" "); 
  for (i = 0; i < sTA.length; i++){
    str = sTA[i];
  }
  if (str==target){
    return true;
  } else {return false;}
}
confirmEnding("Bastian", "n");
There it is without my notes :)
Traek Wells
@TraekWells
May 22 2017 03:49
can someone help me with a javascript function? I’m trying to see if all of the items in an array are the same but I keep getting a return of false?
// write a isUniform function that checks if every item in an array is the same
function isUniform(arr) {
  var numTracker = arr.indexOf(arr[0]);
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] !== numTracker) {
      return false;
    }
  }
  return true;
}
john g
@jgwould
May 22 2017 03:49

function reusableFunction(a, b){
  console.log(a + " " + b);
}

reusableFunction("Hi", "World");
So, in messing around with the code, this won't pass. Why?
"Call reusableFunction after you define it" has a red X
Traek Wells
@TraekWells
May 22 2017 03:50
never mind! figured it out
john g
@jgwould
May 22 2017 03:51
@TraekWells I love figuring out the answer right as I ask the question lol
Traek Wells
@TraekWells
May 22 2017 03:51
@jgwould haha happens all the time
Daniel Zeff
@Diesirae9
May 22 2017 03:53
@jgwould You need to have something that is returning what you are asking
Mihir Shanishchara
@MihirNS
May 22 2017 03:55
@TraekWells you are comparing value (i.e arr[i]) with index of array (i.e numTracker)
Daniel Zeff
@Diesirae9
May 22 2017 03:55
so console.log(a + " " + b); is going to try to log two separate variables that are undefined with a space in the middle of them.
Traek Wells
@TraekWells
May 22 2017 03:57
@MihirNS yeah that part was jacking me up, I found an easier solution
Csaba Balogh
@JasonCorp84
May 22 2017 03:59
Good evening everyone
I am working on Seek and Destroy

function destroyer(arr) {
  // Remove all the values
  var destroyed = arr.filter(function(val){
    for(var i = 0; i < arguments[0].length; i++){
      for (var j = 1; j <arguments.length; j++){
    return arguments[i] !== arguments[j];
    }
    }
  });
  return destroyed;
}
I do not really have a clue how to go forward with this
Daniel Zeff
@Diesirae9
May 22 2017 04:00
@JasonCorp84 past where I am right now.
Csaba Balogh
@JasonCorp84
May 22 2017 04:02
So I guess 1. I want to compare each elements of argument[0] with argument 1 elements and return those that are not equal with argument[1] element
that I want to do the same for the second element
and do it as many arguments we have above 0
Moisés Man
@moigithub
May 22 2017 04:03
every functin have its own argument object @JasonCorp84
soo calling argument inside destroyer its NOT the same as calling inside filter callback function
if u wanna use destroyer arguments inside filter first u need to make a copy
Victor Popescu
@VicPopescu
May 22 2017 04:04
@JasonCorp84 I don't get why you need to use arguments in a iteration
Pedro Pineda
@pedropda
May 22 2017 04:04
@JasonCorp84 Maybe try pushing arguments > arguments[0] in a variable and then filter arr using it
Csaba Balogh
@JasonCorp84
May 22 2017 04:06
@pedropda @VicPopescu thank you
CamperBot
@camperbot
May 22 2017 04:06
jasoncorp84 sends brownie points to @pedropda and @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 425 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
:cookie: 274 | @pedropda |http://www.freecodecamp.com/pedropda
Mark R. Baker
@mrbaker1917
May 22 2017 04:07
In the less than equal to module, will not the code return twice, if the argument stays at 10?
Netrunner21
@Netrunner21
May 22 2017 04:11
@longnt80 I solved it, thanks for the advice!
CamperBot
@camperbot
May 22 2017 04:11
netrunner21 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:warning: netrunner21 already gave longnt80 points
Netrunner21
@Netrunner21
May 22 2017 04:11
function smallestCommons(arr) {
  var arr2 = [];   
  arr.sort();
  for (var i = arr[0]; i <= arr[1]; i++) {
    arr2.push(i);
  } 
  arr2.reverse();
  var num = arr2[0];
  var numadd = 0;  
  for (var j = 0; j < arr2.length ; j++) {
    numadd = num;
    for (var k = 0; k < 1000; k++) {       
       if (num % arr2[j+1] === 0) { break; }
       num += numadd;      
    }
  }  
 return numadd;
}  

smallestCommons([1, 13]);
Rakshit Sinha
@sinharaksh1t
May 22 2017 04:22
Hey guys, can someone pls have a look at this and let me know where am I going wrong?
https://repl.it/IKQ4/0
Long Nguyen
@longnt80
May 22 2017 04:25
@Netrunner21 you can combine numadd and num as k in the second loop
Markus Ivancsics
@ivancsicsmarkus
May 22 2017 04:26
@sinharaksh1t
pq.enqueue(['cat',2]);
pq.printCollection();
@sinharaksh1t But collection is also not defiend
Rakshit Sinha
@sinharaksh1t
May 22 2017 04:27
@ivancsicsmarkus exactly I am not able to understand what it means by saying that collection is not defined? @ivancsicsmarkus
Rabin Rai
@rabinrai44
May 22 2017 04:27
Hello Friends . I just having stuck in JavaScript Escape Sequence challenge. Please any one can help
Long Nguyen
@longnt80
May 22 2017 04:27
@Netrunner21 for (var k = arr2(0); ; k+=arr2[0]) and you can omit k < 1000
Markus Ivancsics
@ivancsicsmarkus
May 22 2017 04:28
@sinharaksh1t Check out now: https://repl.it/IKQ4/1
Flakari
@Flakari
May 22 2017 04:29
var Bike = function() {

  // Only change code below this line.
  var gear = 0;
  this.setGear = function(gearSet){
    gear += gearSet;
  };
  this.getGear = function(){
    return gear;
  };
};

var myCar = new Car();

var myBike = new Bike(); {
  myBike.setGear(1);
  myBike.getGear();
}
So, I'm trying to run the private objects js lesson, it returns what it needs to, yet doesn't say I passed it. What am I overlooking? (Hopefully the code shows up as it should)
Markus Ivancsics
@ivancsicsmarkus
May 22 2017 04:29
@sinharaksh1t That, you are trying to use a variable that is not defined. You are trying to use a global variable in your code, however it is a local variable.
Daniel Zeff
@Diesirae9
May 22 2017 04:30
I am so clooooose!
function repeatStringNumTimes(str, num) {
 var sR = str.repeat(num);
 var bS = "";
  if (num > 0){
    return sR;
  } else {
    return bS;
  }

}

repeatStringNumTimes("donkey donkey ", 1000);
Markus Ivancsics
@ivancsicsmarkus
May 22 2017 04:30
@sinharaksh1t Does it work? Could you say something?
Daniel Zeff
@Diesirae9
May 22 2017 04:30
works up to 0
Any help? :)
Rakshit Sinha
@sinharaksh1t
May 22 2017 04:31
@ivancsicsmarkus thank you so much!!! I was just wondering how it works!! Thanks for that clarification!!!
CamperBot
@camperbot
May 22 2017 04:31
sinharaksh1t sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:cookie: 506 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
Rakshit Sinha
@sinharaksh1t
May 22 2017 04:32
this is such a small thing but has such a huge impact!! thanks again man!! I will remember this always now!!! @ivancsicsmarkus
CamperBot
@camperbot
May 22 2017 04:32
sinharaksh1t sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:warning: sinharaksh1t already gave ivancsicsmarkus points
Markus Ivancsics
@ivancsicsmarkus
May 22 2017 04:32
@sinharaksh1t You are welcome, if you don’t understand anything I did, just ask me!
Rakshit Sinha
@sinharaksh1t
May 22 2017 04:32
you changed all collection references to this.collection right?
that's the only difference I could see
@ivancsicsmarkus
Ryan Nelson
@iamryandnelson
May 22 2017 04:33
Can anyone tell me why my youtube overlay isn't displaying bigger?
http://codepen.io/iamryandnelson/pen/BRPvbr?editors=0100
Markus Ivancsics
@ivancsicsmarkus
May 22 2017 04:33

@sinharaksh1t Yes, inside the object.
Also I changed this:

PriorityQueue.enqueue(['cat',2]);
PriorityQueue.printCollection();

to this:

pq.enqueue(['cat',2]);
pq.printCollection();

Because PriorityQueue is the constructor, the object is pq.

Rakshit Sinha
@sinharaksh1t
May 22 2017 04:34
gotcha!!! You're a savior!!! :D @ivancsicsmarkus
What's the error? @Diesirae9 :point_up: May 22, 2017 12:30 AM
Daniel Zeff
@Diesirae9
May 22 2017 04:38
@sinharaksh1t i get: RangeError: Invalid count value
only if it is below 0 though
at zero I return my boolean
Markus Ivancsics
@ivancsicsmarkus
May 22 2017 04:39
@Diesirae9 You can’t pass a negative number to .repeat method.
@Diesirae9 Move it inside the if statement (if bigger than zero)!
Daniel Zeff
@Diesirae9
May 22 2017 04:39
move .repeat() ?
Ryan Nelson
@iamryandnelson
May 22 2017 04:40
Can anyone help me understand why when I select a movie trailer the youtube overlay doesn't display bigger?
http://codepen.io/iamryandnelson/pen/BRPvbr?editors=0100
Daniel Zeff
@Diesirae9
May 22 2017 04:40
I might have it hang on :)
nvm lol
str.repeat happen after we look at num?
Rakshit Sinha
@sinharaksh1t
May 22 2017 04:45
yes
@Diesirae9
Netrunner21
@Netrunner21
May 22 2017 04:45
@longnt80 Ok I'll try that
Ryan Nelson
@iamryandnelson
May 22 2017 04:48
Nvm
Netrunner21
@Netrunner21
May 22 2017 05:01
I have a question on Sum All Primes
Markus Kiili
@Masd925
May 22 2017 05:27
@Netrunner21 Ask away.
Netrunner21
@Netrunner21
May 22 2017 05:31
@Masd925 since there's only a limited number of prime numbers from 1 to 1000, why not just use a pre asembled table and slice the table and sum it
@Masd925 would that be considered lazy and/or cheating, haha
or resourceful?
Markus Kiili
@Masd925
May 22 2017 05:34
@Netrunner21 That would be good if we knew we only use the function with argument <=1000. That would be optimizing the function for a special case. Here we need to make a general solution that works with any argument.
Such tables are often used if we need the function a lot and we know the limit.
Rakshit Sinha
@sinharaksh1t
May 22 2017 05:36
my code for "Priority Queue" works completely fine and as it should on repl.it but on freecodecamp, it is not able to pass this test case somehow i dont know why: "The priority queue should return items with a higher priority before items with a lower priority and return items in first-in-first-out order otherwise."
Here's a repl link if anyone wants to go through it: https://repl.it/IKVX/0
Netrunner21
@Netrunner21
May 22 2017 05:51
@Masd925 I understand. My loops are too large so I'm trying to find a way to dump out primes efficiently.
sudhanshu tiwari
@sidsid14
May 22 2017 05:52
In Check for Palindromes exercise why should eyeforofeye return false ?
Markus Kiili
@Masd925
May 22 2017 05:53
@Netrunner21 Efficient enough way is to store the primes and only check divisibility of the looped number against the primes found so far (instead of checking against all the smaller numbers).
@sidsid14 You should not remove numbers.
sudhanshu tiwari
@sidsid14
May 22 2017 05:54
Ok thanks.
chameleon07
@chameleon07
May 22 2017 06:03
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor

  str = str.toLowerCase().replace(/[\W_]+/g, "").split("");

  end = [];

  for (i = 0; i < target.length; i++){
    end.push(str[str.length - i]);
  }

  return end;

  if (end.join("") == target){
    return true;
  }
  else {return false;}

  return str;
}

confirmEnding("Bastian", "n");
Why does return end; give a [null] value?
My goal is to confirm that the target value is equal to the end of the string
intcreate
@intcreate
May 22 2017 06:05
nice code
wat part r u on
in javascript
Markus Kiili
@Masd925
May 22 2017 06:05
@chameleon07 Easier without any arrays, splits or joins. You can loop, access and compare characters without using arrays.
chameleon07
@chameleon07
May 22 2017 06:07
@intcreate Basic Algorithm Scripting: Confirm the Ending :3
@Masd925 Ohhh
@Masd925 Will it be shorter too?
Markus Kiili
@Masd925
May 22 2017 06:08
@chameleon07 Yes.
chameleon07
@chameleon07
May 22 2017 06:09
@Masd925 Okie will work on it then Thank you! :D
CamperBot
@camperbot
May 22 2017 06:09
chameleon07 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4107 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
May 22 2017 06:09
@chameleon07 Even simpler way is to use string operations. You can slice the end part of str and compare === it with target.
O'Maiye Tomi
@tomisiin
May 22 2017 06:12

hi, any help with the "return early pattern for functions" challenge? I'm stuck with one instruction

function abTest(a, b) {
// Only change code below this line

if (a && b > 0){

}else {
return undefined;
}

// Only change code above this line

return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,-2);

Markus Kiili
@Masd925
May 22 2017 06:13
@tomisiin You need a condition on both sides of ||. Using && is wrong.
a is not a good condition here.
Also you need to be checking for negative values, not positive.
O'Maiye Tomi
@tomisiin
May 22 2017 06:13
Ohh! Great, thanks @Masd925
CamperBot
@camperbot
May 22 2017 06:13
tomisiin sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4108 | @masd925 |http://www.freecodecamp.com/masd925
Rakshit Sinha
@sinharaksh1t
May 22 2017 06:28

´´´The write pointer should not be allowed to move past the read pointer (our class won't let you overwrite data you haven't read yet) and the read pointer should not be able to advance past data you have written.´´´

What are they trying to say by this? Write head should not move past read head and read head should not move past write head?! lol, then how are we supposed to write data?

Cody Smith
@TheCodingSmith
May 22 2017 06:31
Anyone want to give me feedback on my wikipedia viewer? https://codepen.io/TheCodingSmith/full/NjEbyM/
Markus Kiili
@Masd925
May 22 2017 06:31
@TheCodingSmith A better place is https://gitter.im/FreeCodeCamp/CodeReview
Cody Smith
@TheCodingSmith
May 22 2017 06:32
@Masd925 Oh :p Thanks
CamperBot
@camperbot
May 22 2017 06:32
thecodingsmith sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4109 | @masd925 |http://www.freecodecamp.com/masd925
AIT ASSOU
@toscanoGithub
May 22 2017 06:33
Hello everybody
Markus Kiili
@Masd925
May 22 2017 06:34
@toscanoGithub Hi.
Sulaiman
@suli-g
May 22 2017 06:36
Good morning guys
Markus Kiili
@Masd925
May 22 2017 06:37
@suli-g Morning.
Sulaiman
@suli-g
May 22 2017 06:37
I was quite surprised to find that FontAwesome has a freecodecamp logo (fa-free-code-camp)
AIT ASSOU
@toscanoGithub
May 22 2017 06:38
I have just finished the Caesars Cipher challenge. I have a strange problem:
the code compile and successfully return the desired string as mentioned in the left panel. But nothing Freecodecamp checker says this should return " what ever string " depending on the original string. my return string is the same.
Sulaiman
@suli-g
May 22 2017 06:39
So -- I've completed the Markup viewer quite easily with my basic Codecademy ReactJS knowledge -- but the Leaderboard only returns one entry now... So I'm probably gonna take a day or two off to learn ReactJS properly...
AIT ASSOU
@toscanoGithub
May 22 2017 06:40
I wish someone test the code for me and tell me what is wrong pls
Markus Kiili
@Masd925
May 22 2017 06:41
@toscanoGithub Post the code you have here. I can check it.
AIT ASSOU
@toscanoGithub
May 22 2017 06:43
Here it is

function rot13(str) { // LBH QVQ VG!

var wordsArray = str.split(" ");

var lettersArray = [];
var words = [];
var lettersCoded = [];
var codeToLetters = [];

for(var i=0; i<wordsArray.length; i++) {
lettersArray.push(wordsArray[i].split(""));
}

for(var j=0; j<lettersArray.length; j++) {
words.push(lettersArray[j].join(""));

    for(var k=0; k<words[j].length; k++) {
        var p = words[j].charCodeAt(k);
      if(p <= 77 && p >= 65 ) {
        p += 13;
      } else if(p > 77 && p <= 90) {
        p -= 13;
      } 
        lettersCoded.push(p);
    }
lettersCoded.push("");

}

for(var l=0; l<lettersCoded.length; l++) {
//fromCharCode
codeToLetters.push(String.fromCharCode(lettersCoded[l]));

}
codeToLetters.pop();
return codeToLetters.join(" ").replace(/\u0000/g, "");
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
//rot13("SERR CVMMN!");
//rot13("SERR YBIR?");
//rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");

@Masd925
Markus Kiili
@Masd925
May 22 2017 06:45
@toscanoGithub You have some extra spaces on the result string, for example 'F R E E C O D E C A M P'
'T H E Q U I C K B R O W N D O G J U M P E D O V E R T H E L A Z Y F O X .'
Compare those with the expected returns.
AIT ASSOU
@toscanoGithub
May 22 2017 06:48
@Masd925 So between F and R in FREE there is an extra space ?
Markus Kiili
@Masd925
May 22 2017 06:48
Yes.
venkat kishore
@kittu401
May 22 2017 06:48
hi i need help with wordpress avada theme... in this i need to add text over image using fusion builder plugin .how to do this..???
AIT ASSOU
@toscanoGithub
May 22 2017 06:49
OK thank you, I ll fix it, may be tired to see the spaces :) Thank you
AIT ASSOU
@toscanoGithub
May 22 2017 06:56
fixed:
Should change return codeToLetters.join(" ").replace(/\u0000/g, "");
to
return codeToLetters.join("").replace(/\u0000/g, " ");
Markus Kiili
@Masd925
May 22 2017 06:58
@toscanoGithub It works now?
Rakshit Sinha
@sinharaksh1t
May 22 2017 07:00
[EDIT: FIXED IT]
I am using safari browser and this small "circular queue" code for some reason does the execution in such a way that my browser's print dialog box keeps opening in loop a couple of times.
Any inputs on why's that so?
here's the code: https://repl.it/IK1K/0
tahashin
@tahashinegp
May 22 2017 07:08

// Example
var ourArray = [];

for (var i = 1; i < 10; i += 2) {
ourArray.push(i);
}
console.log( ourArray );//it is showing empty why?
// Setup
var myArray = [];

// Only change code below this line.

for (var i = 1; i < 10; i += 2) {
myArray=ourArray.unshift(i);
}

where is the problem?
Markus Kiili
@Masd925
May 22 2017 07:10
@tahashinegp It doesn't log an empty array [ 1, 3, 5, 7, 9 ]
Tenenbaum
@Tenenbaum
May 22 2017 07:10

In the 'Profile Lookup' challenge I can get the function to return the prop value OR 'No such contact', but NOT both. Anyone know what's going on? Code:
function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<contacts.length;i++){
if(firstName==contacts[i].firstName){
console.log(contacts[i][prop]);
return contacts[i][prop];
}if(firstName!=contacts[i].firstName){
return "No such contact";
}
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

Markus Kiili
@Masd925
May 22 2017 07:11
@Tenenbaum You need another nested if for property existence test.
Donnie
@Donnie-D
May 22 2017 07:11

Fellas Whats wrong in below? it appears to be a little temperamental
```function destroyer(arr) {
// Remove all the values
var result = [];
var args=Array.prototype.slice.call(arguments);

for(i=1; i<=args.length; i++){
args[0].filter(function (val){
if(args[0].indexOf(args[i]) !== -1){
args[0].splice(args[0].indexOf(args[i]),1);
}
return args[0];
});
}

return args[0];

}

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

lol lets try again
function destroyer(arr) {
  // Remove all the values
  var result = [];
  var args=Array.prototype.slice.call(arguments);



  for(i=1; i<=args.length; i++){
    args[0].filter(function (val){
      if(args[0].indexOf(args[i]) !== -1){
        args[0].splice(args[0].indexOf(args[i]),1);
      }
      return args[0];
    });
  }

  return args[0];

}

destroyer([2, 3, 2, 3,3],2,3,2);
Markus Kiili
@Masd925
May 22 2017 07:12
@Donnie-D Inside the filter callback, you need to use indexOf on args, not args[0].
And return false if val is found on args and true otherwise.
@Donnie-D You are using filter just for causing side effects, which is confusing. You should use the filtered array filter returns instead.
Qulu Mammadli
@qulu1
May 22 2017 07:14
hey guys. Any idea , how can i use api of this website? http://forismatic.com/en/api/
Donnie
@Donnie-D
May 22 2017 07:14
@Masd925 that hurts if somebody replies back pointing your errors so quick lol. you're gooooood
Qulu Mammadli
@qulu1
May 22 2017 07:14
when i boot it, console throw access denied error
tahashin
@tahashinegp
May 22 2017 07:18
@Masd925 so my last loop will be shift right ourArray.shift(i) right? but its not working
Veronica Tobias
@vekatobias
May 22 2017 07:21
Hi guys I have some problem resolving my challengue.. The challengues is "Iterate over Arrays with map"

var oldArray = [1,2,3,4,5];

// Only change code below this line.
var timethree = oldArray.map(function(val){
return val * 3;
});

var newArray = oldArray;

Ken Haduch
@khaduch
May 22 2017 07:23
@Donnie-D - just FYI- you can go back and edit or even delete your posts for a few minutes. The three dots appear near the time stamp of the message when you hover there
Tenenbaum
@Tenenbaum
May 22 2017 07:24
No bueno. The right values show up in the console (except for the prop check which is undefined), but FCC only checks the box for "No contact" despite the props showing up in the bar. Something is weird. Here:

function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<contacts.length;i++){
if(firstName==contacts[i].firstName){
console.log(contacts[i][prop]);
return contacts[i][prop];
}if(firstName!=contacts[i].firstName){
console.log("No such contact");
return "No such contact";
}if(prop!=contacts[i]){
console.log("No such property");
return "no such property";
}
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

tahashin
@tahashinegp
May 22 2017 07:25
@Masd925 solved thanks
Veronica Tobias
@vekatobias
May 22 2017 07:25
That's my code but I've to add three to each value in the array.
Donnie
@Donnie-D
May 22 2017 07:27
@khaduch :+1: for the useful tip
Donnie
@Donnie-D
May 22 2017 07:34
@Masd925 sorry i was just stunned by your ferocious help lol could you kindly explain what you mean by me using filter for side effects and also what you meant by using filtered array?
oudomkiri
@kirioudom
May 22 2017 07:38
hey everyone !! how to search for uppercase or lowercase in string?
Rakshit Sinha
@sinharaksh1t
May 22 2017 07:40
regex? @kirioudom
oudomkiri
@kirioudom
May 22 2017 07:41
@sinharaksh1t i dont know how to use it to find uppercase or lowercase.
Cara
@CaraLarissa
May 22 2017 07:46
Hello everyone! I am stuck on the Basic JavaScript challenge "Return Early Pattern for Functions"
Sandeep Chary
@dsandeepchary
May 22 2017 07:46
Anyone here to help me?
How can I handle events on a web page based on the parameters in the URL??
Cara
@CaraLarissa
May 22 2017 07:46

1

2
// Setup
3
function abTest(a, b) {
4
  // Only change code below this line
5

6

7

8
  // Only change code above this line
9

10
  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
11
}
12

13
// Change values below to test your code
14
abTest(2,2);
15
My bad, I reset my code, I didn't mean to send that lol
Chris Juchtmans
@kjuchtmans
May 22 2017 07:48
morning everyone :wave:

'Random Quote Generator' :

Question: why doesnt my Chrome browser render the array of objects returned from my AJAX call?
Can anyone confirm that they at least see an array returned on button click?

JS Code :

$(document).ready(function() {

  $("#getQuote").on("click", function() {

    $.getJSON("https://codepen.io/chrisjuchtmans/pen/OmoaRY.js", function(json) {
      console.log(json);
      var html = "";

      html += '<div class = "newQuote">';
      html += json.quotes;
      html += "</div>";

      $(".message").html(html);

    });
  });
});

Full Pen : (https://codepen.io/chrisjuchtmans/pen/EWRKaB)

I already tried purging Chrome cache, or I.E. but nothing
Thanks !

Rakshit Sinha
@sinharaksh1t
May 22 2017 07:53
@kirioudom use string.match and then use regex for pattern match
@kirioudom like str.match(/[A-Z]/g) this will give you an array containing all the matches
Tenenbaum
@Tenenbaum
May 22 2017 07:55
Mostly fixed. My prop check still comes back 'undefined' in console. Any ideas? Code:
function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<contacts.length;i++){
if(firstName==contacts[i].firstName){
console.log(contacts[i][prop]);
return contacts[i][prop];
}
}
for(j=0;j<contacts.length;j++){
if(firstName!=contacts[j].firstName){
console.log("No such contact");
return "No such contact";
}
}
for(h=0;h<contacts.length;h++){
if(prop!=contacts[h][prop]){
console.log("No such property");
return "No such property";
}
}
// Only change code above this line
}
Ogundele Olumide
@Lumexralph
May 22 2017 07:55
@Tenenbaum why multiple for loops?
Tenenbaum
@Tenenbaum
May 22 2017 07:56
Wouldn't work otherwise.
Kept looping the same check and getting stuck.
Ogundele Olumide
@Lumexralph
May 22 2017 07:57
@Tenenbaum i have a pseudocode that might help
@Tenenbaum
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
@CaraLarissa what're you to do?
Tenenbaum
@Tenenbaum
May 22 2017 07:58
Process of elimination. Will try.
Cara
@CaraLarissa
May 22 2017 08:00
Okay so this is what I have so far
// Setup
function abTest(a, b) {
  // Only change code below this line
  console.log(a < 0);
  console.log(b < 0);


  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,2);
Long Nguyen
@longnt80
May 22 2017 08:00
@kjuchtmans it fail to load your js file. I think this file https://codepen.io/chrisjuchtmans/pen/OmoaRY.js is not valid
Ogundele Olumide
@Lumexralph
May 22 2017 08:01
@CaraLarissa what are the instructions?
O'Maiye Tomi
@tomisiin
May 22 2017 08:01
Hi, please any explanation on using objects for lookups?
Chris Juchtmans
@kjuchtmans
May 22 2017 08:01
@longnt80 okay thanks i will look into it
CamperBot
@camperbot
May 22 2017 08:01
kjuchtmans sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 290 | @longnt80 |http://www.freecodecamp.com/longnt80
Ogundele Olumide
@Lumexralph
May 22 2017 08:01
@tomisiin what have you tried? or what're you to do?
Long Nguyen
@longnt80
May 22 2017 08:03
@kjuchtmans by the way, in Codepen, you don't have to paste all your html file into the HTML window, you only need to copy the html between body tag (not including the body tag)
then you can go to Setting to include your css and script files
Cara
@CaraLarissa
May 22 2017 08:03
@Lumexralph Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
Chris Juchtmans
@kjuchtmans
May 22 2017 08:04
@longnt80 oh, great to know! i use the html window as a cloud backup to my local work
Ogundele Olumide
@Lumexralph
May 22 2017 08:04
@CaraLarissa if(a is less than 0 or b is less than 0) { return undefined ; }
Blauelf
@Blauelf
May 22 2017 08:05

@kjuchtmans If you want to make it JSON, instead of

var quotes = [
...
 ];

maybe try

{
  quotes: [
...
  ]
}
Cara
@CaraLarissa
May 22 2017 08:06
@Lumexralph I didn't realize that I could put undefined as command, thank you, it worked!
CamperBot
@camperbot
May 22 2017 08:06
caralarissa sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1789 | @lumexralph |http://www.freecodecamp.com/lumexralph
Chris Juchtmans
@kjuchtmans
May 22 2017 08:07
@Blauelf Vielen Dank. I'm reading some contradictory input on the interweb, regarding proper JSON syntax.
Is this syntax incorrect JSON then ? : (http://stackoverflow.com/questions/18238173/javascript-loop-through-json-array)
Blauelf
@Blauelf
May 22 2017 08:08
@kjuchtmans The JSON file should contain one object, without any var. That part, the var json = is Javascript, but not JSON.
Rakshit Sinha
@sinharaksh1t
May 22 2017 08:09

can somebody explain the difference between:

this.has = function(element) {
        return (collection.indexOf(element) !== -1);
    };

and this:

this.has = function(element) {
        return (collection.indexOf(element) !== -1) ? true: false;
    };
Chris Juchtmans
@kjuchtmans
May 22 2017 08:10
@Blauelf That makes sense to me.
However, on my code below the codepen JS checker throws me an error unexpected token : for the line quotes:[
{
    quotes: [
   "id": 1,
  "quote":"THIS IS QUOTE 1", 
  "author":"SPOKEN BY AUTHOR ONE" 
   }, 
etc
Blauelf
@Blauelf
May 22 2017 08:10
@sinharaksh1t No difference at all. Second version is longer.
Ogundele Olumide
@Lumexralph
May 22 2017 08:10
@sinharaksh1t collection.indexOf(element) !== -1 returns a boolean
@sinharaksh1t (collection.indexOf(element) !== -1) ? true: false; long journey
Long Nguyen
@longnt80
May 22 2017 08:10
@kjuchtmans quotes should be in ""
Blauelf
@Blauelf
May 22 2017 08:11
@kjuchtmans It's not a JSON editor, I assume. You could wrap your object in extra parentheses, like ({ "quotes" : ... })
@kjuchtmans That way, the parser does not mistake the object for a code block
Chris Juchtmans
@kjuchtmans
May 22 2017 08:13
@Blauelf okay will try that. and no trailing ; ?
Blauelf
@Blauelf
May 22 2017 08:13
If the file's content is a JSON object, I don't think so.
I'm actually not sure parentheses are allowed in the JSON object for it to be JSON...
karan17235
@karan17235
May 22 2017 08:15
This is my code

// Setup
function abTest(a, b) {
// Only change code below this line
if (a is less than 0) or (b is less than 0);
{
return undefined ;
}
// Only change code above this line
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,2);

and the condition is - Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
Rakshit Sinha
@sinharaksh1t
May 22 2017 08:15
@Blauelf @Lumexralph ah right! so both of these return a boolean and not exactly the index! I was getting confused there for a bit! Thanks a lot though! :D
CamperBot
@camperbot
May 22 2017 08:15
sinharaksh1t sends brownie points to @blauelf and @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 4209 | @blauelf |http://www.freecodecamp.com/blauelf
karan17235
@karan17235
May 22 2017 08:15
please help i am unable to resolve this
CamperBot
@camperbot
May 22 2017 08:15
:star2: 1790 | @lumexralph |http://www.freecodecamp.com/lumexralph
Rakshit Sinha
@sinharaksh1t
May 22 2017 08:16
@karan17235
if (a is less than 0) or (b is less than 0); //change this line
{
return undefined ;
}
Blauelf
@Blauelf
May 22 2017 08:16
@karan17235 Translate "is less than" to the correct comparison operator, and combine the two conditions using the || OR operator. Also, remove the semicolon after the if's condition
Ogundele Olumide
@Lumexralph
May 22 2017 08:18
@karan17235 use the JS operator || for or
karan17235
@karan17235
May 22 2017 08:18
Thanks @Blauelf
CamperBot
@camperbot
May 22 2017 08:18
karan17235 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4210 | @blauelf |http://www.freecodecamp.com/blauelf
karan17235
@karan17235
May 22 2017 08:18
It worked
Rakshit Sinha
@sinharaksh1t
May 22 2017 08:26
any reason why this shows a compile time error:
pos === -1 ? this.collection.push(element) : this.collection.splice(pos,0,element);
"Expected an assignment or function call and instead saw an expression"
It does work flawlessly on repl.it by the way.
Ogundele Olumide
@Lumexralph
May 22 2017 08:28
@sinharaksh1t where's it showing the error? on FCC?
Kevin Gong
@kevingong1995
May 22 2017 08:29

hi, I am having trouble with my titling case a sentence.
what am i doing wrong?

function titleCase(str) {
var lower = str.toLowerCase();
var splitString = lower.split(' ');
for (var i = 0; i < splitString.length; i++)
{
splitString[i][0].toUpperCase();
}
var newString = splitString.join(' ');
return newString;
}

titleCase("I'm a little tea pot");

Ogundele Olumide
@Lumexralph
May 22 2017 08:30
@kevingong1995 you need to add the substring of the string at each index of the array with the first character to upper case in the loop
O'Maiye Tomi
@tomisiin
May 22 2017 08:30
Thanks for the help with @CaraLarissa 's question. i also had issues on that
CamperBot
@camperbot
May 22 2017 08:30
tomisiin sends brownie points to @caralarissa :sparkles: :thumbsup: :sparkles:
:cookie: 198 | @caralarissa |http://www.freecodecamp.com/caralarissa
Mark Sorce
@msorce
May 22 2017 08:31
thanks @camperbot
CamperBot
@camperbot
May 22 2017 08:31
msorce sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 3259 | @camperbot |http://www.freecodecamp.com/camperbot
Miljan Grcic
@Nightimer
May 22 2017 08:31
function bouncer(arr) {

  var passed = arr.filter(function(word) {
  return word !== false || null || 0 || "" || undefined || NaN;
  });

  return passed;
}

bouncer([7, "ate", "", false, 9]);
O'Maiye Tomi
@tomisiin
May 22 2017 08:31
@Lumexralph i'm to convert a switch statement into a lookup table , lookup a val argument and assign the associated string to the result variable
Ogundele Olumide
@Lumexralph
May 22 2017 08:31
@kevingong1995 splitString[i] = [splitString[i][0].toUpperCase() + substring of splitString[i] ;
@Nightimer NaN is not equal to anything, even itself
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:32
@Lumexralph yo!
Ogundele Olumide
@Lumexralph
May 22 2017 08:33
@Nightimer and it should be separated , your comparison will do another thing word!== false || word !== null.......
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:33
does NaN even exist? not really
Ogundele Olumide
@Lumexralph
May 22 2017 08:33
@Nightimer use Number.isNaN(word); to check for NaN
@HeebieGeeBee bro
@HeebieGeeBee :joy: it does
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:34
how can something exist if it doesnt equal itself
Ogundele Olumide
@Lumexralph
May 22 2017 08:34
@HeebieGeeBee do 2 * "g" tell me what it gives you
@HeebieGeeBee it's an arbitrary value I think,
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:35
thats what they want you to think
Ogundele Olumide
@Lumexralph
May 22 2017 08:36
@HeebieGeeBee :joy: who are the they ?.... I think NaN helps you debug
ozimanik
@ozimanik
May 22 2017 08:36
is someone here who got a fcc certificate? just wondering...
and how much time you spend to get it?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:36
they, the ones hoarding all the internets lost packets
Ogundele Olumide
@Lumexralph
May 22 2017 08:36
@HeebieGeeBee having a hard time making my ship shoots a missile from the cannon
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:37
how come? @Lumexralph
Ogundele Olumide
@Lumexralph
May 22 2017 08:37
@HeebieGeeBee :joy: .... that's true, where do the lost packets go?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:37
to them
Ogundele Olumide
@Lumexralph
May 22 2017 08:37
@tomisiin have you changed the switch to an object yet?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:37
they consume them to run the matrix
Mark Sorce
@msorce
May 22 2017 08:38
@Nightimer return word !== false && word !== null && word !== 0 && word !== "" && word !== undefined && word !== NaN;
Rakshit Sinha
@sinharaksh1t
May 22 2017 08:38
@Lumexralph yes
Ogundele Olumide
@Lumexralph
May 22 2017 08:38
@HeebieGeeBee :smile:
Mark Sorce
@msorce
May 22 2017 08:38
@Nightimer try this
function bouncer(arr) {

  var passed = arr.filter(function(word) {
    return !!word;
  });

  return passed;
}
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:39
lol why !!?
why not just word
Ogundele Olumide
@Lumexralph
May 22 2017 08:39
@HeebieGeeBee my ship changes position using the control button....arrows , when that happen s I can't trace it to shoop from the cannon tip, it's something small but still not getting the logic
Mark Sorce
@msorce
May 22 2017 08:40
@HeebieGeeBee it turns is into a boolean value
Chris Juchtmans
@kjuchtmans
May 22 2017 08:40

re "Random Quote Gen"

Question: why is my html reported to be out of scope in $(".message").html(html); ?

  1. my JS syntax seems correct
  2. my JSON syntax seems correct
  3. nothing shows on button click

pen: (https://codepen.io/chrisjuchtmans/pen/EWRKaB)

Thanks!

HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:41
just word by itself works too
@Lumexralph do you not have a variable of the canon tip
Chris Juchtmans
@kjuchtmans
May 22 2017 08:41
my overarching attitude is I'm Getting Closer, just takes time
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:41
based on the ships x and y position
Mark Sorce
@msorce
May 22 2017 08:42
@HeebieGeeBee ah didn't think that would work, some reason just thought it wouldn't filter anything
Long Nguyen
@longnt80
May 22 2017 08:42

@kjuchtmans

Question: why is my html reported to be out of scope in $(".message").html(html); ?

just declare it outside of for loop

Ogundele Olumide
@Lumexralph
May 22 2017 08:43
@HeebieGeeBee it's an image, .... i have the position, the missile shows on it's body not on the cannon tip......means the tip can be at any axis when I move
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:44
tihs is in python right?
Ogundele Olumide
@Lumexralph
May 22 2017 08:44
@HeebieGeeBee yes..... that's why I don't want to bug you too much about it
I wish it was in JS
Chris Juchtmans
@kjuchtmans
May 22 2017 08:45
@longnt80 thank you kind sir ! that leaves me with one tiny problem: nothing is displayed on button click. can you see anything on click?
oudomkiri
@kirioudom
May 22 2017 08:45
@sinharaksh1t thanks you so much !
CamperBot
@camperbot
May 22 2017 08:45
kirioudom sends brownie points to @sinharaksh1t :sparkles: :thumbsup: :sparkles:
:cookie: 286 | @sinharaksh1t |http://www.freecodecamp.com/sinharaksh1t
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:45
is the ship a class?
Ogundele Olumide
@Lumexralph
May 22 2017 08:45
@HeebieGeeBee an instance of a class....yes
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:45
and the cannon ball is part of that class?
Ogundele Olumide
@Lumexralph
May 22 2017 08:46
@HeebieGeeBee another class for sprite
Long Nguyen
@longnt80
May 22 2017 08:47
@kjuchtmans it seems that you need to modify your JSON file
Chris Juchtmans
@kjuchtmans
May 22 2017 08:47
again? I seem to be doing nothing else...
Blauelf
@Blauelf
May 22 2017 08:47
@kjuchtmans Your current code expects an array, not an object. Also, json.quotes makes no sense in that context.
Chris Juchtmans
@kjuchtmans
May 22 2017 08:48
@Blauelf alright, that I get ! so var obj is not right?
Blauelf
@Blauelf
May 22 2017 08:49
@kjuchtmans The content of your JSON file does not seem right.
Or at least it does not fit your function.
ozimanik
@ozimanik
May 22 2017 08:49
@Blauelf kann ich dich was fragen
Long Nguyen
@longnt80
May 22 2017 08:49
you can use it to test if you want
Chris Juchtmans
@kjuchtmans
May 22 2017 08:49
@Blauelf JSON is killing me. supposed to be simple syntax right?
@longnt80 much obliged sir, I will make prudent use of it
Adel
@AdelMahjoub
May 22 2017 08:50
@kjuchtmans better that than xml killing you
Ty Tia
@TyTia77
May 22 2017 08:53
haha JSON is so much better than xml.
Mary
@MaryGr
May 22 2017 08:53
Oh my god, already stuck...nickname...?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:54
@Lumexralph im making my arkanoid game in java now
Ogundele Olumide
@Lumexralph
May 22 2017 08:55
@HeebieGeeBee cool..... you know Java well?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:55
not really
but doesnt seem that hard to learn
after javascript
Ogundele Olumide
@Lumexralph
May 22 2017 08:55
@HeebieGeeBee you've already given me the inspiration to convert my python games to JS
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:56
java has weird things about it
Ogundele Olumide
@Lumexralph
May 22 2017 08:56
@HeebieGeeBee it's cool, would just stick with knowing those 2 well for now....if anything arises picking up another language won't be as hard as learning JS as a beginner
@HeebieGeeBee you don't need to say
they are all weird
Markus Kiili
@Masd925
May 22 2017 08:57
Multi-paradigm @HeebieGeeBee , so fancy :bullettrain_front:
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:57
yeah
@Masd925 hello
Markus Kiili
@Masd925
May 22 2017 08:58
@Lumexralph @HeebieGeeBee Hi.
@HeebieGeeBee What weird things have you found?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:58
first oddest thing was this in java and this in javascript seem to be very different
Blauelf
@Blauelf
May 22 2017 08:59
@kjuchtmans I think CORS issues are harder to fight than JSON.
HeebieGeeBee
@HeebieGeeBee
May 22 2017 08:59
and that you have to declare a string with a capital S
whereas all the other variable types dont need a capital letter
also strings have double quotes and single characters have single quotes
which i guess makes sense
Markus Kiili
@Masd925
May 22 2017 09:00
@HeebieGeeBee That is just because java strings are objects, not primitives.
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:01
oh right i see
Dan Couper
@DanCouper
May 22 2017 09:01
Most languages differentiate between strings and chars with double and single quotes I guess, JS is a bit of an anomaly
Kevin
@mybaseball52
May 22 2017 09:02

The Stand in Line I have 2 question can't solve, my code is


function nextInLine(arr, item) {
  // Your code here
 if(arr.length === 0)
    return item;
 else{
   var x = arr.splice(0, 1);
   arr.push(item);
   return x;
 }
}

And I can return 2 but still wrong, why?

HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:02
yeah its just odd remembering it after just writing javascript so long
Ogundele Olumide
@Lumexralph
May 22 2017 09:03
@HeebieGeeBee welcome to my word.i type JS array methods at times in Python then remember almost immediately
@mybaseball52 you need to do just 2 things, push and shift
@HeebieGeeBee cos python methods have names similar to JS
DutchGester
@DutchGester
May 22 2017 09:04

Hello guys, i dont understand

Use two + operators to build myStr with myName inside it

I have this

// Example
var ourName = "Free Code Camp";
var ourStr = "Hello, our name is " + ourName + ", how are you?";

// Only change code below this line
var myName = "asd";
var myName ++ myStr;

HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:04
yeah i will probably start doing stuff with python eventually too
Blauelf
@Blauelf
May 22 2017 09:04
@mybaseball52 You'd want to return arr.splice(0,1)[0], or simply arr.shift(). And doing them in the right order (push first) saves you from that if.
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:05
i cant imagine learning any of them will be too hard to understand
Kevin
@mybaseball52
May 22 2017 09:05
Thanks ! @Blauelf @ HeebieGeeBee
CamperBot
@camperbot
May 22 2017 09:05
mybaseball52 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4211 | @blauelf |http://www.freecodecamp.com/blauelf
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:05
if you have a grasp of javascript
Kevin
@mybaseball52
May 22 2017 09:05
Thanks @HeebieGeeBee
CamperBot
@camperbot
May 22 2017 09:05
mybaseball52 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1675 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:05
what did i do?
think you mean @Lumexralph
Kevin
@mybaseball52
May 22 2017 09:06
Yes, I wll refactoring the code after pass it =)
Ogundele Olumide
@Lumexralph
May 22 2017 09:06
@DutchGester you're to assign the string to myStr variable using myName and 2 strings to be able to use 2 + operators as the example
@HeebieGeeBee you can keep it on my behalf :wink:
Markus Kiili
@Masd925
May 22 2017 09:07
@HeebieGeeBee When you get your 2k patch, I will remind you of that cookie you got in vain.
Ogundele Olumide
@Lumexralph
May 22 2017 09:07
@Masd925 How're you?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:07
lol yeah iit will be undeserved
Ogundele Olumide
@Lumexralph
May 22 2017 09:08
@HeebieGeeBee are you kidding me, i just solved that missile issue
i told you it was something small
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:09
what was it?
DutchGester
@DutchGester
May 22 2017 09:09
i dont understand it @Lumexralph I am not good with javascript
Ogundele Olumide
@Lumexralph
May 22 2017 09:09
@HeebieGeeBee at times the smallest stuffs can be the hardest to wind down
Dan Couper
@DanCouper
May 22 2017 09:09
@kjuchtmans what are you finding difficult? The entire rules of JSON are wrap the whole thing in a pair of curly brackets, everything in double quotes apart from numbers and true/false, lists of things in square brackets, object-like things ({"key": "value"}) in curly brackets. Looks just like a JS object, except you're a only allowed a tiny, set set of properties. I think that's about it?
Markus Kiili
@Masd925
May 22 2017 09:10
@Lumexralph Got over the sports depression by doing some trauma removal exercises. Goal is now set on the 2020 words championships. And women's national record.
Ogundele Olumide
@Lumexralph
May 22 2017 09:10
@DutchGester var myStr = "My name is " + the variable + " I am from anywhere.";
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:10
are you saying you can beat the womens national record just cause youre a man!
patriarchy
Ogundele Olumide
@Lumexralph
May 22 2017 09:10
@Masd925 way to go Bro :clap:
@HeebieGeeBee i render 2 images on the canvas based o what i'm doing
Markus Kiili
@Masd925
May 22 2017 09:11
@HeebieGeeBee I just can't ever beat the men's record.
@HeebieGeeBee I am now on the same level as the best female chess player in Finland. I wan't another patch. Is that bad?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:14
if you get into the intelligence bell curves between men and women it makes you a mysoganist apperently
Ogundele Olumide
@Lumexralph
May 22 2017 09:14
@HeebieGeeBee if I thrust the ship, it changes to a thrusting image, if not another image of the ship not trusting, the initial image as same X and Y coordinates for the image size all I had to do was add that value to the position of the missile so it won't be drawn on the body of the ship
@Masd925 why do you say you can't beat the record?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:15
@Lumexralph well done for sorting it anyways
Ogundele Olumide
@Lumexralph
May 22 2017 09:16
@HeebieGeeBee would have loved to do it with you or anybody, don't like doing these logic debugging alone..... good minds would have made my journey faster
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:16
I have not idea how to solve 'Stand in Line' mission.
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:17
yeah but its also nice to solve problems too
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:17
Yeah
But just played around and tried to add arr.push([]);
Ogundele Olumide
@Lumexralph
May 22 2017 09:17
@aaswissa you are to add item to the end of arr like a queue, then remove the first element in the array which you have to return
Markus Kiili
@Masd925
May 22 2017 09:18
@Lumexralph I started water sports at 44 so that kind of limits it. Record holder is a water behemoth with 12 litre lungs.
AV11D
@AV11D724
May 22 2017 09:18
Hi guys i need help with my code as it wants me to: Remove all of the backslashes and have two single quotes ' and four double quotes. \
Ogundele Olumide
@Lumexralph
May 22 2017 09:18
@aaswissa you need to push iteminto arr which is an array and use shift to remove the first element
AV11D
@AV11D724
May 22 2017 09:18
also here is my code
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:18
I did it
AV11D
@AV11D724
May 22 2017 09:18
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
Ogundele Olumide
@Lumexralph
May 22 2017 09:19
@Masd925 :smile: still cool you didn't allow that stop you
HeebieGeeBee
@HeebieGeeBee
May 22 2017 09:19
@Masd925 lol need to be careful about talking about watersports on the internet
Ogundele Olumide
@Lumexralph
May 22 2017 09:19
@HeebieGeeBee why?
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:20
Mmm... I think my issue is that I didn't remove items correctly
Let me check it out
Victor Popescu
@VicPopescu
May 22 2017 09:20
@AV11D724 then you need regex
Andrey Muha
@AndersFly666
May 22 2017 09:20
Hi everyone!
Can somebody tell me the correct formula of orbital periods in "Map the Debris" task?
Ogundele Olumide
@Lumexralph
May 22 2017 09:20
@aaswissa okay
@AndersFly666 use Wikipedia or Google it
AV11D
@AV11D724
May 22 2017 09:21
@VicPopescu im sorry i am a complete noob at this... May i ask what "regex" is??
Ogundele Olumide
@Lumexralph
May 22 2017 09:21
@AndersFly666 then you break it down into a JS operation
Sem Gebresilassie
@semosem
May 22 2017 09:22
What am I missing?
Victor Popescu
@VicPopescu
May 22 2017 09:22
@AV11D724 regular expressions will allow you to match certain strings, characters, signs and remove, replace them
Sem Gebresilassie
@semosem
May 22 2017 09:23

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

if(firstName==contacts[i].firstName){


 if( contacts[i].hasOwnProperty(prop)){

     return contacts[i][prop];

    } else {

      return "No such property";

    }

} else {
  return "No such contact";
}

}

Profile Lookup
task
AV11D
@AV11D724
May 22 2017 09:23
@VicPopescu Oh ok thank you....I forgot about that!!!
CamperBot
@camperbot
May 22 2017 09:23
av11d724 sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 426 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
Victor Popescu
@VicPopescu
May 22 2017 09:24
@AV11D724 for example
var reg = /\\"/;     //will match any \" sequence of characters
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:24
@Lumexralph Still stuck
Ogundele Olumide
@Lumexralph
May 22 2017 09:25
@semosem you need to return no such contacts when the loop is done looping through contacts, outside the loop
Victor Popescu
@VicPopescu
May 22 2017 09:25
@AV11D724 use https://regex101.com/ to build your regex and then use .match() or .replace() to transform your strings
Ogundele Olumide
@Lumexralph
May 22 2017 09:25
@aaswissa show your code
AV11D
@AV11D724
May 22 2017 09:25
@VicPopescu Now I see the problem, I am missing the single qoute things at the end of the code lines and the biegging too.
@VicPopescu Thanks for the help!!
CamperBot
@camperbot
May 22 2017 09:26
av11d724 sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:warning: av11d724 already gave vicpopescu points
Victor Popescu
@VicPopescu
May 22 2017 09:26
@AV11D724 well I didn't help at all, but I am glad you figured out, good luck!
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:27

@Lumexralph
function nextInLine(arr, item) {
// Your code here
arr.push(1);

return item; // Change this line
}

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

Victor Popescu
@VicPopescu
May 22 2017 09:27
@AV11D724 I tho you want to transform strings, haha, misunderstood
Abhishek Tiwari
@fillopfy
May 22 2017 09:27
@aaswissa use shift also
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:27

'''
function nextInLine(arr, item) {
// Your code here
arr.push(1);

return item; // Change this line
}

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

CamperBot
@camperbot
May 22 2017 09:27
:bulb: to format code use backticks! ``` more info
Ogundele Olumide
@Lumexralph
May 22 2017 09:27
@aaswissa push item into arr not 1
@aaswissa item holds the value, so don't worry about inputting values to your function
Abhishek Tiwari
@fillopfy
May 22 2017 09:29
@aaswissa first use push(item) and then shift() to remove the first element
AV11D
@AV11D724
May 22 2017 09:29
@VicPopescu lol thats ok I might just be one of the most misunderstood people(due to the way i talk and explain things)...I get it alot lol.....
Victor Popescu
@VicPopescu
May 22 2017 09:29
@aaswissa you need to push the item, then return the last element. check out Array.shift(). shift() is returning the element that it will remove, so figure it out from there
@AV11D724 haha
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:30
I forgot 'shit' at all - I'm learning freeCodeCamp only about 15 mins / day and not everyday :smile:
I go to past lesson and check 'Shift'
Ogundele Olumide
@Lumexralph
May 22 2017 09:33
@aaswissa solved now?
Aviran Avraham Swissa
@aaswissa
May 22 2017 09:35
Not yet ...
I'm going to grab something will be back :)
Sem Gebresilassie
@semosem
May 22 2017 09:36
@Lumexralph not solved, what did I do wrong again?

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

if(firstName==contacts[i].firstName){

 if( contacts[i].hasOwnProperty(prop)){

     return contacts[i][prop];

    } else {    
      return "No such property";  
    }

} else {
  return "No such contact";
}

}

Dariusz Sikorski
@dariuszsikorski
May 22 2017 09:37
can i override value inside function, which is imported from external es6 module?
Sem Gebresilassie
@semosem
May 22 2017 09:37
Someone please help! My head is bleeding inside
Dariusz Sikorski
@dariuszsikorski
May 22 2017 09:37
like myFunction(someArguments...).overWriteInside(isSilent = true) <- that's a lot like pseudocode
Ogundele Olumide
@Lumexralph
May 22 2017 09:38
@semosem return no such contact after the loop, it should not be in the loop cos you have to look through contacts before you say you can't find it
Dan Couper
@DanCouper
May 22 2017 09:44
@dariuszsikorski would need to see more of the code, as maybe but depends on implementation is the answer 🙃
Markus Kiili
@Masd925
May 22 2017 09:50
@semosem Most likely your brain mass has just reached its skull capacity. Start unlearning some stuff. Start with all JS content you learned on W3Schools.
Sophietica
@Sophietica
May 22 2017 09:57
and the lyrics for every crappy pop song from the 90s
Blauelf
@Blauelf
May 22 2017 10:04
Oh no. In my head playing "Aqua - Barbie Girl". Thanks @Sophietica :(
CamperBot
@camperbot
May 22 2017 10:04
blauelf sends brownie points to @sophietica :sparkles: :thumbsup: :sparkles:
:cookie: 316 | @sophietica |http://www.freecodecamp.com/sophietica
Jessica Bensch
@lilithlotus
May 22 2017 10:05
Hey all, I am on the Manipulating Complex Objects task, https://www.freecodecamp.com/challenges/manipulating-complex-objects, and I am really struggling with understanding what to do. Can someone help me please.
Sophietica
@Sophietica
May 22 2017 10:05
@Blauelf my head went with the Macarena...
Blauelf
@Blauelf
May 22 2017 10:06
Great. Now that's playing. Head radio is so mean, and it tends to play infinite loops...
Stephen James
@sjames1958gm
May 22 2017 10:11
@lilithlotus You are supposed to edit the existing array, adding a second album object.
Claudio Restifo
@Marmiz
May 22 2017 10:11

@lilithlotus the challenge is presenting you with an array [] of object {}.
At the beginning of the challenge you start with a single object inside the array:

var myMusic = [
  { /* the first object */ }
]

The challenge is asking you to add a second one inside the same array after the one already declared:

var myMusic = [
  { /* the first object */ }
  { /* the second object */}
]
Pieter Stokkink
@forkerino
May 22 2017 10:12
@Blauelf Pro tip, just play the song all the way til the end on youtube or something. Usually it is done after that.
Blauelf
@Blauelf
May 22 2017 10:12
"Queen - I want to break free" (80s, yeah!) finally got my head to better music. I wonder how common listening to head radio is?
Jessica Bensch
@lilithlotus
May 22 2017 10:12
@Marmiz So I just type it in?
Claudio Restifo
@Marmiz
May 22 2017 10:13
@lilithlotus pretty much
Jessica Bensch
@lilithlotus
May 22 2017 10:13
@Marmiz Holy overthinking on my part!! Thank you. I really thought I was supposed to something WAY more complicated.
CamperBot
@camperbot
May 22 2017 10:13
:cookie: 881 | @marmiz |http://www.freecodecamp.com/marmiz
lilithlotus sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
Claudio Restifo
@Marmiz
May 22 2017 10:14
@lilithlotus I fear the complexity will come later, :)
start getting the idea of how's a (common) data structure is made
Rick Willcox
@willcoxDev
May 22 2017 10:14
Hi I am having trouble with the profile lookup in javascript
Long Nguyen
@longnt80
May 22 2017 10:16
@willcoxDev ```
Rick Willcox
@willcoxDev
May 22 2017 10:17
function lookUpProfile(firstName, prop){
// Only change code below this line
  if(contacts.firstName == firstName && contacts.hasOwnProperty.prop){
    return contacts.prop;
  }
  else if (contacts.firstName != firstName){
    return "No such contact";
  }
  else if (contacts.hasOwnProperty.prop === false){
    return "No such property";
  }
// Only change code above this line
}
Long Nguyen
@longnt80
May 22 2017 10:18
@willcoxDev hasOwnProperty.prop this is wrong
Ken Haduch
@khaduch
May 22 2017 10:18
@willcoxDev - note that contacts is an array. Your first thing is that you need to iterate over the array, and use an index to access contact information one at a time. There are other problems, but that is one of the first.
Rick Willcox
@willcoxDev
May 22 2017 10:18
ok
ill give it another crack
Long Nguyen
@longnt80
May 22 2017 10:19
@willcoxDev syntax: obj.hasOwnProperty(prop)
Sophietica
@Sophietica
May 22 2017 10:19
head radio is the number one cheesy music station
Ken Haduch
@khaduch
May 22 2017 10:19
@willcoxDev - definitely think along the lines of a for loop, and how to access array elements to give yourself a better start.
then @longnt80 is giving good info...
Alexander Domikov
@AlexanderDom
May 22 2017 10:20
i have perhaps a simple question for Backbone + Underscore, event delegation
const navigationView = Backbone.View.extend({
  el: '.js-Nav',
  events: {
    'click .js-Nav-categoryItem > a': 'openCategory',
 },
//some code
  openCategory(e) {
  }
})
my problem is i want to execute openCategory once
i saw that undersore has _.once()
does instead of openCategory(e) i can put openCategory : _.once(function(e){ }) ?
Rick Willcox
@willcoxDev
May 22 2017 10:27
is there a good way to test your code outside the browser?
seems like I need to debug everything in a text editor especially when it gets a bit more complex
Stephen James
@sjames1958gm
May 22 2017 10:28
@willcoxDev If your code doesn't interact with browser APIs you can use nodejs which is a js engine.
Sulaiman
@suli-g
May 22 2017 10:28
Hi so I did the Claim Your Front End Development Certificate thingy last night -- but then thought of a really easy way to do the symm diff thing -- can I still modify my original one?
Ken Haduch
@khaduch
May 22 2017 10:28
@willcoxDev - there are many ways. THere is a site http://pythontutor.com - you can go there and actually watch your code execute step by step using their interface.
@suli-g - you can always go and modify your code.
Alexander Domikov
@AlexanderDom
May 22 2017 10:28
^^ everybody ignored my question :(
Stephen James
@sjames1958gm
May 22 2017 10:29
@AlexanderDom I think that openCategory has to be a function.
Sophietica
@Sophietica
May 22 2017 10:29
@AlexanderDom I'd answer if I could :(
Ken Haduch
@khaduch
May 22 2017 10:29
@AlexanderDom - maybe no one here knows Backbone + Underscore? I don't know anything about it.
@willcoxDev - there are other sites like jsbin.com where you can edit and run your code - you can find a lot of resources. Getting familiar with the devtools in the browser is important.
Alexander Domikov
@AlexanderDom
May 22 2017 10:30
i thaught it was more like js function question, because i never seen before this definition for a method
i mean
object = {
  method() {}
}
Stephen James
@sjames1958gm
May 22 2017 10:31
@AlexanderDom Hmm looking at _once it might work, because _once returns a function
@AlexanderDom
This looks like invalid syntax because it is inside an object?
  openCategory(e) {
  }
Alexander Domikov
@AlexanderDom
May 22 2017 10:33
@sjames1958gm ok and all others @Sophietica and @khaduch thank's, it seems to pass compilation ;) if somebody has ideas about this method definition i gonna stay here :)
CamperBot
@camperbot
May 22 2017 10:33
alexanderdom sends brownie points to @sjames1958gm and @sophietica and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 7415 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 2897 | @khaduch |http://www.freecodecamp.com/khaduch
:cookie: 317 | @sophietica |http://www.freecodecamp.com/sophietica
Alexander Domikov
@AlexanderDom
May 22 2017 10:34
@sjames1958gm it's a const navigationView = Backbone.View.extend({ backbone view extend object, perhaps it's ok for it
Stephen James
@sjames1958gm
May 22 2017 10:35
@AlexanderDom openCategory : _.once(function(e){ })
this assigns the return of _once to the property openCategory.
_once wraps a function and returns a function which matches what backbone expects the value of openCategory to be
Rick Willcox
@willcoxDev
May 22 2017 10:35
ok I got it but is there a better way?
function lookUpProfile(firstName, prop){
// Only change code below this line
  var validName = false;
  var index = 0;
  for (var i=0; i<contacts.length; i++){
    if (contacts[i].firstName == firstName){
      validName = true;
      index = i;
    }
  }
  var validProp = false;
  if (contacts[index].hasOwnProperty(prop)){
      validProp = true;
  }

  if(validProp && validName){
    return contacts[index][prop];
  }
  else if (validName === false){
    return "No such contact";
  }
  else if (validProp === false){
    return "No such property";
  }
// Only change code above this line
}
i feel like this could be done much shorter
Long Nguyen
@longnt80
May 22 2017 10:36
@willcoxDev of course
Stephen James
@sjames1958gm
May 22 2017 10:37
@willcoxDev If you return immediately on finding the firstName (either property or no such property)
then you can simply return no such contact when the ends
Ken Haduch
@khaduch
May 22 2017 10:37
@willcoxDev - you are doing a lot of extra work - you can short-circuit some of the extra stuff by immediately returning when you find something like this:
if ( firstName === contacts[i].firstName) {
    if ( contacts[i].hasOwnProperty(prop) ) {
        return contacts[i][prop];
    } else {
        return "No such property";
    }
}
@willcoxDev - and testing for "No such contact" is as simple as running through the entire list, if you didn't return from within the for loop, then after the loop ends, return "No such contact";
so you either return from within the loop (which ends the function) if you find a match on the firstName, or you get out of the loop and return "No such contact"; - much less code.
(I had a typo in my sample code, which I just fixed...)
Sophietica
@Sophietica
May 22 2017 10:41
I'm on Seek & Destroy. I get the error "type error [object array] is not a function "... I'm just not sure where to look for an error, if you see what I mean. I think it means either arrToDestroy or argsToMatch are the wrong kind of 'thing'?
function destroyer(arr) {
  // Remove all the values
  //var arrToDestroy=arguments[0]; 
  var arrToDestroy = Array.prototype.slice.call(arguments,0,1);
  var argsToMatch = Array.prototype.slice.call(arguments, 1);

  //this bit is still being worked on
var destroyArr = arrToDestroy.filter(argsToMatch);





  return arrToDestroy;
}

destroyer([3, 5, 1, 2, 2], 2, 3, 5);
Alexander Domikov
@AlexanderDom
May 22 2017 10:41
@sjames1958gm and others, actually it's an option defined before ^^
initialize(options) {
    // get univers in view
    this.openCategory   = false;
Stephen James
@sjames1958gm
May 22 2017 10:43
@Sophietica You pass a function to filter, not an array.
Alexander Domikov
@AlexanderDom
May 22 2017 10:43

so actually i can do

initialize(options) {
    // get univers in view
    this.openCategory   = _.once(this.openCategory);

?

Ken Haduch
@khaduch
May 22 2017 10:43
@Sophietica - the .filter() method requires a callback function and that is what should be contained in the parentheses - something like:
arrToDestroy.filter( function( arg ) {
    // code to perform the test on arg
    // return something
)};
Stephen James
@sjames1958gm
May 22 2017 10:44
@Sophietica FYI arr is Array.prototype.slice.call(arguments,0,1); so you don't need to create another variable
Sophietica
@Sophietica
May 22 2017 10:44
ok so if argsToMatch was a function it would work, but not like this?
Stephen James
@sjames1958gm
May 22 2017 10:44
@Sophietica It wouldn't get that error, yes.
Ken Haduch
@khaduch
May 22 2017 10:45
@Sophietica - also, you do not need to go through the step to create argsToDestroy because you can just use arr there, since it is the first argument and it is supplied as a named parameter. (I see that @sjames1958gm also said that.)
Sophietica
@Sophietica
May 22 2017 10:45
not entirely the same thing as working @sjames1958gm hahaha
Stephen James
@sjames1958gm
May 22 2017 10:45
@Sophietica :)
Sophietica
@Sophietica
May 22 2017 10:46
thank you @khaduch and @sjames1958gm I've got something to go on now! back to the drawing board
CamperBot
@camperbot
May 22 2017 10:46
sophietica sends brownie points to @khaduch and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2898 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 7416 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ken Haduch
@khaduch
May 22 2017 10:47
@Sophietica - you're welcome. It's good to visit the MDN .filter method docs and see some examples and read the details. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
Sophietica
@Sophietica
May 22 2017 10:48
@khaduch yeah I spotted a line saying 'var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);' and I just kinda ignored the fact that their isBigEnough was a function blush
there was a camelcase word and I just went with it
Ken Haduch
@khaduch
May 22 2017 10:49
@Sophietica - hey, it takes time to pick up on the subtleties - you'll learn more as you go along, and the error messages are at times not too easy to decipher. You'll get there! :)
Rick Willcox
@willcoxDev
May 22 2017 10:50
how do yyou sned brownie points?
Ken Haduch
@khaduch
May 22 2017 10:51
@willcoxDev - you just type the users name @userName and say thanks (it accepts various forms of the word thanks, but not all... ) THen the camperbot has to see it, sometimes that is malfunctioning... :)
@willcoxDev - https://forum.freecodecamp.com/t/free-code-camp-brownie-points/18380 - the official explanation... :)
Rick Willcox
@willcoxDev
May 22 2017 10:52
@khaduch @sjames1958gm thanks
CamperBot
@camperbot
May 22 2017 10:52
willcoxdev sends brownie points to @khaduch and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2899 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 7417 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Rick Willcox
@willcoxDev
May 22 2017 10:55
for those that have actaully finished a certificate.
is it just once you complete all tasks with a * and you press the button you get it or is there some process you go trhough
Sophietica
@Sophietica
May 22 2017 10:57
I just got what you guys meant with the arr thing. I really need to check the top line of the pre-supplied code sometimes
Ken Haduch
@khaduch
May 22 2017 10:59
@Sophietica - the thing is that you can make it work both ways - but why put yourself through the extra work? It's just another little thing to pick up on. There are lots of knobs to twist and buttons to push!
Sophietica
@Sophietica
May 22 2017 10:59
Best to get into good habits asap
khaduch @khaduch - taking a break... have a great day, everyone - happy coding! :)
Ken Haduch
@khaduch
May 22 2017 11:00
@Sophietica :+1:
Sophietica
@Sophietica
May 22 2017 11:00
ty again @khaduch
CamperBot
@camperbot
May 22 2017 11:00
sophietica sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: sophietica already gave khaduch points
Aung Myat Moe
@aungmyatmoe
May 22 2017 11:09
Hello
DexRow
@DexRow
May 22 2017 11:10
myBike.gear should remain undefined.
What need to do?
Pieter Stokkink
@forkerino
May 22 2017 11:10
@DexRow don't use this before it in the constructor
Markus Kiili
@Masd925
May 22 2017 11:13
@ DexRow Inside the constructor this.propName=... creates a new property on the new object being created, and var myVar=... creates a new "private" variable accessible only by the methods of the new object.
DexRow
@DexRow
May 22 2017 11:18
var Bike = function() {

  var gear;

  // Only change code below this line.
  this.getGear = function() {
    return this.gear;
  };

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

};
Markus Kiili
@Masd925
May 22 2017 11:22
@DexRow You should return the private variable, not a property value from the object.
Also setGear should assign to gear, not to this.gear.
Pieter Stokkink
@forkerino
May 22 2017 11:23
@DexRow It would probably be wise to name your gear parameter to something else, so there is no confusion.
Markus Kiili
@Masd925
May 22 2017 11:23
Here we wan't to store the gear info so that it is not accessible from outside using the object (accessible only using the methods).
DexRow
@DexRow
May 22 2017 11:24
I do not understand :D
Pieter Stokkink
@forkerino
May 22 2017 11:26
@DexRow this.gear doesn't exist. Don't use it
just use gear
DexRow
@DexRow
May 22 2017 11:27
@forkerino But then it will not work
Pieter Stokkink
@forkerino
May 22 2017 11:28
@DexRow well.... If you do it correctly it will. It is a step in the right direction.
DexRow
@DexRow
May 22 2017 11:29
@forkerino
var Bike = function() {

  var gear;

  // Only change code below this line.
  this.getGear = function() {
    return gear;
  };

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

};
So?
Stephen James
@sjames1958gm
May 22 2017 11:29
Change the name of the parameter to setGear as suggested above
Pieter Stokkink
@forkerino
May 22 2017 11:30
If you change the name of your setGear parameter, it will probably work.
DexRow
@DexRow
May 22 2017 11:30
it will not work
this.setGear = function(setGear) {
    setGear = gear;
  };
Stephen James
@sjames1958gm
May 22 2017 11:31
  this.setGear = function(newGear) {
    gear = newGear;
  };
Pieter Stokkink
@forkerino
May 22 2017 11:32
@DexRow you have to overwrite the right variable
assignment is right to left
Karol Rostkowski
@Rostkowski
May 22 2017 11:33
Hello i need help with my code. Any1 knows why in this function only else statement executes? function dupaTrupa() {
var timerRuletki = document.querySelector(".latest div:nth-child(2)");
var kakaPipi = 1;
if (timerRuletki === '<div class="last color-2"></div>') {
console.log("WIN")
var kakaPipi = 1;
document.getElementById("minesBet").value = kakaPipi;
document.querySelector('.btn-play').click();
}
else {
console.log("Lost +1")
document.getElementById("minesBet").value = kakaPipi++;
document.querySelector('.btn-play').click();
}
}
test
function dupaTrupa() { var timerRuletki = document.querySelector(".latest div:nth-child(2)"); var kakaPipi = 1; if (timerRuletki === '<div class="last color-2"></div>') { console.log("WIN") var kakaPipi = 1; document.getElementById("minesBet").value = kakaPipi; document.querySelector('.btn-play').click(); } else { console.log("Lost +1") document.getElementById("minesBet").value = kakaPipi++; document.querySelector('.btn-play').click(); } }
Pieter Stokkink
@forkerino
May 22 2017 11:35
@Rostkowski it seems to me that your selector (.latest) will make sure that your first if is never executed, because it doesn't have a class 'latest' in it.
oh wait
strike that
@Rostkowski I think because you compare a DOM Node to a string. Don't think that works.
Karol Rostkowski
@Rostkowski
May 22 2017 11:36
any alternative?
billjen23
@billjen23
May 22 2017 11:41

I am on Accessing Objects Properties with Variables and my code is giving the right answer but still says i am wrong ( // Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};

// Only change code below this line;

var playerNumber = testObj [16]; // Change this Line
var player = [playerNumber]; // Change this Line )

Pieter Stokkink
@forkerino
May 22 2017 11:41
@Rostkowski you can look at classList and see if it includes the class you are looking for.
Stephen James
@sjames1958gm
May 22 2017 11:41
@Rostkowski .classList.contains("last color-2") use the classlist property on the element?
Pieter Stokkink
@forkerino
May 22 2017 11:42
@billjen23 playerNumber should just be a number. Access testObj on the next line.
Stephen James
@sjames1958gm
May 22 2017 11:42
@billjen23 You are supposed to set player number to a number - then use that variable on the next line with the object
@Muturi254
@muturi254
May 22 2017 11:42

help*
var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count +=1;
break;
case 7:
case 8:
case 9:
count = 0;
break;
case 10:
case "J":
case "Q":
case "K":
case "Z":
count -=1;
break;
}
if(count > 0){
return count + " Bet";
}else if(count < 0){
return count + " Hold";
}
return count;
// 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');



var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count +=1;
break;
case 7:
case 8:
case 9:
count = 0;
break;
case 10:
case "J":
case "Q":
case "K":
case "Z":
count -=1;
break;
}
if(count > 0){
return count + " Bet";
}else if(count < 0){
return count + " Hold";
}
return count;
// 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');


billjen23
@billjen23
May 22 2017 11:45
@forkerino @sjames1958gm thank you both very helpful
CamperBot
@camperbot
May 22 2017 11:45
billjen23 sends brownie points to @forkerino and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2335 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 7418 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Pieter Stokkink
@forkerino
May 22 2017 11:46
@muturi254 don't reset count to 0 for cases 7-9
also you have to return something for when count is 0
not just the number, but also " Hold"
Blauelf
@Blauelf
May 22 2017 11:47
@muturi254 Do not count = 0; on 7,8,9. Do nothing in that case. Also, what if count is 0? I think a simple if-else would work better than if-elseif
@Muturi254
@muturi254
May 22 2017 11:47
@forkerino any suggestions
Pieter Stokkink
@forkerino
May 22 2017 11:47
@muturi254 I just gave you two
Alexander Domikov
@AlexanderDom
May 22 2017 11:55
i'm back, i gonna try again my question with methods :)
so its an existing file, i extend a view in backbone, and i have an event listener on a click event, i need to it to be called only once, there are _.once() in underscore, so my question is it good way to add it
// openCategory was defined before with this.openCategory = false;
const navigationView = Backbone.View.extend({
  el: '.js-Nav',
  events: {
    'click .js-Nav-categoryItem > a': 'openCategory'
  },
  openCategory(e) {}
})
Alexander Domikov
@AlexanderDom
May 22 2017 12:02
so like i said openCategory is defined in other page that script extends
initialize(options) {
    // get univers in view
    this.openCategory   = false;
is this.openCategory = _.once(this.openCategory); is correct ?
@Blauelf , @forkerino ? =]
Vismay Patil
@vismay02
May 22 2017 12:04

Can anyone help me with the queue tutorial ?
```

function nextInLine(arr, item) {
// Your code here
testArr.push(10);
testArr.shift();
return item; // Change this line
}

// Test Setup
var testArr = [5,6,7,8,9];

// Display Code

console.log("Before: " + JSON.stringify(testArr));
console.log("Element removed is:" + nextInLine(testArr, 5)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

```

Pieter Stokkink
@forkerino
May 22 2017 12:06
@vismay02 you have 2 function parameters, use those instead of testArr and any numbers.
Vismay Patil
@vismay02
May 22 2017 12:13
``` function nextInLine(arr, item) {

// Your code here
arr.push(10);
arr.shift();
return item; // Change this line
}

// Test Setup
var arr = [5,6,7,8,9];

// Display Code

console.log("Before: " + JSON.stringify(arr));
console.log("Element removed is:" + nextInLine(arr, 5)); // Modify this line to test
console.log("After: " + JSON.stringify(arr));
```
Still confused @forkerino

Pieter Stokkink
@forkerino
May 22 2017 12:13
@vismay02 you are still hardcoding a number in there. Use item instead, it will be the thing you have to put at the end. Also return the number you removed with .shift(), because now you just return the item you were supposed to add.
Markus Kiili
@Masd925
May 22 2017 12:15
@vismay02 The function parameters arr and item hold the function input (array and number). So you need to use arr and item and nothing else as input values.
That way the function works with whatever passed values.
Aamir
@aamirrokz
May 22 2017 12:20
````
Timmaaaa
@Timmaaaa
May 22 2017 12:20
Hello happy coder people
ayy
Aamir
@aamirrokz
May 22 2017 12:20
`
Jopee
@jopeemahmen
May 22 2017 12:21
@vismay02 I'm in the same stage as you and could not get out. Would you like to buddy up to solve this? It's been a day now and I have not yet solved this problem.
shedlerman
@shedlerman
May 22 2017 12:22
Hi can someone help me with FirstLine
\SecondLine\
ThirdLine
samirNox
@samirNox
May 22 2017 12:22
can someone help :) http://prntscr.com/fapyat
Aamir
@aamirrokz
May 22 2017 12:22
@jopeemahmen same here....
shedlerman
@shedlerman
May 22 2017 12:22
how to code it in variable?
Jopee
@jopeemahmen
May 22 2017 12:24

@vismay02 @Masd925 @aamirrokz This is my code below. Would honestly like to get some help with this but not a direct answer.

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

return arr[1]; // Change this line
}

var arr=[[arr.push(1),arr.shift()],[arr.push(2),arr.shift()],[arr.push(5),arr.shift()]];
var item=1;

// 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));

I know I'm not yet defining any arguments,
Aamir
@aamirrokz
May 22 2017 12:25
@shedlerman this should help u "FirstLine\n\SecondLine\\rThirdLine";
Chris Juchtmans
@kjuchtmans
May 22 2017 12:25

n-th attempt at getting JSON right, get AJAX call to append to html..

Question 1 : is this JSON file correctly formatted ? (https://codepen.io/chrisjuchtmans/pen/OmoaRY)
Question 2 : is this JS iteration / indexing correct ? (https://codepen.io/chrisjuchtmans/pen/EWRKaB)

cheers!

Vismay Patil
@vismay02
May 22 2017 12:26
`console.log(nextInLine(testArr, 6));`
What does this line do @forkerino @Masd925 @jopeemahmen
Markus Kiili
@Masd925
May 22 2017 12:27
@vismay02 It tests the function you wrote.
And logs the return value.
Dan Couper
@DanCouper
May 22 2017 12:28
@jopeemahmen Inside the function, you have an array (arr) and a value (item). You want to push the item onto the arr, then shift the first element off the arr, and return that element you've just shifted off. These are two operations, so you do one on one line, then the next on the next line.
Blauelf
@Blauelf
May 22 2017 12:29
@kjuchtmans The first one is probably not valid JSON. Try removing outer {} and leave only the array with the objects within.
Timmaaaa
@Timmaaaa
May 22 2017 12:29
Hey I got stuck at this [Palindrome Algorithm ](https://www.freecodecamp.com/challenges/check-for-palindromes) Can someone help please? <3
function palindrome(str) {
    // Good luck!
    var Array = [];
    var strr = str;
    //removes all non-alphanumeric characters  
    Array = strr.replace(/(\W)|([_])/gi, "");
    Array = Array.toLowerCase();

    for (var i = 0; i < A.length ; i++){
        if (Array[i] == Array[Array.length -1 -i]){
            return true;

        } else {
            return false;
        }
    }
} 
palindrome("almostomla");  //
Dan Couper
@DanCouper
May 22 2017 12:30
@kjuchtmans 1. https://jsonlint.com/ (tl/dr is yes)
Chris Juchtmans
@kjuchtmans
May 22 2017 12:30
@Blauelf so a JSON array doesnt have to be wrapped in curly braces?
Jopee
@jopeemahmen
May 22 2017 12:30
@DanCouper I did that actually earlier, but the return value varies based on what the stan-in-line hints says.
@DanCouper Lemme do what you told me, and I'll get back to you
Diego Mayer
@Chrono79
May 22 2017 12:31
@Timmaaaa you only compare the first and last letter like that, returning in both if and else inside the for loop
And what is A.length?
Chris Juchtmans
@kjuchtmans
May 22 2017 12:32
@DanCouper neat tool thanks!
CamperBot
@camperbot
May 22 2017 12:32
kjuchtmans sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 729 | @dancouper |http://www.freecodecamp.com/dancouper
Pieter Stokkink
@forkerino
May 22 2017 12:32
@Timmaaaa and you are overwriting the global Array object!!
Blauelf
@Blauelf
May 22 2017 12:32
@kjuchtmans Many services provide an object, with one of its properties providing the array you actually are interested in. The benefit of this design is that you can easily add more fields.
Jopee
@jopeemahmen
May 22 2017 12:32
@DanCouper so in this case, item is called as 1?
Markus Kiili
@Masd925
May 22 2017 12:32
@Timmaaaa You can explode the intsernetz!
Timmaaaa
@Timmaaaa
May 22 2017 12:33
oh really? :/ then how do I continiue the true down
I did :c
Chris Juchtmans
@kjuchtmans
May 22 2017 12:33
okay I understand.
Diego Mayer
@Chrono79
May 22 2017 12:33
@forkerino I don't think so, maybe he's creating a local var that obscure the global object?
Chris Juchtmans
@kjuchtmans
May 22 2017 12:33
@Blauelf then whats wrong with my iteration / append? I still get nothing on click
Blauelf
@Blauelf
May 22 2017 12:34
@forkerino That one's function scope, it will only shadow global Array
Dan Couper
@DanCouper
May 22 2017 12:34
@kjuchtmans 2. Yes, but. Each of those quotes is an object, so if you just try to render the whole object (which is what you're doing with html += myQuote it won't quite work, you want myQuote.
Pieter Stokkink
@forkerino
May 22 2017 12:34
@Chrono79 @Blauelf ah, yes, you're right, I missed the first declaration
Blauelf
@Blauelf
May 22 2017 12:35
@kjuchtmans ReferenceError: obj is not defined
Timmaaaa
@Timmaaaa
May 22 2017 12:35
@Chrono79 it was a misspelling
Chris Juchtmans
@kjuchtmans
May 22 2017 12:35
@DanCouper okay, I need to index further then?
SusieTech
@SusieTech
May 22 2017 12:35
Hi guys, I am currently trying to create an About Me page for my blog and I am having difficulty understanding how bootstrap works in terms of creating text boxes and other elements like linking the blog to social media. My team members aren't really helping me
Timmaaaa
@Timmaaaa
May 22 2017 12:35
Diego Mayer
@Chrono79
May 22 2017 12:36
@Timmaaaa ok, fix that, and think which one (between true and false) you should return inside the loop and which one outside
Chris Juchtmans
@kjuchtmans
May 22 2017 12:36
@Blauelf the bizarre thing is: i get no JS errors, not in Chrome console, not in codepen JS check
Dan Couper
@DanCouper
May 22 2017 12:36
Sorry, myQuote.theQuoteProp, myQuote.theCitationProp etc
getJson takes someone and parses it into a JS object, so it just acts like a normal object at that point, you access the properties as normal
Blauelf
@Blauelf
May 22 2017 12:37
@kjuchtmans The console.log(obj.id) is causing the error. Maybe you fixed it already in your copy.
Chris Juchtmans
@kjuchtmans
May 22 2017 12:37
@Blauelf right! obj is undefined, lets kill that
Dan Couper
@DanCouper
May 22 2017 12:38
Also that rogue console log needs to be killed. Also not sure what happens if you try to load a JS file using getJSON? I assume nothing bad but might not help
Ah snap
Blauelf
@Blauelf
May 22 2017 12:38
@kjuchtmans You might want to write something like html += myQuote.quote + " -- " + myQuote.author; instead of html += myQuote;
Dan Couper
@DanCouper
May 22 2017 12:39
I think you can now have projects on Codependent where you can have multiple files, haven't investigated but that would let you have a JSON file alongside the JS
Blauelf
@Blauelf
May 22 2017 12:39
@DanCouper Luckily, nowadays JSON parsing is no longer done using eval :)
Dan Couper
@DanCouper
May 22 2017 12:39
Ah brill, was worried it would just silently ignore it
Aaagh CodePen, not Codependent!
Blauelf
@Blauelf
May 22 2017 12:40
@DanCouper You mean CodePen Projects? Isn't that a pro feature?
Dan Couper
@DanCouper
May 22 2017 12:41
Not sure, might be, they must be hammering it cos it's the first thing that appears when I go to codepen now, not sure if I'm subject to a/b testing and they're trying to get me to buy stuff, I've just been ignoring it
HeebieGeeBee
@HeebieGeeBee
May 22 2017 12:42
think they changed it to a free feature a few weeks back
Chris Juchtmans
@kjuchtmans
May 22 2017 12:42
@Blauelf owkay, now on click it shows... nothing :
$(document).ready(function() {
    $("#getQuote").on("click", function() {
          $.getJSON("https://codepen.io/chrisjuchtmans/pen/OmoaRY.js", function(json) {

            var html = "";
            for (var i = 0; i < json.length; i ++) {       
                var myQuote = json[i];
            //console.log(json.id);

                html += '<div class = "newQuote">';
                html += myQuote.quote + '--' + myQuote.author;
                html += "</div>";
                 }
                 $(".message").html(html);

                      });       
          });

    });
Vismay Patil
@vismay02
May 22 2017 12:42
`function nextInLine(arr, item) {

// Your code here
arr.push(item);

return arr.shift(); // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(arr));
console.log(nextInLine(arr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(arr));`
@jopeemahmen bingo !

Thanks for guiding @forkerino @Masd925 !
CamperBot
@camperbot
May 22 2017 12:44
vismay02 sends brownie points to @forkerino and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2336 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 4110 | @masd925 |http://www.freecodecamp.com/masd925
Blauelf
@Blauelf
May 22 2017 12:45
@kjuchtmans This very code for me outputs
THIS IS QUOTE 1--SPOKEN BY AUTHOR ONE
THIS IS QUOTE 2--SPOKEN BY AUTHOR TWO
THIS IS QUOTE 3--SPOKEN BY AUTHOR THREE
THIS IS QUOTE 4--SPOKEN BY AUTHOR FOUR
THIS IS QUOTE 5--SPOKEN BY AUTHOR FIVE
JohnGalt
@osirisseye
May 22 2017 12:47
when doing the Truncate a string task I have to slice the str according to argument given (num) and append it with 3 dots - but should I replace last 3 charactes of truncated string to fit in the num limit? or should I just add '...' at the end?
http://bit.ly/2rI9Mdh
Jopee
@jopeemahmen
May 22 2017 12:47
@vismay02 wait, I thought you could change the code inside between these?:
// Your code here
// Change this line
shedlerman
@shedlerman
May 22 2017 12:48
var myStr = "FirstLine\n\SecondLine\rThirdLine";// Change this line
Adarsh_petr
@Adarsh1303
May 22 2017 12:48
@klbm9999 Hi Bhanu..can you read?
shedlerman
@shedlerman
May 22 2017 12:48
not working
Pieter Stokkink
@forkerino
May 22 2017 12:48
@osirisseye depends on the value of num
Blauelf
@Blauelf
May 22 2017 12:48
@osirisseye If you need to truncate, and num>3, then the triple dots do count towards num. If you need to truncate and num<=3, they are extra.
Moisés Man
@moigithub
May 22 2017 12:48

> var myStr = "FirstLine\n\SecondLine\\rThirdLine";// Change this line

ur backslashes around SecndLine are NOT escaped @shedlerman

JohnGalt
@osirisseye
May 22 2017 12:49
@forkerino @Blauelf thank you
CamperBot
@camperbot
May 22 2017 12:49
osirisseye sends brownie points to @forkerino and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2337 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 4212 | @blauelf |http://www.freecodecamp.com/blauelf
K L Bhanu
@klbm9999
May 22 2017 12:52
@Adarsh1303 yea, ssup
Adarsh_petr
@Adarsh1303
May 22 2017 12:53
@klbm9999 thanks
CamperBot
@camperbot
May 22 2017 12:53
adarsh1303 sends brownie points to @klbm9999 :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @klbm9999 |http://www.freecodecamp.com/klbm9999
Vismay Patil
@vismay02
May 22 2017 12:54
@jopeemahmen its about completing the challenge
I modified the code according to the given challenge.
Pre defined array made it easier.
I hope you understood the code ?
Reading the challenge with full concentration is the key!
Marco Galizzi
@Tezenn
May 22 2017 12:54

guys if i have a function like this

function test (){
// blabla
}

and i put test(5)(8)
how can i access to the 8? what is his name?

Jopee
@jopeemahmen
May 22 2017 12:55
@vismay02 yeah, I guess that will make it easier. But still trying to get around it haha
Vismay Patil
@vismay02
May 22 2017 12:56
@jopeemahmen yes, It's alright keep finding new solutions. :smile:
Moisés Man
@moigithub
May 22 2017 12:56
@Tezenn google about currying
ChrstnDmbchr
@ChrstnDmbchr
May 22 2017 12:56
Hey all, got an issue on the Return Early Pattern for Functions section of the front end dev section... Here is my solution, maybe im looking at this wrong but it's not working:
function abTest(a, b) {
  // Only change code below this line

  if (a || b < 0){
    return undefined;
  }

  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,2);
the function returns fine if a or b is less than 0 but the functions fails if either a or b is over 0
Moisés Man
@moigithub
May 22 2017 12:56
@ChrstnDmbchr u need to put logical expression on both sides of OR operator
ur actual condition saying... if a is truthy OR b <0
Jopee
@jopeemahmen
May 22 2017 12:56
@vismay02 thanks! will solve this once and for all
CamperBot
@camperbot
May 22 2017 12:56
jopeemahmen sends brownie points to @vismay02 :sparkles: :thumbsup: :sparkles:
:cookie: 175 | @vismay02 |http://www.freecodecamp.com/vismay02
ChrstnDmbchr
@ChrstnDmbchr
May 22 2017 12:56

whoops!!!
Pieter Stokkink
@forkerino
May 22 2017 12:57
@Tezenn it would only make sense if in some cases your function returns a function.
Marco Galizzi
@Tezenn
May 22 2017 12:58
@forkerino yes that is the case, how i access to that second value?
ChrstnDmbchr
@ChrstnDmbchr
May 22 2017 12:58
That worked @moigithub , thanks for the quick response. i've spent too long in front of the computer! Making silly mistakes.
CamperBot
@camperbot
May 22 2017 12:58
chrstndmbchr sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3245 | @moigithub |http://www.freecodecamp.com/moigithub
Pieter Stokkink
@forkerino
May 22 2017 13:01
@Tezenn you can access it only inside the function you return from the function. So:
function addTo(a) {
  return function(b) {
     return a+b;
  }
}
addTo(2)(3) -> 5
addTo(1) -> function(b) { return 1 + b; }
Marco Galizzi
@Tezenn
May 22 2017 13:01
@moigithub very interesting
@forkerino thanks :+1: that's it
CamperBot
@camperbot
May 22 2017 13:02
tezenn sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2338 | @forkerino |http://www.freecodecamp.com/forkerino
Ben
@bhmann
May 22 2017 13:03

Need some help: working on Factorialize a Number algorithm challenge. Have the code working for everything except when num=0 (which should return value of 1). I know I could add an if/else statement to cover this, but there has to be a more elegant solution... what am I missing?

function factorialize(num) {
var i=num;
var array=[];
while (i>0){
array.push(num--);
i--;
}
num = array.reduce(function(a,b) {
return a*b;
});
return array;
}

factorialize(5);

Carson Michael
@Carson2003
May 22 2017 13:05
do you have to use a for loop in the find the longest word in a string challenge
4sipita
@4sipita
May 22 2017 13:05
sup guys, i got stuck

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

switch (answer) {
case "a":
answer = "apple";
break;
case "b":
answer = "bird";
break;
case "c":
answer = "cat";
break;

  default:
  answer = "stuff";
  break;

}

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

// Change this value to test
switchOfStuff("a");

appsk
@appsk
May 22 2017 13:07
@Carson2003 that's right
Jopee
@jopeemahmen
May 22 2017 13:07
``` 

function nextInLine(arr, item) {
// Your code here
arr.push(testArr[0]);

return arr.shift((arr.push(testArr[0]))); // 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));

shedlerman
@shedlerman
May 22 2017 13:07
how i can change var myStr = "FirstLine\n\SecondLine\rThirdLine";// Change this line
to pass test
Jopee
@jopeemahmen
May 22 2017 13:08
``` (shift+enter for line break)

function nextInLine(arr, item) {
// Your code here
arr.push(testArr[0]);

return arr.shift((arr.push(testArr[0]))); // 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));

```

Michele Cattellani
@michelecik
May 22 2017 13:08
@4sipita switch(val) {
Matt Desrosiers
@Mattd1234
May 22 2017 13:09
Anyone willing to help me out? I know that this will seem elementary to some but I need assistance with converting Celsius to Fahrenheit. I have the input values already in the terminal, but I am struggling with the var for the conversion.
Anindita
@Ananditadas
May 22 2017 13:09
@4sipita the switch condition will be on val and not answer. switch(val)
@Mattd1234 please explain your problem further..here to help
Matt Desrosiers
@Mattd1234
May 22 2017 13:10

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
var fahrenheit= 9/5 + 32;

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

// Change the inputs below to test your code
convertToF(30);
convertToF(0);
convertToF(-30);
convertToF(-10);
convertToF(20);
convertToF(30);

I am lost with the var, do I add the var Fahrenheit with the algorithm defined as such?
appsk
@appsk
May 22 2017 13:11
@Mattd1234 you need to use algorithm operators like *, + etc and also use paranthesis
Anindita
@Ananditadas
May 22 2017 13:11
(9/5)*celsius + 32...thats where the problem is
Carson Michael
@Carson2003
May 22 2017 13:12
I need help on how to do the longest word in a string challenge
Anindita
@Ananditadas
May 22 2017 13:12
@Mattd1234 make its (9/5)*celsius
Matt Desrosiers
@Mattd1234
May 22 2017 13:12
Geez..... It makes sense now :) Thank you all for the help!
Carson Michael
@Carson2003
May 22 2017 13:12

function findLongestWord(str) {
var myArray = [];
var wordLength;

myArray = str.split(' ');

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

}

return str.length;
}

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

here is my code
CraZy biRd
@Preeetrockz
May 22 2017 13:13
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
 if (myObj.hasOwnProperty("checkProp")=== true);
{return myObj[checkProp];}
  else, {
return "Not Found" ; }
}
// Test your code by modifying these values
checkObj("house");
what's the problem in this code ?? :/
Markus Kiili
@Masd925
May 22 2017 13:13
@Preeetrockz Should you be using checkProp or "checkProp" on the hasOwnProperty line?
Remove the semicolon ); after the if condition. It makes an empty if block.
Also remove the comma after else.
shedlerman
@shedlerman
May 22 2017 13:15
var myStr = "FirstLine\n\SecondLine\rThirdLine";// Change this line how to escape \?
CraZy biRd
@Preeetrockz
May 22 2017 13:15
@Masd925 I'm using checkprop
Anindita
@Ananditadas
May 22 2017 13:15
@Preeetrockz you don't have to use === in the if statement...the condition itself returns true or false...also after else remove the comma(,)
CraZy biRd
@Preeetrockz
May 22 2017 13:15
??
appsk
@appsk
May 22 2017 13:15
@Carson2003 You need another variable assigned a 0 value and then in the forloop, next you need to check if each myArray.length is greater than the new variable.
Markus Kiili
@Masd925
May 22 2017 13:16
@Preeetrockz You are not using the parameter checkProp on line if (myObj.hasOwnProperty("checkProp")=== true). You are using a string "checkProp".
appsk
@appsk
May 22 2017 13:16
@shedlerman var myStr="FirstLine\n\SecondLine\\rThirdLine";
Roxroy
@roxroy
May 22 2017 13:17
@Ananditadas , a couple things. You only need to declare a variable once, so remove var from the second fahrenheit. You need to include celsius in the line fahrenheit= 9/5 + 32;
Diego Mayer
@Chrono79
May 22 2017 13:17
@shedlerman see the table, using another backslash
appsk
@appsk
May 22 2017 13:18
hi @Chrono79
CraZy biRd
@Preeetrockz
May 22 2017 13:18
@Ananditadas Indian :heart_eyes:
Diego Mayer
@Chrono79
May 22 2017 13:18
:wave:
Anindita
@Ananditadas
May 22 2017 13:18
@Preeetrockz yep :)
CraZy biRd
@Preeetrockz
May 22 2017 13:19
@Ananditadas @Masd925 m tring but still not understand :(
Teo
@Teo03
May 22 2017 13:19
Can someone help I can't figure it out?
function mutation(arr) {
  arr[0].toLowerCase();
  arr[2].toLowerCase();
  if(arr[0].indexOf(arr[1]) < 0){
    return true;
  } else {
    return false;
  }
  }

mutation(["hello", "hey"]);
CraZy biRd
@Preeetrockz
May 22 2017 13:19
@Ananditadas hello mam I ' Preet from Punjab :)
@Ananditadas indian ko Js me ekh ke achha laga :+1:
Diego Mayer
@Chrono79
May 22 2017 13:20
@Teo03 you're testing if the whole second word is containes in the first one, and toLowerCase doesn't mutate the string
CraZy biRd
@Preeetrockz
May 22 2017 13:20
@Chrono79 hello :)
Anindita
@Ananditadas
May 22 2017 13:20

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

}

Diego Mayer
@Chrono79
May 22 2017 13:20
Hi
Teo
@Teo03
May 22 2017 13:20
@Chrono79 How can I test each letter?
Diego Mayer
@Chrono79
May 22 2017 13:20
@Teo03 using a loop
Note that arr[2] isn't defined either
Teo
@Teo03
May 22 2017 13:21
@Chrono79 Thanks that makes sense
CamperBot
@camperbot
May 22 2017 13:21
teo03 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4067 | @chrono79 |http://www.freecodecamp.com/chrono79
CraZy biRd
@Preeetrockz
May 22 2017 13:21
@Ananditadas ok thanks :)
CamperBot
@camperbot
May 22 2017 13:21
:cookie: 214 | @ananditadas |http://www.freecodecamp.com/ananditadas
preeetrockz sends brownie points to @ananditadas :sparkles: :thumbsup: :sparkles:
Roxroy
@roxroy
May 22 2017 13:22
@Carson2003 , here is what you need to do. Create a var to store the longest word, (longestWord) and set it to 0. In the loop, get the length of each word and compare it with the longestWord and if it is greater store the length in the longestWord. At the end return the longestWord
Anindita
@Ananditadas
May 22 2017 13:23

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for(var i = 0; i < multiplyAll.length; i++){

for(var j = 0; j < multiplyAll[i].length; j++){

  product *= multiplyAll[i][j];
}

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

can anybody help me with this?

Diego Mayer
@Chrono79
May 22 2017 13:23
@Ananditadas multiplyAll is your function's name, not the array name
Moisés Man
@moigithub
May 22 2017 13:23
multiplyAll is ur funciton name.. u should use the array (which holds the numbers u need to do math with) @Ananditadas
Stephen James
@sjames1958gm
May 22 2017 13:23
@Ananditadas multiplyAll this is the function name
You should be using the array which is arr
@Ananditadas function multiplyAll(arr) here multiplyAll is the name of the function
The values in the () are values passed to the function which it can use.
Anindita
@Ananditadas
May 22 2017 13:25
@Chrono79 @moigithub @sjames1958gm thanks people...I missed that out
CamperBot
@camperbot
May 22 2017 13:25
ananditadas sends brownie points to @chrono79 and @moigithub and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4068 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 3246 | @moigithub |http://www.freecodecamp.com/moigithub
:star2: 7419 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 22 2017 13:25
@Ananditadas :checkered_flag: :+1:
Carson Michael
@Carson2003
May 22 2017 13:26
would I use i.length for the length of each individual word
Diego Mayer
@Chrono79
May 22 2017 13:26
@Carson2003 I 'd say no, but show your code
Carson Michael
@Carson2003
May 22 2017 13:27

function findLongestWord(str) {
var myArray = [];
var wordLength = 0;
var longestWord = 0;

myArray = str.split(' ');

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

}

return str.length;
}

Diego Mayer
@Chrono79
May 22 2017 13:27
i is a number there, and <= myArray.length is wrong, the last word is myArray[myArray.length - 1]
Carson Michael
@Carson2003
May 22 2017 13:27
should it be equal to it
Gabriela
@gradeva
May 22 2017 13:28
function golfScore(par, strokes) {
  // Only change code below this line
  if (par>0 && strokes===1){
    return "Hole in one";
  }

  else if (strokes<=par-2){
    return "Eagle";
  }

  else if (strokes==par-1){
    return "Birdie";
  }

  else if (strokes==par){
    return "Par";
  }

  else if (strokes==par+1){
    return "Bogey";
  }

  else if (strokes==par+2){
    return "Double Bogey";
  }

  else if (strokes>=par+3){
    return "Go Home";
  }
  else {
  return "Change Me";
  }
  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);
Hey, guys, there's something wrong with the first and the last conditional, help me please :(
Carson Michael
@Carson2003
May 22 2017 13:28
should "i" be equal to it
Diego Mayer
@Chrono79
May 22 2017 13:28
no, only less than myArray.length, or less or equal myArray.length - 1
HeebieGeeBee
@HeebieGeeBee
May 22 2017 13:28
@gradeva !!!
Moisés Man
@moigithub
May 22 2017 13:28
@gradeva make sure u write the exact text the instruction tells .. like one! <-- with that bang
Diego Mayer
@Chrono79
May 22 2017 13:29
@gradeva check your strings
return "Change Me" will never be reached
Carson Michael
@Carson2003
May 22 2017 13:29
then how do i get the length of the individual words
Diego Mayer
@Chrono79
May 22 2017 13:30
@Carson2003 your array, brackets, the loop indice inside them, dot length
studentzero
@studentzero
May 22 2017 13:31
In the golf exercise I keep getting the red X error saying "Expacted a conditional expression and instead saw an assignment" for example my code is "else if (strokes <= par-2 {return "Eagle";" The test condition is golfScore 4, 2. Is this error a problem. And why is the code not working?
Moisés Man
@moigithub
May 22 2017 13:31
first u need to access the word string on the array....
then u can .length on that @Carson2003
Gabriela
@gradeva
May 22 2017 13:31
@Chrono79 @HeebieGeeBee @moigithub Thank you! I added the "!'s" but the first one is still not working
CamperBot
@camperbot
May 22 2017 13:31
gradeva sends brownie points to @chrono79 and @heebiegeebee and @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 1676 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
:star2: 4069 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 3247 | @moigithub |http://www.freecodecamp.com/moigithub
Diego Mayer
@Chrono79
May 22 2017 13:32
@gradeva aren't there some - ?
HeebieGeeBee
@HeebieGeeBee
May 22 2017 13:32
@gradeva check the capitalization
or that
Carson Michael
@Carson2003
May 22 2017 13:32
so do a .length.length or would that not work
Diego Mayer
@Chrono79
May 22 2017 13:32
@studentzero Eagle shouldn't use <= and you need to close the parentheses
Moisés Man
@moigithub
May 22 2017 13:33
@Carson2003 length is an array or string property (ONLY)... it return a number value
soo if u have this ... arr = ["hello", "world"]
first u need to access "hello" doing arr[0]
then u can check its length
Gabriela
@gradeva
May 22 2017 13:33
@Chrono79 @HeebieGeeBee Uggh correct! I need to pay more attention to those things! Thanks again guys, you are great!