29th
Jun 2017
Diego Mayer
@Chrono79
Jun 29 2017 00:00
  for (var i =0; i<arr.length; i++); //see the semicolon here?
luccifer00
@luccifer00
Jun 29 2017 00:00
Is not the loop doing that??? @Chrono79
Diego Mayer
@Chrono79
Jun 29 2017 00:00
that loop does nothing
luccifer00
@luccifer00
Jun 29 2017 00:00
ookk the loop is doing nothing1 thanks @Chrono79
Joseph
@revisualize
Jun 29 2017 00:00
The ; is a statement terminator.
CamperBot
@camperbot
Jun 29 2017 00:00
luccifer00 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4440 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jun 29 2017 00:01
and you're returning arr[i] plus or minus something or simply arr[i]
luccifer00
@luccifer00
Jun 29 2017 00:01
jajaja @revisualize
mmmm @Chrono79 my logic says when arr[i] is equal to num, so replace the index of arr[i], if num is less than arr[i] so replace the index to arr[i]+1, .....
Brittani
@Carowyn
Jun 29 2017 00:03
Is anyone available to help me with the "Mutations" challenge?
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:03
yup
Brittani
@Carowyn
Jun 29 2017 00:04
@kumquatfelafel
Diego Mayer
@Chrono79
Jun 29 2017 00:04
@luccifer00 you're returning some number that's not the index value
even if you write those if/else inside the loop, the loop itself won't run more than once, because return exits the loop (and the function)
Joseph
@revisualize
Jun 29 2017 00:04

Note:

for (var i = 0; i < 1000000; i++) {
if (i === 10) {
return 10;
}
else {
return "Not 10";
}
}

This loop will NOT lop. Because...
The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
And IF something isn't true.. It is false...
In this case the else statement is a return value... SOOO.. It not only halts the loop but, It halts the whole function.

@meredithhazan Still here?
Brittani
@Carowyn
Jun 29 2017 00:05
sorry hit enter too early. I have it passing all but one test. Its the test listed that doesn't work.

function mutation(arr) {
var testOne = arr[1].toLowerCase();
var testTwo = arr[0].toLowerCase();
for (i=0; i<testOne.length; i++) {
if (testTwo.indexOf(testOne[i]) < 0) {
return false;
} else {
return true;
}
}
}

mutation(["hello", "hey"]);
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:05
^was considering saying something along these lines but decided not to since your if statements weren't even in for loop, but you should consider carefully what @revisualize just said @luccifer00
Diego Mayer
@Chrono79
Jun 29 2017 00:05
@Carowyn you can't return both true and false inside the loop like that if you want to pass the challenge, you'll only be testing a single letter that way
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:06
@Chrono79 well, can, but shouldn't :+1:
Diego Mayer
@Chrono79
Jun 29 2017 00:07
;)
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:07
@Carowyn return ends the function, @revisualize comment actually applies for you here. They must be psychic. :p
Joseph
@revisualize
Jun 29 2017 00:07
I am.
Meredith H.
@meredithhazan
Jun 29 2017 00:08
@revisualize still here. Just re-reading your explanation & still not getting to the answer. I changed the function to if (myObj.hasOwnProperty() === true) but I still don't understand how to return the value of the property.
Joseph
@revisualize
Jun 29 2017 00:08
@meredithhazan LEt's work through something else.
Diego Mayer
@Chrono79
Jun 29 2017 00:08
What color am I thinking of @revisualize ? :P
Joseph
@revisualize
Jun 29 2017 00:08
@Chrono79 Green.
Brittani
@Carowyn
Jun 29 2017 00:08
Ahh, I see what I did. took out the else, and moved return true down to outside the loop and it passed :)
Joseph
@revisualize
Jun 29 2017 00:08
@meredithhazan Do you have a few moments?
@Carowyn You're welcome.
:D
Brittani
@Carowyn
Jun 29 2017 00:08
thanks @kumquatfelafel
CamperBot
@camperbot
Jun 29 2017 00:08
carowyn sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
Diego Mayer
@Chrono79
Jun 29 2017 00:08
More like red, but nice try ;)
Meredith H.
@meredithhazan
Jun 29 2017 00:08
@revisualize A few before I head to class.
Joseph
@revisualize
Jun 29 2017 00:09
@Chrono79 I was going to gues blue.. Because that's standard.
onejo578
@onejo578
Jun 29 2017 00:09
// Setup
var myObj = {
pet: "kitten",
bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");
Can someone help me out here please? :\
Brittani
@Carowyn
Jun 29 2017 00:09
thanks @Chrono79
CamperBot
@camperbot
Jun 29 2017 00:09
carowyn sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4441 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jun 29 2017 00:09
:+1:
Joseph
@revisualize
Jun 29 2017 00:09

@meredithhazan
An example:

function addThree (num) {  }

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
...
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

If you make the function call of addThree(21) the value of num inside the function is 21.
If you make the function call of addThree(1000) the value of num inside the function is 1000.
If you make the function call of addThree(123456) the value of num inside the function is 123456.

Diego Mayer
@Chrono79
Jun 29 2017 00:10
@onejo578 checkObj() is a call to your function, you don't want to do that without a good reason
Meredith H.
@meredithhazan
Jun 29 2017 00:10
Ah, @onejo578 that's the one that's giving me trouble too!
Joseph
@revisualize
Jun 29 2017 00:10
@meredithhazan Please just focus on my example for a few seconds.
@meredithhazan I have some additional questions for you.
Meredith H.
@meredithhazan
Jun 29 2017 00:11
@revisualize Okay, I'm following so far.
Joseph
@revisualize
Jun 29 2017 00:11
@meredithhazan Great.. If (using that example) .. If I make the function call of: addThree(42); What is the value of the parameter num?
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:12
Why is this returning "1" instead of an array?
// 1) join them all together.
// 2) get rid of numbers that were repeated.
function uniteUnique(arr) {
var args = Array.from(arguments);
// Combines all the arrays together.
var flattened = args.reduce(function(a, b) {return a.concat(b);}, []);

//Counts the times a number is present.
var countedNums = flattened.reduce(function (allNums, num) {
if (num in allNums) {allNums[num]++;}
else {allNums[num] = 1;}
return allNums;}, {});

//Eliminates the numbers by index.
var result = flattened.reduce(
function (
accumulator,
currentValue,
currentIndex,
array
) {
return currentValue;
}, []
);
return result;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Meredith H.
@meredithhazan
Jun 29 2017 00:12
@revisualize 42
Joseph
@revisualize
Jun 29 2017 00:12
@meredithhazan Okay...
@meredithhazan If we change the function.

@meredithhazan

function greeting(name) { }

If I make the function call
greeting("Meredith");
What's the value of the parameter name?

kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:13
@Carowyn another thing, I would avoid saying "if (blah.indexOf(blahblah) < 0)". If you're testing for false condition of indexOf, I would just go with === -1. It's not difficult to accidentally use > instead of < or read it wrong and think it's checking for something that it's not. === -1 on the other hand is very clear and there's nothing much you could really confuse it with.
Meredith H.
@meredithhazan
Jun 29 2017 00:14
@revisualize It's Meredith
Joseph
@revisualize
Jun 29 2017 00:14

@meredithhazan

function greeting(name) { }

If I make the function call
greeting("Happy Feet");
What's the value of the parameter name?

Meredith H.
@meredithhazan
Jun 29 2017 00:14
@revisualize Happy Feet
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:14
Nevermind. I figured it out.
Joseph
@revisualize
Jun 29 2017 00:14

@meredithhazan

function checkObj(checkProp) { }

If I make the function cal of:
checkObj("banana");
What's the value of the parameter checkProp

Meredith H.
@meredithhazan
Jun 29 2017 00:15
It's banana. @revisualize I do understand that concept.
Joseph
@revisualize
Jun 29 2017 00:15
@meredithhazan Great.
@meredithhazan So, checkProp is used inside of your function block { } just like any other variable.
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:16
Banana!
Joseph
@revisualize
Jun 29 2017 00:16
@meredithhazan .hasOwnProperty() needs a value to check for......
Diego Mayer
@Chrono79
Jun 29 2017 00:16
luccifer00
@luccifer00
Jun 29 2017 00:16
@Chrono79 @revisualize thanks, that is the thing i fight with the loops..... by the way how can i change that return?? just createing a var instead the return??? i will think about that a little bit more
CamperBot
@camperbot
Jun 29 2017 00:16
:warning: luccifer00 already gave chrono79 points
luccifer00 sends brownie points to @chrono79 and @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4280 | @revisualize |http://www.freecodecamp.com/revisualize
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:17
@Chrono79 I figured it out myself. I spoke too soon :P
var result = flattened.reduce(
function (
accumulator,
currentValue,
currentIndex,
array
) {
return accumulator.concat(currentValue);
}, []
);
Diego Mayer
@Chrono79
Jun 29 2017 00:17
@luccifer00 only return on certain condition
Joseph
@revisualize
Jun 29 2017 00:17
@meredithhazan So, inside of your myObj.hasOwnProperty( ) ... You need to put property to check for...
onejo578
@onejo578
Jun 29 2017 00:18

@revisualize

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

still doesn't work. I'm close though, I know it...

Joseph
@revisualize
Jun 29 2017 00:18
@onejo578 You're not accessing your object property value. You're just returning the parameter value.
@onejo578 Also, === true is redundant.
Diego Mayer
@Chrono79
Jun 29 2017 00:19
@HappyViki aren't you returning the flattened array?
onejo578
@onejo578
Jun 29 2017 00:19
oh durr, yeah cause it already returns true/false.
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:19
@Chrono79 no.
Shawshank
@code2shank
Jun 29 2017 00:19
i need help with the weather app
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:20
@Chrono79 I’m doing stuff with it. I’m just slowely adding things on so I know what I’m doing.
Diego Mayer
@Chrono79
Jun 29 2017 00:20
@HappyViki ok
Meredith H.
@meredithhazan
Jun 29 2017 00:21
@revisualize Okay? But we're trying to return the property's value, which is where I'm stuck.
Joseph
@revisualize
Jun 29 2017 00:21
Meredith H.
@meredithhazan
Jun 29 2017 00:23

@revisualize function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp)) {

return myObj.val;
} else {
}
}
// Test your code by modifying these values

kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:23
@meredithhazan what is val in myObj.val?
Joseph
@revisualize
Jun 29 2017 00:24
@meredithhazan @meredithhazan 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];
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:24
^this as well.
Joseph
@revisualize
Jun 29 2017 00:25
@meredithhazan I'm also confused.. What is val ?
onejo578
@onejo578
Jun 29 2017 00:25
@revisualize so like return myObj [checkProp]?
Meredith H.
@meredithhazan
Jun 29 2017 00:25
@revisualize okay, I'm trying to use val to get the value. Obviously incorrect.
Joseph
@revisualize
Jun 29 2017 00:25
@onejo578 Without a space.
onejo578
@onejo578
Jun 29 2017 00:26
@revisualize ZING thankyou very much :) That was a bit painful!
Joseph
@revisualize
Jun 29 2017 00:26
@onejo578 You don't access object properties with spaces between the object name and the [
CamperBot
@camperbot
Jun 29 2017 00:26
onejo578 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4281 | @revisualize |http://www.freecodecamp.com/revisualize
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:26
Wait…why is this giving me an error?
// 1) join them all together.
// 2) get rid of numbers that were repeated.
function uniteUnique(arr) {
var args = Array.from(arguments);
// Combines all the arrays together.
var flattened = args.reduce(function(a, b) {return a.concat(b);}, []);

//Counts the times a number is present.
var countedNums = flattened.reduce(function (allNums, num) {
if (num in allNums) {allNums[num]++;}
else {allNums[num] = 1;}
return allNums;}, {});

//Eliminates the numbers by index.
var result = flattened.reduce(
function (
accumulator,
currentValue,
currentIndex,
array
) {
console.log(accumulator);
if (accumulator.indexOf(currentValue) === -1) {
return accumulator.concat(currentValue);
}
}, []
);
console.log(result);
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
TypeError: accumulator is undefined
Meredith H.
@meredithhazan
Jun 29 2017 00:27
@revisualize I see @onejo578 answer worked, but I'm still confused. I thought checkProp was referring to the property, not the value.
@meredithhazan checkProp is just a parameter / variable
Meredith H.
@meredithhazan
Jun 29 2017 00:28
@revisualize So how does it return the value? It is the square brackets that return the value of the property, not the parameter?
Joseph
@revisualize
Jun 29 2017 00:28

@meredithhazan
Let's say you have an object.

var myFriend = {
"firstName": "Happy",
"lastName": "Feet",
"number": "-i",
"likes": ["rhythm", "dancing", "soul"]
}

var name = "lastName";

What does myFriend[name] output?

Meredith H.
@meredithhazan
Jun 29 2017 00:29
@revisualize Happy?
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:29
@revisualize what the heck is that :O
onejo578
@onejo578
Jun 29 2017 00:29
@revisualize feet, right?
Joseph
@revisualize
Jun 29 2017 00:29
@HappyViki 1000% awesome.
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:29
@meredithhazan what is stored in name?
Meredith H.
@meredithhazan
Jun 29 2017 00:29
@revisualize oops, right.
Diego Mayer
@Chrono79
Jun 29 2017 00:29
@HappyViki when your if condition is false accumulator is undefined and you can't use indexOf next time
Joseph
@revisualize
Jun 29 2017 00:30
@meredithhazan Really you could do anthing.
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:30
@Chrono79 oh. thanks :)
CamperBot
@camperbot
Jun 29 2017 00:30
happyviki sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4442 | @chrono79 |http://www.freecodecamp.com/chrono79
onejo578
@onejo578
Jun 29 2017 00:31
@HappyViki that screencap hurts my brain
Joseph
@revisualize
Jun 29 2017 00:31

@meredithhazan
Let's say you have an object.

var myFriend = {
"firstName": "Happy",
"lastName": "Feet",
"number": "-i",
"likes": ["rhythm", "dancing", "soul"]
}

var myBuddyIsSuperAwesomeAndHasABunchOfAwesomeLikes = "likes";

...
What does myFriend[myBuddyIsSuperAwesomeAndHasABunchOfAwesomeLikes] output?

Veronica Eulenberg
@HappyViki
Jun 29 2017 00:31
@onejo578 mine too. It makes no sense.
Joseph
@revisualize
Jun 29 2017 00:32
@meredithhazan I'm not trying to be silly here.. I'm just trying to drive home a point.
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:32
@revisualize "puppies and garbanzo beans"
Joseph
@revisualize
Jun 29 2017 00:32
@kumquatfelafel That is NOT what Happy Feet likes!
Diego Mayer
@Chrono79
Jun 29 2017 00:32
kittens, who doesn't like kittens?
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:32
@revisualize whoa! okay okay. :o
:p
Meredith H.
@meredithhazan
Jun 29 2017 00:32
@revisualize rhythm, dancing, soul - and I get that you're assigning "likes" that variable.
Joseph
@revisualize
Jun 29 2017 00:33
@meredithhazan checkProp is just a parameter. You basically treat it just like any other variable.
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:33
@Chrono79 And apple strudel, of course.
Meredith H.
@meredithhazan
Jun 29 2017 00:34
@revisualize I just don't see where checkProp was assigned. I'm not sure why this is so puzzling but I appreciate the help immensely.
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:34
@meredithhazan ah
Joseph
@revisualize
Jun 29 2017 00:34
@meredithhazan It's assigned at the function call.
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:34
so functions then
Joseph
@revisualize
Jun 29 2017 00:34
@meredithhazan 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".
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:35
@Chrono79 am I supposed to use filter instead of reduce?
Joseph
@revisualize
Jun 29 2017 00:35
@meredithhazan It's the same thing with addThree(42); ... where the parameter num was 42
Diego Mayer
@Chrono79
Jun 29 2017 00:35
@HappyViki I think you overused reduce there, yes, filter sounds ok, but think how to use it
Joseph
@revisualize
Jun 29 2017 00:35
@meredithhazan Just a different function name and different parameter name.
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:35
@Chrono79 I thought that reduce reduced though...
Meredith H.
@meredithhazan
Jun 29 2017 00:36
@revisualize @kumquatfelafel Yes, but those are properties. How does it know that I want the value of the property....oh wait, I think I just got it. Haha.
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:36
// This is our function definition.vvv
function thisIsAFunction(val1, val2) { //val1 and val2 are like variable "placeholders", known as "parameters" that wait for actual values, known as "arguments" to be passed into function. It is in these parameters that the passed in values will be stored
return val1 + val2; //this returns the value of val1 + val2 to the caller
}

//Now that we have defined our function, we can call it as many times as we want. Here's how we call our function
thisIsAFunction(3, 6); //here we're telling it to execute lines of code in the function using 3 for val1 and 6 for val2.
thisIsAFunction(4,9);
thisIsAFunction(1,8);

//we can store the return into a variable if we want.
var returnedValue = thisIsAFunction(2,7); //stores 9 (returned from function) into returnedValue
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:36
@Chrono79 This does what I want it to do except for the stupid undefined stuff.
// 1) join them all together.
// 2) get rid of numbers that were repeated.
function uniteUnique(arr) {
var args = Array.from(arguments);
// Combines all the arrays together.
var flattened = args.reduce(function(a, b) {return a.concat(b);}, []);

//Counts the times a number is present.
var countedNums = flattened.reduce(function (allNums, num) {
if (num in allNums) {allNums[num]++;}
else {allNums[num] = 1;}
return allNums;}, {});

//Eliminates the numbers by index.
var result = flattened.reduce(
function (
accumulator,
currentValue,
currentIndex,
array
) {
console.log(accumulator);
if (accumulator.indexOf(currentValue) === -1) {
return accumulator.concat(currentValue);
}
}, []
);
console.log(result);
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Diego Mayer
@Chrono79
Jun 29 2017 00:36
@HappyViki first unite two, then unite the third one with the previous union and so on
Joseph
@revisualize
Jun 29 2017 00:37
@kumquatfelafel You need to do js
Diego Mayer
@Chrono79
Jun 29 2017 00:37
@HappyViki add else return accumulator;
But you'll get the numbers not in the right order, and why did you create countedNums?
Meredith H.
@meredithhazan
Jun 29 2017 00:37
@revisualize @kumquatfelafel Thanks everyone. I have to sign off but I'll look this over later.
CamperBot
@camperbot
Jun 29 2017 00:37
meredithhazan sends brownie points to @revisualize and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:star2: 4282 | @revisualize |http://www.freecodecamp.com/revisualize
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:38
@Chrono79 I’m doing things the hard way.
Diego Mayer
@Chrono79
Jun 29 2017 00:39
then, add the else, see if that works
Veronica Eulenberg
@HappyViki
Jun 29 2017 00:39
@Chrono79 Thanks that line helped. now I need to add stuff so uniteUnique([1, 3, 2], [1, [5]], [2, [4]]) works.
CamperBot
@camperbot
Jun 29 2017 00:39
happyviki sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: happyviki already gave chrono79 points
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:39
@revisualize yeah. realized I lost a lot of formatting in the transfer. :laughing:
luccifer00
@luccifer00
Jun 29 2017 00:40
@Chrono79 it was more harder than i thought...... if (arr[i]>=num)
return i;
}
return arr.length; after see it, i can understand, just give the number.... i was obsessed with the result should be a index [i].... shit!! thanks anyway for the advices
CamperBot
@camperbot
Jun 29 2017 00:40
luccifer00 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: luccifer00 already gave chrono79 points
Diego Mayer
@Chrono79
Jun 29 2017 00:41
@luccifer00 :+1:
Cole Maly
@malycole
Jun 29 2017 00:57
for some reason my strArr.join(); does not work in this block of code. am I missing something obvious?
function myReplace(str, before, after) {

var strArr = str.split(" ");
for (var i = 0; i < strArr.length; i++){
if (strArr[i] == before){
strArr.splice(i, 1);
strArr.splice(i, 0, after);
break;
}
}
strArr.join();
console.log(strArr);
}
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
kumquatfelafel
@kumquatfelafel
Jun 29 2017 00:59
@malycole str.join() needs a parameter to let it know what you're joining with.
e.g.
["Hello", "world"].join(' ') will give you "Hello world"
Baibhav Gautam
@baibhavx
Jun 29 2017 00:59
@baibhavx
Hey guys I am almost done with TicTacToe AI logic. Please help me test it and let me know if you can beat it(you shouldn't be able to) as I am still testing. Any feedback/suggestions appreciated :)
https://codepen.io/baibhavx/full/wePJdp/
Cole Maly
@malycole
Jun 29 2017 01:00
@kumquatfelafel I was under the impression that the separator was optional. Nonetheless if I use strArr.join(" "); the result is still incorrect (it remains an array)
kumquatfelafel
@kumquatfelafel
Jun 29 2017 01:01
@malycole you don't want to leave it out here.
sec
@malycole where are you storing the string you've created? Saying join won't make the variable that holds an array suddenly hold a string.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
Manish Giri
@Manish-Giri
Jun 29 2017 01:03
@kumquatfelafel console.log(strArr.join(" "));
try this line
notice the difference
Diego Mayer
@Chrono79
Jun 29 2017 01:05
@baibhavx I won (clicking fast enough)
Baibhav Gautam
@baibhavx
Jun 29 2017 01:06
damn ok i need to see whatss up
ahh
i see
kumquatfelafel
@kumquatfelafel
Jun 29 2017 01:09
@Chrono79 Well I won and lost. :o
Tic tac toe is one of those games where you're like "this is so cool" when you're a kid, but then when you get slightly older you're like "oh... every game ends in a draw. :/"
Raymond Igle
@r-igle
Jun 29 2017 01:14
@malycole don't you have to 'return' the val.
Diego Mayer
@Chrono79
Jun 29 2017 01:18
@kumquatfelafel more like lost and won
kumquatfelafel
@kumquatfelafel
Jun 29 2017 01:18
shrugs nonchalantly
Win or lose, it's how you finish the race that matters.
@baibhavx but yeah, barring the... well...
Your AI consistently wins if player goes second and doesn't pick the center at start. In the case player picks center, AI forces player into a draw. So pretty much tic tac toe in a nutshell.
jasonrest
@jasonrest
Jun 29 2017 01:23
Quick question. I should be able to chain a ".fadeIn()" right here. next to the .quote class right?

var randomQuote;
var author;

function getQuote(){
var url = "http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";
$.getJSON(url, function(data){$(".quote").html(data.quoteText).fadeIn();
$(".author").html(data.quoteAuthor); }); };$("#newQuote").on("click", function(){
getQuote();
});

$('#tweet').on("click", function(){ window.open("https://twitter.com/intent/tweet"); }); }); Prashanth Vaidya @thecodearrow Jun 29 2017 01:30 In FCC projects, should we paste a codepen link only or can it be a link of any other hosted site? like bitballoon Ginger @GingerChew Jun 29 2017 01:38 Hey I'm having some trouble with this destroyer algorithm, can I get a second pair of eyes? I think I'm like wayyyyy off function destroyer(arr) { // Remove all the values var args = arr.slice(arguments,3); function des(args){ if (args.indexOf(arr[1]) != -1) { return arr } } return args; } kumquatfelafel @kumquatfelafel Jun 29 2017 01:41 @GingerChew why 3? Ginger @GingerChew Jun 29 2017 01:41 oh shoot, that should be a 1 I was trying to grasp how the slice was working with the object although that doesn't seem to get the result I want eitehr Moisés Man @moigithub Jun 29 2017 01:42 slice syntax wrong mdn.io/slice it requires 1 (or 2) numbers indices Ginger @GingerChew Jun 29 2017 01:43 even with an arguments object? Moisés Man @moigithub Jun 29 2017 01:43 check the link... Ginger @GingerChew Jun 29 2017 01:44 this is what I'm referring to Moisés Man @moigithub Jun 29 2017 01:44 mdn.io/slice var args = arr.slice(arguments,3); <---wrong syntax Ginger @GingerChew Jun 29 2017 01:46 @moigithub yeah, I got it now thansk kumquatfelafel @kumquatfelafel Jun 29 2017 01:46 @GingerChew @moigithub is correct. you'll want to scroll down to the section where it says.. nvm @r-igle I think they're in the middle of modifying code. kumquatfelafel @kumquatfelafel Jun 29 2017 01:51 @r-igle @baibhavx though I'm able to replicate similar errors kumquatfelafel @kumquatfelafel Jun 29 2017 01:58 @r-igle should keep post up. May be related to what they're currently doing, but also chance it's not and just something haven't noticed Keon Samuel @keonsam Jun 29 2017 01:59 who knows a good web search api? Ayush Mahajan @ay2306 Jun 29 2017 01:59 Hey guys i need some help, I have clone of 8 buttons with text of 1 to 8. How can I assign click event task to them without creating 8 of these $('class').on('click',function());
Christopher Blakely
@chrisbchrist
Jun 29 2017 02:00

I'm trying to make a call to the GoogleMaps API to get an address from a lat/long for the weather app. I know my key works and the link is responding, wondering if I screwed up the code somehow
function getCity(a, b) {
var google_url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + a + "," + b + "&key=*";
$.getJSON(google_url, function(data) { var address = data.results.formatted_address; $("#location").html(address);

});
}

Keon Samuel
@keonsam
Jun 29 2017 02:00
this.id @ay2306
Ayush Mahajan
@ay2306
Jun 29 2017 02:01
@keonsam A little more help please
Moisés Man
@moigithub
Jun 29 2017 02:01
@chrisbchrist check ur browser devtools - console
IF u have any errors
Keon Samuel
@keonsam
Jun 29 2017 02:01
$('button')on('click', ()=>{ var id = this.id; }) Ayush Mahajan @ay2306 Jun 29 2017 02:02 @keonsam I get it. thanks man CamperBot @camperbot Jun 29 2017 02:02 ay2306 sends brownie points to @keonsam :sparkles: :thumbsup: :sparkles: :cookie: 404 | @keonsam |http://www.freecodecamp.com/keonsam Christopher Blakely @chrisbchrist Jun 29 2017 02:02 @moigithub Nada Moisés Man @moigithub Jun 29 2017 02:02 r u working on codepen ? @chrisbchrist Christopher Blakely @chrisbchrist Jun 29 2017 02:03 Moisés Man @moigithub Jun 29 2017 02:03 @chrisbchrist press F12 key to open ur browser devtools then switch to console tab or right click anywhere on ur browser.. and inspect element then switch tab Keon Samuel @keonsam Jun 29 2017 02:03 @ay2306 I did something like that in the past not sure how that works now. Ayush Mahajan @ay2306 Jun 29 2017 02:04 @keonsam Will send you link after I try it out... Christopher Blakely @chrisbchrist Jun 29 2017 02:05 @moigithub looks like I forgot to make it https, but it still won't work Keon Samuel @keonsam Jun 29 2017 02:05 I got the code $("button").on("click",function(){
switch(this.id){
case "2player":
Raymond Igle
@r-igle
Jun 29 2017 02:06

@baibhavx

Sequence crashes due to X(4) not being genrated and I select O(5)

## O(4) | X(1) | X(3)

.........|.......| O(3)

Moisés Man
@moigithub
Jun 29 2017 02:11
@chrisbchrist use console.log on ur callback
check what data u getting
Long Nguyen
@longnt80
Jun 29 2017 02:15

@baibhavx
try this:

o(1) | x(4) |
-------------------
| x(2) | 0(3)
-------------------
| 0(5) |

it just stopped after the fifth move

Christopher Blakely
@chrisbchrist
Jun 29 2017 02:16
@moigithub It doesn't return anything, I can't even return a number or a string, like the function's not even running
Moisés Man
@moigithub
Jun 29 2017 02:17
where u checking ??
check WHAT value ur ajax/getJSON request is returning...
Christopher Blakely
@chrisbchrist
Jun 29 2017 02:18
Object {results: Array(7), status: "OK"}
So it is returning data
Moisés Man
@moigithub
Jun 29 2017 02:18
soo results is an ARRAY
how u access array elements ??
ie: arr = [1,2,3]
how u access 1 ?
Christopher Blakely
@chrisbchrist
Jun 29 2017 02:20
Yeah I need to look at the notation again
Let's see
kumquatfelafel
@kumquatfelafel
Jun 29 2017 02:20
@longnt80 That appears to be intermittent, though I managed to get it to happen once when clicking very fast. From there, I was able to move before X and actually win. So it could be in part a result of similar problems to what they're trying to fix at moment.
Long Nguyen
@longnt80
Jun 29 2017 02:21
@kumquatfelafel oh yes
Christopher Blakely
@chrisbchrist
Jun 29 2017 02:22
@moigithub Got it, thank you man looks like I needed another set of eyes
CamperBot
@camperbot
Jun 29 2017 02:22
chrisbchrist sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3448 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Jun 29 2017 02:22
:+1:
Long Nguyen
@longnt80
Jun 29 2017 02:25
@baibhavx also you should stop any click event after the game is won/lost/draw
Tricia
@patricia07
Jun 29 2017 02:41
is this right?

// Setup
var lastName = "Lovelace";

// Only change code below this line
var secondToLastLetterOfLastName = lastName[lastName.length -6];

BlackTiger
@BlackTigerRoar
Jun 29 2017 02:42
@patricia07 Lovelace has length 8. lastName[8 - 6], you get lastName[2].
Ginger
@GingerChew
Jun 29 2017 02:46
I need some help with this sorted array algorithm 
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
function compare() {
for (var i=0;i<arr.length;i++) {
if (arr[i] >= arr[i+1]){
arr.splice(i+1,0);
}
}
}
var sorted = arr.sort(compare);
for (var i=0;i<sorted.length;i++) {
if (sorted[i] < num && sorted[i+1] > num && sorted[i] !== num){
sorted.splice(i+1,0,num);
}
}
return sorted;
}
I am having trouble sorting this array properly [3, 10, 5]
kumquatfelafel
@kumquatfelafel
Jun 29 2017 02:49

http://beta.freecodecamp.com/en/challenges/es6/understand-the-differences-between-import-and-require

import { capitalizeString } from "string_functions";
capitalizeString("hello!");

Am I missing something here, or is it just buggy challenge?

Claudio Restifo
@Marmiz
Jun 29 2017 02:50
@GingerChew you are splicing an array mid-looping. Meaning that you won't be sure that the array will be the same during every iteration
avoid doing that
Ginger
@GingerChew
Jun 29 2017 02:50
oh good point
thanks @Marmiz
CamperBot
@camperbot
Jun 29 2017 02:50
gingerchew sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
Claudio Restifo
@Marmiz
Jun 29 2017 02:51
@GingerChew if all your point is sorting an array, have you read the array.sort documentation?
it's full of examples on how to sort ^^
Ginger
@GingerChew
Jun 29 2017 02:52
Yeah, I read through it to try and figure out why 10 was coming before 3 and 5, which lead me to the unicode issue
Claudio Restifo
@Marmiz
Jun 29 2017 02:52
@kumquatfelafel try with
import { capitalizeString } from "./string_functions";
Ginger
@GingerChew
Jun 29 2017 02:52
but when I try and make a compare function for sort to use, it gets all haywire
kumquatfelafel
@kumquatfelafel
Jun 29 2017 02:52
@patricia07 They want the c, you're getting the v
@Marmiz ahhhhhh
@Marmiz thanks
CamperBot
@camperbot
Jun 29 2017 02:53
kumquatfelafel sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
Claudio Restifo
@Marmiz
Jun 29 2017 02:53

@kumquatfelafel they say:

"string_functions", and it is in the same directory as the current file.

kumquatfelafel
@kumquatfelafel
Jun 29 2017 02:54
@Marmiz still not happy, but it's fine. :p
tiger500
@tiger500
Jun 29 2017 02:55
guys i am stuck on this challenge convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86
Claudio Restifo
@Marmiz
Jun 29 2017 02:55
@kumquatfelafel the lesson is definitely bugged. See the test case? ;)
kumquatfelafel
@kumquatfelafel
Jun 29 2017 02:55
@Marmiz yeah :p
Claudio Restifo
@Marmiz
Jun 29 2017 02:56
@kumquatfelafel it's probably still in dev
Tricia
@patricia07
Jun 29 2017 02:56
@kumquatfelafel oh okay thanks!!
CamperBot
@camperbot
Jun 29 2017 02:56
patricia07 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
Claudio Restifo
@Marmiz
Jun 29 2017 02:56
you can see if there's an open issue for it, and in case fix it yourself ;) @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jun 29 2017 02:56
@Marmiz as long as I have a set of eyes on here that knows what they're doing, I'm fine with buggy es6 tutorials. :p
Claudio Restifo
@Marmiz
Jun 29 2017 02:57
@tiger500 how's your code looking like?
tiger500
@tiger500
Jun 29 2017 02:58

@Marmiz function convertToF(celsius) {
var fahrenheit=(0+4);

// Only change code below this line
fahrenheit=();
fahrenheit=(-30+8);
fahrenheit=(-10+24);
fahrenheit=(0+32);
// Only change code above this line
return fahrenheit;
}

// Change the inputs below to test your code
convertToF(30+56);

Tricia
@patricia07
Jun 29 2017 02:58
is this right?

var result = "";
// Your code below this line
result = "My " + myAdjective + "" myNoun + " can " + "myVerb + " + myAdverb + ""

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

Manish Giri
@Manish-Giri
Jun 29 2017 02:59
@patricia07 does it pass?
Tricia
@patricia07
Jun 29 2017 03:00
var result = "";
// Your code below this line
result = "My " + myAdjective + "" + myNoun + " can " + "myVerb + " + myAdverb + ".";
this one doesn't
Claudio Restifo
@Marmiz
Jun 29 2017 03:01

@tiger500 why hardcoding the values inside?
You have a function that will receive a variable (celsius).
simply write a formula to convert it.

The formula is written on the page:
The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.

It's the same in basic math where you have something like:
x = y +2
but instead of x and y they are called Celsius and Fahrenheit

kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:02
@patricia07 you're getting closer though.
"" + myNoun n.b. they want spaces in between the words.
"myVerb + " what is this?
Tricia
@patricia07
Jun 29 2017 03:02
it doesn't work @Manish-Giri
Claudio Restifo
@Marmiz
Jun 29 2017 03:02
@patricia07 you have the " all wrong and random
Manish Giri
@Manish-Giri
Jun 29 2017 03:02
put the spaces consistently
@patricia07
Tricia
@patricia07
Jun 29 2017 03:02
Manish Giri
@Manish-Giri
Jun 29 2017 03:02
myAdjective + "" + myNoun
like there's no space in between these 2
@patricia07
Tricia
@patricia07
Jun 29 2017 03:05
between these two? +""+
or the words?
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:05
between those quotes, yes. There doesn't appear to be a space.
A space inside those quotes will result in a space between the words in the resulting string.
tiger500
@tiger500
Jun 29 2017 03:08
@Marmiz what is the short way to write Fahrenheit is the temperature in Celsius times 9/5, plus 32.
Tricia
@patricia07
Jun 29 2017 03:08
Claudio Restifo
@Marmiz
Jun 29 2017 03:09
@tiger500 the one you just listed. But converted with math symbol
instead of "plus", in math you write +
instead of "times" you write *
...
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:10
and * instead of times
Claudio Restifo
@Marmiz
Jun 29 2017 03:10
:sparkles: math :sparkles:
not even once
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:18
@patricia07 I see nothing obviously wrong with it. If you're still having problems, post the rest of code.
Tricia
@patricia07
Jun 29 2017 03:19
var myArray = [1,2,3];
var myData = [0]; @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:23
What's [0]? What are you store in myData?
Ayush Mahajan
@ay2306
Jun 29 2017 03:29
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:31

@ay2306 no question (that I don't already know answer to)... Just a bit tired.

What are you store

* storing

Ayush Mahajan
@ay2306
Jun 29 2017 03:32
@kumquatfelafel okay
bnichole
@bnichole
Jun 29 2017 03:34
Hello, I need a little please. Anyone willing?
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:34
sure
bnichole
@bnichole
Jun 29 2017 03:35
the following code works when i change true to gift. why doesnt true work?

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

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

return "Change Me!";
}

*if(checkProp == "gift") works and displays the correct info on the console
Moisés Man
@moigithub
Jun 29 2017 03:37
hasOwnProperty return true or false.. IF the object u checking have or not the property u specify @bnichole
soo u need to use this.. as ur IF conditional expression
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:38
@bnichole myObj.hasOwnProperty(checkProp); will check for checkProp and return true. checkProp itself is not true though. checkProp is a string. So when you say
if(checkProp === true)
You are checking if a String is the same type as true and also has same value.
@bnichole if(checkProp == "gift") yeah, if checkProp is gift, then gift is gift. But it's not what you want. What you want is @moigithub solution to use hasOwnProperty in if statement.
The idea is you're using hasOwnProperty to check if object has a property, then, only if it has that property you return it.
Moisés Man
@moigithub
Jun 29 2017 03:42
checkObj("gift") <-- is how u calling the function... notice u passing "gift" inside the ( ... )
function checkObj(checkProp) { <---this is ur function header.. which accept 1 parameter named checkProp
javascript will store "gift" on checkProp parameter @bnichole
Ednor
@ednor
Jun 29 2017 03:47
hello hello !
@kumquatfelafel , nice to see you there !
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:48
@bnichole https://repl.it/JGgy See what happens if I remove gift from object. Try running this code
@ednor hey. Not for long though. About ready to pass out. :p
Ednor
@ednor
Jun 29 2017 03:49
I imagine that you have been there for a while
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:50
@ednor been doing beta challenges mostly :)
Ednor
@ednor
Jun 29 2017 03:50
I need help with this challenge:
Instructions: Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.

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

// 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);
here is what I tried, but it didn't work:

// Setup
function abTest(a, b) {
// Only change code below this line
console.log(a > 0 || b > 0);
return;
console.log(a < 0 || 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);
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:53

console.log(a > 0 || b > 0); return let's pretend this doesn't exist

(a < 0 || b < 0) so these conditions are correct, but do you want console.log?

what does console.log do?
Ednor
@ednor
Jun 29 2017 03:56
console.log is in the example, that's why I've used it
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:57
@ednor Sometimes the examples should not be followed too closely. :p
If you were going with your gut, what would you use instead? We want a way to return undefined only if a < 0 || b < 0.
Ednor
@ednor
Jun 29 2017 03:57
Example
function myFun() {
console.log("Hello");
return "World";
console.log("byebye")
}
myFun();
kumquatfelafel
@kumquatfelafel
Jun 29 2017 03:59
@ednor Do take a look at what happens when you run this code though. See if anything appears to be missing. https://repl.it/JGh6
Since it brings up an important point.
Looking at the output, can you figure out what's missing?
Ednor
@ednor
Jun 29 2017 04:01
@kumquatfelafel , okay, let me see
bnichole
@bnichole
Jun 29 2017 04:02
@kumquatfelafel and @moigithub Thank You! I understand now. I came up with: if (myObj.hasOwnProperty(checkProp) === true) {
return myObj[checkProp];
CamperBot
@camperbot
Jun 29 2017 04:02
bnichole sends brownie points to @kumquatfelafel and @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3449 | @moigithub |http://www.freecodecamp.com/moigithub
Ednor
@ednor
Jun 29 2017 04:03
@kumquatfelafel , please take a look: https://repl.it/JGhi/0
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:04
@bnichole that will work. :)
You can also just have
if(myObj.hasOwnProperty(checkProp)) since hasOwnProperty returns a value of true or false
Ednor
@ednor
Jun 29 2017 04:04
It doesn't work ;(
Baibhav Gautam
@baibhavx
Jun 29 2017 04:08
Thanks @longnt80, @r-igle, @kumquatfelafel for your help. Just got home, I'll try to fix the issues that you guys mentioned :)
CamperBot
@camperbot
Jun 29 2017 04:09
baibhavx sends brownie points to @longnt80 and @r-igle and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:09
@ednor Switch statements aren't the only thing you've learned. Can you think of any other way to only do something under certain conditions?
Ednor
@ednor
Jun 29 2017 04:11
@kumquatfelafel , we came from conditions (if, else if, else) to switch, that's the progress
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:12
Good evening everyone
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:12
@ednor so we've tried switch, and we can't figure out how to get that one to work... now what? ;)
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:12
I am confused with the following code:
function pairElement(str) {
var aSize = str.length;
var arr = new Array(aSize);

for (var i = 0; i < aSize; i++){

arr[i] = new Array(2);
arr[i][0] = str[i];

if (arr[i][0] == 'G') {
arr[i][1] = 'C';
}
else if (arr[i][0] == 'C'){
arr[i][1] = 'G';
}
else if (arr[i][0] == 'A'){
arr[i][1] = 'T';
}
else if (arr[i][0] == 'T'){
arr[i][0] = 'A';
}

}

return arr;
}
this code is working with 'GCG '
but not working with: pairElement("ATC");
fdemaa
@fdemaa
Jun 29 2017 04:14
Why this wont work ?


function bouncer(arr) {

for ( var i = 0; i<arr.length; i++){
if( arr[i] === Boolean || arr[i] === null || arr[i] === 0 || arr[i]=== "" ||arr[i]=== undefined|| arr[i]=== isNaN){
arr.splice([i],[i]);
} else {

}
}
return arr;

}

bouncer([false, null, 0, NaN, undefined, ""])
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:14
I got something like [[A,T][A, NULL],[C,G]
Markus Kiili
@Masd925
Jun 29 2017 04:15
@fdemaa Boolean and isNaN are functions.
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:15
so what the hack ? :P
fdemaa
@fdemaa
Jun 29 2017 04:15
@Masd925 :shipit:
Ednor
@ednor
Jun 29 2017 04:16
@kumquatfelafel , let me stop for today, I will continue tomorrow. Thanks for your availability.
CamperBot
@camperbot
Jun 29 2017 04:16
ednor sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
fdemaa
@fdemaa
Jun 29 2017 04:16
@Masd925 thanks!
CamperBot
@camperbot
Jun 29 2017 04:16
fdemaa sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4280 | @masd925 |http://www.freecodecamp.com/masd925
Kelechi Chinaka
@ke1echi
Jun 29 2017 04:17
what book can i use to learn js oop
Manish Giri
@Manish-Giri
Jun 29 2017 04:18
@kelechichinaka MDN is good
Kelechi Chinaka
@ke1echi
Jun 29 2017 04:18
ok @Manish-Giri
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:18
@JasonCorp84 arr[i][0] = 'A';
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:19
@kumquatfelafel thanks !
CamperBot
@camperbot
Jun 29 2017 04:19
jasoncorp84 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:19
lol
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:19
@JasonCorp84 it happens :p
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:20
I am still in a love with coding :D
CallMeOrange
@EgnaroDev
Jun 29 2017 04:21
Is there anyway to get last item in an array besides array[array.length - 1];?
M-C-Haker
@M-C-Haker
Jun 29 2017 04:22
quick question: why are all the functions so far in FCC written var x = function ()i 've only seen them writen like function getMoney () {} is there something different about constructor functions?
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:22
@MCTwoDigitZero my_array.slice(-1)[0]
CallMeOrange
@EgnaroDev
Jun 29 2017 04:22
Well Im not supposed to use slice method yet
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:22
@MCTwoDigitZero you can also pop, but thats... a bit more destructive.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:23
Well forget it array[array.length - 1]; is fine
Long Nguyen
@longnt80
Jun 29 2017 04:23
@M-C-Haker I think it's the same
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:23
_.last([5, 4, 3, 2, 1]);
will be 1
CallMeOrange
@EgnaroDev
Jun 29 2017 04:23
Its just a solution that I looked up, how to get last number
JasonCorp84 @JasonCorp84 copy paste stack overflow
CallMeOrange
@EgnaroDev
Jun 29 2017 04:24
Im not sure if there is something like arr[-1]
@JasonCorp84 Nah, I only added length - 1 to that set
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:25
(-1)
CallMeOrange
@EgnaroDev
Jun 29 2017 04:25
Maybe I can try to use pop method, store it then...
Long Nguyen
@longnt80
Jun 29 2017 04:25
@MCTwoDigitZero but pop also modify the original array
CallMeOrange
@EgnaroDev
Jun 29 2017 04:26
Finally, I found better way by myself
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:26
@MCTwoDigitZero what is that ?
CallMeOrange
@EgnaroDev
Jun 29 2017 04:26
@longnt80 I think this works fine for finding a longest word length
@JasonCorp84
 var lastn = array.pop();
return lastn;
Just storing last number using pop method then return it
function findLongestWord(str) {
str = str.split(" ");
var array = [];
for (var i = 0; i < str.length; i++) {
var lengthn = str[i].length;
array.push(lengthn);
array.sort(function(a, b){
return a - b;
});
}
var lastn = array.pop();
return lastn;

}

findLongestWord("The quick brown fox jumped over the lazy dog");
Long Nguyen
@longnt80
Jun 29 2017 04:27
what's wrong with array[array.length-1]?
CallMeOrange
@EgnaroDev
Jun 29 2017 04:28
@longnt80 Well since its a solution that I looked up online so I didnt want to use it
Only if I knew about it :p
Long Nguyen
@longnt80
Jun 29 2017 04:28
all the solutions are from online though
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:28
my question is this: fearNotLetter("bcd") should return undefined.
fearNotLetter("yz") should return undefined.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:28
Whats wrong with variable that contain pop method then return it?
Csaba Balogh
@JasonCorp84
Jun 29 2017 04:28
what returns undefined ? why ?
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:29
A fair amount of coding is understanding and using good solutions you find online :p
M-C-Haker
@M-C-Haker
Jun 29 2017 04:29
@longnt80 weird i'll have to experiment thanks
CamperBot
@camperbot
Jun 29 2017 04:29
m-c-haker sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
Long Nguyen
@longnt80
Jun 29 2017 04:29
nothing wrong with search for the answer online, as long as you understand it
CallMeOrange
@EgnaroDev
Jun 29 2017 04:29
Eh, I could use length - 1 If I wanted but I actually love the idea that I created a variable containing last number by using pop method then return it
@longnt80 True
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:32
@MCTwoDigitZero :wave: how would you find the largest number in an array like [ 5, 7, 6, 9, 14, 1, 7, 3 , 4, 42]?
CallMeOrange
@EgnaroDev
Jun 29 2017 04:32
@saifsmailbox98 No idea, cant use sort method since it sort by first digit only
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:33
@MCTwoDigitZero yes its a unicode sort.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:33
This will take me time to figure it out
Yeah
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:33
still you can sort it.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:33
I know how sort method works
really? how?
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:33
@MCTwoDigitZero that function a - b
CallMeOrange
@EgnaroDev
Jun 29 2017 04:34
Of course... using sort method with compare function
I guess I was overthinking it
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:34
here is the exercise to find the largest number.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:34
oh I guess Im ready to complete that algorithm
Thanks @saifsmailbox98
CamperBot
@camperbot
Jun 29 2017 04:34
mctwodigitzero sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:35
@MCTwoDigitZero you can even find the required number without using sort.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:35
No need to complete it right now, want to complete Title Case a Sentence first
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:35
@MCTwoDigitZero :+1:
CallMeOrange
@EgnaroDev
Jun 29 2017 04:35
@saifsmailbox98 There is a method that return the number I want?
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:37
@MCTwoDigitZero no, you create a variable say max and keep on accessing all the values in the list, and if its greater than max(initially set of the first item) assign that greater number to max
CallMeOrange
@EgnaroDev
Jun 29 2017 04:37
hm..
Could you make an example?
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:37
that way, at the end of the loop you will end up having the greatest number in the variable max
var arr = [ 5, 7, 6, 9, 14, 1, 7, 3 , 4, 42];
var max = arr[0];

for(var i=1;i<arr.length;i++){
if(arr[i]>max)
max=arr[i];
}

max; // 42
CallMeOrange
@EgnaroDev
Jun 29 2017 04:39
I see
Not sure if I understand it really clear but I can use pythontutor
@saifsmailbox98 oh I understand now
Claudio Restifo
@Marmiz
Jun 29 2017 04:40
@MCTwoDigitZero You can always use reduce to find the largest number. The wa reduce works is by checking the current number in the array vs the next one.
So the logic would be to keep only the biggest one of the 2.
At the end of the iteration you have only the biggest
CallMeOrange
@EgnaroDev
Jun 29 2017 04:40
It just look for number that is greater than 0 until loop end
@saifsmailbox98 so It just works same way as sort method with compare function?
Well not work same way but return same thing
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:41
I think probably by and large the best way to do it though, would be to sort the array in unicode, then apply your ( @saifsmailbox98 ) solution to find the largest number, then sort the array from smallest to largest, then perform a binary search using the number obtained from saif's solution in order to find the maximum number. :o
Claudio Restifo
@Marmiz
Jun 29 2017 04:42
[ 5, 7, 6, 9, 14, 1, 7, 3 , 4, 42].reduce((prev, curr) => {
return prev > curr ? prev : curr
}, 0)
CallMeOrange
@EgnaroDev
Jun 29 2017 04:42
@kumquatfelafel Yeah I was going to use sort method with compare function then return last item in an array
@Marmiz Can you explain it without ternary operator :/
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:43
@MCTwoDigitZero returns the same thing, without sorting the array in place.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:43
True
Claudio Restifo
@Marmiz
Jun 29 2017 04:43
@MCTwoDigitZero the ternary is just:
" is the previous number bigger than the current? YES: kepp it, NO: keep current"
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:43
just...
condition ? this when true : this when false
CallMeOrange
@EgnaroDev
Jun 29 2017 04:43
I dont like ternary
:p
Claudio Restifo
@Marmiz
Jun 29 2017 04:44
No sorting in place, no unecessary looping
kumquatfelafel
@kumquatfelafel
Jun 29 2017 04:44
<3 ternary.
Ternary is life. :p
Claudio Restifo
@Marmiz
Jun 29 2017 04:44
only one iteration
O(n)
CallMeOrange
@EgnaroDev
Jun 29 2017 04:45
Why tell me about how to return biggest number? Even if I was ready to start that algorithm, I could've figure it out by myself since I used sort method with compare function for finding longest word length
:p
So quiet..
EgnaroDev @MCTwoDigitZero has left the chatroom
MRLSU
@MRLSU
Jun 29 2017 04:53
Does chat not exist on the normal freecode camp assignments anymore?
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 29 2017 04:54
i see only hint too
MRLSU
@MRLSU
Jun 29 2017 04:54
also can anyone tell me what im doing wrong with Modify the data stored at index 0 of myArray to a value of 3.
i have ar myArray = [1,2,3];
ourArray[0] = 3;
CallMeOrange
@EgnaroDev
Jun 29 2017 04:54

@MRLSU

the chat was removed because there were complaints about people being forced to create a gitter account.. FCC was asking for too many accounts to be created. the Help is now a 'get hint' button that bring you to the forum

MRLSU
@MRLSU
Jun 29 2017 04:54
*var
@MCTwoDigitZero i see
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:54
ourArray? myArray ?
MRLSU
@MRLSU
Jun 29 2017 04:54

// Example
var ourArray = [1,2,3];
ourArray[1] = 3; // ourArray now equals [1,3,3].

// Setup
var myArray = [1,2,3];

// Only change code below this line.
var myArray = [1,2,3];
ourArray[0] = 3;

idk ive always used myArray and stuff in the assignments
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:55
@MRLSU dont using var twice.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:55
CamperBot
@camperbot
Jun 29 2017 04:55
CallMeOrange
@EgnaroDev
Jun 29 2017 04:55
:(
CamperBot
@camperbot
Jun 29 2017 04:55
saifsmailbox98 sends brownie points to @mctwodigitzero :sparkles: :thumbsup: :sparkles:
CallMeOrange
@EgnaroDev
Jun 29 2017 04:55
@saifsmailbox98 :D
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:55
@MRLSU you should be using myArray
MRLSU
@MRLSU
Jun 29 2017 04:55
is this better myArray = [1,2,3];
ourArray[0] = 3;
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:55
@MRLSU :point_up: June 29, 2017 10:24 AM
@MRLSU what do you want to do?
MRLSU
@MRLSU
Jun 29 2017 04:56
Modify the data stored at index 0 of myArray to a value of 3.
Markus Kiili
@Masd925
Jun 29 2017 04:56
@Lumexralph Morning.
CallMeOrange
@EgnaroDev
Jun 29 2017 04:56
@MRLSU remove =3 and ourArray[0]; return 3
You know computer starting counting at 0
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:56
@MRLSU then you're referencing ourArray instead of myArray
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:56
@MRLSU you are modifying the data of the other array, ourArray
CallMeOrange
@EgnaroDev
Jun 29 2017 04:56
So
1,2,3
--
0,1,3
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:56
@Masd925 was thinking you had gone into hiding like @HeebieGeeBee
CallMeOrange
@EgnaroDev
Jun 29 2017 04:57
Oh yeah, use same variable..
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:57
@Masd925 Good Morning
Ayush Mahajan
@ay2306
Jun 29 2017 04:57

this is my javascript code

$('#right-side-operaters').append('<button class="btn btn-primary col-xs-6">+</button><button class="btn btn-primary col-xs-6">-</button><button class="btn btn-primary col-xs-6">x</button> <button class="btn btn-primary col-xs-6">/</button>'); i want to write is as this like this $('#right-side-operaters').append('<button class="btn btn-primary col-xs-6">+</button>
<button class="btn btn-primary col-xs-6">-</button>
<button class="btn btn-primary col-xs-6">x</button>
<button class="btn btn-primary col-xs-6">/</button>');

But it doesnt accept multilines like this this. what should i do?

CallMeOrange
@EgnaroDev
Jun 29 2017 04:57
or have that variable assign to ourArray
Markus Kiili
@Masd925
Jun 29 2017 04:57
@Lumexralph Occasionally doing something productive ;)
CallMeOrange
@EgnaroDev
Jun 29 2017 04:57
Bye bye...
Night
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:57
@ay2306 where do you want to multiline it?
@MCTwoDigitZero bye :wave: gn
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:57
@Masd925 where've you been drifting to? what's that ?
@Masd925 :laughing:
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:58
@Lumexralph :hand:
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:58
@Masd925 I finally finished my calculator :smirk:
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:58
@Lumexralph wow
Ayush Mahajan
@ay2306
Jun 29 2017 04:58
@saifsmailbox98 inside append.. so i could read it easily while debugging
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:58
@saifsmailbox98 Good Morning man
Ayush Mahajan
@ay2306
Jun 29 2017 04:59
read both the code, you will get an idea of problem @saifsmailbox98
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:59
@Lumexralph are we in the same timezone?
Ogundele Olumide
@Lumexralph
Jun 29 2017 04:59
@saifsmailbox98 it's 6am here.....
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 04:59
@Lumexralph 10.29
still morning.
Ogundele Olumide
@Lumexralph
Jun 29 2017 05:00
@saifsmailbox98 :smile: cool
Ayush Mahajan
@ay2306
Jun 29 2017 05:00
@saifsmailbox98 are you from India?
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 05:00
@ay2306 yes
Ayush Mahajan
@ay2306
Jun 29 2017 05:00
@saifsmailbox98 yeah dude, me too
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 05:00
@ay2306 where do you want to multiline it gitter, or your project?
@ay2306 i know.
Ayush Mahajan
@ay2306
Jun 29 2017 05:00
@saifsmailbox98 project
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 05:00
@ay2306 codepen?
Ayush Mahajan
@ay2306
Jun 29 2017 05:01
@saifsmailbox98 yes
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 05:01
isn't enter working?
Markus Kiili
@Masd925
Jun 29 2017 05:01
@Lumexralph I need something on the portfolio, so I am rewriting the JS game/physics engine. Maybe doing some simple game also.
Level32
@BENticLabs
Jun 29 2017 05:02
$('#right-side-operaters').append('<button class="btn btn-primary col-xs-6">+</button><br><button class="btn btn-primary col-xs-6">-</button><br><button class="btn btn-primary col-xs-6">x</button> <br><button class="btn btn-primary col-xs-6">/</button>'); Does <br> help you with what you're trying to do? @ay2306 Ogundele Olumide @Lumexralph Jun 29 2017 05:03 @Masd925 cool, been getting down with git and github proper, putting all my works there now Saif Ur Rahman @saifsmailbox98 Jun 29 2017 05:03 @BENticLabs <br> would change the html content. Ayush Mahajan @ay2306 Jun 29 2017 05:03 @saifsmailbox98 https://codepen.io/ayush2306/pen/pwRRoX. In the start of JS. I want to write like that. but it causes error Markus Kiili @Masd925 Jun 29 2017 05:03 @Lumexralph :+1: I will do the same at some point too. Saif Ur Rahman @saifsmailbox98 Jun 29 2017 05:04 @ay2306 try this. $('#right-side-operaters').append('<button class="btn btn-primary col-xs-6">+</button>\
<button class="btn btn-primary col-xs-6">-</button>\
<button class="btn btn-primary col-xs-6">x</button>\
<button class="btn btn-primary col-xs-6">/</button>');
Ogundele Olumide
@Lumexralph
Jun 29 2017 05:04
@Masd925 so, I'm waiting for you to be done with the portfolio page, mine is a big trash just have to work on them all again but not until when i'm done with the frontend stuffs
@Masd925 it's was a knock in the head at times for me but it's finally sticking in :disappointed_relieved:
Ayush Mahajan
@ay2306
Jun 29 2017 05:06
@saifsmailbox98 thanks man
CamperBot
@camperbot
Jun 29 2017 05:06
ay2306 sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
Saif Ur Rahman
@saifsmailbox98
Jun 29 2017 05:06
:+1: @ay2306
@ay2306 remove the last \ that you added in your pen
Ayush Mahajan
@ay2306
Jun 29 2017 05:08
@saifsmailbox98 yes I did. :laughing:
Level32
@BENticLabs
Jun 29 2017 05:11
$(function(){ var url = "https://api.twitch.tv/kraken/users/freecodecamp"; var clientid = "140lhdo2d409r0e0owt4xqt8yazlry";$.getJSON(url + '?client_id=' + clientid).done(function(data){
console.log(data);
})
})
I'm doing the FCC Twitch TV project. Console.log(data) logs nothing to the console. Can anyone tell me what else I have to do to be able to use the Twitch.tv JSON API?
Lhats0
@stahloliver
Jun 29 2017 05:12

Hi channel. How do you call a function defined in var? Let's say var myFunction = $.ajax... myFunction() doesn't work. Manish Giri @Manish-Giri Jun 29 2017 05:13 @stahloliver no function keyword? Lhats0 @stahloliver Jun 29 2017 05:13 no because when I put ajax call in a function the promise doesn't work... I call my promise like myFunction.done({ do whatever }) Ogundele Olumide @Lumexralph Jun 29 2017 05:15 @Manish-Giri Gggggggggggggm :smiling_imp: good morning Manish Giri @Manish-Giri Jun 29 2017 05:15 @Lumexralph ggggggggggggggmmmmmmmmmmmm :smiling_imp: good morning Ogundele Olumide @Lumexralph Jun 29 2017 05:16 @Manish-Giri been knocking my head around git and github but it's finally sticking Manish Giri @Manish-Giri Jun 29 2017 05:16 @Lumexralph niice worth the pain Ogundele Olumide @Lumexralph Jun 29 2017 05:17 @Manish-Giri so now I know if you change something on the github site, you commit it, you have to pull the remote repo to working directory, commit it and push back :disappointed_relieved: Manish Giri @Manish-Giri Jun 29 2017 05:17 yup Ogundele Olumide @Lumexralph Jun 29 2017 05:18 @Manish-Giri seriously, i banged my head over this, my impatience led me to that guess I should just switch to gear 1 Manish Giri @Manish-Giri Jun 29 2017 05:18 lol Ogundele Olumide @Lumexralph Jun 29 2017 05:19 so pull does a merge with working directory by default Manish Giri @Manish-Giri Jun 29 2017 05:19 yeah pull = fetch + merge Ogundele Olumide @Lumexralph Jun 29 2017 05:20 interesting, .... Manish Giri @Manish-Giri Jun 29 2017 05:20 I always do fetch and merge rather than pull Ogundele Olumide @Lumexralph Jun 29 2017 05:20 why? Manish Giri @Manish-Giri Jun 29 2017 05:20 coz I don't like git doing it lol might mess things up Ogundele Olumide @Lumexralph Jun 29 2017 05:21 @Manish-Giri if you've set your gitignore rules, what could possibly go wrong Manish Giri @Manish-Giri Jun 29 2017 05:22 Ogundele Olumide @Lumexralph Jun 29 2017 05:27 @Manish-Giri hmm....wow Adri Jenie @Adrifajar Jun 29 2017 05:33 hello i would like to ask on how to combine string array ["a" "b" "c"]. is it using string.join(). i want ["abc"] for the result kumquatfelafel @kumquatfelafel Jun 29 2017 05:36 @Adrifajar if your array is called string this will work, yes. Saif Ur Rahman @saifsmailbox98 Jun 29 2017 05:36 string.join("") @Adrifajar @Adrifajar you want an array? kumquatfelafel @kumquatfelafel Jun 29 2017 05:36 err ^ possibly not? Could you clarify this? Adri Jenie @Adrifajar Jun 29 2017 05:37 i want a string. not an array kumquatfelafel @kumquatfelafel Jun 29 2017 05:37 @Adrifajar then you want join, yes. Saif Ur Rahman @saifsmailbox98 Jun 29 2017 05:38 @Adrifajar then this would work string.join("") if string = ["a", "b", "c"] Baibhav Gautam @baibhavx Jun 29 2017 05:39 Hi guys I am testing my TicTacToe AI logic. Can you please help me by letting me know if you are able to win or the game breaks in the middle. Appreciate your help https://codepen.io/baibhavx/full/wePJdp/ Adri Jenie @Adrifajar Jun 29 2017 05:39 i use str.join("") for str = ["a", "b", "c"]; "abc" should be the result. Baibhav Gautam @baibhavx Jun 29 2017 05:39 @kumquatfelafel thanks for your help earlier man :) CamperBot @camperbot Jun 29 2017 05:39 baibhavx sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles: :cookie: 402 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel Adri Jenie @Adrifajar Jun 29 2017 05:39 i am doing "Reverse a String" challenge but im stuck at the answer ["o" ,"l", "l", "e", "h"] not able to join it Manish Giri @Manish-Giri Jun 29 2017 05:40 @Adrifajar your code? Adri Jenie @Adrifajar Jun 29 2017 05:40 function reverseString(str) { str = str.split(""); str.reverse(); str.join(""); return str; } Manish Giri @Manish-Giri Jun 29 2017 05:41 you need to return str.join("") not str Adri Jenie @Adrifajar Jun 29 2017 05:41 ah i see so if i use this function reverseString(str) { str = str.split(""); str.reverse(); str=str.join(""); return str; } it will also work? kumquatfelafel @kumquatfelafel Jun 29 2017 05:42 like @Manish-Giri says. str.join will return a new string. You either have to store it in a variable or use it right away. Otherwise it is lost Manish Giri @Manish-Giri Jun 29 2017 05:42 try it Adri Jenie @Adrifajar Jun 29 2017 05:42 it does. thank you @Manish-Giri thank you Manish Giri @Manish-Giri Jun 29 2017 05:42 :+1: AShunc @AShunc Jun 29 2017 05:44 From Celsius degrees Celsius to Fahrenheit degrees Fahrenheit algorithm is: Celsius temperature multiplied by 9, in addition to 5, plus 32. Create a variable Fahrenheit, and then calculate the degree of Fahrenheit corresponding to fahrenheit. who can help me thanks kumquatfelafel @kumquatfelafel Jun 29 2017 05:45 @Adrifajar you can also chain this entire thing if you want, so you have  return str.split("").reverse().join(""); Manish Giri @Manish-Giri Jun 29 2017 05:46 @AShunc what's the problem? kumquatfelafel @kumquatfelafel Jun 29 2017 05:47 @AShunc the conversion formula is Fº = Cº * 9/5 + 32 Ayush Mahajan @ay2306 Jun 29 2017 05:47 please help, why is operator buttons not taking full space I am trying to assign them https://codepen.io/ayush2306/pen/pwRRoX AShunc @AShunc Jun 29 2017 05:47 function convert(celsius) { var celsius=document.getElementById("Celsius"); var fahrenheit=document.getElementById("Fahrenheit"); celsius.onkeyup=function(){ fahrenheit.value=celsius.value*9/5+32; return fahrenheit; } convert(30); kumquatfelafel @kumquatfelafel Jun 29 2017 05:50 you're overcomplicating this. We've already been given variables for celsius and fahrenheit. Use those variables. // This is our function definition.vvv function thisIsAFunction(val1, val2) { //val1 and val2 are like variable "placeholders", known as "parameters" that wait for actual values, known as "arguments" to be passed into function. It is in these parameters that the passed in values will be stored return val1 + val2; //this returns the value of val1 + val2 to the caller } //Now that we have defined our function, we can call it as many times as we want. thisIsAFunction(3, 6); //here we're telling it to execute lines of code in the function using 3 for val1 and 6 for val2. thisIsAFunction(4,9); //here we pass in 4 for val1 and 9 for val2 thisIsAFunction(1,8); //what are we passing in for val1 and val2 this time? //we can store the return into a variable if we want. var returnedValue = thisIsAFunction(2,7); //stores 9 (returned from function) into returnedValue //we can also pass variables into a function var a = 3; var b = 6; var c = thisIsAFunction(a,b); //can you guess what gets stored into c? //we can even do something like this... var d = thisIsAFunction(thisIsAFunction(a,b), c); //calling a function inside a function’s arguments? Wow! How cool is that? :p @AShunc basically, remove these lines altogether. var celsius=document.getElementById("Celsius"); var fahrenheit=document.getElementById("Fahrenheit"); celsius.onkeyup=function(){ Now try and modify this single line to work using the variables provided. vvv fahrenheit.value=celsius.value*9/5+32; AShunc @AShunc Jun 29 2017 05:57 oo thank you ! Vikram @vikramnr Jun 29 2017 06:02 Hi all How can i use npm package in JavaScript..Any links to study/examples please Ghost @ghost~56ef2a8b85d51f252ab9dec9 Jun 29 2017 06:08 @vikramnr Hi, FreeCodeCamp have a section dedicated to this :) @vikramnr But honestly, there's not really much to know as NPM is a package manager. Basically all you need to know is that when you want to build an app, you need some packages that already do what you want to do. For example, you want to authenticate users, there's the passport package for this. So, what you want to do is add the package and you do it with npm : npm install passport Ghost @ghost~56ef2a8b85d51f252ab9dec9 Jun 29 2017 06:13 And this package will then be saved into a folder called node_modules. And finally you can see all your packages into a file called package.jsonin the dependencies @vikramnr @vikramnr But I suggest you go through the freecodecamp section. You'll learn a lot more :) Pieter Stokkink @forkerino Jun 29 2017 06:16 @vikramnr one addition: to actually use the package in a js file, you need to either use require or import Owais Ahmed @owaisehmed Jun 29 2017 06:18 // Declare your variable here var myGlobal = 10; function fun1() { // Assign 5 to oopsGlobal Here oopsGlobal = 5; } // Only change code above this line function fun2() { var output = ""; if (typeof myGlobal != "undefined") { output += "myGlobal: " + myGlobal; } if (typeof oopsGlobal != "undefined") { output += " oopsGlobal: " + oopsGlobal; } console.log(output); } can someone please explain this to me how does it work fun2(){.....} Sweet Coding :) @SweetCodingInc Jun 29 2017 06:20 @forkerino : One addition: Some package install themselves on host object (on window in browsers. Example jQuery). They work without import/require Saif Ur Rahman @saifsmailbox98 Jun 29 2017 06:20 Pieter Stokkink @forkerino Jun 29 2017 06:24 @SweetCodingInc really? https://www.npmjs.com/package/jquery shows examples where they do use require. ... Do you have any more info? @owaisehmed that second function is just for testing purposes. At this point it is not entirely necessary to understand what it does. Sweet Coding :) @SweetCodingInc Jun 29 2017 06:26 @forkerino : Depends on the way you're loading the library. See first example where they load via script tag. There are multiple ways. But libraries like jQuery are best loaded on window than loaded via import/requre. Pieter Stokkink @forkerino Jun 29 2017 06:26 @SweetCodingInc yeah of course, but that has little to do with node/npm Sweet Coding :) @SweetCodingInc Jun 29 2017 06:27 Even import/require have nothing to do with npm :) Ghost @ghost~56ef2a8b85d51f252ab9dec9 Jun 29 2017 06:27 @owaisehmed Well what happens is that myGlobal is in the global scope, which means roughly that it is accessible "anywhere" in your javascript code. But oopsGlobal is declared and assigned in a function, so it is accessible only in the fun1 scope. So when you'll run fun2(), you'll get : myGlobal: 10 Owais Ahmed @owaisehmed Jun 29 2017 06:28 @forkerino yeah thats what i wanted to understand actually. how is it working Ghost @ghost~56ef2a8b85d51f252ab9dec9 Jun 29 2017 06:28 @owaisehmed If oopsGlobal were declared and assigned in your fun2() function you'll get : myGlobal: 10 oopsGlobal: 5 BlackTiger @BlackTigerRoar Jun 29 2017 06:28 oh man, just finished all the basic algorithm scripting problem. Caesars Cipher took me 4.5 hours @_@. Now moving to JSON APIs and Ajax.... Pieter Stokkink @forkerino Jun 29 2017 06:28 @owaisehmed ok. Well it basically checks if the variables exist in the scope and does something depending on whether they do or not. @SweetCodingInc they work independent of node, but we both know that it is the pattern used with node to modularize your code and work with 3rd party libraries. and .require() is a native node function. https://nodejs.org/api/modules.html kumquatfelafel @kumquatfelafel Jun 29 2017 06:52 @thomlom this isn't entirely true. oopsGlobal is accessible outside of fun1, but it isn't actually initialized to 5 unless you call fun1. https://repl.it/JGh6/1 If you declared it with var, then it would only have scope of fun1 Kamal @kpbro Jun 29 2017 07:20 need help for tweet button. i have made a button, but how do i tweet that quote? Claudio Restifo @Marmiz Jun 29 2017 07:21 @forkerino how's the new job? :) @kpbro have you looked into twitter button doc? Kamal @kpbro Jun 29 2017 07:26 yea. it adds its own button for tweet but i want to use the one that i created Claudio Restifo @Marmiz Jun 29 2017 07:27 @kpbro then you need to check the web intent Kamal @kpbro Jun 29 2017 07:28 @Marmiz ok. trying Johnny @JohnnyBizzel Jun 29 2017 07:32 @kpbro that colour scheme is hard on the :eyes: Nitin Sahu @globefire Jun 29 2017 07:49 anyone there? Csaba Balogh @JasonCorp84 Jun 29 2017 07:50 Good evening  function fearNotLetter(str) { var arr = []; var missing; var char; for (var i = 0; i < str.length; i++){ arr.push(str.charCodeAt(i)); } for (var j = 0; j < arr.length; j++){ if (arr[j]+1 != arr[j+1]){ missing = arr[j] -1; } } char = String.fromCharCode(missing); return arr; } fearNotLetter("abcdefghjklmno"); is there any idea why is it return the correct character if I use abce but return something else when I use the above example ? @globefire case a is not equal with value a Maks Ushakov @maks-ushakov Jun 29 2017 07:54 why you return an array? Csaba Balogh @JasonCorp84 Jun 29 2017 07:56 @maks-ushakov that is just aleftover, wanted to see if the indexes are right in the array char = String.fromCharCode(missing); return char; } I know I could return String.fromCharCode(missing); since I won't use that char variable anyway fearNotLetter("abcdefghj"); this returns i fearNotLetter("abcdefghjklmno") Maks Ushakov @maks-ushakov Jun 29 2017 07:59 Ouh i see why Csaba Balogh @JasonCorp84 Jun 29 2017 07:59 this returns n why? Maks Ushakov @maks-ushakov Jun 29 2017 08:00 your last char is 'o' has some index and you check it with index+1 (undefined) Csaba Balogh @JasonCorp84 Jun 29 2017 08:01 @maks-ushakov lol nice thanks CamperBot @camperbot Jun 29 2017 08:01 jasoncorp84 sends brownie points to @maks-ushakov :sparkles: :thumbsup: :sparkles: :cookie: 364 | @maks-ushakov |http://www.freecodecamp.com/maks-ushakov Maks Ushakov @maks-ushakov Jun 29 2017 08:01 in your script missing always will be last char code - 1 Claudio Restifo @Marmiz Jun 29 2017 08:01 @globefire the val you are passing inside the switch is a string: --> val = 'a' yet in your switch you have this misterious a case: case a: maybe you meant: case 'a': ? Maks Ushakov @maks-ushakov Jun 29 2017 08:05 @JasonCorp84 you have another mistake, try to find out it EpicTriffid @EpicTriffid Jun 29 2017 08:07 A question! I've finally (FINALLY) succeeded in pulling a quote through an API. However, I want to know why one worked one way, and the other worked a different way.$(document).ready(function() {
$("#motiv").on("click", function () {$("#quote").fadeOut(function() {
$.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?') .done(function(quote) {$("#quote").html(quote.quoteText);
})
})
$("#funny").on("click", function () {$("#quote").fadeOut(function() {
$.getJSON('https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=', function(quote) {$("#quote").html(quote[0].content);
});
});
So why do i require the .done with the top api but not the bottom
and why do i require to reference the array element in the bottom one?
Csaba Balogh
@JasonCorp84
Jun 29 2017 08:10
@maks-ushakov thanks again. Now it is working, however when everything is correct I do not get undefined
CamperBot
@camperbot
Jun 29 2017 08:10
jasoncorp84 sends brownie points to @maks-ushakov :sparkles: :thumbsup: :sparkles:
:warning: jasoncorp84 already gave maks-ushakov points
Csaba Balogh
@JasonCorp84
Jun 29 2017 08:10
how can I return undefined ?
is it related to the other mistake ?
Maks Ushakov
@maks-ushakov
Jun 29 2017 08:11
@JasonCorp84 i do not remeber which case you should return undefined?
Csaba Balogh
@JasonCorp84
Jun 29 2017 08:11
v
fearNotLetter("bcd") should return undefined.
fearNotLetter("yz") should return undefined.
Maks Ushakov
@maks-ushakov
Jun 29 2017 08:12
for return undefined just type return;
Csaba Balogh
@JasonCorp84
Jun 29 2017 08:13
hm
Maks Ushakov
@maks-ushakov
Jun 29 2017 08:13
Find condition to return this
CamperBot
@camperbot
Jun 29 2017 08:13
find condition to return this
nothing found
Csaba Balogh
@JasonCorp84
Jun 29 2017 08:14
alright, will find out tomorrow
good night
Maks Ushakov
@maks-ushakov
Jun 29 2017 08:18

So why do i require the .done with the top api but not the bottom

http://api.jquery.com/jQuery.getJSON/

it is different way

and why do i require to reference the array element in the bottom one?

To answer fo this question see what JSON object is returned from https://quotesondesign.com and from https://api.forismatic.com/

Aishvarya Gupta
@aishvarya0502
Jun 29 2017 08:24

@MCTwoDigitZero hey in your solution to finding a longest word length


function findLongestWord(str) {
str = str.split(" ");
var array = [];
for (var i = 0; i < str.length; i++) {
var lengthn = str[i].length;
array.push(lengthn);
array.sort(function(a, b){
return a - b;
});
}
var lastn = array.pop();
return lastn;

}

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


you are calling sort each time a array is being populated : which is increasing the complexity i.e. calling sort once after whole array is being populated is good rather than calling it again and again the later will produce the same result and in time efficient way by just sorting once.

@longnt80
Owais Ahmed
@owaisehmed
Jun 29 2017 08:27
Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
Getting confused with the switch statement
help needed
wonder
@wonder2991
Jun 29 2017 08:30
switch @owaisehmed
Ghost
@ghost~593024a8d73408ce4f63eac0
Jun 29 2017 08:35
does x=5/9y mean x= 5/(9y) or x=(5/9)*y
Owais Ahmed
@owaisehmed
Jun 29 2017 08:36
where am i going wrong
Maks Ushakov
@maks-ushakov
Jun 29 2017 08:37
Owais Ahmed
@owaisehmed
Jun 29 2017 08:38

function caseInSwitch(val) {
// Only change code below this line
switch(val){
case 1:
console.log("alpha");
break;
case 2:
console.log("beta");
break;
case 3:
console.log("gamma");
break;
case 4:
console.log("delta");
break;
}

// Only change code above this line
}

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

but it says to change the code below that line
Maks Ushakov
@maks-ushakov
Jun 29 2017 08:40

but it says to change the code below that line

so you have to do something to get right string inside variable answer

wonder
@wonder2991
Jun 29 2017 08:40
Rrakeshkrrakesh
@Rrakeshkrrakesh
Jun 29 2017 08:41
@KshitijaaJaglan it means x=5/(9y)
Baibhav Gautam
@baibhavx
Jun 29 2017 08:41
just finished fixing some bugs in my TicTacToe. Can I please get help testing the game. Please let me know if you're able to win or the game crashes. Appreciate any suggestions/advices.
https://codepen.io/baibhavx/full/wePJdp/
Owais Ahmed
@owaisehmed
Jun 29 2017 08:41
Not getting it
wonder
@wonder2991
Jun 29 2017 08:43
Owais Ahmed
@owaisehmed
Jun 29 2017 08:44
This returns the answer for only one
wonder
@wonder2991
Jun 29 2017 08:45
change for all the cases
b'coz as of now answer is still an empty string;
Owais Ahmed
@owaisehmed
Jun 29 2017 08:53
not able to do it for all
pfff
wonder
@wonder2991
Jun 29 2017 08:54
which part are you not getting? @owaisehmed
switch(val){
case 1:
break;
case 2:
break;
case 3:
break;
default:
}
Owais Ahmed
@owaisehmed
Jun 29 2017 08:58
I had been using console.log ...damn
wonder
@wonder2991
Jun 29 2017 09:00
so damn
Joe Franco
@BoostedB14
Jun 29 2017 09:03
Hey guys, I have a question. I'm currently doing the basic JavaScript section. I'm about half way done with it, but I'm not exactly sure how any of this stuff ties together. Is there a point where it starts making sense later or should
I go back and redo the sections?
I feel like i'm just blindly doing what it asks me but I'm not fully understanding it.
Vivek Ranjan
@vivekranjan92
Jun 29 2017 09:03
@BoostedB14 go to map t the top
at the top
Joe Franco
@BoostedB14
Jun 29 2017 09:05
@vivekranjan92 What i'm trying to say is I'm passing the assignments, but i'm not fully sure i have any understanding of what I'm doing. I'm not sure if this is normal when starting wiht javascript though.
Vivek Ranjan
@vivekranjan92
Jun 29 2017 09:05
@BoostedB14
you will get it slowly slowly
suppose if u complete html then if someone ask you to make a simple html page
you will be aware of div img etc tags
similarly you will get things here as well
sandy02
@sandy02
Jun 29 2017 09:08
guys I have completed basic alog scripting challenges, but how can I make sure that my solutions are good or best from all the solutions available to solve the problm..Any suggestions?
Joe Franco
@BoostedB14
Jun 29 2017 09:09
@vivekranjan92 OK thank you for the advice.
CamperBot
@camperbot
Jun 29 2017 09:09
boostedb14 sends brownie points to @vivekranjan92 :sparkles: :thumbsup: :sparkles:
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:13

let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};

function isEveryoneHere(obj) {
// change code below this line

if(obj in users)
{
return true;
}
else{
return false;
}

// change code above this line
}

console.log(isEveryoneHere(users));
how come that this returns false
The function isEveryoneHere returns true if Alan, Jeff, Sarah, and Ryan are properties on the users object
but the if statement takes care for it right
Bryan Büster
@BryanBuster
Jun 29 2017 09:16
Can anyone help with the Profile Lookup assignment I'm so dam stuck
sandy02
@sandy02
Jun 29 2017 09:18
@BryanBuster stuck where?
Bryan Büster
@BryanBuster
Jun 29 2017 09:18
Well this is what I got.

//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++)
if (firstName == contacts["firstName"])

else if (firstName !== contacts["firstName"])
return "No such contact";
else if (prop !== contacts)
return "No such property";

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
wonder
@wonder2991
Jun 29 2017 09:18
@IsmailHusseinCR because 'users' is not a property of your object users
try console.log(isEveryoneHere('Alan')); should return true
Bryan Büster
@BryanBuster
Jun 29 2017 09:19
the first line is to make sure it check all of the stuff on contacts, but then I'm pretty sure you can;t place an if inside it
sandy02
@sandy02
Jun 29 2017 09:20
@IsmailHusseinCR u r passing users itself
Alan Alickovic
@alan2207
Jun 29 2017 09:20
@IsmailHusseinCR you should check if user in obj
sandy02
@sandy02
Jun 29 2017 09:21
@BryanBuster you can.. this is what i did:
var found= false;
for( var i= 0; i<contacts.length; i++){
if(contacts[i].firstName === firstName){
found = true;
if(contacts[i][prop] === undefined){
return "No such property";
}else{
return contacts[i][prop];
}

}
}
if(!found)
return "No such contact";
// Only change code above this line
}
wonder
@wonder2991
Jun 29 2017 09:22
use backticks
Bryan Büster
@BryanBuster
Jun 29 2017 09:22
@BryanBuster you can.. this is what i did:
  var found= false;
for( var i= 0; i<contacts.length; i++){
if(contacts[i].firstName === firstName){
found = true;
if(contacts[i][prop] === undefined){
return "No such property";
}else{
return contacts[i][prop];
}

}
}
if(!found)
return "No such contact";
// Only change code above this line
}
Ogundele Olumide
@Lumexralph
Jun 29 2017 09:23
@BryanBuster
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
sandy02
@sandy02
Jun 29 2017 09:23
@wonder2991 yup :)
@BryanBuster you just have to do some tweaking with ur if blocks.. think step by step
Stephen James
@sjames1958gm
Jun 29 2017 09:24
@IsmailHusseinCR Your code is checking if (users in users) because you pass users as obj
It seems the code needs to check if every person is online?
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:24
yeah
i saw that
that i was checking users in users
:)
Stephen James
@sjames1958gm
Jun 29 2017 09:25
@BryanBuster YOu have a for loop, but you are not using the loop variable i?
Bryan Büster
@BryanBuster
Jun 29 2017 09:25
okay so I am stuck at the 1.1.1.1 part
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:25
yeah it needs to return true if those persons are in the users object
Stephen James
@sjames1958gm
Jun 29 2017 09:25
@BryanBuster no, you are stuck at the 1.1.1 part because you are not checking contacts[i].firstName
Bryan Büster
@BryanBuster
Jun 29 2017 09:26
I am?
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++)
if (firstName == contacts[i]["firstName"])
if ( prop == )

else if (firstName !== contacts["firstName"])
return "No such contact";
else if (prop !== contacts)
return "No such property";

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:26
@sjames1958gm i tried to do it with a for loop tho
Bryan Büster
@BryanBuster
Jun 29 2017 09:26
ow I pasted my old code xD
Stephen James
@sjames1958gm
Jun 29 2017 09:26
@BryanBuster Oh, sorry, looked at old code.
@BryanBuster recall testing object for properties challenge.
@IsmailHusseinCR YOu can use Object.keys to get array of user keys. then loop over that.
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:28
is that a method ?
Stephen James
@sjames1958gm
Jun 29 2017 09:28
@IsmailHusseinCR Or for (user in users) { } then check each online status
yes
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:29
i only need to look that they are a property of users
let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};
that they are online is not neccessary though
wonder
@wonder2991
Jun 29 2017 09:30
@IsmailHusseinCR hasOwnProperty
Object.keys() will returns an array of the object's properties
Ogundele Olumide
@Lumexralph
Jun 29 2017 09:31
@IsmailHusseinCR you just use their property name/key
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:31
@wonder2991 yes, but writing users.hasOwnProperty("Alan"), users.hasOwnProperty("Jeff") , users.hasOwnProperty("Sarah") etc seems hardcoded
Stephen James
@sjames1958gm
Jun 29 2017 09:33
@IsmailHusseinCR So what exactly is this function supposed to do?
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:33
the function must work so that it returns true only if the users object contains all four names, Alan, Jeff, Sarah, and Ryan, as keys, and false otherwise.
Alan Alickovic
@alan2207
Jun 29 2017 09:34
@sjames1958gm i am a bit confused too
this couldn't pass last test:
function isEveryoneHere(obj) {
// change code below this line
for(var user in obj) {
if(!obj.hasOwnProperty(user) ) {
return false;
}
}
return true;
// change code above this line
}
Stephen James
@sjames1958gm
Jun 29 2017 09:35
@IsmailHusseinCR You could create an array at the top of the function with each name and then loop over that array checking hasOwnProperty
@alan2207 you have to explicitly test the names given.
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 09:36
Is there any better way to do this?

function titleCase(str) {
var a = str.split(" ");
var b = [];
for(var i = 0 ; i < a.length ; i++){

if(i!==0){
b.push(" ");
}

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

if(j===0){
b.push(a[i][j].toUpperCase());
}else{
b.push(a[i][j].toLowerCase());
}

}

}

return b.join("");
}

titleCase("I'm a little tea pot");
Alan Alickovic
@alan2207
Jun 29 2017 09:36
@sjames1958gm i see, i thought it would be more elegant to do this without hardcoding
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 09:37
I'm getting the desired result and fcc shows the challenge complete but still searching for an alternative way out
Stephen James
@sjames1958gm
Jun 29 2017 09:37
@alan2207 The requirements are hardcoded :(
@aishvarya0502 You can use map instead of a for loop, then just rebuild the string
str.split(" ").map(function(word) {
return word[0].toUpperCase() + word.split(1).toLowerCase();
}).join(" ");
@alan2207 You can make it at least data driven.
  var list = ["Alan", "Jeff", "Sarah", "Ryan"];

return list.every(function(u) {
return obj.hasOwnProperty(u);
});
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:39
let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};

// change code below this line
var isEveryoneHere = function(obj, props) {

for(var i = 0; i < props.length; i++) {
if(!obj.hasOwnProperty(props[i])) {
return false;
}
else{
return true;
}
}

};

isEveryoneHere(users, ["Alan", "Jeff","Sarah","Ryan"]);
@sjames1958gm i tried this
Stephen James
@sjames1958gm
Jun 29 2017 09:40
@IsmailHusseinCR That would work, but you need to return true only after checking all the values.
Problem is that FCC test will not pass that array to you
Alan Alickovic
@alan2207
Jun 29 2017 09:41
@sjames1958gm good solution, actually i wasn't doing the exercise, but tried now, when @IsmailHusseinCR needed help, and saw that my solution didn't work which was a bit confusing
Stephen James
@sjames1958gm
Jun 29 2017 09:42
I think the problem would be better if they passed an array of users, like @IsmailHusseinCR tried above. The challenge as written makes you hard code users :(
Alan Alickovic
@alan2207
Jun 29 2017 09:43
@sjames1958gm i totally agree with you, but i hope they will fix it when beta becomes regular
Chris Juchtmans
@kjuchtmans
Jun 29 2017 09:43
Morning all coders! :wave:
Stephen James
@sjames1958gm
Jun 29 2017 09:43
@kjuchtmans :wave:
Chris Juchtmans
@kjuchtmans
Jun 29 2017 09:44
@sjames1958gm Good day sir, judging from your avatar you havent aged a single day :smile:
Stephen James
@sjames1958gm
Jun 29 2017 09:45
I have stopped going to the theatre though
koder3
@koder3
Jun 29 2017 09:45
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};
// change code below this line
const half = ({max, min}) => ((stats.max + stats.min) / 2.0); // use function argument destructurung
// change code above this line

console.log(half(stats)); // should be 28.015
the beta challenge passes with the reset code as well as my code, so not sure if my code uses destructuring. have i used any destructuring here?
and what does this console.log(half(stats)); mean ?
Alan Alickovic
@alan2207
Jun 29 2017 09:49
@koder3 the half function adds min and max values and divides its sum in 2
@koder3 it gets max and min via object destructuring from stats object
koder3
@koder3
Jun 29 2017 09:50
so that means i have used destructuring ?
@alan2207
Maks Ushakov
@maks-ushakov
Jun 29 2017 09:51

and what does this console.log(half(stats)); mean ?

I think it is mean : ' If function half get object stats, then result should be 28.015 '

Alan Alickovic
@alan2207
Jun 29 2017 09:51
@koder3 yes, you can get rid on stats from stats.max and stats.min
just leave max and min, since they are extracted from the stats object
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 09:51
@alan2207 cool
ISU
@isu17
Jun 29 2017 09:52
Any experienced javascript dev that can help me out ?
Chris Juchtmans
@kjuchtmans
Jun 29 2017 09:52

"Twitch.tv API" -- who wants to give me feedback?

My pen is here

## Questions:

1. User story 6 cannot be fulfulled at present, if you ask me. No way to distinguised between offline and closed or non-existent user from the JSON data returned.
Who has a workaround here?
This issue came up on this forum and Rafase282/My-FreeCodeCamp-Code#30 Unanswered though.

2. Why is my element order set to -99 for CSS class li.online not working?
I want to display online channels first, disregarding their JS query order

3. How can I query all channels in one query string?
My JSON call breaks if I use comma separated user names in the string.
My workaround now is bloated: repeating JSON calls

This is my first attempt at Flexbox design ; any critique is welcome.

k

IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:52

let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};

function isEveryoneHere(obj) {
// change code below this line
if('Alan' in users)
{
return true;
}
else{
return false;
}

if('Jeff' in users)
{
return true;
}
else{
return false;
}

if('Sarah' in users)
{
return true;
}
else{
return false;
}

if('Ryan' in users)
{
return true;
}
else{
return false;
}
// change code above this line
}

console.log(isEveryoneHere(users));
:(
Alan Alickovic
@alan2207
Jun 29 2017 09:52
ISU
@isu17
Jun 29 2017 09:52
I was wondering if its possible to implement a "DIY" .reduce function... I know it sounds silly but I think it will help me learn JS better and especially the reduce functionallity and logic
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 09:53

@aishvarya0502 You can use map instead of a for loop, then just rebuild the string

str.split(" ").map(function(word) {
return word[0].toUpperCase() + word.split(1).toLowerCase();
}).join(" ");

what does split(1) does?????????????

Stephen James
@sjames1958gm
Jun 29 2017 09:53
@IsmailHusseinCR If that works, then the tests are bad. This will return true if only Alan is in the object
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 09:53
@sjames1958gm
Stephen James
@sjames1958gm
Jun 29 2017 09:53
@aishvarya0502 returns the rest of the string after the first character
Alan Alickovic
@alan2207
Jun 29 2017 09:54
@isu17 you mean your own reduce method?
koder3
@koder3
Jun 29 2017 09:54
@maks-ushakov @alan2207 i see, thanks. understandable. have a nice day.
CamperBot
@camperbot
Jun 29 2017 09:54
koder3 sends brownie points to @maks-ushakov and @alan2207 :sparkles: :thumbsup: :sparkles:
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 09:54
@sjames1958gm :+1:
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 09:54
@sjames1958gm thats true :(
ISU
@isu17
Jun 29 2017 09:54
@alan2207 yeah, like from scratch
Stephen James
@sjames1958gm
Jun 29 2017 09:55
@isu17 Sure you can.
Alan Alickovic
@alan2207
Jun 29 2017 09:55
@isu17 try this : http://reactivex.io/learnrx/
@isu17 you will learn to build your own map, filter, reduce.....
Dan Couper
@DanCouper
Jun 29 2017 09:55
:point_up: it's really good that tutorial
ISU
@isu17
Jun 29 2017 09:55
thanks a lot @alan2207
CamperBot
@camperbot
Jun 29 2017 09:55
isu17 sends brownie points to @alan2207 :sparkles: :thumbsup: :sparkles:
ISU
@isu17
Jun 29 2017 09:56
this is exactly what I was looking for
:)
:fire:
Alan Alickovic
@alan2207
Jun 29 2017 09:56
@isu17 you are welcome
Sourabh
@hace123
Jun 29 2017 09:57
can anyone help me with the weather app, i am making requests and its even getting the request but not showing in the console log
Dan Couper
@DanCouper
Jun 29 2017 09:57
Implementing reduce is a pretty common task for learning how it works (well, how all of the array functions work because you can implement all of them with reduce), it is ver6 useful @isu17
heroiczero
@heroiczero
Jun 29 2017 09:57
Sourabh
@hace123
Jun 29 2017 09:58
i was able to do it for the http requests but https arent working
Stephen James
@sjames1958gm
Jun 29 2017 09:59
@kjuchtmans You cannot query all channels in one query, the API doesn't support that.
For offline vs. non-existant - you shouldn't get any json for non-existant users, you get a request error
@hace123 you have cross origin or CORS request issue.
Since you are using getJSON you can add ?callback=? to your URL to invoke jsonp behaviour to get around that
@hace123
var api='https://api.darksky.net/forecast/'+apikey+'/'+lat+','+lon + '?callback=?';
Sourabh
@hace123
Jun 29 2017 10:01
okay i will try :)
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:02

let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};

function countOnline(obj) {
// change code below this line

for (let user in users)
{
if(user.hasOwnProperty(online))
{
return user;
}
}
// change code above this line
}

console.log(countOnline(users));
@sjames1958gm this should look for those people who are online right
Sourabh
@hace123
Jun 29 2017 10:03
it worked thanks @sjames1958gm
CamperBot
@camperbot
Jun 29 2017 10:03
hace123 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7951 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jun 29 2017 10:04
@IsmailHusseinCR No, that just checks if they have the property, also it just returns the first one that has the property.
@hace123 :+1:
Sourabh
@hace123
Jun 29 2017 10:04
i was scratching my head for 1 whole day lol
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:05
oh so i should do hasOwnProperty(online) === true)
Alan Alickovic
@alan2207
Jun 29 2017 10:05
@IsmailHusseinCR check if(user.online === true)
Chris Juchtmans
@kjuchtmans
Jun 29 2017 10:06

@sjames1958gm okay, so csv query is something I will forget about, and keep my multiple JSON calls.

thanks

CamperBot
@camperbot
Jun 29 2017 10:06
kjuchtmans sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7952 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
jordyweerwag
@jordyweerwag
Jun 29 2017 10:06
hi guys i need help i just started wit javascript
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:06
@alan2207 yeah
but what do they mean with this
The function countOnline returns the number of users with the online property set to true
hmm the function returns undefined
Alan Alickovic
@alan2207
Jun 29 2017 10:08
@IsmailHusseinCR you should count them somehow
Chris Juchtmans
@kjuchtmans
Jun 29 2017 10:08
@kjuchtmans any ideas on how to enforce element order when rendering the stream results? So that, results with online streams will precede those for offline?
jordyweerwag
@jordyweerwag
Jun 29 2017 10:08
this is my code i must chance the myVar but is alredy diffrent than the original.

var myVar = 87;

// Only change code below this line
myVar = ++myVar;
Alan Alickovic
@alan2207
Jun 29 2017 10:09
add a count variable, and if the condition from above is true, increment that variable, and then at the end return that variable @IsmailHusseinCR
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:10

let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};

function countOnline(obj) {
// change code below this line

for (let user in users)
{
if(user.hasOwnProperty(user.age) > 22)
{
return user;
}
}
// change code above this line
}

console.log(countOnline(users));
its weird tho that this also calls undefined @alan2207
Marco Galizzi
@Tezenn
Jun 29 2017 10:11
@jordyweerwag what you have to do?
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 10:11

@sjames1958gm

@aishvarya0502 You can use map instead of a for loop, then just rebuild the string

str.split(" ").map(function(word) {
return word[0].toUpperCase() + word.split(1).toLowerCase();
}).join(" ");

i tried this but its not working

Alan Alickovic
@alan2207
Jun 29 2017 10:12
@IsmailHusseinCR whu are you checking for users age if you are looking for users online status?
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:12
i got the console log undefined when i ran the function
tried to change the if statement
still get undefined with this ' console.log(countOnline(users));'
Stephen James
@sjames1958gm
Jun 29 2017 10:14
@aishvarya0502 Oops that is what I get for coding live.
That should be slice(1) not split(1). My bad, sorry for wasting your time with bad code :(
Owais Ahmed
@owaisehmed
Jun 29 2017 10:14

'''

function isLess(a, b) {
// Fix this code
return a === b;
}

// Change these values to test
isLess(10, 15);
'''

CamperBot
@camperbot
Jun 29 2017 10:14
:bulb: to format code use backticks!  more info
Owais Ahmed
@owaisehmed
Jun 29 2017 10:15

function isLess(a, b) {
// Fix this code
return a === b;
}

// Change these values to test
isLess(10, 15);
Stephen James
@sjames1958gm
Jun 29 2017 10:15
@owaisehmed you changed the meaning of the function.
You should have used the same comparison from the if statement before
Owais Ahmed
@owaisehmed
Jun 29 2017 10:15
How to use it without if/else
Stephen James
@sjames1958gm
Jun 29 2017 10:15
@owaisehmed isLess and === don't match
Owais Ahmed
@owaisehmed
Jun 29 2017 10:16
i know
its gonna return false
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:16

let users = {
Alan: {
age: 27,
online: false
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: false
},
Ryan: {
age: 19,
online: true
}
};

function countOnline(obj) {
// change code below this line

let count = 0;
for (let user in users)
{
if(user.hasOwnProperty(user.online) === true)
{

}
return count++;
}
// change code above this line
}

console.log(countOnline(users));
heroiczero
@heroiczero
Jun 29 2017 10:16
@owaisehmed you need to fix return a === b;
Stephen James
@sjames1958gm
Jun 29 2017 10:16
@owaisehmed so change === to something that test isLess
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:16
@alan2207 used the increment
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 10:16
@sjames1958gm :smile:
Alan Alickovic
@alan2207
Jun 29 2017 10:16
@IsmailHusseinCR do you wanna see my solution?
Owais Ahmed
@owaisehmed
Jun 29 2017 10:17
return b === a
would return true in that case
Alan Alickovic
@alan2207
Jun 29 2017 10:17
it will be easier to understand
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:17
alright
Alan Alickovic
@alan2207
Jun 29 2017 10:18
function countOnline(obj) {
// change code below this line
var count = 0;
for(var user in obj) {
// check if user is online
if(obj[user].online) {
// if so increment it
count++;
}
}
return count;
// change code above this line
}
heroiczero
@heroiczero
Jun 29 2017 10:18
@owaisehmed your function is function isLess(a, b) so you need less than sign
Alan Alickovic
@alan2207
Jun 29 2017 10:18
@IsmailHusseinCR check commonts
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:19
ah
the count only returns the (count) of people online
aww shit why did i got hardstuck on this lmao
Alan Alickovic
@alan2207
Jun 29 2017 10:19
yes
Stephen James
@sjames1958gm
Jun 29 2017 10:19
@owaisehmed Before the change the code was if (a < b)
Then you should have return a < b;
Alan Alickovic
@alan2207
Jun 29 2017 10:20
@IsmailHusseinCR you should try to use console.log at different parts of your code, that way you will know if something is wrong and why
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:20
if(user.hasOwnProperty(user.online) === true) || if(obj[user].online)
i should also look better at obj[user]
Alan Alickovic
@alan2207
Jun 29 2017 10:21
@IsmailHusseinCR in this case user is string, which we must wrap with []
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:21
is the if statement i had wrong @alan2207
Alan Alickovic
@alan2207
Jun 29 2017 10:22
@IsmailHusseinCR compare the two codes and look where you were wrong,
@IsmailHusseinCR you were returning count++ which you shouldn;t
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:24
ouch :(
Alan Alickovic
@alan2207
Jun 29 2017 10:25
@IsmailHusseinCR and your if statement was wrong
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:25
cuz it was all this > console.log(countOnline(users));
Alan Alickovic
@alan2207
Jun 29 2017 10:27
@IsmailHusseinCR it means that we are logging whatever is returned from countOnline(users) function
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:27
@alan2207 i finally get it :)
 if (obj[user].online){
equals if(users[alan].online)
Alan Alickovic
@alan2207
Jun 29 2017 10:28
@IsmailHusseinCR it is the same as obj["Alan"].online if "Alan" was the current user
alan should be a string
that is how we are accessing properties via string values
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:29
yeah
if it was a number i could use the dot
Alan Alickovic
@alan2207
Jun 29 2017 10:29
no
it would me the same
as with arrays
obj[1]
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:30
oh thats right
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:31
thanks @alan2207 will work more with objects
CamperBot
@camperbot
Jun 29 2017 10:34
ismailhusseincr sends brownie points to @alan2207 :sparkles: :thumbsup: :sparkles:
Stephen James
@sjames1958gm
Jun 29 2017 10:34
@owaisehmed Did you solve the challenge?
Alan Alickovic
@alan2207
Jun 29 2017 10:34
@IsmailHusseinCR just play with it, try different things, you will understand it better
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:35
yeah like that count stuff
didnt do it before
wrapped without a function it looks so much easier tho
with function countOnline(obj) { } and console.log(countOnline(users));
it made it for me a bit harder than expected
Alan Alickovic
@alan2207
Jun 29 2017 10:36
@IsmailHusseinCR well when a function is called, it results to an expression, just think about it as the value of what is being returned from that function
function one() {
return 1;
}

// these log same result
console.log(one())
console.log(1)
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:39
and the expression there is the "return 1" ?
Alan Alickovic
@alan2207
Jun 29 2017 10:39
@IsmailHusseinCR the expression is just 1
the return keyword is is used to return an expression from a function
Ayush Mahajan
@ay2306
Jun 29 2017 10:40
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:41
@alan2207 hmm can u give me another function where u can explain those expressions too
Keon Samuel
@keonsam
Jun 29 2017 10:41
I finished the file metadata in one second.
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:41
it might be more clearer for me to use it in the future
Viperish
@Viperish
Jun 29 2017 10:42
$(document).ready(function() {$("#getMessage").on("click", function(){
\$(".message").html("Here is the message");

});
});
Is there something wrong with this? Shouldn't be since I practically copy pasted it but for some reason it doesn't work
Alan Alickovic
@alan2207
Jun 29 2017 10:42
@IsmailHusseinCR an expression is anything that can produce a value
@IsmailHusseinCR 1 produces value 1 so it is an expression
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:43
function printoutStuff(num1,num2)
{
return num1 * num2;
}
console.log(printoutStuff(1,3));
so the expression here is num1 * num2
or just 3
Owais Ahmed
@owaisehmed
Jun 29 2017 10:43
@sjames1958gm got it!
Alan Alickovic
@alan2207
Jun 29 2017 10:43
num * num @IsmailHusseinCR
it is evaluated before it has been returned
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:44
alright
odinolini
@odinolini
Jun 29 2017 10:45
Hello I have a problem. In this code snippet:
´´´
for (i=0;i<arr1.length;i++) {
var checks = 1;
console.log("ok");
if (longarr[i] == shortarr[i]) {
console.log(longarr[i], shortarr[i]);
checks++;
console.log(checks);
if (checks == arr2.length) {console.log("true dat");}
}
´´´
Maks Ushakov
@maks-ushakov
Jun 29 2017 10:45
@Viperish @Viperish did you add jquery?
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:45
so the computer first does num1 * num2 then returns it
odinolini
@odinolini
Jun 29 2017 10:45
checks will only increment once?
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:45
and after that it logs it just out
Alan Alickovic
@alan2207
Jun 29 2017 10:46
@IsmailHusseinCR yes, because it is returned from the function
it is explained in more details
Ronald T. Casili
@nvlled
Jun 29 2017 10:47
@odinolini move the var checks = 1 outside the for loop
putting it inside the loop will always make it reset to the value of 1.
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:48
@alan2207 TY alan will read this. fresh information is good. I hope i will understand functional programming well :)
CamperBot
@camperbot
Jun 29 2017 10:48
ismailhusseincr sends brownie points to @alan2207 :sparkles: :thumbsup: :sparkles:
:warning: ismailhusseincr already gave alan2207 points
odinolini
@odinolini
Jun 29 2017 10:48
@nvlled Of course... Thank you!
CamperBot
@camperbot
Jun 29 2017 10:48
odinolini sends brownie points to @nvlled :sparkles: :thumbsup: :sparkles:
Alan Alickovic
@alan2207
Jun 29 2017 10:49
@IsmailHusseinCR this is a series of 6 books, some are more advanced, but go ahead and read them, you will understand javascript much better
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:50
@alan2207 and they all free ?
or is it just a recap of it
Alan Alickovic
@alan2207
Jun 29 2017 10:50
@IsmailHusseinCR yes, if you read them on github, they are free, and they are complete
Stephen James
@sjames1958gm
Jun 29 2017 10:52
@owaisehmed :+1:
Greta Piliponytė
@gpiliponyte
Jun 29 2017 10:53
HELPS PLS weather app buttons don't work due to asynchronic function use and I don't know how to fix it .....
IsmailHusseinCR
@IsmailHusseinCR
Jun 29 2017 10:54
@alan2207 This is great. i will finish the course of the objects and will read this before i go on basic algorithmic scripting
Alan Alickovic
@alan2207
Jun 29 2017 10:55
:+1:
no not recap, they are complete and free on github
Maks Ushakov
@maks-ushakov
Jun 29 2017 11:03
@ay2306 i can't type second value and a can't deal with float numbers
firefox
ISU
@isu17
Jun 29 2017 11:04

function factorialize(num) {
if (num < 1) {
return 1;
} else {
return num * factorialize(num - 1);
}
}

factorialize(5);
is there other more forward method of doing this ?
without recursion *
Maks Ushakov
@maks-ushakov
Jun 29 2017 11:06
@isu17 with loop for example
Dan Couper
@DanCouper
Jun 29 2017 11:14
init a variable to 1 then for loop the length, multiply by the for loop's counter each time
Using recursion for it isn't very efficient in a language not built from the ground up to optimize recursion (even then, not using tail calls will normally kill it anyway)
Blauelf
@Blauelf
Jun 29 2017 11:16
I think tail recursion optimisation will be the ES6 feature implemented by the least engines.
I wonder what a stack trace should show when in a tail call recursion optimised away? Especially when doing indirect recursion? In theory, great concept. I'll probably leave it to the Haskells.
Dan Couper
@DanCouper
Jun 29 2017 11:18
yeah, Node had it one point then they dropped it
it is great having it available, but yeah, not sure it's ever going to go that well in JS
Ronald T. Casili
@nvlled
Jun 29 2017 11:20
@gpiliponyte I think you should familiarize yourself with callbacks so you could handle asynchronous problems with less difficulties.
function print(msg, callback) {
setTimeout(function() {
console.log(msg);
if (callback) callback();
}, Math.random()*300);
}
// Task: print one, two and three in order

// print order will be jumbled
print("one");
print("two");
print("three");

// TODO:
print("one", function() {
});
Dan Couper
@DanCouper
Jun 29 2017 11:21
That recursive method is 100% the most straighforward way of doing it though @isu17, it's the most direct translation of the mathematical equation, it's just super slow
for/while loop is probably the most understandable to the majority of devs though, and the most efficient
Blauelf
@Blauelf
Jun 29 2017 11:22
I think $n!=\Pi_{k=1}^n k$ is also a valid definition.
Dan Couper
@DanCouper
Jun 29 2017 11:23
ha, I was just looking for that
is that not the approximation?
jordyweerwag
@jordyweerwag
Jun 29 2017 11:23
@Tezenn i need to chance the myVar = myVar +1
with ++ increment
Blauelf
@Blauelf
Jun 29 2017 11:23
$\Pi$ works like $\Sigma$, just for product instead of sum (hence pi instead of sigma)
jordyweerwag
@jordyweerwag
Jun 29 2017 11:24
i have is alredy equals 88
@Tezenn is only says myVar = myVar shoud be chanced
Dan Couper
@DanCouper
Jun 29 2017 11:25
ah, I see. Was thinking of this:
function stirlingFactorial(n) {
return Math.sqrt(2 * Math.PI * n) * (n / Math.E) ** n;
}
I think that's right
Blauelf
@Blauelf
Jun 29 2017 11:28
@DanCouper In thermodynamics, we used the approximation of $\ln n!\approx n \ln n - n$ (ignoring more terms)
Dan Couper
@DanCouper
Jun 29 2017 11:28
just looking at the wiki, I think that gives same result? https://en.wikipedia.org/wiki/Stirling%27s_approximation
Blauelf
@Blauelf
Jun 29 2017 11:34
Guess it's a simplification then, as I omitted the $\sqrt{2\pi n}$ factor, or its logarithm (It's $\frac{1}{2}\ln{2\pi}+\frac{1}{2}\ln n$, which is much less than the rest for larger $n$)
And we always calculated with $n$ in the range of $10^{23}$...
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 11:38
Can anyone suggest other method of doing this. I am not satisfied with my code style

function largestOfFour(arr) {
var largest = [-1,-1,-1,-1];
var result;

for(var i = 0 ; i < arr.length ;i++){
for(var j = 0 ; j < arr[i].length ; j++){
if(largest[i] < arr[i][j]){
largest[i] = arr[i][j];
}
}
}

return largest ;
}

largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1005]]);
Alan Alickovic
@alan2207
Jun 29 2017 11:39
@aishvarya0502 you can use Math.max method
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 11:39
@Blauelf can you suggest any alternate method for above problem
@alan2207 okay. Thanks
CamperBot
@camperbot
Jun 29 2017 11:39
aishvarya0502 sends brownie points to @alan2207 :sparkles: :thumbsup: :sparkles:
Alan Alickovic
@alan2207
Jun 29 2017 11:40
@aishvarya0502 but to use it to find max num in array you need to use it like this: Math.max.apply(null, arr)
or Math.max.apply(null, arr[i]) if the array is nested
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 11:41
@alan2207 where do i get to know this stuff about the method usage..??/
Blauelf
@Blauelf
Jun 29 2017 11:41
Or with ES6, Math.max(...arr[i])
Alan Alickovic
@alan2207
Jun 29 2017 11:42
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 11:43
@alan2207 @Blauelf thank you both :+1:
CamperBot
@camperbot
Jun 29 2017 11:43
aishvarya0502 sends brownie points to @alan2207 and @blauelf :sparkles: :thumbsup: :sparkles:
:warning: aishvarya0502 already gave alan2207 points
:star2: 4491 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jun 29 2017 11:43
@aishvarya0502 The ES6 one-liner would be return arr.map(subArr => Math.max(...subArr));, in ES5, you could use neither an arrow function nor the spread operator, which makes it
  return arr.map(function(subArr) {
return Math.max.apply(null, subArr);
});`
Those are still two nested loops, but outer one is done in map, inner one is done in Math.max.
Aishvarya Gupta
@aishvarya0502
Jun 29 2017 11:46
@Blauelf yeah i was getting some trouble there thanks you mentioned and also for both ES implemention
CamperBot
@camperbot
Jun 29 2017 11:46
aishvarya0502 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles: