These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
Jan 2018
叶紫柠檬
@liukaixin123
Jan 22 2018 01:29

我们有一个对象数组,里面存储着通讯录。

函数 lookUp 有两个预定义参数:firstName值和prop属性 。

函数将会检查通讯录中是否存在一个与传入的 firstName 相同的联系人。如果存在,那么还需要检查对应的联系人中是否存在 prop属性。

如果它们都存在,函数返回prop属性对应的值。

如果firstName 值不存在,返回 "No such contact"。

如果prop 属性不存在,返回 "No such property"。

怎么写呢?

Ken Haduch
@khaduch
Jan 22 2018 01:35
@liukaixin123 - there is a room with Chinese speakers - I think that it's https://gitter.im/FreeCodeCamp/chinese
@liukaixin123 - yes, that is the room
叶紫柠檬
@liukaixin123
Jan 22 2018 01:41
thank you
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jan 22 2018 09:49
hey everyone, does anybody know how to make a download button in react? the a tags with downlad are not working in html
Keon Samuel
@keonsam
Jan 22 2018 14:58
any angular guy here?
Jason Luboff
@JLuboff
Jan 22 2018 16:05
:wave: morning all
Matej Bošnjak
@mbosnjak01
Jan 22 2018 16:06
:wave:
Jason Luboff
@JLuboff
Jan 22 2018 16:06
Hows it going?
Blauelf
@Blauelf
Jan 22 2018 16:11
Good afternoon @JLuboff :D
Jason Luboff
@JLuboff
Jan 22 2018 16:11
@Blauelf Hmmm..yes...I would imagine it is afternoon there :P
Blauelf
@Blauelf
Jan 22 2018 16:12
With the winter, it looks more like evening. Little sunshine left somewhere behind the horizon.
Jason Luboff
@JLuboff
Jan 22 2018 16:15
Its bright and sunny here...but cold this morning (well.. cold for here.. 43* F)
Markus Kiili
@Masd925
Jan 22 2018 16:16
Yo.
Kaz Baig
@kbaig
Jan 22 2018 16:16
We seem to be alternating between 0-10F and 40-50F
Blauelf
@Blauelf
Jan 22 2018 16:16
Similar here, 8.6°C. Pretty warm winter, and rainy.
Tiago Correia
@tiagocorreiaalmeida
Jan 22 2018 17:36
hello everyone
Jason Luboff
@JLuboff
Jan 22 2018 17:36
Yo
Tiago Correia
@tiagocorreiaalmeida
Jan 22 2018 17:36
@JLuboff what api ahve you used on the game app you made? will try to build a wishlist about games to pratice react
Jason Luboff
@JLuboff
Jan 22 2018 17:37
@tiagocorreiaalmeida igdb
Tiago Correia
@tiagocorreiaalmeida
Jan 22 2018 17:37
cool thank you :D
Jason Luboff
@JLuboff
Jan 22 2018 17:37
:+1:
Just so you know...its kind of a shitty api. It has a ton of info, but the structure is garbage
sabahatullah
@sabahatullah
Jan 22 2018 17:52
@tiagocorreiaalmeida hey could you help me.
I have been tasked to remove the the second carousel image from this page.
http://www.marksandspencer.com/floral-print-scuba-bodycon-midi-dress/p/p60119469?
I tried doing the following
document.querySelector(".pdp-carousel__list li:nth-child(2)").remove();
but it doesn't remove the main image
sabahatullah
@sabahatullah
Jan 22 2018 18:40
anyone?
could you help me.
I have been tasked to remove the the second carousel image from this page.
http://www.marksandspencer.com/floral-print-scuba-bodycon-midi-dress/p/p60119469?
I tried doing the following
document.querySelector(".pdp-carousel__list li:nth-child(2)").remove();
but it doesn't remove the main image
Diego Mayer
@Chrono79
Jan 22 2018 18:46
As far as I can tell, that way you only remove the control, but you're not modifying the carousel, is there a way you can catch the data before it's rendered and delete it from there?
Diego Mayer
@Chrono79
Jan 22 2018 19:08
I can be wrong as I know very little about angular, I tell what I'm seeing
Christopher McCormack
@cmccormack
Jan 22 2018 19:23
@Chrono79 Agreed - it looks like there's a loadNextImage function that probably references an array and that image is still in the array. Better to remove it before it renders, like you said
Brad
@bradtaniguchi
Jan 22 2018 19:26
I've got a lot of experience with angular if ya need it :D
Jason Luboff
@JLuboff
Jan 22 2018 19:31
@Chrono79 @cmccormack :wave:
Christopher McCormack
@cmccormack
Jan 22 2018 19:31
@JLuboff heya
Diego Mayer
@Chrono79
Jan 22 2018 19:32
:wave:
Jason Luboff
@JLuboff
Jan 22 2018 19:33
How's it going?
Kaz Baig
@kbaig
Jan 22 2018 19:34
@JLuboff what ya workin on? SQL stuff?
Christopher McCormack
@cmccormack
Jan 22 2018 19:34
Went to the office to discover none of my team is in today. Wouldn't be so bad but I usually work from home so I'm not sure why I'm even here :)
Kaz Baig
@kbaig
Jan 22 2018 19:35
FeelsBadMan
Christopher McCormack
@cmccormack
Jan 22 2018 19:35
Oh well at least I get a midsize conference room all to myself for the day
Jason Luboff
@JLuboff
Jan 22 2018 19:35
@kbaig ...been kind of lazy so far this morning. Dealt with a tech coming in to repair a laptop (stupid Lenovo wouldn't just send me the part). Worked a little bit on my C# app. Not much in SQL today
@cmccormack Isn't the office a few hours away?
Christopher McCormack
@cmccormack
Jan 22 2018 19:36
@JLuboff yeah but I stayed in town, we were down for the weekend anyway
i'll head back tomorrow
Jason Luboff
@JLuboff
Jan 22 2018 19:36
Ah
Christopher McCormack
@cmccormack
Jan 22 2018 19:38
@kbaig what are you working on lately?
Jason Luboff
@JLuboff
Jan 22 2018 19:47
@cmccormack So why did your team play hookie today anyhow? Its not a holiday or anything
Christopher McCormack
@cmccormack
Jan 22 2018 19:48
They're all just working at home I guess
Everyone's been sick so it's not that surprising I guess
Jason Luboff
@JLuboff
Jan 22 2018 19:49
Oh man... the flu this year has been horrible apparently
Knock on wood I haven't gotten it. My little man wouldn't be able to deal with it
Brad
@bradtaniguchi
Jan 22 2018 19:50
I was around so many sick people in December, only now I'm getting it tho
Jason Luboff
@JLuboff
Jan 22 2018 19:50
I'm constantly washing my hands/using hand sanitizer at work
Especially if I have to go use someone elses keyboard/mouse :worried:
Brad
@bradtaniguchi
Jan 22 2018 19:51
I think I only got it cuse I went on vacation and was around A LOT of people haha
Christopher McCormack
@cmccormack
Jan 22 2018 19:53
Holiday season is the worst. We are never around kids until the holidays and then BAM one of us or both of us get sick
Never sick the rest of the year
Jason Luboff
@JLuboff
Jan 22 2018 19:56
I generally do okay with not getting sick but my wife has a tendency to get sick more frequently
Kaz Baig
@kbaig
Jan 22 2018 19:57
@JLuboff ah tech issues always suck
@cmccormack struggling to build a weekly reporting system in Wolfram Language using the inbuilt form functionality
Christopher McCormack
@cmccormack
Jan 22 2018 19:57
@JLuboff she needs to touch more doorknobs to build up that immunity :)
Kaz Baig
@kbaig
Jan 22 2018 19:58
It's kinda new so I'm basically the first person to use it to build a 'real product'
Christopher McCormack
@cmccormack
Jan 22 2018 20:01
Looks... interesting
Jason Luboff
@JLuboff
Jan 22 2018 20:01
@cmccormack I have my own office, she's always been in offices with multiple people so.. :satisfied:
Christopher McCormack
@cmccormack
Jan 22 2018 20:01
I remember Wolfram talking about how they would change the world by providing global objects that any app could use without having to create everything over and over again
@JLuboff you get all the gross computers though :D
Kaz Baig
@kbaig
Jan 22 2018 20:03
@cmccormack We're still working on it. I'm one of 7 people whose job it is to actually talk to people outside the company to figure it out
Jason Luboff
@JLuboff
Jan 22 2018 20:03
@cmccormack Hence the bottle of hand sanitizer on my desk :P And if I can, I do my best to just remote in versus going to their desk lol
Kaz Baig
@kbaig
Jan 22 2018 20:04
For the foreseeable future, it's still through iframes that you access our cloud objects to use on your webpages
Christopher McCormack
@cmccormack
Jan 22 2018 20:04
@kbaig somehow I was unaware you worked for Wolfram
Kaz Baig
@kbaig
Jan 22 2018 20:04
@cmccormack ;)
Jason Luboff
@JLuboff
Jan 22 2018 20:05
Damn. @cmccormack throwing mad shade at @kbaig work place
Brad
@bradtaniguchi
Jan 22 2018 20:05
ah good old wolfram, saved my butt in math+physics many times haha
Kaz Baig
@kbaig
Jan 22 2018 20:05
(it's well deserved)
shhh
Christopher McCormack
@cmccormack
Jan 22 2018 20:05
I didn't say anything negative did I? haha
Jason Luboff
@JLuboff
Jan 22 2018 20:06
Well.. you made it sound like so long ago they mentioned this and didn't pull through lol
Christopher McCormack
@cmccormack
Jan 22 2018 20:07
Hah well I wasn't sure if they did or didn't, I just remember that and thought it was a really cool idea
Kaz Baig
@kbaig
Jan 22 2018 20:07
nah he's talking about high level long term goals basically
we're focusing on wolfram language while wolfram|alpha makes us money :D
Jason Luboff
@JLuboff
Jan 22 2018 20:08
What is wolfram language similar to?
Christopher McCormack
@cmccormack
Jan 22 2018 20:12
@kbaig What is Wolfram Notebook? There are references to it but I don't see a way to download it. Is it similar to Jupyter Notebook?
Christopher
@bradley1492
Jan 22 2018 20:14

Hey guys,
I work on the https://www.freecodecamp.org/challenges/exact-change challenge.
Here's my code on codepen:
https://codepen.io/bradley1492/pen/eyXbBw?editors=0012

I tried to establish the following logic but I am hitting a wall here.

  1. Turn everything into pennies in order to avoid floating point error
  2. Create change variable that is the difference between the given cash and the product-price
  3. Replace the Denomination Names like "PENNY" with Numbers in a new array called tester here
  4. Assign the values of the denominations in the cid-array to the tester array
  5. Check by which denomination can the change variable be divided without remain

But at this point something happens that I don't understand. Why is the returnValue getting added up to 41 and not 50 which would be 2x 25 pennies?

Okay I think I would have to work with a break statement, but then my whole loop breaks which I don't want.
Then it would stop in this case with adding 25 once...
Christopher
@bradley1492
Jan 22 2018 20:22

Also I asked this sort of before, but is the following hint saying, that I should convert the denominations into numbers instead of words, like I have done?:

"Life is easier when you get to know the value of each currency type in the register instead of how much money is composed of that particular currency. So be sure to watch out for that."

Tiago Correia
@tiagocorreiaalmeida
Jan 22 2018 20:30
@JLuboff that's some confusing documentation or maybe im on the wrong place
Christopher McCormack
@cmccormack
Jan 22 2018 20:32
@bradley1492 I'd highly recommend just using a reversed version of CID rather than creating a new array and manually assigning values to each element
@bradley1492 if you need to isolate the second value just use the Array map method
@bradley1492 Also using a for loop as your only looping mechanism is probably not the way to go, at least not without a while loop or a recursive call. You need to check each denomination multiple times
Jason Luboff
@JLuboff
Jan 22 2018 20:35
@tiagocorreiaalmeida No, its confusing. There are a ton of different endpoints and some you can link back to others in the same query while others you can't. Its actually pretty shitty lol. Took me a while to grasp how to use it in a way that worked for me
got to this almost what I want
finding confusing where I define what fields to bring back :\
it only brings the game id
not sure if its the normal behavior
Jason Luboff
@JLuboff
Jan 22 2018 20:36
I gotta go run an errand,..but I'll see if I can help when I get back
Tiago Correia
@tiagocorreiaalmeida
Jan 22 2018 20:36
no worries will let you know aswell if I get it works and thanks :D
Kaz Baig
@kbaig
Jan 22 2018 20:37
@cmccormack Jupyter notebooks are actually inspired by us. WL notebooks are basically the front end interface for writing WL
@cmccormack look at Wolfram|One if you want to demo the downloadable version, or Wolfram Development Platform for an in-browser limited experience
Christopher McCormack
@cmccormack
Jan 22 2018 20:40

Huh I wasn't aware of that

IPython Notebook was added to IPython in the 0.12 release[8] (December 2011). IPython Notebook is similar to the notebook interface of other programs such as Maple, Mathematica, and SageMath, a computational interface style that originated with Mathematica in the 1980s.

Pretty cool, I used to use iPython quite a bit and my wife uses Jupyter all the time
Kaz Baig
@kbaig
Jan 22 2018 20:41
Yeah we keep an eye on em ;)
Christopher McCormack
@cmccormack
Jan 22 2018 20:43
Non-sequitur - did FCC recently remove all challenge submissions? I don't see any of them anymore
Tiago Correia
@tiagocorreiaalmeida
Jan 22 2018 20:43
@JLuboff got it working took me a while to understand this docs :D
Kaz Baig
@kbaig
Jan 22 2018 20:43
@cmccormack you mean to submit projects?
Christopher McCormack
@cmccormack
Jan 22 2018 20:44
@kbaig no, the link to your submitted code, under your profile
Kaz Baig
@kbaig
Jan 22 2018 20:45
Maybe. Someone was asking why they couldn't access their old code today
Oh I see the following on my profile page:
Note: We have temporarily disabled viewing and sharing solutions, however they are safely stored in your profile. You can learn more about this here.
Christopher McCormack
@cmccormack
Jan 22 2018 20:46
Guess I should have read more closely :)
Kaz Baig
@kbaig
Jan 22 2018 20:47
Yeah I didn't see that either when trying to help them
Looks like they found an XSS vulnerability. For now, your code won't be pulled up unless it happens to be in localStorage
Christopher McCormack
@cmccormack
Jan 22 2018 20:54
@kbaig thanks good to know
CamperBot
@camperbot
Jan 22 2018 20:54
cmccormack sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 547 | @kbaig |http://www.freecodecamp.org/kbaig
Christopher
@bradley1492
Jan 22 2018 20:58
@cmccormack Thanks a lot for your answer.
  • What would a "reversed" version of cid indicate? What would I reverse here?
  • I created the array, so that I can exchange the denomination description strings like "Penny", "Nickel", "Quarter" etc.. with the numbers like 1, 25, 50.
    I didn't see another possibility. Because I couldn't think of a way to check the sizes of the denominations, without the numbers written out in the array...
  • Is a recursive call a recursive function?
CamperBot
@camperbot
Jan 22 2018 20:58
bradley1492 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1297 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Jan 22 2018 20:59
@bradley1492 your tester array is already doing the reverse, but with a lot more manual work
Christopher
@bradley1492
Jan 22 2018 21:00
@cmccormack Do you mean by reverse --> replacing the description strings with ints?
@cmccormack ohhh reversing the order :) hahaha thanks
CamperBot
@camperbot
Jan 22 2018 21:01
bradley1492 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
api offline
Christopher McCormack
@cmccormack
Jan 22 2018 21:02
@bradley1492 yup :)
@bradley1492 you can do something as simple as this to get the values in reverse order, and use a seperate array in the same order that contains the denomination value ([100, 50, 20, 10, etc...])
> cid.map( function(value) { return Math.round(value[1]*100) } ).reverse()
Christopher
@bradley1492
Jan 22 2018 21:07
@cmccormack alright this is neat, I felt quite awkward "building" up that tester array ^^
Christopher McCormack
@cmccormack
Jan 22 2018 21:08
@bradley1492 good - whenever you feel like you're doing too much work then you probably are :D
Christopher
@bradley1492
Jan 22 2018 21:09
@cmccormack yea I can imagine that, often it's just so tempting to grab the tried and tested lengthy solution...
Christopher McCormack
@cmccormack
Jan 22 2018 21:10
@bradley1492 you'll find that the lengthy code is much more likely to trip over itself in the form of mistypes and errors. If you can keep your code tight and functional you're much less likely to cause an error
Christopher
@bradley1492
Jan 22 2018 21:13

@cmccormack yes I don't even really know how to use map at this point, it was mostly about filter and reduce up until this point.
Hence my use of for-loops
In general I don't quite feel like I reaally grasped filter, map and reduce quite yet.
So I think I have to really get to know the concepts of those inside out, at this point of fcc and the harder algorithms..

But this will be a good moment, to get to know map a bit better! :)

Christopher McCormack
@cmccormack
Jan 22 2018 21:14
@bradley1492 go to https://mdn.io and read up on Map/Filter/Reduce, read all the examples, and test them out with your own examples. They are some of the most useful methods you'll use
Christopher
@bradley1492
Jan 22 2018 21:16
@cmccormack alright, I'll do that certainly. Do you think recursion is as important to really fully understand at this point? I understand it on a basic level, but not really with executing it properly in examples...
Christopher McCormack
@cmccormack
Jan 22 2018 21:16
Map basically just applies a function to your iterable, Reduce uses an accumulator to store a final value in that you build while iterating over an iterable, and Filter requires a true or false to determine if the returned iterable contains the existing value
@bradley1492 Also read up on callbacks if you don't 100% understand them, very important to understand them fully
@bradley1492 recursion is useful in some things, but don't get hung up on it, you probably won't use it again for a while after the recursion exercises
Christopher
@bradley1492
Jan 22 2018 21:20
@cmccormack Okay thanks.
With the afore mentioned functional programming methods, I always got caught up on one specific and basic example. What is the functional equivalent of logging all the values of an array to the console? I never seem to find an example for this, which would be the most basic sort of action in my head...
CamperBot
@camperbot
Jan 22 2018 21:20
bradley1492 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
api offline
Christopher McCormack
@cmccormack
Jan 22 2018 21:20
If you're really interested in recursion, set aside some time to really get to know that as well
Christopher
@bradley1492
Jan 22 2018 21:21
@cmccormack Okay, yes I would do that if it proves its usability in my FCC solutions etc... otherwise I can wait to really understand at a later point...
Christopher McCormack
@cmccormack
Jan 22 2018 21:21
@bradley1492 pretty sure console.log(array) is just fine
Diego Mayer
@Chrono79
Jan 22 2018 21:21
@bradley1492 if you didn't know it, here's a helpful tool to debug your code: http://www.pythontutor.com/javascript.html#mode=edit
Jefferson
@jeffersonnnn
Jan 22 2018 21:22
hi guys, i need help for a piece of code i am playing around with. Can i get help, please? Here is it.

var orderCount = 0

function takeOrder(orderCount = orderCount++){

}

function getSubTotal(itemCount) {
   return itemCount * 7.5;
}

function getTax () {
  return getSubTotal(itemCount) * 0.06;
 }

takeOrder();
console.log(getSubTotal(orderCount));
Christopher McCormack
@cmccormack
Jan 22 2018 21:23
@jeffersonnnn what is the point of this? orderCount = orderCount++
@jeffersonnnn you're basically saying ordercount is equal to ordercount, then incrementing ordercount.
@jeffersonnnn
> var a = 0
> var b = a++
> b
0
> a
1
Diego Mayer
@Chrono79
Jan 22 2018 21:24
@cmccormack it doesn't work either
Christopher McCormack
@cmccormack
Jan 22 2018 21:25
@jeffersonnnn also orderCount will be local to takeOrder, you should move that into the body
Diego Mayer
@Chrono79
Jan 22 2018 21:25
var orderCount = 0

function takeOrder() {
  orderCount++; //you'll be using the global value like this
}

function getSubTotal(itemCount) {
   return itemCount * 7.5;
}

function getTax () {
  return getSubTotal(itemCount) * 0.06;
 }

takeOrder();
console.log(orderCount)
console.log(getSubTotal(orderCount));
takeOrder();
console.log(orderCount)
console.log(getSubTotal(orderCount));
takeOrder();
console.log(orderCount)
console.log(getSubTotal(orderCount));
Christopher
@bradley1492
Jan 22 2018 21:26
@cmccormack Thanks, I'll go and try catching up on functional methods a bit more now! :)
CamperBot
@camperbot
Jan 22 2018 21:26
bradley1492 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
api offline
Jason Luboff
@JLuboff
Jan 22 2018 21:27
@tiagocorreiaalmeida Glad you got it.
Jefferson
@jeffersonnnn
Jan 22 2018 21:27
@cmccormack the idea for the orderCount = orderCount++ is for orderCount to be incremented every time the takeOrder function is called.
Dan Lafferty
@DanLaff
Jan 22 2018 21:30
That looks like a CodeCademy problem - care to share the instructions for what you are trying to accomplish?
Christopher McCormack
@cmccormack
Jan 22 2018 21:30
@jeffersonnnn the first assignment doesn't do anything at all. orderCount++ is equivelent to orderCount = orderCount + 1. orderCount = orderCount++ is saying orderCount = orderCount; orderCount++.
Jefferson
@jeffersonnnn
Jan 22 2018 21:33
adjusted. Here is the code now
var orderCount = 0

function takeOrder(orderCount++){

}

function getSubTotal(itemCount) {
   return itemCount * 7.5;
}

function getTax() {
  return getSubTotal(itemCount) * 0.06;
 }

takeOrder();
console.log(getSubTotal(orderCount));
Christopher McCormack
@cmccormack
Jan 22 2018 21:34
@jeffersonnnn :point_up: January 22, 2018 2:25 PM
I gotta run see you all later
Jefferson
@jeffersonnnn
Jan 22 2018 21:36
@cmccormack thanks youu.
CamperBot
@camperbot
Jan 22 2018 21:36
jeffersonnnn sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1298 | @cmccormack |http://www.freecodecamp.org/cmccormack
Jefferson
@jeffersonnnn
Jan 22 2018 21:54
@Chrono79 it worked. Apparently, i need to take notice if where i place my code because local and global scope. Thanks for the headsup
CamperBot
@camperbot
Jan 22 2018 21:54
jeffersonnnn sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4608 | @chrono79 |http://www.freecodecamp.org/chrono79
Diego Mayer
@Chrono79
Jan 22 2018 21:54
no problem