These are chat archives for FreeCodeCamp/HelpJavaScript

5th
Jun 2017
Frank McCroy
@fmccroy
Jun 05 2017 00:03
Good evening all! Is there a particular book or on-line course that comes highly recommended for learning JavaScript? I do the challenges here, but get the feeling I am probably not doing them very efficiently
Joseph
@Big-jo
Jun 05 2017 00:05
@fmccroy exactly how i feel
Caleb David
@microworlds
Jun 05 2017 00:09
Hello guys, please how do I create schema using mongojs npm package?
Johnny
@JohnnyBizzel
Jun 05 2017 00:12
@microworlds You create the schema in your JS code.
@fmccroy freecodecamp! Seriously, how about W3schools? I don't like recommending books because a year later and things have moved on!
Frank McCroy
@fmccroy
Jun 05 2017 00:15
@JohnnyBizzel I look at W3schools to see what commands do a lot and the right format. Do they have an actual course? and I know what you mean about books not keeping up.
Caleb David
@microworlds
Jun 05 2017 00:18

@JohnnyBizzel Please look at my code and suggest how I'll do that
db_config.js

require('dotenv').config();

var mongojs = require('mongojs');
var db_url = process.env.APP_CONFIG_MONGO_CONNECTION_STRING;
var db = mongojs(db_url, ['test']);

module.exports = db;

index.js

router.post('/test', function(req, res){

    db.test.insert({"fname" : req.body.fname, "lname" : req.body.lname}, function(err, ok){
        if (err) {
            console.log(err);
            res.json(err);
        } else {
            console.log(ok);
            res.json(ok);
        }
    });

})

So how do I create the Schema from that?

Frank McCroy
@fmccroy
Jun 05 2017 00:21
@JohnnyBizzel Thanks for the recommendation, I will check out the W3schools tutorial.
CamperBot
@camperbot
Jun 05 2017 00:21
fmccroy sends brownie points to @johnnybizzel :sparkles: :thumbsup: :sparkles:
:star2: 1703 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
tommy
@tommygebru
Jun 05 2017 00:27
a general book online is Eloquent... it is interactive... also maybe try to find a "best practices" slideshow or resource for JS... another resource is w3schools , also whenever you become comfortable with these materials you can proceed to read YDKJS series in Physical or ebook or github :smile: @fmccroy @Big-jo
Frank McCroy
@fmccroy
Jun 05 2017 00:30
@tommygebru Cool, thanks. I saw the Eloquent book at Barnes and Noble today, I didn’t know there was an on-line version.
CamperBot
@camperbot
Jun 05 2017 00:30
fmccroy sends brownie points to @tommygebru :sparkles: :thumbsup: :sparkles:
:cookie: 800 | @tommygebru |http://www.freecodecamp.com/tommygebru
tommy
@tommygebru
Jun 05 2017 00:31

.
.
.
Is anyone familiar with the javascript challenge centuryFromYear?

essential a function passes a year and I would have to return a century, therefore a parameter has an argument of 4 digits and I have to return 2 or 1 digit (like the 6th century or the 21st century )

Caleb David
@microworlds
Jun 05 2017 00:31
I've figured that, thanks guys
tommy
@tommygebru
Jun 05 2017 00:33
@microworlds if you arent getting enough responses also try https://gitter.im/mongodb/node-mongodb-native
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 00:34
'code'

'function testSize(num) {
// Only change code below this line
if (num < 5) {
return "tiny";
} else if (num < 10) {
return "Small";
} else if (num < 15) {
return "medium";
} else if (num < 20) {
return "Large";
} else (num = 20) {
return "Huge";
}

return testSize();
// Only change code above this line
}'

on the last else it says I'm missing a semicolon
right after the parentheses
tommy
@tommygebru
Jun 05 2017 00:36
Screenshot 2017-06-04 at 5.35.42 PM.png
@dmsdesignz how to format code :smile_cat:
Joseph
@Big-jo
Jun 05 2017 00:36
@tommygebru what books show you how to incoperate it with html and stuff?
tommy
@tommygebru
Jun 05 2017 00:36
do you mean the dom? @Big-jo
dom is how javascript interacts/manipulates the html, but there is also a library called jQuery... however I recommend trying to learn DOM first and then jQuery
LoserNoOne
@LoserNoOne
Jun 05 2017 00:38
function sym(args) {
// var result = arguments[0];
var fruits = ["Banana", "Orange", "Apple", "Mango"];
return fruits.splice(2,2);
Help
Frank McCroy
@fmccroy
Jun 05 2017 00:39
@dmsdesignz On your last else, num=20 is setting num to 20, did you mean to use num === 20 ?
LoserNoOne
@LoserNoOne
Jun 05 2017 00:39
Why this function returns ["Apple", " Mango"] instead of the first two term??
Frank McCroy
@fmccroy
Jun 05 2017 00:39
Or was it supposed to be inside the { } ?
Joseph
@Big-jo
Jun 05 2017 00:40
@tommygebru how do i do that.
tommy
@tommygebru
Jun 05 2017 00:40
@LoserNoOne please share the Challenge name and a link to it :thumbsup:
@Big-jo do what?
Frank McCroy
@fmccroy
Jun 05 2017 00:40
@LoserNoOne Because you are asking the splice to start at element [2] and asking for the next two elements.
Joseph
@Big-jo
Jun 05 2017 00:41
@tommygebru any resources for learning about the document object model(DOM)
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 00:41
@fmccroy actuall it is supose to be >= but that was throwing an error also

'''function testSize(num) {
// Only change code below this line
if (num < 5) {
return "tiny";
} else if (num < 10) {
return "Small";
} else if (num < 15) {
return "medium";
} else if (num < 20) {
return "Large";
} else (num = 20) {
return "Huge";
}

return testSize();
// Only change code above this line
}'''

CamperBot
@camperbot
Jun 05 2017 00:41
:bulb: to format code use backticks! ``` more info
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 00:41

```function testSize(num) {
// Only change code below this line
if (num < 5) {
return "tiny";
} else if (num < 10) {
return "Small";
} else if (num < 15) {
return "medium";
} else if (num < 20) {
return "Large";
} else (num = 20) {
return "Huge";
}

return testSize();
// Only change code above this line
}```

Frank McCroy
@fmccroy
Jun 05 2017 00:41
@dmsdesignz You don
@dmsdesignz You don’t have an actual “if” statement there, you can’t compare without it.
Joseph
@Big-jo
Jun 05 2017 00:43
@tommygebru thanks i have the first two i'll checkout the last one
CamperBot
@camperbot
Jun 05 2017 00:43
big-jo sends brownie points to @tommygebru :sparkles: :thumbsup: :sparkles:
:cookie: 801 | @tommygebru |http://www.freecodecamp.com/tommygebru
LoserNoOne
@LoserNoOne
Jun 05 2017 00:43
@fmccroy I thought the second argument means how much terms do I want to delete. It's not true?
Isabel Gan
@gnisabel
Jun 05 2017 00:44
Hey guys! I'm on "Local Scope and Functions" and I'm stuck :/
Could anyone help me?
Aakriti
@Aakriti94
Jun 05 2017 00:44
@gnisabel yeah say
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 00:45
@fmccroy t @fmccroy thanks but, what am I missing?
CamperBot
@camperbot
Jun 05 2017 00:45
dmsdesignz sends brownie points to @fmccroy :sparkles: :thumbsup: :sparkles:
:cookie: 331 | @fmccroy |http://www.freecodecamp.com/fmccroy
Frank McCroy
@fmccroy
Jun 05 2017 00:45
@LoserNoOne Although you are deleting them from the array, you used returned those values with your “return” statement
Isabel Gan
@gnisabel
Jun 05 2017 00:45

function myLocalScope() {
'use strict';

var myVar = "foo";
console.log(myVar);//"undefined"
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

// Now remove the console log line to pass the test

@Aakriti94 ^^^ this is my current code
The instructions are "Declare a local variable myVar inside myLocalScope. Run the tests and then follow the instructions commented out in the editor."
tommy
@tommygebru
Jun 05 2017 00:46

Is anyone familiar with the javascript challenge centuryFromYear?

essential a function passes a year and I would have to return a century, therefore a parameter has an argument
of 4 digits and I have to return 2 or 1 digit (like the 6th century or the 21st century )

function centuryFromYear(year) {
//Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, 
//the second - from the year 101 up to and including the year 200, etc.
/*
For year = 1905, the output should be
centuryFromYear(year) = 20;
*/
/*
For year = 1700, the output should be
centuryFromYear(year) = 17
*/
}
LoserNoOne
@LoserNoOne
Jun 05 2017 00:46
@fmccroy Oh, thanks a lot!!
CamperBot
@camperbot
Jun 05 2017 00:46
losernoone sends brownie points to @fmccroy :sparkles: :thumbsup: :sparkles:
:cookie: 332 | @fmccroy |http://www.freecodecamp.com/fmccroy
Frank McCroy
@fmccroy
Jun 05 2017 00:46
@dmsdesignz Change: else (num = 20) {
return "Huge”; to else return “Huge”;
Aakriti
@Aakriti94
Jun 05 2017 00:47
@gnisabel
function myLocalScope() {
  'use strict';
  var myVar = "Aakriti";
  console.log(myVar);
}
myLocalScope();
Jason Luboff
@JLuboff
Jun 05 2017 00:47
@awb715 Not yet. Was on vacation for just shy of 2 weeks. Haven't picked back up yet. Started a Mongo course (through mongodb university). I'm almost done with the node course though, on the web sockets section
Manish Giri
@Manish-Giri
Jun 05 2017 00:47
@Aakriti94 hey!
good to see you helping out
@JLuboff :wave:
Jason Luboff
@JLuboff
Jun 05 2017 00:48
@Manish-Giri Yo. What up?
Isabel Gan
@gnisabel
Jun 05 2017 00:48
Hey @Aakriti94 I tried that but it says "ReferenceError: myVar is not defined"
Belinda
@besumi
Jun 05 2017 00:48
hey all, having some trouble with Steamroller
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 00:48
`
Aakriti
@Aakriti94
Jun 05 2017 00:49
@Manish-Giri hey!! yeah.. thats what fcc is all about. helping each other
Isabel Gan
@gnisabel
Jun 05 2017 00:49
omg nevermind it works!!
tommy
@tommygebru
Jun 05 2017 00:49
@dmsdesignz essentially the last else statement in the if/else structure does not carry a condtion...
if (condition) {
    block of code to be executed if the condition is true
} else if (condition){ 
    block of code to be executed if the condition is true
} else { 
    block of code to be executed if the previous conditions are false
}
Isabel Gan
@gnisabel
Jun 05 2017 00:49
Thanks @Aakriti94 :D
CamperBot
@camperbot
Jun 05 2017 00:49
gnisabel sends brownie points to @aakriti94 :sparkles: :thumbsup: :sparkles:
:cookie: 264 | @aakriti94 |http://www.freecodecamp.com/aakriti94
Belinda
@besumi
Jun 05 2017 00:49
my solution returns the correct results but isn't validating against the tests
Aakriti
@Aakriti94
Jun 05 2017 00:49
@gnisabel welcome :)
Alexander Køpke
@alexanderkopke
Jun 05 2017 00:49
@gnisabel forgot the var? ;)
Jason Luboff
@JLuboff
Jun 05 2017 00:49
@besumi Don't use a global variable
@besumi move var flattendArr = []; inside your function
Isabel Gan
@gnisabel
Jun 05 2017 00:50
Forgot to remove it actually HAHA @alexanderkopke
I'm always doing these small errors omg
Manish Giri
@Manish-Giri
Jun 05 2017 00:50
@JLuboff trying out some angular crap
it sucks
Belinda
@besumi
Jun 05 2017 00:50
@JLuboff hm. i tried that, but then it doesn't return the proper results anymore...
Jason Luboff
@JLuboff
Jun 05 2017 00:51
@Manish-Giri :) I'm working on my mongo homework
Manish Giri
@Manish-Giri
Jun 05 2017 00:51
@JLuboff it's a pity that react isn't MVC
otherwise I wouldn't have cared for Angular
:disappointed:
Jason Luboff
@JLuboff
Jun 05 2017 00:51
@Manish-Giri What're you using it for?
Manish Giri
@Manish-Giri
Jun 05 2017 00:52
@JLuboff for now just to learn an MVC f/w
Aakriti
@Aakriti94
Jun 05 2017 00:52
@Manish-Giri what time is it there?
Manish Giri
@Manish-Giri
Jun 05 2017 00:52
@Aakriti94 almost 9 pm
Aakriti
@Aakriti94
Jun 05 2017 00:52
haha its 6 in morning here
Jason Luboff
@JLuboff
Jun 05 2017 00:52
@besumi Ya...the multiple function structure presents an issue (and was the reason you were using the global variable). You may want to try to rework into a single function or a function within a function
FlashHero
@FlashHero
Jun 05 2017 00:53
I'm stuck on this challenge called Smallest Common Multiple, does that mean that i suck at it or would anyone solve this very easily, here's the link https://www.freecodecamp.com/challenges/smallest-common-multiple
Belinda
@besumi
Jun 05 2017 00:53
@FlashHero just finished that earlier today
took a while
:)
Jason Luboff
@JLuboff
Jun 05 2017 00:53
@Manish-Giri Ah. Fun stuff. I need to start looking into some MS SQL courses...need to get some certifications
FlashHero
@FlashHero
Jun 05 2017 00:53
@besumi how long did it take you
Manish Giri
@Manish-Giri
Jun 05 2017 00:54
@Aakriti94 up so early?
Caleb David
@microworlds
Jun 05 2017 00:54
@tommygebru Thanks fort that suggestion
CamperBot
@camperbot
Jun 05 2017 00:54
microworlds sends brownie points to @tommygebru :sparkles: :thumbsup: :sparkles:
:cookie: 802 | @tommygebru |http://www.freecodecamp.com/tommygebru
Aakriti
@Aakriti94
Jun 05 2017 00:55
@Manish-Giri yeah!! at 5 actually. I have to start with the portfolio today
Aaron Bell
@awb715
Jun 05 2017 00:55
@JLuboff im finishing up the mongo section
Manish Giri
@Manish-Giri
Jun 05 2017 00:56
@Aakriti94 all the best :sparkles:
Joseph
@Big-jo
Jun 05 2017 00:56
can i still work as a freelance web designer while i'm still learning javascript over here.I'm good at html,css and i know jquery(a bit)
Jason Luboff
@JLuboff
Jun 05 2017 00:56
@Big-jo Sure
Belinda
@besumi
Jun 05 2017 00:56
ah, got it... thanks @JLuboff
CamperBot
@camperbot
Jun 05 2017 00:56
besumi sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1833 | @jluboff |http://www.freecodecamp.com/jluboff
Frank McCroy
@fmccroy
Jun 05 2017 00:56
@Aakriti94 Is your portfolio going to be a work of art like your Tribute was?
Belinda
@besumi
Jun 05 2017 00:56
@FlashHero probably 2 hours
it helped to write out the whole thing in pseudocode
found logical errors easier that way
Joseph
@Big-jo
Jun 05 2017 00:57
@JLuboff where would be the best freelance website for that?
Jason Luboff
@JLuboff
Jun 05 2017 00:57
@Big-jo The only one I'm aware of is upworks
Joseph
@Big-jo
Jun 05 2017 00:57
@JLuboff have you used it before?
Aakriti
@Aakriti94
Jun 05 2017 00:57
@fmccroy yeah!! been driving through a lot of ideas, I have chosen the minimalist form for this. lets see, how it comes!!
FlashHero
@FlashHero
Jun 05 2017 00:58
@besumi what algorithm did you use ?
Jason Luboff
@JLuboff
Jun 05 2017 00:58
@Big-jo No, it was my original intent to...but haven't had the chance
Rick Willcox
@willcoxDev
Jun 05 2017 00:59
how come I get undefined here? function truthCheck(collection, pre) { console.log(collection[1].pre);
truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "sex");
Joseph
@Big-jo
Jun 05 2017 00:59
@JLuboff thanks i'll try it out and see, hope the pay is good.
CamperBot
@camperbot
Jun 05 2017 00:59
big-jo sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1834 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Jun 05 2017 00:59
@willcoxDev Use bracket notation, not dot
Belinda
@besumi
Jun 05 2017 00:59
@FlashHero i took the larger number and stored its first 100 multiples in an array. then i checked whether each one was evenly divisible by the smaller one. if it was, i checked whether it was also divisible by all the numbers in between the two initial numbers.
Rick Willcox
@willcoxDev
Jun 05 2017 00:59
ok
FlashHero
@FlashHero
Jun 05 2017 01:01
@besumi ok thanks maybe i'll implement that
CamperBot
@camperbot
Jun 05 2017 01:01
flashhero sends brownie points to @besumi :sparkles: :thumbsup: :sparkles:
:cookie: 292 | @besumi |http://www.freecodecamp.com/besumi
Rick Willcox
@willcoxDev
Jun 05 2017 01:02
@JLuboff thanks that worked, finished hte problem 20 seconds leter :)
CamperBot
@camperbot
Jun 05 2017 01:02
willcoxdev sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1835 | @jluboff |http://www.freecodecamp.com/jluboff
Brooks
@Brodavis
Jun 05 2017 01:03
Why isn't my switch working?

function caseInSwitch(val) {
  var answer = "";
  // 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  
  return answer;  
}

// Change this value to test
caseInSwitch(1);
Jason Luboff
@JLuboff
Jun 05 2017 01:04
@willcoxDev :+1:
Manish Giri
@Manish-Giri
Jun 05 2017 01:04
you're not assigning anything to answer
Jason Luboff
@JLuboff
Jun 05 2017 01:04
@Brodavis 1,2, etc are numbers, not strings
Manish Giri
@Manish-Giri
Jun 05 2017 01:04
also "1" is a string
@Brodavis
Brooks
@Brodavis
Jun 05 2017 01:05
so instead of "1" it'll just be 1
Jason Luboff
@JLuboff
Jun 05 2017 01:06
Yes
Brooks
@Brodavis
Jun 05 2017 01:06
and then instead of console.log that should be answer =?
Jason Luboff
@JLuboff
Jun 05 2017 01:06
Yes
Brooks
@Brodavis
Jun 05 2017 01:07
im confused on the second part
switch (answer) {
  case 1:
  answer = alpha;
  break;
Jason Luboff
@JLuboff
Jun 05 2017 01:07
case 1:
answer = "alpha";
break;
gerome0123
@gerome0123
Jun 05 2017 01:08
how to convert my [Resource] to Resource???
how to convert my [Resource] to Resource???
Joseph
@revisualize
Jun 05 2017 01:09
@Brodavis Look at the breakdown of the code.

@Brodavis If you do...

var answer = "";

then immediately do:

switch (answer) { }

You may as well do...

switch ("") { }
@Brodavis Your function needs to RETURN a value. So, you need to modify answer in your switch case statements.
@Brodavis doing console.log() like you had before only outputs things to the browser console. That doesn't really do anything to modify a variable or how your function returns information.
Raymond
@Raymondshen
Jun 05 2017 01:14
@revisualize Hey whats up! again haha.
Brooks
@Brodavis
Jun 05 2017 01:17
@revisualize Thank you! after some trial and error i got it
CamperBot
@camperbot
Jun 05 2017 01:17
:star2: 4095 | @revisualize |http://www.freecodecamp.com/revisualize
brodavis sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
Bashir Harrell
@bookofbash
Jun 05 2017 01:37
How do I make sure that my project functions on all browsers? I am being told that it isn't working on firefox on windows.
Scott Bell
@KaydenceRyerson
Jun 05 2017 01:44
@xp0sr I'm struggling with the same problem

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

}

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

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);

Yuck that looks gross. sorry everyone. that's what I've got so far, but mine doesn't work either
xp0sr
@xp0sr
Jun 05 2017 01:46
I don't even understand the question
Scott Bell
@KaydenceRyerson
Jun 05 2017 01:47
You're supposed to make a function that keeps a running count of the cards that get played, and then print out whether you should "bet" or "hold" depending on what the number is.
But I feel like this excercise is a big jump from the last problems.
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 01:48

`
function isLess(a, b) {
// Fix this code
switch(a, b){
case (a < b):
return true;

default: 
return false;

}
}

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

Scott Bell
@KaydenceRyerson
Jun 05 2017 01:48
If anyone else has any experience with this xp0sr and I would appreciate it.
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 01:49
can someone tell me why this is not working?

function isLess(a, b) {
// Fix this code
switch(a, b){
case (a < b):
return true;

default: 
return false;

}
}

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

function isLess(a, b) {
// Fix this code
switch(a, b){
case (a < b):
return true;
default:
return false;
}
}

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

xp0sr
@xp0sr
Jun 05 2017 01:50
@dmsdesignz send me the link of the section
how do you use a switch with only two cases?
xp0sr
@xp0sr
Jun 05 2017 01:52
@KaydenceRyerson freeCodeCamp needs to work on their curriculum haha
@dmsdesignz trying to figure it out
@dmsdesignz delete all the switch statements and add
return a<=b;
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 01:58
@xp0sr duh...
thanks for helping!
CamperBot
@camperbot
Jun 05 2017 01:58
dmsdesignz sends brownie points to @xp0sr :sparkles: :thumbsup: :sparkles:
:cookie: 197 | @xp0sr |http://www.freecodecamp.com/xp0sr
xp0sr
@xp0sr
Jun 05 2017 01:59
@dmsdesignz anytime
@KaydenceRyerson no clue?
BernardMaling
@BernardMaling
Jun 05 2017 02:03

I am super confused right now, can anyone direct me to a good resource to read about what I'm doing wrong? Thanks in advance!

function nextInLine(arr, item) {
  // Your code here
 var next = item++; 

  arr.push();
  arr.shift();


  return next;  // Change this line
}

```

Guderian Raborg
@hypercuber
Jun 05 2017 02:05
var arr = [1,2,3,4];
arr.push(5); //adds to last
arr.pop(); //deletes last
arr.shift(); //deletes first
arr.unshift(1); //adds to first @BernardMaling 
Scott Bell
@KaydenceRyerson
Jun 05 2017 02:05
xp0sr
@xp0sr
Jun 05 2017 02:06
@hypercuber @BernardMaling or simply
function nextInLine(arr, item) {
  // Your code here
  arr.push(item);

  return arr.shift();  // Change this line
}
Scott Bell
@KaydenceRyerson
Jun 05 2017 02:06
I think on yours you just needed to add the if statement at the end and you would have had it
xp0sr
@xp0sr
Jun 05 2017 02:07
I almost had it. thanks a bunch @KaydenceRyerson
CamperBot
@camperbot
Jun 05 2017 02:07
xp0sr sends brownie points to @kaydenceryerson :sparkles: :thumbsup: :sparkles:
:cookie: 198 | @kaydenceryerson |http://www.freecodecamp.com/kaydenceryerson
Guderian Raborg
@hypercuber
Jun 05 2017 02:08
I need help. When making a button in html you can use value. In js you would use .value but why not instead of dealing with value you use .innerHTML?
BernardMaling
@BernardMaling
Jun 05 2017 02:08
thanks @hypercuber @xp0sr.. My mind is blown.
CamperBot
@camperbot
Jun 05 2017 02:08
bernardmaling sends brownie points to @hypercuber and @xp0sr :sparkles: :thumbsup: :sparkles:
:cookie: 198 | @xp0sr |http://www.freecodecamp.com/xp0sr
:cookie: 355 | @hypercuber |http://www.freecodecamp.com/hypercuber
Guderian Raborg
@hypercuber
Jun 05 2017 02:09
@BernardMaling np :)
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 02:10
how do you do the markups? like for the code box
xp0sr
@xp0sr
Jun 05 2017 02:10
I think innerHTML returns all the markup and stuff but value returns the text node or whatever
@dmsdesignz "" code ""
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 02:10
"code"
""code""
xp0sr
@xp0sr
Jun 05 2017 02:11
@dmsdesignz surround it by three quote looking thingies under the esc key
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 02:11
code
ah ok
and the black box?
BernardMaling
@BernardMaling
Jun 05 2017 02:12
@dmsdesignz 3 backquotes
xp0sr
@xp0sr
Jun 05 2017 02:12
' ' ' code ' ' ' @dmsdesignz
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 02:12
@xp0sr did you get your cards figured out
?
I'm starting it now
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 02:15
i think i have it covered but thanks :)
xp0sr
@xp0sr
Jun 05 2017 02:18
@dmsdesignz np
Guderian Raborg
@hypercuber
Jun 05 2017 02:22
Do I have to use .value stuff here:
<button id="btn">click me</button>

var btn = document.getElementById('btn');//.addEventListener('click', updateBtn);

function updateBtn() {
if (btn.innerHTML === 'click me') {
btn.innerHTML = 'clicked';
} else {
btn.innerHTML = 'click me';
}
}

xp0sr
@xp0sr
Jun 05 2017 02:26
Not necessarily but you have to keep up with your code in case there's other markup inside your <button> tag like <em></em> or <i></i> @hypercuber
Yevgeniy Kudravets
@Kudravets
Jun 05 2017 02:29
hello can someone help me with Mutations?

function mutation(arr) {
var y= arr[0].toLowerCase().toString();
var z= arr[1].toLowerCase().toString();

var answer ='';
for (var i=0; i <y[0].length ; i++){
if(y.indexOf(z[i]) <= -1 ){
answer = false;
}else{
answer = true;
}

}
return answer;
}

mutation(["hello", "hey"]);

but only this is wrong mutation(["hello", "hey"]) should return false.
Guderian Raborg
@hypercuber
Jun 05 2017 02:30
@xp0sr so value is the best option right?
Raymond
@Raymondshen
Jun 05 2017 02:30
function golfScore(par, strokes) {
  // Only change code below this line
  if (strokes === 1) {
    return "Hole-in-one!";
  } else if ( strokes <= par - 2){
    return "Eagle";
  }

  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);
Guderian Raborg
@hypercuber
Jun 05 2017 02:31
@xp0sr thanks
Raymond
@Raymondshen
Jun 05 2017 02:31
so like does the ? par -2 area literally means par subrtacting 2?
xp0sr
@xp0sr
Jun 05 2017 02:31
@hypercuber it depends.
Joseph
@revisualize
Jun 05 2017 02:31
@hypercuber I can get this to work:
<button id="demo" onclick="myFunction()">Try it</button>

<script>
   function myFunction() {
          document.getElementById("demo").innerHTML = "Hello World";
   }
</script>
xp0sr
@xp0sr
Jun 05 2017 02:33
@Raymondshen yes
Raymond
@Raymondshen
Jun 05 2017 02:34
@xp0sr so it says im correct. but it doesnt make sense to me on how it would return if strokes = 4 and par = 5 and if par -2 = "3" then how is that statement still true?
so in the end its 4 <= 3 ? so it should be false?
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 02:35
@xp0sr
var count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
      case (2):
      case (3):
      case (4):
      case (5):
      case (6):
        count++;
        break;
      case (10):
      case ("J"):
      case ("Q"):
      case ("K"):
      case ("A"):
        count--;
        break;
  }
  if (count>0) {
    return count + " bet";
  } else {
    return count + " hold";
  }


  // Only change code above this line
}
can you tell me whats wrong here?
xp0sr
@xp0sr
Jun 05 2017 02:37
@dmsdesignz maybe capitalization. try 'Bet' and 'Hold'
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 02:37
YEP!
thanks
...
lol
xp0sr
@xp0sr
Jun 05 2017 02:39
you need to add more else if statements @Raymondshen
Raymond
@Raymondshen
Jun 05 2017 02:40
@xp0sr yeah i understand but how is it correct though? like why would it return the statement if its false?
Guderian Raborg
@hypercuber
Jun 05 2017 02:40
@xp0sr depends? so if you have <em> <i> etc use value but if it is plain use .innerHTML?
Raymond
@Raymondshen
Jun 05 2017 02:41
@xp0sr it should return the statement as false right?
xp0sr
@xp0sr
Jun 05 2017 02:41
vice versa @hypercuber
Guderian Raborg
@hypercuber
Jun 05 2017 02:41
also what is the dif between <em> <i> ?
xp0sr
@xp0sr
Jun 05 2017 02:42
@hypercuber plus innerHTML is not recommended for security
Guderian Raborg
@hypercuber
Jun 05 2017 02:42
oh
xp0sr
@xp0sr
Jun 05 2017 02:42
@Raymondshen I'm lost here
Guderian Raborg
@hypercuber
Jun 05 2017 02:43
okay @xp0sr
Raymond
@Raymondshen
Jun 05 2017 02:44
@xp0sr you know how when you do the challenges / exercises it will have a green check mark if done correctly. What I'm not understanding from this function I've posted is that. How can it be correct when strokes(4) <= par(5) - 2 => 4 <= 3?
@xp0sr and 4 <= 3 shouldn't be correct but the answers said golf score(4,3) should return "Birdie" and it indeed did.
@xp0sr I thought only if the statement is true then it would return the given string?
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 03:01
why is this not working?

// Setup
var testObj = {
  "hat": "ballcap",
  "shirt": "jersey",
  "shoes": "cleats"
};

// Only change code below this line

var hatValue = testObj.prop1;      // Change this line
var shirtValue = testObj.prop2;    // Change this line
Claudio Restifo
@Marmiz
Jun 05 2017 03:02
@dmsdesignz look at the example:
prop1 and prop2 should be substitued with the key inside the object:
var myObj = {
  key: value
};
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 03:03
ah ok...
well it makes sense now...
Claudio Restifo
@Marmiz
Jun 05 2017 03:06
:+1:
Christopher Watson
@BocWatson
Jun 05 2017 03:13
Hey folks, I'm learning how to make object properties private and I'm at my whit's end with this one... Can someone tell me what I'm doing wrong?

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

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

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

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

var Bike = function() {

 var gear;

  this.getGear = function(num) {
    gear = num;
  };

  this.setGear = function() {

    return gear;
  };
 };


var myCar = new Car();

var myBike = new Bike();
Claudio Restifo
@Marmiz
Jun 05 2017 03:15
@BocWatson well I think that getGear should return the gear you're on, while setGear should update the gear value.
Check what your functions are doing :)
Christopher Watson
@BocWatson
Jun 05 2017 03:15
@Marmiz OH!! haha thanks
CamperBot
@camperbot
Jun 05 2017 03:15
bocwatson sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 922 | @marmiz |http://www.freecodecamp.com/marmiz
ReedGotSpeed
@ReedGotSpeed
Jun 05 2017 03:16
@BocWatson how do you do that.
Christopher Watson
@BocWatson
Jun 05 2017 03:17
@ReedGotSpeed brownie points, or show here code as it does on the exercise?
AminaKhan13
@AminaKhan13
Jun 05 2017 03:17

function bouncer(arr) {
// Don't show a false ID to this bouncer.
var unFalsy = [];

unFalsy = arr.filter(function(arr){
for(var i = 0; i < arr.length; i++){
unFalsy = typeof(arr[i]) === 'boolean';
return unFalsy;
}
});
} Hey can anybody help me with the Falsy bouncers challenge !

Proconsul
@proconsu1
Jun 05 2017 03:18
@BocWatson if you mean the brownie points, just say 'thanks' or 'thank you' in a message in which you tag the person you want the points sent to
tommy
@tommygebru
Jun 05 2017 03:21
@AminaKhan13 is boolean meant to be checked as a string?
Claudio Restifo
@Marmiz
Jun 05 2017 03:24

@tommygebru you can check with type of:

if(typeof(variable) === "boolean")

Or with a Boolean obj wrapper:

Boolean(expression)
AminaKhan13
@AminaKhan13
Jun 05 2017 03:25
@tommygebru no but i dont know how to check it as the normal boolean
AJ
@ShinobiDatCodes
Jun 05 2017 03:26
Hey guys, got a question about accessing nested arrays.
Proconsul
@proconsu1
Jun 05 2017 03:27
@AminaKhan13 note that if you check typeof against the boolean type you can only test against the primitive form, i.e. true and false. you cannot test truthy or falsy that way
Claudio Restifo
@Marmiz
Jun 05 2017 03:27

@AminaKhan13
you can check with type of:

if(typeof(variable) === "boolean")

Or with a Boolean obj wrapper:

Boolean(expression)
AminaKhan13
@AminaKhan13
Jun 05 2017 03:27
@proconsu1 okay then how do i check falsy values ?
Joseph
@revisualize
Jun 05 2017 03:27
@AminaKhan13 Use the Boolean Object Wrapper
Proconsul
@proconsu1
Jun 05 2017 03:28
@AminaKhan13 the second method mentioned my @Marmiz
AminaKhan13
@AminaKhan13
Jun 05 2017 03:28
@ marmis ohh okay ..
Joseph
@revisualize
Jun 05 2017 03:28
@AminaKhan13 You don't even need a for loop
AminaKhan13
@AminaKhan13
Jun 05 2017 03:28
okay i'll try that !
AJ
@ShinobiDatCodes
Jun 05 2017 03:28

If I had for example:

var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    }

and suppose I cannot see the array, so I cannot read the strings inside. How can I ask to know what the value of the second position inside of the array "likes" is?

Joseph
@revisualize
Jun 05 2017 03:28
@AminaKhan13 I don't understand why you have a for loop in your .filter() function.
@ShinobiDatCodes contacts[0].likes[1]
AJ
@ShinobiDatCodes
Jun 05 2017 03:29
usually you can write contacts[0].likes[2] yes...
Joseph
@revisualize
Jun 05 2017 03:30
@ShinobiDatCodes Then what do you want?
AJ
@ShinobiDatCodes
Jun 05 2017 03:30
but what I did not know that there was a property called likes at that position. If I wanted to reference that position with a general call, how would I do it?
Joseph
@revisualize
Jun 05 2017 03:31
@ShinobiDatCodes Do you know that there is a likes key in your object?
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:31
HI everyone.
Proconsul
@proconsu1
Jun 05 2017 03:31
howdy ho
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:31
I am working on the random quote challnage
Joseph
@revisualize
Jun 05 2017 03:31
@ShinobiDatCodes I'm confused what you mean by 'position'.
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:31
anyone know how the quoteondesign.com work?
i am not really underdstand it well and it give me a static
instead of random each time.
tommy
@tommygebru
Jun 05 2017 03:32
@revisualize have a contacts[0].likes[2]
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:32
if you dont use that, canyou suggest another api
Claudio Restifo
@Marmiz
Jun 05 2017 03:32
@tgsoon2002 how's your API call? maybe you're requesting a specific value
AminaKhan13
@AminaKhan13
Jun 05 2017 03:32
@revisualize because without that for loop, it was not showing anything
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:32
this is waht i got $.getJSON("https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1", function(a) {
  console.log(a);
  $("#quoteText").html(a[0].content + "<p>&mdash; " + a[0].title + "</p>")
  $("#twitIcon").href=("https://twitter.com/intent/tweet?text=\"" + a[0].content+ "\"" +  a[0].title)
});
AJ
@ShinobiDatCodes
Jun 05 2017 03:32
@revisualize yes I do because I can see it in the array. My question refers to the application of for loops. If I wanted my function to scan the entire array, is there a way to write a scan for a third level on an array?
Joseph
@revisualize
Jun 05 2017 03:33
@ShinobiDatCodes
var myObj1 = {
     "fName": "Happy",
     "likes": ['dancing' , 'rhythm'],
     "lName": "Feet"
}
@ShinobiDatCodes Do you see that object that I made?
tommy
@tommygebru
Jun 05 2017 03:33
@ShinobiDatCodes write loops within loops
Proconsul
@proconsu1
Jun 05 2017 03:34
@AminaKhan13 the .filter method automatically iterates through the entire source array one element at a time, so a loop inside to do the same thing would be redundant
AJ
@ShinobiDatCodes
Jun 05 2017 03:34
@revisualize yes I do
Claudio Restifo
@Marmiz
Jun 05 2017 03:34
@tgsoon2002 the call is correct. if you visit the url and refresh the page you'll see the quote changing. So there's something wrong in how you handle the new quote
YozhikM
@YozhikM
Jun 05 2017 03:34
Hello, how I can optimize this file? http://mysolaris.xyz/js/custom-slider.js
Joseph
@revisualize
Jun 05 2017 03:34
@ShinobiDatCodes
var myObj2 = {
     "lName": "Feet",
     "likes": ['dancing' , 'rhythm'],
     "fName": "Happy"
}
AminaKhan13
@AminaKhan13
Jun 05 2017 03:34
@proconsu1 yeah i figured that out hehe
Joseph
@revisualize
Jun 05 2017 03:34
@ShinobiDatCodes
var myObj3 = {
     "likes": ['dancing' , 'rhythm'],
     "lName": "Feet",
     "fName": "Happy"
}
@ShinobiDatCodes Out of all 3 objects that I just made.
@ShinobiDatCodes You access all of the "likes" the same way.
myObj1.likes; Gets you the whole array of likes
myObj2.likes; Gets you the whole array of likes
myObj3.likes; Gets you the whole array of likes
@ShinobiDatCodes So, I'm confused what you mean when you state.
AJ
@ShinobiDatCodes
Jun 05 2017 03:35

@revisualize correct. My question then refers to one like this:

var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]

how would you write a look to scan the second value inside of likes, the one that says "Magic" for example.

xp0sr
@xp0sr
Jun 05 2017 03:36

@Raymondshen if golfScore(4,3) is called, the function uses the condition
else if (strokes == par - 1) { return 'Birdie';

so tecnically (3 == 4 - 1) is true. it returns 'Birdie'

Joseph
@revisualize
Jun 05 2017 03:36
@ShinobiDatCodes but what I did not know that there was a property called likes at that position.
AminaKhan13
@AminaKhan13
Jun 05 2017 03:36

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

return Boolean(arr);
}

Raymond
@Raymondshen
Jun 05 2017 03:36
@xp0sr yup i got it
Joseph
@revisualize
Jun 05 2017 03:36
@AminaKhan13 That doesn't work.
Raymond
@Raymondshen
Jun 05 2017 03:36
@xp0sr thanks brotha
CamperBot
@camperbot
Jun 05 2017 03:36
raymondshen sends brownie points to @xp0sr :sparkles: :thumbsup: :sparkles:
:cookie: 207 | @xp0sr |http://www.freecodecamp.com/xp0sr
Joseph
@revisualize
Jun 05 2017 03:36
@AminaKhan13 You need to use .filter()
xp0sr
@xp0sr
Jun 05 2017 03:36
@Raymondshen sorry for the delay
AminaKhan13
@AminaKhan13
Jun 05 2017 03:36
ahhhh this is so frustrating
Raymond
@Raymondshen
Jun 05 2017 03:36
no problem haha.
Joseph
@revisualize
Jun 05 2017 03:37
@ShinobiDatCodes Just write a loop
AJ
@ShinobiDatCodes
Jun 05 2017 03:37
@revisualize I did, but I can only get as far as i and j
AminaKhan13
@AminaKhan13
Jun 05 2017 03:37
@revisualize okay i'll do that
Proconsul
@proconsu1
Jun 05 2017 03:37
@AminaKhan13 the proper way to call the boolean object is Boolean(expression)not boolean(expression) - see the tiny difference?
AminaKhan13
@AminaKhan13
Jun 05 2017 03:38
@proconsu1 OHHH!
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:38
@Marmiz as you see in the quote i show. i just add the content and title direct to my page.
so the url "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1" didnt give me something new. I right now just give me quote from Ken Dyment
AminaKhan13
@AminaKhan13
Jun 05 2017 03:38
okay cool
AJ
@ShinobiDatCodes
Jun 05 2017 03:38
@revisualize I need a third level to scan for multiple values inside the array likes in this example:
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
Joseph
@revisualize
Jun 05 2017 03:38
@ShinobiDatCodes
var myObj3 = {
     "likes": ['dancing' , 'rhythm'],
     "lName": "Feet",
     "fName": "Happy"
}

for (var i = 0; i < myObj3["likes"].length; i++) {
      console.log(myObj3["likes"][i]);
}
@ShinobiDatCodes ...
@ShinobiDatCodes Are you doing this just as a side understanding to that challenge?
@ShinobiDatCodes Like, you've already solved the challenge and you're trying to get a deeper understanding?
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:39
@ShinobiDatCodes scine you can access to the object contacts, you see the property "likes" as array.
AJ
@ShinobiDatCodes
Jun 05 2017 03:39
@revisualize yes, I am trying to understand how would I extend a loop when the multidimensional array goes past 2 or 3 levels.
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:39
so you can just use the index to get that value.
AminaKhan13
@AminaKhan13
Jun 05 2017 03:39
@proconsu1 it says boolean is not defined
Proconsul
@proconsu1
Jun 05 2017 03:40
@AminaKhan13 but don't forget what @revisualize pointed out. you still need to filter that initial array first
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:40
@ShinobiDatCodes so example, you want get second like of akira
AminaKhan13
@AminaKhan13
Jun 05 2017 03:40
arr.filter(function(arr){
return Boolean(arr);
});
}
okay like this ? @proconsu1 @revisualize
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:40
@ShinobiDatCodes contacts[0]["likes"][1]
Joseph
@revisualize
Jun 05 2017 03:41
@AminaKhan13 There is some ambiguity here.
Proconsul
@proconsu1
Jun 05 2017 03:41
@AminaKhan13 very very close
Joseph
@revisualize
Jun 05 2017 03:41

@AminaKhan13

arr.filter(function(x){
     return Boolean(x);
});

I want to remove the ambiguity of the parent arr variable value.

AminaKhan13
@AminaKhan13
Jun 05 2017 03:41
see when i write small b it says boolean is not defined :/
Joseph
@revisualize
Jun 05 2017 03:42
@AminaKhan13 Because Boolean() is a thing in JavaScript
Samwise Lee
@SamwiseUP
Jun 05 2017 03:42
Hello FreeCodeCampers
AminaKhan13
@AminaKhan13
Jun 05 2017 03:42
okay okay ...
Samwise Lee
@SamwiseUP
Jun 05 2017 03:42
working on the weather api exercise and realized codepen is now only using https
Joseph
@revisualize
Jun 05 2017 03:42
@AminaKhan13 Boolean() with a capital B is an object wrapper.
Samwise Lee
@SamwiseUP
Jun 05 2017 03:42
and forces redirect if attemted http connection
Joseph
@revisualize
Jun 05 2017 03:42
@SamwiseUP CORS
AJ
@ShinobiDatCodes
Jun 05 2017 03:43

@revisualize I wrote something like this:

for (i=0;i<contacts.length;i++){
  for (j=0;j<contacts[i].length;j++){
    for(k=0;k<contacts[i].i[j].length;k++)
  }

because the first 2 for looks are fine, they can scan through every position of contacts, then every position on the second level, but when I want to scan through a third level, I have no clue what to write.

I am going based on this array:

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"]
    }
];
Proconsul
@proconsu1
Jun 05 2017 03:43
@AminaKhan13 that return of the Boolean is going to return that object value to the function that called it, in this case the filter. so what is going to return the resulting array to the parent function?
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:43
@Marmiz The URL only give me static quote. the data only contain 1 element and it the same even after i refresh the page. Do you know how to pull new one?
AJ
@ShinobiDatCodes
Jun 05 2017 03:43
@revisualize I meant the first 2 for loops, not for looks. Typo...
AminaKhan13
@AminaKhan13
Jun 05 2017 03:43
@proconsu1 i dont know ....
Joseph
@revisualize
Jun 05 2017 03:44
@ShinobiDatCodes First off.. objects don't have lengths.
Proconsul
@proconsu1
Jun 05 2017 03:44
@AminaKhan13 it would have to be another return statement, wouldn't it? can you spot a good place for it?
AminaKhan13
@AminaKhan13
Jun 05 2017 03:44
@proconsu1 ohhh okay okay
@proconsu1 outside the filter function right ?
AJ
@ShinobiDatCodes
Jun 05 2017 03:45
@revisualize ok, go on. I need to learn this properly.
Proconsul
@proconsu1
Jun 05 2017 03:45
@AminaKhan13 and as before, dont neglect what @revisualize advised
Samwise Lee
@SamwiseUP
Jun 05 2017 03:45
@revisualize Thanks. I'll read up on CORS. So there's a good practice way of making it work?
CamperBot
@camperbot
Jun 05 2017 03:45
samwiseup sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4096 | @revisualize |http://www.freecodecamp.com/revisualize
Proconsul
@proconsu1
Jun 05 2017 03:46
@AminaKhan13 hint: the arr.filter()... call is going to return the filtered array right? the array that you then want to return to end the function call?
Kien Ngoc Nguyen
@tgsoon2002
Jun 05 2017 03:46
@ShinobiDatCodes Your data is not actually Array in Array in Array. It is Array of Object which contain Array
Joseph
@revisualize
Jun 05 2017 03:46
@ShinobiDatCodes
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"]
    }
];

for (var i=0; i < contacts.length; i++){
  console.log(contacts[i].firstName);
  for (j=0;j<contacts[i].likes.length;j++){
    console.log("- " + contacts[i].likes[j]);
  }
}
AminaKhan13
@AminaKhan13
Jun 05 2017 03:46
OMG! Finally got it !! thanks so much @proconsu1 and @revisualize !!
CamperBot
@camperbot
Jun 05 2017 03:46
aminakhan13 sends brownie points to @proconsu1 and @revisualize :sparkles: :thumbsup: :sparkles:
:cookie: 170 | @proconsu1 |http://www.freecodecamp.com/proconsu1
:star2: 4097 | @revisualize |http://www.freecodecamp.com/revisualize
Proconsul
@proconsu1
Jun 05 2017 03:46
@Aminakhan13 :+1:
Joseph
@revisualize
Jun 05 2017 03:47
@ShinobiDatCodes Here's where I think part of your confusion may be.
@ShinobiDatCodes I don't think that you understand Array elements store values.
@ShinobiDatCodes The value that an array element can store can be ANYTHING in JavaScript
@ShinobiDatCodes a string, a number, Another array, An object, a function ... on and on.
@ShinobiDatCodes So, if you want to do something inside of an array element that may be complicated. Make it smaller
var contact = { // note no s ...  contacts  ...  it is just one contact
     "fName": "Happy"
     "lName": "Feet",
     "number": "i",
     "likes": ['dancing' , 'rhythm']
}
@ShinobiDatCodes Then ask yourself. How can I loop through the Likes of this one contact?
Ken Haduch
@khaduch
Jun 05 2017 03:51
@ShinobiDatCodes - your first for loop is a good one - you have an array of objects and your for loop will generate an index that will be useful for accessing the objects. You used contacts[i] as part of your second for loop. You don't need the second (or third) for loops, but you can use contacts[i] to access each object. Now, think about how you would find out if the contact that you are examining (contacts[i]) has a match on the firstName variable's value, using the objects firstName property? That's the first step. Then, how do you determine if an object (again, it's contacts[i] as the object in question) has a particular property, which is given in the variable prop... if you can sort out thost questions and answer them, then you're on the way...
Joseph
@revisualize
Jun 05 2017 03:52
@ShinobiDatCodes
  for (j=0;j<contact.likes.length;j++){
    console.log(contact.likes[j]);
  }
@ShinobiDatCodes Then you can expand upon that by adding the additional for loop wrap to iterate across a larger array.
AJ
@ShinobiDatCodes
Jun 05 2017 03:59
@revisualize @khaduch thank you for taking the time to explain, I have a lot to learn and think about. I have to get these basics down first and understand them fully before trying more complex code. JS is new to me, but I find it beautiful.
@revisualize @khaduch I saved all your explainations, I will read them tomorrow and try some coding. I have to get some shut eye. Good night guys.
Ken Haduch
@khaduch
Jun 05 2017 04:01
@ShinobiDatCodes - good luck and good night!
danghv
@danghv
Jun 05 2017 04:05
i get stuck at https://www.freecodecamp.com/challenges/arguments-optional . Who can help me out, plz
danghv
@danghv
Jun 05 2017 04:08
@jaysie16 how do you need help?
@jaysie16 i think that is a basic challenge
jaysie16
@jaysie16
Jun 05 2017 04:09
i dont understand what it wants me to do
T_T
Manish Giri
@Manish-Giri
Jun 05 2017 04:11
@jaysie16 did you do the earlier challenges on push, shift, unshift, etc?
jaysie16
@jaysie16
Jun 05 2017 04:11
yah2x.
Joseph
@revisualize
Jun 05 2017 04:12

Stand In Line is a CheckPoint where you're supposed to:
Write a function nextInLine which has two parameters
an array (arr) and a number (item).
That part has been done for you here:

function nextInLine(arr, item) { }

With that function declaration you have a function name of nextInLine. You have two parameters arr which represents an array passed into the function and item that represents a number passed to the function.
A few example function calls:

nextInLine([4,3,2] , 1) the values passed to arr is [4,3,2] and the value passed to item is 1

nextInLine([2,4,6,8] , 10) ... arr is [2,4,6,8] & item is 10

nextInLine([2,3,5,7,11] , 13) ... arr is [2,3,5,7,11] & item is 13 (first 5 and 6th prime numbers)

nextInLine([] , 0) ... arr is [] & item is 0

var myArr = [1,3,5,7]; nextInLine(myArr , 9) ... arr is myArr the value [1,3,5,7] a reference to the value of the global variable myArr & item is 9

Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Again the two parameters for the nextInLine function are arr & item.

Per the instructions: Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.

You need to add the number (item) to the end of an array (arr).
You also need to remove the first element from an array (arr).

Then you need to have your function return the removed element from the array arr.

Manish Giri
@Manish-Giri
Jun 05 2017 04:12
there are two steps in that challenge -
  1. add the number item to the end of the array arr
  2. remove the first element from the array arr and return it.
@jaysie16
Joseph
@revisualize
Jun 05 2017 04:12
@jaysie16 ... Can you read my post?
Ken Haduch
@khaduch
Jun 05 2017 04:14
@revisualize - that's a great and detailed description!
Joseph
@revisualize
Jun 05 2017 04:15
@khaduch Thanks.
CamperBot
@camperbot
Jun 05 2017 04:15
revisualize sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2944 | @khaduch |http://www.freecodecamp.com/khaduch
Joseph
@revisualize
Jun 05 2017 04:16
@khaduch I need to try and make it better so that people understand what they need to do.
jaysie16
@jaysie16
Jun 05 2017 04:16
@revisualize TY soo much. ^_^
CamperBot
@camperbot
Jun 05 2017 04:16
jaysie16 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4098 | @revisualize |http://www.freecodecamp.com/revisualize
rod poblete
@rodpoblete
Jun 05 2017 04:19

hi, y need help with the challeng Where do I belong my script dont pass the last test

function getIndexToIns(arr, num) {
  var index = 0;
  var arrAsc = arr.sort(function(a, b) { return a - b;});
  for (var i = 0; i < arr.length; i++)
    if (arr[i] < num)
      index = arr.indexOf(arr[i + 1]);
  return index;
}

only fail with getIndexToIns([2, 5, 10], 15) return -1 instead 3

Proconsul
@proconsu1
Jun 05 2017 04:22
@rodpoblete you did that a bit differently than i did. looking
Travis Rank
@tdrank
Jun 05 2017 04:24

Guys, I need some help with this part:


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

// Only change code above this line
}

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

I don't know why, I've done great and totally understood everything up until this point. I'm totally drawing a blank here. I'm thinking for the parts that have to return "No such contact" and "No such property" maybe an if then would work..

rod poblete
@rodpoblete
Jun 05 2017 04:25
@proconsu1 Could you solve it?
Manish Giri
@Manish-Giri
Jun 05 2017 04:25
@rodpoblete there's an easier way to solve that challenge.
What if you first .push() the number onto the array, then sort it?
Proconsul
@proconsu1
Jun 05 2017 04:26
@rodpoblete i did, but i used a simple push, didn't do a reassignment, and didnt use a loop. so i'm going slow parsing yours before i say anything
Luc Martin
@fmartin5
Jun 05 2017 04:27
@rodpoblete arr.indexOf(arr[i + 1]); is always equal to i+1 right ?
Proconsul
@proconsu1
Jun 05 2017 04:28
ahh, i thought something looked off down there, but couldn't put my finger on it. the use of the loop was throwing me
rod poblete
@rodpoblete
Jun 05 2017 04:29
@Manish-Giri ok. I'll try
Luc Martin
@fmartin5
Jun 05 2017 04:29
Anyway, your loop does not handle the case where the input value is greater than the max element of the array, @rodpoblete
rod poblete
@rodpoblete
Jun 05 2017 04:29
@proconsu1 I'll see, I'll try your method
Proconsul
@proconsu1
Jun 05 2017 04:31
@rodpoblete minor tip, the .indexOf method can be appended to close of the sort function to tighten it up a bit
rod poblete
@rodpoblete
Jun 05 2017 04:32
@proconsu1 ok thanks
CamperBot
@camperbot
Jun 05 2017 04:32
rodpoblete sends brownie points to @proconsu1 :sparkles: :thumbsup: :sparkles:
:cookie: 171 | @proconsu1 |http://www.freecodecamp.com/proconsu1
rod poblete
@rodpoblete
Jun 05 2017 04:32
@fmartin5 thanks
Luc Martin
@fmartin5
Jun 05 2017 04:32
you're welcome
Proconsul
@proconsu1
Jun 05 2017 04:33
@fmartin5 silly bot doesn't wanna give out thanks cookies
CamperBot
@camperbot
Jun 05 2017 04:33
proconsu1 sends brownie points to @fmartin5 :sparkles: :thumbsup: :sparkles:
:cookie: 300 | @fmartin5 |http://www.freecodecamp.com/fmartin5
Luc Martin
@fmartin5
Jun 05 2017 04:33
haha
rod poblete
@rodpoblete
Jun 05 2017 04:33
jajaja
@fmartin5 thanks again
CamperBot
@camperbot
Jun 05 2017 04:33
rodpoblete sends brownie points to @fmartin5 :sparkles: :thumbsup: :sparkles:
:cookie: 301 | @fmartin5 |http://www.freecodecamp.com/fmartin5
Luc Martin
@fmartin5
Jun 05 2017 04:34
@proconsu1 did more than me
Jeremy
@JeremyAntonoff
Jun 05 2017 04:34
Do unit testing or assertion test functions go before or after your code typically
Proconsul
@proconsu1
Jun 05 2017 04:37
curious to see the answer to that one myself
Luc Martin
@fmartin5
Jun 05 2017 04:37
unit tests often go in separate files
Manish Giri
@Manish-Giri
Jun 05 2017 04:38
there's typically two separate folders(packages)
like in jUnit you have main and test
main holds all your implementation code
test holds your test code to test out your implementations.
Luc Martin
@fmartin5
Jun 05 2017 04:40
if you have tests just next to your code then it is almost like python doctests
Jody LeCompte
@jodylecompte
Jun 05 2017 04:41
LPT: 6/5 scientists agree writing your tests first will lead to less pain
Jeremy
@JeremyAntonoff
Jun 05 2017 04:41
that makes sense.
Jody LeCompte
@jodylecompte
Jun 05 2017 04:41
but yeah, I keep them in a separate directory that mirrors my src directory
Manish Giri
@Manish-Giri
Jun 05 2017 04:41
ayyy Jody
Jeremy
@JeremyAntonoff
Jun 05 2017 04:41
thanks @fmartin5 and @Manish-Giri
CamperBot
@camperbot
Jun 05 2017 04:41
jtoddfl sends brownie points to @fmartin5 and @manish-giri :sparkles: :thumbsup: :sparkles:
:cookie: 302 | @fmartin5 |http://www.freecodecamp.com/fmartin5
:star2: 5835 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jun 05 2017 04:41
how's it going bud
@jodylecompte
Luis Felipe López G.
@luishendrix92
Jun 05 2017 04:41
ayyy LMAO
Manish Giri
@Manish-Giri
Jun 05 2017 04:41
ayyy
Luis Felipe López G.
@luishendrix92
Jun 05 2017 04:41
want some clojure help?
Manish Giri
@Manish-Giri
Jun 05 2017 04:41
:alien:
Jody LeCompte
@jodylecompte
Jun 05 2017 04:41
Which channel am I in?!?!
Jeremy
@JeremyAntonoff
Jun 05 2017 04:41
manish i think i saw your stuff on github
Jody LeCompte
@jodylecompte
Jun 05 2017 04:41
:alien:
Manish Giri
@Manish-Giri
Jun 05 2017 04:41
@luishendrix92 :wave:
Luis Felipe López G.
@luishendrix92
Jun 05 2017 04:41
HelpClojure
we've taken over
:wave:
Manish Giri
@Manish-Giri
Jun 05 2017 04:41
lol
Jody LeCompte
@jodylecompte
Jun 05 2017 04:42
I assumed this was coming
Manish Giri
@Manish-Giri
Jun 05 2017 04:42
been a while guys
how's it going
Jody LeCompte
@jodylecompte
Jun 05 2017 04:42
Ill sign up for the Racket Rebel Alliance
I'll fight your lisp with my lisp
Manish Giri
@Manish-Giri
Jun 05 2017 04:42
@JToddFL really?! cool!
Jeremy
@JeremyAntonoff
Jun 05 2017 04:42
@Manish-Giri did you ever finish the HR prep
Manish Giri
@Manish-Giri
Jun 05 2017 04:42
@JToddFL I did like 80% of module 1, then I left it
Luis Felipe López G.
@luishendrix92
Jun 05 2017 04:42
just came to see what was cooking with the javas scripts
Jeremy
@JeremyAntonoff
Jun 05 2017 04:42
did you do the interview?
Manish Giri
@Manish-Giri
Jun 05 2017 04:42
got sick of them repeating the same shitty problems over and over again
no not yet
maybe soon
Jeremy
@JeremyAntonoff
Jun 05 2017 04:43
i needed that repetition in module 1
the next modules are harder
and better
Manish Giri
@Manish-Giri
Jun 05 2017 04:44
how far along are you?
Jeremy
@JeremyAntonoff
Jun 05 2017 04:44
almost done with module 2
Manish Giri
@Manish-Giri
Jun 05 2017 04:44
nice
Jody LeCompte
@jodylecompte
Jun 05 2017 04:44
@Manish-Giri y u no talk to us in lobby no more
You hate us now!?!! :'(
Jeremy
@JeremyAntonoff
Jun 05 2017 04:44
which is why i asked about assertion testing because it makes you do it
Manish Giri
@Manish-Giri
Jun 05 2017 04:44
ayyy lol
Jeremy
@JeremyAntonoff
Jun 05 2017 04:45
but it never tells you exactly where to put it in your code
but i guess it assumes you will prob have seperate files for it
Manish Giri
@Manish-Giri
Jun 05 2017 04:45
@jodylecompte i'm not on gitter that often anymore
Jeremy
@JeremyAntonoff
Jun 05 2017 04:45
in real world
Jody LeCompte
@jodylecompte
Jun 05 2017 04:45
Should be on gitter all the time
If busy, add more monitors
CS101
Manish Giri
@Manish-Giri
Jun 05 2017 04:45
lol
Timothy Bui
@timothyqbui
Jun 05 2017 05:00

hi guys, anyone able to help?```js
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
var checkObj = myObj.hasOwnProperty("");
return checkObj;
}
// Test your code by modifying these values
checkObj("pet");
```

Travis Rank
@tdrank
Jun 05 2017 05:01
I really need some help on this one:
//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
 if (prop != contacts[0])
   return "No such property";
  else if (firstName != contacts.firstName)
    return "No such contact";
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
xp0sr
@xp0sr
Jun 05 2017 05:01
@tdrank on same challenge hah
Travis Rank
@tdrank
Jun 05 2017 05:01
I know the "no such contact" part is def not right...
Thomas Mullen
@t-mullen
Jun 05 2017 05:01
@timothyqbui myObj.hasOwnProperty("") checks if myObj has the property named "". (Or just an empty string)
Travis Rank
@tdrank
Jun 05 2017 05:01
Ya I don't know why but I just can't see it..
Normally I can kinda see it in my head and then I just have to figure out the right syntax but I am really blank on this one...
any tips?
Manish Giri
@Manish-Giri
Jun 05 2017 05:02
@timothyqbui return checkObj;
what's this returning?
the function name?
Travis Rank
@tdrank
Jun 05 2017 05:03
I think on fcc it is basically like console.log
Timothy Bui
@timothyqbui
Jun 05 2017 05:03
suuposed to do this
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found"
xp0sr
@xp0sr
Jun 05 2017 05:03
@timothyqbui
if (myObj.hasOwnProperty(checkProp) === false) { return "Not Found"; } else if (myObj.hasOwnProperty(checkProp) === true) { return myObj[checkProp]; }
connor-5
@connor-5
Jun 05 2017 05:03
@tdrank I struggled with that one a couple days ago. You'll want to use a loop
Thomas Mullen
@t-mullen
Jun 05 2017 05:04
@tdrank You're going to want to look at each contact. Your first comparison is comparing this:
"likes"
to this:
{
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    }
Travis Rank
@tdrank
Jun 05 2017 05:04
Ahhhh... So just check each part of the the array one at a time?
Timothy Bui
@timothyqbui
Jun 05 2017 05:04
@xp0sr thanks...thats...a bit difficult to figure for me
CamperBot
@camperbot
Jun 05 2017 05:04
timothyqbui sends brownie points to @xp0sr :sparkles: :thumbsup: :sparkles:
:cookie: 219 | @xp0sr |http://www.freecodecamp.com/xp0sr
Proconsul
@proconsu1
Jun 05 2017 05:04
@tdrank you have a few problems there. first you are skipping the step of checking if the name is present . also, you are leaving out the curly brackets for your if/else statements
Thomas Mullen
@t-mullen
Jun 05 2017 05:04
@tdrank Exactly. Time for a For loop.
Travis Rank
@tdrank
Jun 05 2017 05:04
Hmmm.. Lemme see what I can come up with..
Thanks so much @RationalCoding
CamperBot
@camperbot
Jun 05 2017 05:05
tdrank sends brownie points to @rationalcoding :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @rationalcoding |http://www.freecodecamp.com/rationalcoding
Travis Rank
@tdrank
Jun 05 2017 05:05
And thanks @proconsu1
CamperBot
@camperbot
Jun 05 2017 05:05
:cookie: 172 | @proconsu1 |http://www.freecodecamp.com/proconsu1
tdrank sends brownie points to @proconsu1 :sparkles: :thumbsup: :sparkles:
Manish Giri
@Manish-Giri
Jun 05 2017 05:05
@xp0sr we don't post answers like that here.
doesn't help people learn.
xp0sr
@xp0sr
Jun 05 2017 05:06
@Manish-Giri sorry beginner mistake
Manish Giri
@Manish-Giri
Jun 05 2017 05:06
np
Proconsul
@proconsu1
Jun 05 2017 05:07
@xp0sr twenty lashes with a piece of boneless spaghetti! ... err, or something...
tommy
@tommygebru
Jun 05 2017 05:08
spaghetti code
xp0sr
@xp0sr
Jun 05 2017 05:09
@proconsu1 lost here
Proconsul
@proconsu1
Jun 05 2017 05:10
@xp0sr just a variation an old joke, 20 lashes with a wet noodle, i.e. fake punishment
xp0sr
@xp0sr
Jun 05 2017 05:11
I suck at getting jokes hah @proconsu1
Proconsul
@proconsu1
Jun 05 2017 05:11
@xp0sr prolly means yer a lot better at coding than i am. a literal turn of mind is an asset here
xp0sr
@xp0sr
Jun 05 2017 05:12
I wish that was right @proconsu1
@proconsu1 can u help me understand this?
https://www.freecodecamp.com/challenges/profile-lookup#?solution=%0A%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUpProfile(firstName%2C%20prop)%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afor%20(var%20i%20%3D%200%3B%20i%20%3C%20contacts.length%3B%20i%2B%2B)%20%7B%0A%20%20if%20(contacts%5Bi%5D.firstName%20%3D%20firstName)%20%7B%0A%20%20%20%20%0A%20%20%7D%3B%0A%7D%0A%20%20%0A%20%20%0A%20%20%0A%20%20%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Akira%22%2C%20%22likes%22)%3B%0A
Proconsul
@proconsu1
Jun 05 2017 05:15
you're starting out fine there, testing first for the name. now, if the name is indeed there, what do you need to do next according to the instructions?
oops
there is a problem. the = sign is an assignment, not a comparison. what sign do you use to test for equivalence rather than assign it?
xp0sr
@xp0sr
Jun 05 2017 05:16
@proconsu1 ==
Raymond
@Raymondshen
Jun 05 2017 05:16
Not sure what I'm doing wrong or how to even approach it much... any help here?
Proconsul
@proconsu1
Jun 05 2017 05:17
@xp0sr yep, see where you put = instead of ==?
Raymond
@Raymondshen
Jun 05 2017 05:17

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (1) {
    case 'a                                                                                                  lpha':
      console.log("alpha");
      break;
    case 'two':
      console.log("beta");
      break;
    case 'three':
      console.log("gamma");
      break;
    case 'four':
      console.log("delta");
      break;
  }


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

// Change this value to test
caseInSwitch(1);
Donnie
@Donnie-D
Jun 05 2017 05:17
function destroyer(arr) {
  // Remove all the values
  var result=[];
  var args=Array.prototype.slice.call(arguments);
  return args[0].filter(function(val){
    for(i=1; i<=args.length; i++){
    result.push(val!==args[i]);
    }
    return result;
  });
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
whats wrong with above plz?
xp0sr
@xp0sr
Jun 05 2017 05:18
@proconsu1 yeah got it. but I wrote that blinded. I don;t even get the question
Bhargavi Bhat
@Bhargavi23
Jun 05 2017 05:18
==
Raymond
@Raymondshen
Jun 05 2017 05:18

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (1) {
    case 'alpha':
      console.log("alpha");
      break;
    case 'two':
      console.log("beta");
      break;
    case 'three':
      console.log("gamma");
      break;
    case 'four':
      console.log("delta");
      break;
  }


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

// Change this value to test
caseInSwitch(1);
Proconsul
@proconsu1
Jun 05 2017 05:18
@Raymondshen are you testing against strings , e.g. 'a' 'two', etc. or are you supposed to be testing against numbers, e.g. 1, 2, 3?
Raymond
@Raymondshen
Jun 05 2017 05:18
@proconsu1 rn im learning switch in javascript
Claudio Restifo
@Marmiz
Jun 05 2017 05:19
@Manish-Giri sorry went afk for a bit.
In reply to your question, I really don't know.
I had the same thought as you had, but maybe in that function's process there's something we're missing?
Like how the pointers are assigned?
Proconsul
@proconsu1
Jun 05 2017 05:19
@xp0sr take it one step at a time. you got step, check if the name is present. if it is, what do the instructions ask you to do about it?
Raymond
@Raymondshen
Jun 05 2017 05:19
@proconsu1 I get the foundation and what it does but not really sure how to apply what is being asked in the instruction.
@proconsu1 http://bit.ly/2s7XL3W here's the link
Claudio Restifo
@Marmiz
Jun 05 2017 05:19
@Raymondshen assign the value to answer and return it
Raymond
@Raymondshen
Jun 05 2017 05:20
@Marmiz hmmm as in? like
xp0sr
@xp0sr
Jun 05 2017 05:20
@proconsu1 return its value
Claudio Restifo
@Marmiz
Jun 05 2017 05:20
@Raymondshen but make sure to implement a correct switch first
xp0sr
@xp0sr
Jun 05 2017 05:20
I edited the == and it returned the name
Raymond
@Raymondshen
Jun 05 2017 05:20

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (answer) {
    case 'one':
      console.log("alpha");
      break;
    case 'two':
      console.log("beta");
      break;
    case 'three':
      console.log("gamma");
      break;
    case 'four':
      console.log("delta");
      break;
  }


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

// Change this value to test
caseInSwitch(1);
@Marmiz
Proconsul
@proconsu1
Jun 05 2017 05:21
@Raymondshen a switch is a little similar to a for loop, except that you are defining a specific case for each possible value of the incoming argument. so case 'a':... is saying if the incoming argument is the string 'a', then do whatever... that make sense?
Claudio Restifo
@Marmiz
Jun 05 2017 05:21
@Raymondshen what you want to pass inside the switch is the value (val) of the function
Raymond
@Raymondshen
Jun 05 2017 05:22
@Marmiz okay so the (val) in switch would be subsituted with each case?
Proconsul
@proconsu1
Jun 05 2017 05:22
@xp0sr but back to the instructions now. you have a test to see if the name is present and it appears to be working. so what does the exercise tell you should be done if the name is indeed present?
Raymond
@Raymondshen
Jun 05 2017 05:22
@proconsu1 kind of haha.
Donnie
@Donnie-D
Jun 05 2017 05:22
can somebody tell please why the below messing up?
function destroyer(arr) {
  // Remove all the values
  var result=[];
  var args=Array.prototype.slice.call(arguments);
  return args[0].filter(function(val){
    for(i=1; i<=args.length; i++){
    result.push(val!==args[i]);
    }
    return result;
  });
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Claudio Restifo
@Marmiz
Jun 05 2017 05:24

@Raymondshen

A switch statement first evaluates its expression. It then looks for the first case clause whose expression evaluates to the same value as the result of the input expression

so in other word

var Animal = 'Giraffe';
switch (Animal) {
  case 'Cow':
  case 'Giraffe':
  case 'Dog':
  case 'Pig':
    console.log('This animal will go on Noah\'s Ark.');
    break;
  case 'Dinosaur':
  default:
    console.log('This animal will not.');
}

as you can see I pass into the switch a value, in this case animal.
Since animal=giraffe the function will look far a match and execute the statement console.log

Proconsul
@proconsu1
Jun 05 2017 05:24
@Donnie-D you don't need a for loop inside a filter. the .filter method automatically iterates through the entire source array on its own
Raymond
@Raymondshen
Jun 05 2017 05:25
@Marmiz I see. This made much more sense.
Donnie
@Donnie-D
Jun 05 2017 05:25
@proconsu1 loop is not for the args[0] its for the outer array, filter is on args[0]
xp0sr
@xp0sr
Jun 05 2017 05:25
@proconsu1 return its value
Raymond
@Raymondshen
Jun 05 2017 05:26
@Marmiz so in my case they already provided the caseInSwitch(1);
Proconsul
@proconsu1
Jun 05 2017 05:26
@Donnie-D args[0] isnt an array. it's a number
Raymond
@Raymondshen
Jun 05 2017 05:27
@Marmiz so val would equal 1; and in switch(val), the val would look for the equality of 1 am i correct
Claudio Restifo
@Marmiz
Jun 05 2017 05:27
@Raymondshen in your case they are passing the value from the function caseInSwitch();
so for caseInSwitch(1); val = 1
yes you are :)
Proconsul
@proconsu1
Jun 05 2017 05:27
@xp0sr no, there is something else that it wants you to check.
Raymond
@Raymondshen
Jun 05 2017 05:27
@Marmiz okay so for each case how do i write it out?
Proconsul
@proconsu1
Jun 05 2017 05:27
@xp0sr "The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact."
Raymond
@Raymondshen
Jun 05 2017 05:28
@Marmiz cause I'm thinking of case (1):
console.log("alpha");
break;
Markus Kiili
@Masd925
Jun 05 2017 05:29
@Donnie-D You don't need to transform the arguments object into array if you just loop and access it.
Proconsul
@proconsu1
Jun 05 2017 05:29
@donnie. wait my bad. ignore my last msg to you
Claudio Restifo
@Marmiz
Jun 05 2017 05:29

@Raymondshen as you were:

case [some value]
  expression

no need for the parenthesis in case -->

case 1:
  expression

I'll let you figure out the expression yourself. ;)
The expression is what you want "your function to do"

Proconsul
@proconsu1
Jun 05 2017 05:29
@Donnie-D getting myself messed up trying to juggle 2 challenges at once
Raymond
@Raymondshen
Jun 05 2017 05:30
@Marmiz alright thank you man I'll let you know if i got it figured haha thanks for leaving me to figure it out helps me alot! :+1:
CamperBot
@camperbot
Jun 05 2017 05:30
:cookie: 923 | @marmiz |http://www.freecodecamp.com/marmiz
raymondshen sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
Markus Kiili
@Masd925
Jun 05 2017 05:31
@Marmiz Morning.
Claudio Restifo
@Marmiz
Jun 05 2017 05:32
@Masd925 :wave: morning to you :sunny:
xp0sr
@xp0sr
Jun 05 2017 05:32
@proconsu1 this is the part i dont get
Proconsul
@proconsu1
Jun 05 2017 05:34
@Donnie-D ok, here are a couple of bits and then a general tip. first bit: result.push(val!==args[i]); .push is going to send either true or false into the designated array.
second bit: for(i=1; i<=args.length; i++){ this end condition is going to overrun the end of the array, because there no position in the array that has the same index number as the length. remember, array are zero-index, not 1-index.
and the tip, this might be easier to parse if you first split the initial array out of the larger array so that you can perform operations on the test values separate from the array you testing them against
Travis Rank
@tdrank
Jun 05 2017 05:34
ok one more thing.. I am having trouble figuring out how to check if the "prop" is in the array.. Here's what I've got so far:

//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 (contacts[i].firstName === firstName) {
    return contacts[i][prop];}
  }

   if (contacts.firstName != firstName) {
   return "No such contact";
   }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "address");
Raymond
@Raymondshen
Jun 05 2017 05:34

function caseInSwitch(val) {
  var answer = "";
  // 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  
  return answer;  
}

// Change this value to test
caseInSwitch(1);
@Marmiz
still not quite sure what is wrong? like expression like you've said is
case 1:
expression
Manish Giri
@Manish-Giri
Jun 05 2017 05:41
@Raymondshen console.log("alpha");
Proconsul
@proconsu1
Jun 05 2017 05:41
@Raymondshen you put the case values in [] - that means they are arrays.
Manish Giri
@Manish-Giri
Jun 05 2017 05:41
what's the purpose of these console.log statements?
@Raymondshen
Raymond
@Raymondshen
Jun 05 2017 05:41
@Manish-Giri oh I'm just basing off of the examples provided on the tutorial.
@proconsu1 I remvoed them and stillt he same.
function caseInSwitch(val) {
  var answer = "";
  // 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  
  return answer;  
}

// Change this value to test
caseInSwitch(1);
Manish Giri
@Manish-Giri
Jun 05 2017 05:42
@Raymondshen yes, that's where you're going wrong.
those are just examples, not meant to be copy-pasted as is.
look in your code - return answer;
Proconsul
@proconsu1
Jun 05 2017 05:42
@Raymondshen you're closing in on it. look closer at what the instruction want to do with each match
Manish Giri
@Manish-Giri
Jun 05 2017 05:43
the last line returns the value of answer
which, as of now, is still an empty string
because var answer = "";
connor-5
@connor-5
Jun 05 2017 05:43
@tdrank you can make two if statements in one with the logical and operator, to text both for the name and the prop
Raymond
@Raymondshen
Jun 05 2017 05:43
@Manish-Giri i see
Manish Giri
@Manish-Giri
Jun 05 2017 05:43
@Raymondshen
Raymond
@Raymondshen
Jun 05 2017 05:43
@proconsu1 alright.
Manish Giri
@Manish-Giri
Jun 05 2017 05:43
inside your case statements, instead of console.log
assign the right value to answer
@Raymondshen
Raymond
@Raymondshen
Jun 05 2017 05:44
@Manish-Giri okay let me see if i can figure it out from what you have explained to me.
Travis Rank
@tdrank
Jun 05 2017 05:44
@connor-5 it asks for different messages to be returned: "No such property" or "No such contact"
Proconsul
@proconsu1
Jun 05 2017 05:45
@tdrank right. but take each in its turn, one by one
Raymond
@Raymondshen
Jun 05 2017 05:45
@Manish-Giri AHHH! got it thanks man
CamperBot
@camperbot
Jun 05 2017 05:45
raymondshen sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5838 | @manish-giri |http://www.freecodecamp.com/manish-giri
Proconsul
@proconsu1
Jun 05 2017 05:45
@tdrank first case, the name is there AND the property is associated with that name.
Manish Giri
@Manish-Giri
Jun 05 2017 05:45
:+1:
Raymond
@Raymondshen
Jun 05 2017 05:45
@proconsu1 Thank you too!
CamperBot
@camperbot
Jun 05 2017 05:45
raymondshen sends brownie points to @proconsu1 :sparkles: :thumbsup: :sparkles:
:cookie: 173 | @proconsu1 |http://www.freecodecamp.com/proconsu1
Travis Rank
@tdrank
Jun 05 2017 05:45
Ohhhh
connor-5
@connor-5
Jun 05 2017 05:45
@tdrank yeah but for the first part, you want to test both if the name exists, and then if the property exists somewhere for that name, and then return the property
Raymond
@Raymondshen
Jun 05 2017 05:45

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


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

// Change this value to test
caseInSwitch(1);
@Manish-Giri
Travis Rank
@tdrank
Jun 05 2017 05:46
I see...
Raymond
@Raymondshen
Jun 05 2017 05:46
@Manish-Giri thank you once again haha!
CamperBot
@camperbot
Jun 05 2017 05:46
raymondshen sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: raymondshen already gave manish-giri points
Manish Giri
@Manish-Giri
Jun 05 2017 05:46
so, moral of the story - the examples on the left are only there as a reference
Travis Rank
@tdrank
Jun 05 2017 05:47
I'm having trouble with how to check if prop is in the array
Raymond
@Raymondshen
Jun 05 2017 05:47
@Manish-Giri yeah haha, but i still didn't fully understand how it worked but now i understand what you mean haha. Thanks again man!
CamperBot
@camperbot
Jun 05 2017 05:47
raymondshen sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: raymondshen already gave manish-giri points
Travis Rank
@tdrank
Jun 05 2017 05:47
like what would it look like? contacts.prop?
Manish Giri
@Manish-Giri
Jun 05 2017 05:47
welcome
@Raymondshen
Markus Kiili
@Masd925
Jun 05 2017 05:47
@tdrank First you need to loop and access each contact. Then test the looped contact.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 05:48
need help in reversing a string

var string;
var output;
function reverseString(str) {
string = str.split(" ");
output=string.reverse() ;
return output.join(" ");
}

reverseString("hello");

Travis Rank
@tdrank
Jun 05 2017 05:48
@connor-5 thank you!
CamperBot
@camperbot
Jun 05 2017 05:48
tdrank sends brownie points to @connor-5 :sparkles: :thumbsup: :sparkles:
:cookie: 242 | @connor-5 |http://www.freecodecamp.com/connor-5
Travis Rank
@tdrank
Jun 05 2017 05:48
you are a great teacher!
Markus Kiili
@Masd925
Jun 05 2017 05:48
@Tatwamsiddha-Nanda Split to an array of characters with .split("")
You can also chain those method calls.
Travis Rank
@tdrank
Jun 05 2017 05:49
lemme see what I can come up with..
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 05:49
shit i thought just to reverse the sentence without reversing the words
Markus Kiili
@Masd925
Jun 05 2017 05:50
@Tatwamsiddha-Nanda Declare those variables inside the function.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 05:50
thanks @Masd925
CamperBot
@camperbot
Jun 05 2017 05:50
tatwamsiddha-nanda sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4193 | @masd925 |http://www.freecodecamp.com/masd925
Vedant Kashyap
@vedant15188
Jun 05 2017 05:51

Hey guys im stuck in Everything Be True challenge...
https://www.freecodecamp.com/challenges/everything-be-true

Could anybody tell me what's wrong with my code?


function truthCheck(collection, pre) {
  console.log(collection[0][pre]);
  // Is everyone being true?
  for(var i=0; i<collection.length; i++) {
//     console.log(collection[i][pre]);
    if(collection[i][pre]===undefined || collection[i][pre]===0 || collection[i][pre]===null || collection[i][pre]==="" || isNaN(collection[i][pre]))
      return false;
  }
  return true;
}

truthCheck([{"single": "double"}, {"single": NaN}], "single");
Matt Smith
@Aakduce
Jun 05 2017 05:53
i dont get the last part of Storing Values with the Assignment Operator i have a and b = 7 but i dnt get how to get a and b togather
Proconsul
@proconsu1
Jun 05 2017 05:54
@vedant15188 i wonder if the Boolean(expression) object wrapper might work better for the truthy/falsy check
Markus Kiili
@Masd925
Jun 05 2017 05:54
@vedant15188 You need a second nested loop or iteration through source's keys.
@proconsu1 Even simpler way to test for truthy value is if(val){...}
Markus Kiili
@Masd925
Jun 05 2017 05:56
@proconsu1 Boolean(val) is using the Boolean function. Boolean wrapper would be new Boolean(val).
Andrea Mammoliti
@AndreusSH
Jun 05 2017 05:57
hi @all I have problems with "Target the same element with multiple jQuery Selectors".
jQuery.PNG
Proconsul
@proconsu1
Jun 05 2017 05:57
@Masd925 yeah, my bad
@connor-5 i'm in no way adept with .map yet. i did that one with a cludge of nested for loops, so i'll be eavesdropping on the advice you get here :-P
ErickMateli
@Erickmateli
Jun 05 2017 06:00
Hello everyone i have a -problem with the escape sequences in string...first what does this error mean...myStr should have encoded text with the proper escape sequences and no spacing...coz that is the test remaining for me to pass the test....here is my code for the challenge........var myStr ="FirstLine \n\SecondLine\ThirdLine\r"; // Change this line
connor-5
@connor-5
Jun 05 2017 06:00
@proconsul1 yeah I had to do the same thing with the Title case challenge, which wound up being like 12 lines of code in length lol (probly should've been 5)
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:00
function factorialize(num) {
var k=1;
var x;
while(num>0)
{
x=num%10;
k=k*x;
num=(num-x)/10;
}
return k;
}
factorialize(5);
cant factorialize
xp0sr
@xp0sr
Jun 05 2017 06:02
I need Help
https://www.freecodecamp.com/challenges/profile-lookup#?solution=%0A%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUpProfile(firstName%2C%20prop)%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afor%20(var%20i%20%3D%200%3B%20i%20%3C%20contacts.length%3B%20i%2B%2B)%20%7B%0A%20%20if%20(contacts%5Bi%5D.firstName%20%3D%3D%20firstName)%20%7B%0A%20%20%20%20return%20firstName%3B%0A%20%20%7D%20else%20if%20(contacts%5Bi%5D.hasOwnProperty(prop))%20%7B%0A%20%20%20%20return%20contacts%5Bi%5D%5Bprop%5D%3B%0A%20%20%7D%20else%20if%20(contacts%5Bi%5D.hasOwnProperty(prop)%20%3D%3D%3D%20false)%7B%0A%20%20%20%20return%20%22No%20such%20property%22%3B%0A%20%20%7D%20else%20if%20(contacts%5Bi%5D.firstName%20!%3D%20firstName)%20%7B%0A%20%20%20%20return%20%22No%20such%20contact%22%3B%0A%20%20%7D%0A%7D%0A%20%20%0A%20%20%0A%20%20%0A%20%20%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Akira%22%2C%20%22likes%22)%3B%0A
connor-5
@connor-5
Jun 05 2017 06:02
@Tatwamsiddha-Nanda a for loop is probably easier to work with for that one
Markus Kiili
@Masd925
Jun 05 2017 06:02
@Tatwamsiddha-Nanda No need for that remainder business. Just loop numbers from 2->num and multiply the result with them.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:02
anyone
God I messed up... Thanks @Masd925 and @connor-5
CamperBot
@camperbot
Jun 05 2017 06:05
tatwamsiddha-nanda sends brownie points to @masd925 and @connor-5 :sparkles: :thumbsup: :sparkles:
:cookie: 243 | @connor-5 |http://www.freecodecamp.com/connor-5
:warning: tatwamsiddha-nanda already gave masd925 points
Proconsul
@proconsu1
Jun 05 2017 06:05
@xp0sr a couple of things jumped out at me.
return firstName; - did the instructions ask you return a name?
else if (contacts[i].hasOwnProperty(prop)) { else? aren't you supposed to check if both the name is present AND it has the property? the else here means it will check if the name is NOT present
else if (contacts[i].hasOwnProperty(prop) === false){ no need for the false test. that is implicit in an else statement
return "No such contact"; as long as this is inside the for loop, the loop will never get past one iteration
xp0sr
@xp0sr
Jun 05 2017 06:07
@proconsu1 i joined them with && but I couldn't return both values
Proconsul
@proconsu1
Jun 05 2017 06:08
@xp0sr maybe a nested if would work better. logically like if name is present nested if it has property else if...continue the loop
xp0sr
@xp0sr
Jun 05 2017 06:09
the question is how lol @proconsu1
Proconsul
@proconsu1
Jun 05 2017 06:10
if (code to test name){
   if (code to test property){
      return whateverinstructions said for this case
      }
   } else if (....continue your for loop from here)
Markus Kiili
@Masd925
Jun 05 2017 06:10
@xp0sr As @proconsu1 said, if you make two nested if's for the first name and property existence tests, the structure is the simplest and you only need to add the returns. All elses are then optional and you avoid repeating the conditions too.
xp0sr
@xp0sr
Jun 05 2017 06:12
give me a sec @proconsu1 @Masd925
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:13
how do i remove special characters from a string
Apoorve
@apugoneappu
Jun 05 2017 06:14

function destroyer(arr) {
  // Remove all the values
  var result = arr.filter(function(val){
    for (var i = 1; i < arguments.length; i++) {
      if (val == arguments[i]) {
        return false;
      }
    }
    return true;
  });
  return result;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Can somebody please help as to why this isn't working?
Proconsul
@proconsu1
Jun 05 2017 06:14
@Tatwamsiddha-Nanda remove as i make them show, i.e. remove as in make them not break the string? if the latter you escape them by placing a backslash in front of each one
Markus Kiili
@Masd925
Jun 05 2017 06:14
@apugoneappu You are not accessing destroyers arguments there.
Filter callback function has its own arguments object.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:15
i need to remove them and store the new string
Apoorve
@apugoneappu
Jun 05 2017 06:15
@Masd925 Thank you so much!
CamperBot
@camperbot
Jun 05 2017 06:15
apugoneappu sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4194 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jun 05 2017 06:15
@apugoneappu You can store destroyers arguments object on a variable and use it inside the callback. Or pass it into the callback as value of this using filter syntax arr.filter(callback[, thisArg])
Proconsul
@proconsu1
Jun 05 2017 06:15
@Tatwamsiddha-Nanda ahh, well strings are immutable, so you might consider converting them to something that isn't, like an array perhaps
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:16
can i extract the characters and check their ASCII values with that of the special characters
and then add the characters to a string one by one
i used to do this in c and java
Apoorve
@apugoneappu
Jun 05 2017 06:16
@Masd925 Thanks a ton, will handle it from here. I just can't explain what it's like to have such awesome people ready to help!
CamperBot
@camperbot
Jun 05 2017 06:16
apugoneappu sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: apugoneappu already gave masd925 points
Proconsul
@proconsu1
Jun 05 2017 06:16
@Tatwamsiddha-Nanda yeah, but that is pretty darned inefficient.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:17
so the method here is to change it to an array then filter the special characters?
Markus Kiili
@Masd925
Jun 05 2017 06:17
@Tatwamsiddha-Nanda The easiest way is to use .replace() method and suitable regexp object.
Proconsul
@proconsu1
Jun 05 2017 06:17
@Tatwamsiddha-Nanda like i said, if you convert the string to an array, then you can run a simple .filter method in it to keep just the letters and numbers. then put the resulting array back together into a string again
@Masd925 gah. regexp. i still haven't mustered the mental grit to tackle learning that....
xp0sr
@xp0sr
Jun 05 2017 06:18

@proconsu1 @Masd925

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

what's wrong with this?

Joseph
@revisualize
Jun 05 2017 06:19
@xp0sr You're returning No such contact too early.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:19
how do i just keep alphnumeric characters
Mithun reddy
@mithunreddyt
Jun 05 2017 06:19
Can any one help me I am trying to solve algorithms I am not able solve them. In basic javascript as there are instructions I completed them but in algorithms as there are no instructions I am not getting how to solve them, can any one help me how to approach for problem how to think to get solution
Markus Kiili
@Masd925
Jun 05 2017 06:19
@xp0sr You only need those first two if's and the returns on correct spots.
Proconsul
@proconsu1
Jun 05 2017 06:19
@xp0sr if the catchall "none of this matches" return statement is inside the loop it ends the loop before it can run the second iteration
Joseph
@revisualize
Jun 05 2017 06:19
@Tatwamsiddha-Nanda Regex
@mithunreddyt Which?
Manish Giri
@Manish-Giri
Jun 05 2017 06:20
@mithunreddyt what I do is first trace out the algorithm on paper, then head to the docs(MDN) to see which functions would be useful for my algo.
xp0sr
@xp0sr
Jun 05 2017 06:20
@revisualize too early?
Proconsul
@proconsu1
Jun 05 2017 06:21
@xp0sr remember, a return statement ends the function call, including the loop in progress. so the fail condition, the thing that is supposed to happen if nothing in the loop matches, needs to happen AFTER the loop has ended
Mithun reddy
@mithunreddyt
Jun 05 2017 06:21
From basic algorithms on wards
xp0sr
@xp0sr
Jun 05 2017 06:21
@proconsu1 Oh I see
@proconsu1 @revisualize @Masd925 THANK YOU!!!!!
CamperBot
@camperbot
Jun 05 2017 06:23
xp0sr sends brownie points to @proconsu1 and @revisualize and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 174 | @proconsu1 |http://www.freecodecamp.com/proconsu1
:star2: 4195 | @masd925 |http://www.freecodecamp.com/masd925
:star2: 4099 | @revisualize |http://www.freecodecamp.com/revisualize
Proconsul
@proconsu1
Jun 05 2017 06:23
@xp0sr :+1:
wonder
@wonder2991
Jun 05 2017 06:29

help
```
var charLen = [];
function findLongestWord(str) {
var arr = str.split(' ');
for(var i = 0; i< arr.length; i ++){
charLen.push(arr[i].length);
}
return Math.max.apply(Math, charLen);
}

findLongestWord("May the force be with you");

error: findLongestWord("May the force be with you") should return 5.

Markus Kiili
@Masd925
Jun 05 2017 06:32
@wonder2991 Using a global variable like that can mess up fcc tests.
-> declare it inside the function.
Xarri Jorge
@xarrijorge
Jun 05 2017 06:33
@wonder2991 What is that code suppose to be doing?
Markus Kiili
@Masd925
Jun 05 2017 06:34
@kodinglife That code works fine.
wonder
@wonder2991
Jun 05 2017 06:35
Yeah. It worked. Thanks @Masd925
Xarri Jorge
@xarrijorge
Jun 05 2017 06:35
@Masd925 I not saying it doesn't, I just don't get the Math, charLen part
Stygma Sheikh
@Stygme
Jun 05 2017 06:35
hey can anyone help me on how to do this "properCamelCase should use camelCase in both declaration and assignment sections. " im having a heard time
Markus Kiili
@Masd925
Jun 05 2017 06:36
@kodinglife With apply method, you can pass an array of arguments into any function, instead of the normal argument list.
Xarri Jorge
@xarrijorge
Jun 05 2017 06:38
@Masd925 Ahh. Now that was my confusion. It is easier in ES6 with rest and spread
Markus Kiili
@Masd925
Jun 05 2017 06:38
@kodinglife Yes.
Xarri Jorge
@xarrijorge
Jun 05 2017 06:39
@Masd925 :thumbsup:
Alex Funk
@Ironmetalfist
Jun 05 2017 06:45
for (var i = 0; i > contacts.length; i++){
if (contacts[i].firstName == firstName){
if (contacts[i].hasOwnProperty(prop)){
return contacts[i].prop;
}
else {
return "No such property";
}
}
}
return "No such contact";
for the profile lookup I do not se why this does not work
Markus Kiili
@Masd925
Jun 05 2017 06:45
@Ironmetalfist .prop looks for property key "prop", and not the key stored in parameter prop.
Also use i<contacts.length
I would also recommend to always use strict equality ===.
Joseph
@revisualize
Jun 05 2017 06:47
@Ironmetalfist To add to what @Masd925 stated: 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];
Xarri Jorge
@xarrijorge
Jun 05 2017 06:49
@revisualize well said
Alex Funk
@Ironmetalfist
Jun 05 2017 06:54
@revisualize that makes sense. They made it seem like they did the same thing.
Markus Kiili
@Masd925
Jun 05 2017 06:56
@Ironmetalfist Another way to put it is that when you use the dot notation, you just write the key after the dot, and when you use bracket notation, the key is evaluated from an expression inside the brackets.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:56
cant solve the palindrome challenge

function palindrome(str) {
var a; var b;
var expression =/\W/g;
var noSpecial = str.replace(expression,"");
noSpecial= noSpecial.toLowerCase();
a=noSpecial.split("");
b=a.reverse();
if(str==b) return true;
else return false;
}

palindrome("eye");

Markus Kiili
@Masd925
Jun 05 2017 06:57
@Tatwamsiddha-Nanda You are not removing underscore.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 06:57
where did i go wrong
how to remove underscore
Markus Kiili
@Masd925
Jun 05 2017 06:57
@Tatwamsiddha-Nanda You also need to join the reversed array back to a string and compare it with noSpecial.
@Tatwamsiddha-Nanda You can form the correct regexp using [ ], \W, and _
vksharmaa
@vksharmaa
Jun 05 2017 07:00
help me ! chapter "Stand in Line"
Xarri Jorge
@xarrijorge
Jun 05 2017 07:01
@vksharmaa two moves: arr.push(item); return arr.shift();
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 07:01
is this the expression /\W_/g
Markus Kiili
@Masd925
Jun 05 2017 07:02
@Tatwamsiddha-Nanda You need to group them using [ ] I think.
Manuel
@manny45
Jun 05 2017 07:04
any tips to make my website look nicer https://codepen.io/Mexica/pen/xdBZKE
I mean portfolio
Markus Kiili
@Masd925
Jun 05 2017 07:04
@manny45 You will get more tips if you post on https://gitter.im/FreeCodeCamp/CodeReview
Manuel
@manny45
Jun 05 2017 07:05
thx
@Masd925
Travis Rank
@tdrank
Jun 05 2017 07:05
I can't figure out why when I add in else {return "No such property"; } it gives every result as "No such property". When I take out the else statement it works for all that meet requirements.

//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 (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)) {
    return contacts[i][prop];}
    else {
      return "No such property";
    }
   }



// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Harry", "likes");
aamirfreecode
@aamirfreecode
Jun 05 2017 07:06
function binary(num){
return parseInt(num, 2).toString(10);
}
binary(10000001);
if i do this than its fine
but when I call binary function with argument start with 0 its not work. like if I call function with binary(00100010); it is not working. Can anyone help me to understand why its happening
Markus Kiili
@Masd925
Jun 05 2017 07:06
@manny45 To me, underlining links as an hover effect looks old fashioned.
Tatwamsiddha
@Tatwamsiddha-Nanda
Jun 05 2017 07:07

function palindrome(str) {
var a; var b;
var expression =/[_\W]/g;
var noSpecial = str.replace(expression,"");

noSpecial= noSpecial.toLowerCase();
a=noSpecial.split("");
b=a.reverse();
if(str==b.join("")) return true;
else return false;
}

palindrome("eye");

still not working
Manuel
@manny45
Jun 05 2017 07:07
I tried to make it look more like buttons if know what I mean
@Masd925
Markus Kiili
@Masd925
Jun 05 2017 07:07
@Tatwamsiddha-Nanda You need to compare the joined string with noSpecial, not str.
@manny45 Only the underlining disturbs my eye.
Manuel
@manny45
Jun 05 2017 07:09
How do I make make it more "block looking"
Travis Rank
@tdrank
Jun 05 2017 07:12
Got it!!! :smile: :+1:
RahulP248
@RahulP248
Jun 05 2017 07:15
hi.. i'm lil stuck at a point where i need to make first letter capital of each word in a string. below is the code i've written and it's not working. can someone suggest?

unction titleCase(str) {

var mystr = str.toLowerCase();
var newstr;
var finalstr;

mystr = mystr.split(" ");

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

mystr[i][0] =  mystr[i][0].toUpperCase();

 }

return mystr;

}

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

Markus Kiili
@Masd925
Jun 05 2017 07:16
@RahulP248 Strings are immutable so assigning to string characters is not possible.
@RahulP248 You need to make a new titlecased word from the original mystr[i] and assign it back to myStr[i].
You can use string operations for making the titlecased word.
Xarri Jorge
@xarrijorge
Jun 05 2017 07:21
@RahulP248 after that you also have to add the remainder of the word to mystr[i] using slice(0)
vksharmaa
@vksharmaa
Jun 05 2017 07:22
Hellllppp? chapter "Stand in Line"
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 07:26
what am I missing here?
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = 4;
  this.seats = 5;
  this.engines = 1;
};

//Try it out here
var myCar = new Car(3, 1, 2);
Markus Kiili
@Masd925
Jun 05 2017 07:26
@dmsdesignz You need to use the constructor parameters (wheels, seats, engines) to initialize the object properties defined inside the constructor.
Now you are using fixed values.
Mike Saalwaechter
@dmsdesignz
Jun 05 2017 07:27
oh
tahashin
@tahashinegp
Jun 05 2017 07:28

function titleCase(str) {
var totalString="";
var splitedString= str.split(' ');
for(var i=0;i<splitedString.length;i++){
var newString=splitedString[i];
for(var j=0;j<newString.length;j++){
var c=0;
if(j==0){
if(newString[j]==newString[j].toUpperCase()){
newString[j]+=newString[j];
}
else{
console.log( newString[j]);
newString[j]+=newString[j].toUpperCase();
console.log( newString[j]);
}
}
else{
newString[j]+=newString[j].toLowerCase();
}
}
totalString +=newString;
totalString +=' ';
console.log(totalString);
}

return totalString;

}

titleCase("I am a little tea pot");
can someone tell me why toUpperCase() is not working. It suppose to work.?

Mukul Agrawal
@mukul09
Jun 05 2017 07:28
@vksharmaa what's the problem?
tahashin
@tahashinegp
Jun 05 2017 07:29

function titleCase(str) {
var totalString="";
var splitedString= str.split(' ');
for(var i=0;i<splitedString.length;i++){
var newString=splitedString[i];
for(var j=0;j<newString.length;j++){
var c=0;
if(j==0){
if(newString[j]==newString[j].toUpperCase()){
newString[j]+=newString[j];
}
else{
console.log( newString[j]);
newString[j]+=newString[j].toUpperCase();
console.log( newString[j]);
}
}
else{
newString[j]+=newString[j].toLowerCase();
}
}
totalString +=newString;
totalString +=' ';
console.log(totalString);
}

return totalString;

}

titleCase("I am a little tea pot");

Mike Saalwaechter
@dmsdesignz
Jun 05 2017 07:29
@Masd925 what do you mean?
Markus Kiili
@Masd925
Jun 05 2017 07:29
@tahashinegp It is much simpler if you use string operation for titlecasing a word instead of using character arrays. Strings were invented so we could avoid them.
@dmsdesignz Assign the parameter into this.wheels = and not 4 etc.
lol.lit
@lalit-mohan
Jun 05 2017 07:31

Help: Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.

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

mutation(["hello", "hey"]);

I'm getting true on the given mutation: ["hello", "hey"]. I wonder why and how should I rectify this?

Mukul Agrawal
@mukul09
Jun 05 2017 07:31
@dmsdesignz you are taking parameters as wheels engines and seats so you need to assign them to this.wheels, this.engines and this.seats
Manish Giri
@Manish-Giri
Jun 05 2017 07:34
@el-sulfate so here
if(arr[0].indexOf(arr[1][j]) !== -1){
      //return (arr[0].indexOf(arr[1][j]));
      return true;
    }
tahashin
@tahashinegp
Jun 05 2017 07:34
@Masd925 so i should use subStr(); something like that?
Manish Giri
@Manish-Giri
Jun 05 2017 07:34
if a letter is not present, you're returning true
that indicates it is present.
Deepika Gupta
@deepika-gupta
Jun 05 2017 07:36
what does => symbol do??
Kamal
@kpbro
Jun 05 2017 07:36
I am stuck on profile lookup challenge
function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<contacts.length;i++){
  if(firstName == contacts[i].firstName){
    if(contacts[i].hasOwnProperty(prop)===true){
      return contacts[i][prop];
    }
    else{return "No such property";}
  }
 else {return "No such contact";}
}
// Only change code above this line
}
Manish Giri
@Manish-Giri
Jun 05 2017 07:37
@deepika-gupta it's es6 notation, for fat arrow.
replaces the older function keyword
Kamal
@kpbro
Jun 05 2017 07:37
what i am doing wrong here?
Manish Giri
@Manish-Giri
Jun 05 2017 07:38
add = function (a,b) {
return a + b;
}
can be written as
add = (a,b) => a + b
@deepika-gupta
Claudio Restifo
@Marmiz
Jun 05 2017 07:40
@kpbro how would you know that there is not such contact if you're daclaring it inside the loop?
Isn't it better to assume that there is no one if I look over all the entries first, and if nothing shows up I can assume it's not there?
lol.lit
@lalit-mohan
Jun 05 2017 07:41

@Manish-Giri oh, OK. So if I make the statement as:

if(arr[0].indexOf(arr[1][j])) >= 0

should that work?
am I lacking some concept here?

Manish Giri
@Manish-Giri
Jun 05 2017 07:41
@el-sulfate arr[1][j]
this looks like a 2D array
I don't think you've got one in your code..
Kamal
@kpbro
Jun 05 2017 07:42
@Marmiz So what should I do ?
i mean what I should change?
i am comparing firstname from function parameter with firstname of all array elements.
Claudio Restifo
@Marmiz
Jun 05 2017 07:44
@kpbro after the loop, if nothing shows up return that there is no such contact
for [....]{
}
return [what I have to return]
Kamal
@kpbro
Jun 05 2017 07:47
@Marmiz ok. trying
Didun Morodolu
@wombolo
Jun 05 2017 07:50
Help with Golf Code topic please...
Vedant Kashyap
@vedant15188
Jun 05 2017 07:52

Hey guys im stuck in Everything Be True challenge...
https://www.freecodecamp.com/challenges/everything-be-true

Could anybody tell me what's wrong with my code?


function truthCheck(collection, pre) {
  console.log(collection[0][pre]);
  // Is everyone being true?
  for(var i=0; i<collection.length; i++) {
    var flag=0;
    var keys=Object.keys(collection[i]);
    for(var j=0; j<keys.length; j++) {
      if(keys[i]==pre)
        flag=1;
    }
    if(flag===0)
      return false;
//     if(isNaN(collection[i][pre]))
//       return false;
//     console.log(collection[i][pre]);
    if(collection[i][pre]===0 || collection[i][pre]===undefined || collection[i][pre]===null || collection[i][pre]==="")
      return false;
  }
  return true;
}

truthCheck([{"single": "yes"}], "single");
Benny Thomas
@bentom03
Jun 05 2017 07:52
@wombolo what is the issue with Golf Code?