18th
Aug 2017
Ruchika Sharma
@ruchika90
Aug 18 2017 00:03
@Manish-Giri thx, got it working
CamperBot
@camperbot
Aug 18 2017 00:03
ruchika90 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6432 | @manish-giri |http://www.freecodecamp.com/manish-giri
aRtoo
@artoodeeto
Aug 18 2017 01:11
hi everyone. i dont get the algorithm problem entitled smallest common multiple. i dont quite understand the question but heres my solution and its wrong.

function smallestCommons(arr) {

var lcm = arr[0] * arr[1];
var result = 0;

for(var i=0; i<lcm; i++){
if(i % 2 === 0){
result +=i;
}
}

return result;
}
smallestCommons([1,5]);
Christopher McCormack
@cmccormack
Aug 18 2017 01:39
@artoodeeto I believe for this one you need to test only the numbers between arr[0] and arr[1], and you need to keep doing this until you find the lowest common multiple for all
Greg Duncan
@GregatGit
Aug 18 2017 01:40
@artoodeeto I would write a series of steps (as comments) to break it up and then solve each piece as you go along
Christopher McCormack
@cmccormack
Aug 18 2017 01:41
@cmccormack so first find the larger of the two numbers and make that your lcm, then test all numbers between the lowest and the highest number, then if they don't all divide into the LCM, increase the LCM by itself and try again. Keep doing this until all numbers between arr[0] and arr[1] divide into LCM
Braxton Fair
@fairbraxton
Aug 18 2017 01:59
Hey can anyone here help me with my local weather application JS? I keep getting undefined variables
The latitude and longitude variables aren't being logged
logged in the console, I mean
Manish Giri
@Manish-Giri
Aug 18 2017 02:04
@fairbraxton those variables will be available in the callback that handles them
function setVariables(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
Braxton Fair
@fairbraxton
Aug 18 2017 02:04
is there anyway I could set those globally?
@Manish-Giri ?
Manish Giri
@Manish-Giri
Aug 18 2017 02:10
@fairbraxton one sec
Christopher McCormack
@cmccormack
Aug 18 2017 02:10
@fairbraxton you can set the globally but unless you use them after the async call returns, they will be useless to you
@fairbraxton in the success callback function of your location call is where you want to use that data in the weather app
Gersho
@Gersho
Aug 18 2017 02:11
why not put all that needs to trigger after that within the callback (including whatever api call you'll do next)
Braxton Fair
@fairbraxton
Aug 18 2017 02:12
The .click() callback @Gersho?
I get what you mean, I could, I just kinda went this route for clean code
Christopher McCormack
@cmccormack
Aug 18 2017 02:13
@fairbraxton navigator.geolocation.getCurrentPosition(setVariables); setVariables is the current callback, you could call your weather api function from that function if you want, or combine them
Braxton Fair
@fairbraxton
Aug 18 2017 02:15
Ohhh I see
Let me try that and see how it goes
Manish Giri
@Manish-Giri
Aug 18 2017 02:17
@fairbraxton I tried to use a promise to access the global variables outside of the async callback, but no it didn't work..
Braxton Fair
@fairbraxton
Aug 18 2017 02:20
Alright, thank you @cmccormack, @Gersho, and @Manish-Giri, I think I have what I need to move on!
CamperBot
@camperbot
Aug 18 2017 02:20
fairbraxton sends brownie points to @cmccormack and @gersho and @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 1154 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 6434 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Aug 18 2017 02:23
@fairbraxton take a look
check out the console
Braxton Fair
@fairbraxton
Aug 18 2017 02:24
Thank you @Manish-Giri I got it now!
CamperBot
@camperbot
Aug 18 2017 02:24
fairbraxton sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: fairbraxton already gave manish-giri points
Manish Giri
@Manish-Giri
Aug 18 2017 02:24
:+1:
christopher clarke
@chrisdclarke
Aug 18 2017 02:42
hey guys im trying to use an api for my page, http://labs.bible.org/api/?passage=random but i cant get the getjson(http://labs.bible.org/api/,[passage=random]) function to work... ? any ideas how i can call this and save a passage to random? tx..
Manish Giri
@Manish-Giri
Aug 18 2017 02:43
@chrisdclarke you're on codepen?
christopher clarke
@chrisdclarke
Aug 18 2017 02:43
yep
u think it might have to do with calling apis on codepen??....
Manish Giri
@Manish-Giri
Aug 18 2017 02:46
yep
Ogundele Olumide
@Lumexralph
Aug 18 2017 02:47
@Manish-Giri :smiling_imp: ggggggggggm
christopher clarke
@chrisdclarke
Aug 18 2017 02:47
thanks alot @Manish-Giri
CamperBot
@camperbot
Aug 18 2017 02:47
chrisdclarke sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6435 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Aug 18 2017 02:47
@Lumexralph hey bro how're you
@chrisdclarke :+1:
Ogundele Olumide
@Lumexralph
Aug 18 2017 02:48
@Manish-Giri i'm good, you?
what's up?
Manish Giri
@Manish-Giri
Aug 18 2017 02:55
usual crap
trying to revisit Java, and prep for interviews
haven't been here recently
@Lumexralph
Ogundele Olumide
@Lumexralph
Aug 18 2017 03:00
@Manish-Giri same here bro, the vibe ain't like before but'll always pop in to say hello to you and others I'm familiar with
aRtoo
@artoodeeto
Aug 18 2017 03:18
hey bros i have question. on the finders keepers algo challenge i used .push() method to get the first true number of the filter. what if .push() cant be use how can i stop the loop when it hits the first true value. note you cant use return inside the funcntion filter. heres my code:

function findElement(arr, func) {

var numArr = [];

for(var i=0; i<arr.length; i++){
thisIsShit(arr[i]);
console.log(arr[i]);
}

function thisIsShit(n){
[n].filter(function(x){
console.log(func(x));
if(func(x) === true){
numArr.push(x); //this one. what if i dont want to use push? how can i stop the
code to run after the it hits the first true num?
}
});
}
return numArr[0];
}
Long Nguyen
@longnt80
Aug 18 2017 03:28

@artoodeeto

note you cant use return inside the funcntion filter

Why do you need the filter then?

Eunice Park
@eunicode
Aug 18 2017 03:36
Can anyone please explain what's happening in this callback example from MDN ? My brain is going in circles
function greeting(name) {
}

function processUserInput(callback) {
callback(name);
}

processUserInput(greeting);
Long Nguyen
@longnt80
Aug 18 2017 03:40
@eunipa
processUserInput(greeting); this will call the function processUserInput(callback)
Claudio Restifo
@Marmiz
Aug 18 2017 03:40
@eunipa processUserInput is a function that call another function, passing the name that gets executed after the prompt is confirmed
Long Nguyen
@longnt80
Aug 18 2017 03:40
with the parameter greeting
christopher clarke
@chrisdclarke
Aug 18 2017 03:41
@Manish-Giri are you still here??? how would i call the api at... http://labs.bible.org/api/?passage=random would it be under the variable passage.... so i could.. document.write(passage)?
Manish Giri
@Manish-Giri
Aug 18 2017 03:42
@chrisdclarke
$.getJSON("http://labs.bible.org/api/?passage=random", function(data) { document.write(JSON.stringify(data)) } christopher clarke @chrisdclarke Aug 18 2017 03:43 k.. thanks again.... Claudio Restifo @Marmiz Aug 18 2017 03:43 @Manish-Giri :wave: Manish Giri @Manish-Giri Aug 18 2017 03:44 @Marmiz hey buddy :wave: long time how've you been Eunice Park @eunicode Aug 18 2017 03:45 @longnt80 @Marmiz Thank you very much. Can I ask how greeting is being passed as a parameter? I'm sorry for being so slow. CamperBot @camperbot Aug 18 2017 03:45 eunipa sends brownie points to @longnt80 and @marmiz :sparkles: :thumbsup: :sparkles: :cookie: 511 | @longnt80 |http://www.freecodecamp.com/longnt80 :star2: 1025 | @marmiz |http://www.freecodecamp.com/marmiz Claudio Restifo @Marmiz Aug 18 2017 03:45 busy as heck @Manish-Giri Marc @MWBauer Aug 18 2017 03:45 Hi everyone Claudio Restifo @Marmiz Aug 18 2017 03:47 @eunipa greeting is a regular function call: function greeting(name) { alert('Hello ' + name); } function processUserInput(callback) { var name = prompt('Please enter your name.'); callback(name); // callback == function greeting() [ has been passed as argument in the function call ] } processUserInput(greeting); // this call the function processUserInput with greeting as argument Marc @MWBauer Aug 18 2017 03:47 function palindrome(x) { var lowerCase = x.toLowerCase(); array = lowerCase.match(/\s\W/g); var revStr = array.from(lowerCase).reverse().join(""); if (revStr === lowerCase) { return true; } else { return false; } } THis here is what I hav. Claudio Restifo @Marmiz Aug 18 2017 03:48 @Manish-Giri managed to build a couple of things at work that I'm actually proud of :) What about you? How's your thesis coming along? Marc @MWBauer Aug 18 2017 03:49 just kidding. Long Nguyen @longnt80 Aug 18 2017 03:49 @eunipa Can I ask how greeting is being passed as a parameter? with this: processUserInput(callback) Marc @MWBauer Aug 18 2017 03:49 Have a good night. Long Nguyen @longnt80 Aug 18 2017 03:52 @eunipa (callback) can be anything, it is just a parameter but inside the function, it assumes that callback is a function with this: callback(name) and greeting happens to be that function Eunice Park @eunicode Aug 18 2017 03:54 @Marmiz @longnt80 Thank you both for the detailed explanations. That helped me a lot. I was struggling with the concept of parameters. CamperBot @camperbot Aug 18 2017 03:54 eunipa sends brownie points to @marmiz and @longnt80 :sparkles: :thumbsup: :sparkles: :warning: eunipa already gave longnt80 points :warning: eunipa already gave marmiz points Long Nguyen @longnt80 Aug 18 2017 03:56 @eunipa here's the explaination from FCC, maybe it is easier to understand: https://beta.freecodecamp.com/en/challenges/basic-javascript/passing-values-to-functions-with-arguments Claudio Restifo @Marmiz Aug 18 2017 03:57 @eunipa Without going into deep details consider that: Function parameters are the names listed in the function definition. Function arguments are the real values passed to (and received by) the function. Eunice Park @eunicode Aug 18 2017 04:00 @Marmiz Thank you for summarizing everything so nicely for me CamperBot @camperbot Aug 18 2017 04:00 eunipa sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles: :warning: eunipa already gave marmiz points Eunice Park @eunicode Aug 18 2017 04:01 @longnt80 Thank you for providing an exercising to reinforce learning what parameters are CamperBot @camperbot Aug 18 2017 04:01 eunipa sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles: :warning: eunipa already gave longnt80 points heroiczero @heroiczero Aug 18 2017 04:01 @MWBauer Well \W includes _ @MWBauer you want to get rid of all non-alphanumeric and \Wis equivalent to [^A-Za-z0-9_] from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#character-classes christopher clarke @chrisdclarke Aug 18 2017 04:12 so do i have to do anything besides adding jquery in the settings at codepen to be able to get api's? heroiczero @heroiczero Aug 18 2017 04:14 @chrisdclarke you have to call the APIs with callback so a jsonp christopher clarke @chrisdclarke Aug 18 2017 04:15 ok.. what would the code for that be tx.. heroiczero @heroiczero Aug 18 2017 04:17 @chrisdclarke something like you can either use $.getJSON() or

$.ajax({ dataType: "jsonp", url: url, data: data, success: success }); http://api.jquery.com/jquery.getjson/ christopher clarke @chrisdclarke Aug 18 2017 04:18 ok thanks... Tina Townes @tinatownes Aug 18 2017 04:20 Hello! Can someone tell me if these are the same way of creating the variable args? var args = Array.prototype.slice.call(arguments); and var args = Array.prototype.slice.call(arguments); oops, I mean: var args = Array.from(arguments).slice(1); heroiczero @heroiczero Aug 18 2017 04:22 @tinatownes if you are using ES2015: then var args = Array.from(arguments); is the same as the first statement; @tinatownes or it is slicing at index 1 for the second one Tina Townes @tinatownes Aug 18 2017 04:25 @heroiczero Ah, so, is the second method also ES2015 and allows you to be more flexible and change what index you slice at? Brian @BrianCodes33 Aug 18 2017 04:25 I don’t understand how to write your own tests on code wars heroiczero @heroiczero Aug 18 2017 04:26 @tinatownes yeah it begins .slice(begin, end); where begin and end is optional Tina Townes @tinatownes Aug 18 2017 04:26 but with Array.prototype.slice.call(arguments); I cannot specify where it slices from, or is default slice at 0? John @AnonymousLords Aug 18 2017 04:28 Guys how do i round down a number? Zebralight @zebralight Aug 18 2017 04:29 Math.floor() John @AnonymousLords Aug 18 2017 04:29 thanks @zebralight @zebralight CamperBot @camperbot Aug 18 2017 04:29 anonymouslords sends brownie points to @zebralight :sparkles: :thumbsup: :sparkles: :cookie: 11 | @zebralight |http://www.freecodecamp.com/zebralight Zebralight @zebralight Aug 18 2017 04:29 @AnonymousLords np John @AnonymousLords Aug 18 2017 04:29 How much FCC have you done? 11 cookies :P You knew coding before FCC? heroiczero @heroiczero Aug 18 2017 04:30 @tinatownes you can slice by doing Array.prototype.slice.call(arguments,1); which is the same as the previous statement Zebralight @zebralight Aug 18 2017 04:30 @AnonymousLords a bit, yeah I dunno what 11 cookies means is that a lot? heroiczero @heroiczero Aug 18 2017 04:30 means you completed 11 exercises John @AnonymousLords Aug 18 2017 04:30 Or yuou got some from being thanked Zebralight @zebralight Aug 18 2017 04:31 aah I see gotcha thanks Ogundele Olumide @Lumexralph Aug 18 2017 04:31 @BrianCodes33 depends on the knowledge of TDD or BDD you have to do a unit testing for your function Tina Townes @tinatownes Aug 18 2017 04:32 @heroiczero Ohhh, I see now. Whew. Sometimes reading those Mozilla docs can be confusing. Thank you so much! CamperBot @camperbot Aug 18 2017 04:32 tinatownes sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles: :star2: 1622 | @heroiczero |http://www.freecodecamp.com/heroiczero Tai Jones @taiJones00 Aug 18 2017 04:58 var search = document.getElementById("search").value;$.getJSON(https://www.mediawiki.org/w/api.php?action=query&list=prefixsearch&pssearch=${search}, function() { console.log("it works");$("#wiki-results").write(json[query][prefixsearch][title])
});
why isn't this working in the case where the search id belongs to an html form
it's not writing the json title value or printing to the conosol
Gulsvi
@gulsvi
Aug 18 2017 04:59
@taiJones00 The default behavior of a form is to refresh the page on submit. Are you using preventDefault() above that code to prevent the refresh by chance?
Tai Jones
@taiJones00
Aug 18 2017 04:59
no
the only thing I have above is a document.ready
but does this logic look right
Gulsvi
@gulsvi
Aug 18 2017 05:00
You'll need to attach a sumbit event handler to your form element and use preventDefault() to prevent the refresh on submit. After that, your code looks fine - but your url isn't pointing at wikpedia, it's looking at mediawiki
Here's an example of how to search on enter/submit/click: https://codepen.io/skycoder/pen/MpKpJj
Tai Jones
@taiJones00
Aug 18 2017 05:01
Isn't media wiki the api to get the wiki articles
Gulsvi
@gulsvi
Aug 18 2017 05:01
Yes, but that API is used on all the various media wiki sites, including wikipedia
Tai Jones
@taiJones00
Aug 18 2017 05:01
oh hi sky you get a new profile picture
oh I see
Gulsvi
@gulsvi
Aug 18 2017 05:02
I've been changing it around, thought I'd look like an asian blue-eyed blond-haired guy for a while :)
Tai Jones
@taiJones00
Aug 18 2017 05:02
good on ya
the point of this pen is showing that it recognizes something was typed and what was typed?
Gulsvi
@gulsvi
Aug 18 2017 05:04
Yes, it's meant to show you how to capture what the person wants to search for
John
@AnonymousLords
Aug 18 2017 05:04
@SkyC0der i need help in help frontend if you have time :P
ArchivalBoat50
@ArchivalBoat50
Aug 18 2017 05:47
Hey guys, how do I get this JSON to show it's default properties? for example I viewed freecodecamps and it is currently offline right now so one of it's properties would say stream = null. But I wanna know what the property is when it is online. Like is it : stream: online
{
"stream": null,
"self": "https://api.twitch.tv/kraken/streams/freecodecamp",
"channel": "https://api.twitch.tv/kraken/channels/freecodecamp"
}
}
Markus Kiili
@Masd925
Aug 18 2017 05:53
@ArchivalBoat50 Where are you getting that JSON?
ArchivalBoat50
@ArchivalBoat50
Aug 18 2017 05:55
Markus Kiili
@Masd925
Aug 18 2017 05:56
@ArchivalBoat50 APIs usually have docs that describe such things.
ArchivalBoat50
@ArchivalBoat50
Aug 18 2017 05:58
@Masd925 Hmm where can I find the docs?
@Masd925 oh nvm i think i may have found it
Markus Kiili
@Masd925
Aug 18 2017 06:00
@ArchivalBoat50 :+1:
ArchivalBoat50
@ArchivalBoat50
Aug 18 2017 06:04

Ok so my code would be kind of like

if (data.stream = null) {
(stuff happens) ;
}
else if (data.stream = live) {
(stuff happens);
}

How exactly would I input the condition of it being online but the property looking like this:

"stream": {
"_id": 23932774784,
"game": "BATMAN - The Telltale Series",
"viewers": 7254,
"video_height": 720,
"average_fps": 60,
"delay": 0,
"created_at": "2016-12-14T22:49:56Z",
"is_playlist": false,
"preview": {
"small": "https://static-cdn.jtvnw.net/previews-ttv/live_user_dansgaming-80x45.jpg",
"medium": "https://static-cdn.jtvnw.net/previews-ttv/live_user_dansgaming-320x180.jpg",
"large": "https://static-cdn.jtvnw.net/previews-ttv/live_user_dansgaming-640x360.jpg",
"template": "https://static-cdn.jtvnw.net/previews-ttv/live_user_dansgaming-{width}x{height}.jpg"
},

Do I use the individual properties that the stream has?

Because this way, I would actually have no idea of how I can use jquery with these properties to show a certain streamer being online
Joseph
@revisualize
Aug 18 2017 06:07
Hello.
ArchivalBoat50
@ArchivalBoat50
Aug 18 2017 06:08
Hi
Markus Kiili
@Masd925
Aug 18 2017 06:08
@ArchivalBoat50 Just else {...}
ArchivalBoat50
@ArchivalBoat50
Aug 18 2017 06:08
@Masd925 Ohhh
Markus Kiili
@Masd925
Aug 18 2017 06:08
@revisualize Yo.
Joseph
@revisualize
Aug 18 2017 06:08
@Masd925 How goes it?
Markus Kiili
@Masd925
Aug 18 2017 06:09
@ArchivalBoat50 It needs to be if(data.stream===null) <- not =
Joseph
@revisualize
Aug 18 2017 06:09
@ArchivalBoat50 = is assignment
Markus Kiili
@Masd925
Aug 18 2017 06:09
@revisualize Same old. 2 hours still for lunch.
Joseph
@revisualize
Aug 18 2017 06:09
@Masd925 You get 2hrs for lunch!?
You lucky bastard.
Markus Kiili
@Masd925
Aug 18 2017 06:10
@revisualize I mean its 9:10 and lunch is at 11:00
ArchivalBoat50
@ArchivalBoat50
Aug 18 2017 06:10
@Masd925 @revisualize Oh sorry, I haven't coded in like 2 months lol thx for pointing that out
CamperBot
@camperbot
Aug 18 2017 06:10
archivalboat50 sends brownie points to @masd925 and @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4440 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 4423 | @masd925 |http://www.freecodecamp.com/masd925
Joseph
@revisualize
Aug 18 2017 06:10
OH ... 2 hrs till lunch.
LOL.
@Masd925 I spent my lunch today down at the Department of Licencing trying to get my ID card renewed.
Lunch + 45min.
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:11
Can someone tell me how to use the json data I added to this to display the weather and whatnot?
Joseph
@revisualize
Aug 18 2017 06:12
/collapse-all
Markus Kiili
@Masd925
Aug 18 2017 06:13
@EricHasegawa Usually you pass a callback function to the geolocation method. You access DOM inside that callback function.
Aug 18 2017 06:27
can anyone solve my problem really appreciated...
https://pastebin.com/cgkq0BFk
Markus Kiili
@Masd925
Aug 18 2017 06:31
@rohyadav You get help better by pasting some code and asking specific questions.
zongsheng Lu
@melzs
Aug 18 2017 06:35
Aug 18 2017 06:35
@Masd925 yes i get but i am just know how do get start, i am not that good in javascript if i get even little bit help ..
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:35
@Masd925 Okay thank you
CamperBot
@camperbot
Aug 18 2017 06:35
erichasegawa sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4425 | @masd925 |http://www.freecodecamp.com/masd925
zongsheng Lu
@melzs
Aug 18 2017 06:36
what's the meaning of headers: {
"X-Mashape-Key": "OivH71yd3tmshl9YKzFH7BTzBVRQp1RaKLajsnafgL2aPsfP9V",
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:36
Also, can someone tell me how I could access the air conditions? ie. clear sky, cloudy etc. , I'm not sure what pathway I need to put in, like json.weather.0.main or what
Markus Kiili
@Masd925
Aug 18 2017 06:37
@EricHasegawa "0" is not a valid JS identifier, so only bracket notation works.
@EricHasegawa Access the object parsed from json and use console.log. That way you can tell if you know how to access it properly.
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:39
@Masd925 It's been a while since I took the course, I forget how to use bracket notation, could you refresh my memory or suggest anywhere for me to look to relearn it quickly?
Markus Kiili
@Masd925
Aug 18 2017 06:40
@EricHasegawa If you are accessing an array or an array-like object, then both arr[0] or arr["0"] etc work.
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:42
@Masd925 How would I access the description property in this situation
Markus Kiili
@Masd925
Aug 18 2017 06:42
@EricHasegawa Paste the whole JSON here and ask.
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:44
@Masd925 When I try to do that it comes in without any line breaks or anything, I logged it to the console within my program, could you check it from there?
Gulsvi
@gulsvi
Aug 18 2017 06:44
@EricHasegawa Use your browser's console Ctrl+Shift+J or Command+Option+J on mac
right-click the data you want and select "Copy Property Path"
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:48
@SkyC0der Command option J just closes the console on my browser
Gulsvi
@gulsvi
Aug 18 2017 06:48
@EricHasegawa Chrome?
Firefox:
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:50
@SkyC0der Yeah on Chrome, I've tried it a few times
Gulsvi
@gulsvi
Aug 18 2017 06:51
@EricHasegawa If you can't use your browser's developer console, you are at a big disadvantage with these API projects
That's something to get figured out soon :/
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:53
@SkyC0der Fair enough, I'll learn how to use them better soon, for now is there any chance you could tell me how to access the weather description property? You can see it by checking the console
Gulsvi
@gulsvi
Aug 18 2017 06:54
json.weather[0].description
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:55
@SkyC0der So that selects the json object, then the item at index 0 on the weather array, and then the description property within that index?
Gulsvi
@gulsvi
Aug 18 2017 06:56
@EricHasegawa Yes, similar to getting one of the "likes" for our contacts in the profile lookup challenge: https://www.freecodecamp.org/challenges/profile-lookup
contacts[0].likes[0] = pizza
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 06:58
@EricHasegawa If you can't open the console in your browser, reinstall your browser now.
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:58
@SkyC0der Yeah it makes sense now, thank you so much!
CamperBot
@camperbot
Aug 18 2017 06:58
erichasegawa sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:warning: erichasegawa already gave skyc0der points
Eric Hasegawa
@EricHasegawa
Aug 18 2017 06:59
@khanh2003 I can open the console and everything , but the Command + Option + J command just closed it for some reason, I probably did something wrong
Gulsvi
@gulsvi
Aug 18 2017 06:59
Kind of cool when an old challenge makes a light bulb go off - then it all comes together :)
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 06:59
because you are toggling the console, not open?
Owais Ahmed
@owaisehmed
Aug 18 2017 07:49
The code in my JS section isn't working? Do i need to change some settings or what?
Pieter Stokkink
@forkerino
Aug 18 2017 08:19
@owaisehmed In codepen? It should work automatically, but if you are using any libraries (like jQuery, for example) you need to include them in the settings.
If that's not it, a link would help
Markus Kiili
@Masd925
Aug 18 2017 08:44
@forkerino Hi.
Blauelf
@Blauelf
Aug 18 2017 08:54
@Masd925 Lo.
How would one translate a third logic state where the output is currently set to not drive any current at all (playing not-connected)? I always said "hochohmig" in German, translating to "high-ohmic", but not sure that's even a thing, and is used same way in English.
Claudio Restifo
@Marmiz
Aug 18 2017 09:02
Hello guys, someone knows a way to bring back the focus from a child window to its parent?
Tried the usual focus() but I believe the browser prevent it for obvious security reason.
The only workaround I've found is using alert but it's not gracious
Blauelf
@Blauelf
Aug 18 2017 09:18
So that's how pop-under ads work, calling window.opener.focus()? (Maybe they use window.focus() in the parent window instead - I'm still amazed by how they just ignore the popup blocker on some sharehoster sites)
Blauelf
@Blauelf
Aug 18 2017 09:32
Sharehosters force you to click, so not so amazing once you think about it.
Thomas
@sjurs1
Aug 18 2017 09:54
Is it not possible to type brackets in cmd prompt on windows...?
Claudio Restifo
@Marmiz
Aug 18 2017 10:03

@Blauelf usually browser prevents window.opener.focus() for obvious security reason (unless you didn't activate it in the permission settings)

I have found a way to make it work in chrome, but it won't in firefox unfortunately :/

(once again firefox wins in restrictions ;) )
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:05
@Blauelf can you give me a little help?
Claudio Restifo
@Marmiz
Aug 18 2017 10:06

@Blauelf but if we are talking about ads, they open a new instance straight away with window.open() (afaik) and many browser switch focus to it automatically.
If not just a

var a = window.open('instanceToOpen')
a.focus()

Now we can make some dumb aggressive intrusive pop-up.
My problem was a legit "how I go back after I open a window?" :)

Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:06
im doing a exercise the idea is return the biggest result of a product of an array
when its positive numbers it goes well
function adjacentElementsProduct(inputArray) {
var max = 0;
var temp = 0;
for(var i = 1; i < inputArray.length; i++){
temp = inputArray[i] * inputArray[i-1];
if(temp > max){
max = temp;
}
}
return max;
}
but when its negative
Input:
inputArray: [-23, 4, -3, 8, -12]
Output:
0
Expected Output:
-12
Console Output:
Empty
how can I avoid this?confused :D
Blauelf
@Blauelf
Aug 18 2017 10:07
@Marmiz The popups I understand, but what about the popunders (popups moving to the background)?
@tiagocorreiaalmeida Use var max = -Infinity;
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:08
how can I preform that?
plus
-12
will be bigger than -18
so that doesnt help :|
Blauelf
@Blauelf
Aug 18 2017 10:09
Have you tried replacing var max = 0; with var max = -Infinity;?
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:10
how does -Infinity; works?
Blauelf
@Blauelf
Aug 18 2017 10:10
Well, it's the negated Infinity.
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:11
Blauelf
@Blauelf
Aug 18 2017 10:11
Infinity is a global variable of value positive infininity, which is a special floating point value.
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:11
and why it will accept that -18 is bigger than -12?:D
Blauelf
@Blauelf
Aug 18 2017 10:15
-18 is less than -12, what do you mean with "bigger"?
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:16
nm confuising it
thanks @Blauelf
CamperBot
@camperbot
Aug 18 2017 10:16
tiagocorreiaalmeida sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4572 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Aug 18 2017 10:17
-Infinity is also the value used by Math.max. Just try Math.max() without arguments, it'll return -Infinity. There's just no value less than that, so it won't restrict the result space like your 0 did.
Markus Kiili
@Masd925
Aug 18 2017 10:19
@tiagocorreiaalmeida You can think that Infinity is just a number larger than any other number (with the exception of NaN)..
and -Infinity is smaller than any other number.
Blauelf
@Blauelf
Aug 18 2017 10:21
Fun with infinities. And beyond.
1/0  // Infinity
1/-0 // -Infinity, yes that's negative zero!
0/0  // NaN
Infinity-Infinity // NaN
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 10:22
now I get it thanks @Masd925 and @Blauelf really helpfull
CamperBot
@camperbot
Aug 18 2017 10:22
tiagocorreiaalmeida sends brownie points to @masd925 and @blauelf :sparkles: :thumbsup: :sparkles:
:warning: tiagocorreiaalmeida already gave blauelf points
:star2: 4426 | @masd925 |http://www.freecodecamp.com/masd925
Blauelf
@Blauelf
Aug 18 2017 10:24
It's one of the things that I sometimes wish were a keyword. Same goes for undefined, NaN, and a few more.
xuzixiang
@xucoder
Aug 18 2017 10:37
var myStr="I am a \"double quoted\" string inside\"double quotes\""; this line codes won't output ( I am a "double quoted" string inside "double quotes") ? how I can't pass the challenge
@Blauelf
Stephen James
@sjames1958gm
Aug 18 2017 11:14
@xucoder Is there a . at the end that is missing, and make sure all original spaces are included
@xucoder I am a "double quoted" string inside "double quotes". the original string has a . and a space after inside
Jim Tryon
@jimtryon
Aug 18 2017 11:38
Is there anyone that can help with writing promises?
Samuel Suther
@xstable
Aug 18 2017 11:45

I have this async function to fetch JsonData:

fetchData = async (requestServer=true) => {
if(requestServer===true){
const data = await fetchJson(url.contact);
this.setState({
data: data,
searchResult: data
});
}
}

But the this.state is fired before data was fetched form await-function.
I even try with callback-function:

await fetchJson(url.contact,(data)=>{
this.setState({
data: data,
searchResult: data
});
});

But even not work. Where is my issue?

btw. "this.setState is react native. But my question is for the behavior of this async function
alpox
@alpox
Aug 18 2017 11:47
@xstable What does fetchJson do? Can you show the code for it?
Samuel Suther
@xstable
Aug 18 2017 11:47
export const fetchJson = (url) => {
const myRequest = new Request(url, {
method: 'POST',
body: '{"security":"token"}'
});
return fetch(myRequest)
.then((response) => {
if (response.status == 200) {
return response.json();
}
else throw new Error("Couldn't fetch JSON-Data from "+url+" Something went wrong on api server!");
})
.catch((error) => {
console.error(error);
});
}
Jim Tryon
@jimtryon
Aug 18 2017 11:47
This is my code for promises
'use strict';

require('es6-promise');

var promise = new Promise((fulfill, reject) => {
setTimeout(function() {
throw new Error('REJECTED!');
}, 300);
});

function onReject (error) {
console.log(error.message);
}

promise.then((onReject) => {
return Promise.reject(error);
});
alpox
@alpox
Aug 18 2017 11:48
@xstable Did you check for errors in your console?
@jimtryon You never fulfill or reject your promise
Jim Tryon
@jimtryon
Aug 18 2017 11:50
@alpox I’m attempting to wrap my head around what I did wrong
alpox
@alpox
Aug 18 2017 11:50
@jimtryon You have to use the fullfill and/or reject parameters inside of the promise constructor
Jim Tryon
@jimtryon
Aug 18 2017 11:51
I only want to work with reject in this promise
alpox
@alpox
Aug 18 2017 11:51
@jimtryon I wonder what you try to achieve. Do you want to create a promise which rejects after 300 ms and then logs the error?
Samuel Suther
@xstable
Aug 18 2017 11:51
@alpox seems to be an logical error in react-native. Think I got it. Thanx anyway
CamperBot
@camperbot
Aug 18 2017 11:51
xstable sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1303 | @alpox |http://www.freecodecamp.com/alpox
alpox
@alpox
Aug 18 2017 11:51
@xstable :thumbsup:
Jim Tryon
@jimtryon
Aug 18 2017 11:51
@alpox I’ll give you the description

Create a promise that after a delay of 300ms, rejects with an Error object.
The Error object should be constructed with parameter 'REJECTED!', which is
the textual message of the error.

Create a function onReject to print error.message using console.log. Pass
this function as a rejection handler to the then method of your promise.

I kind of got confused about the whole part where it says to reject with an Error object
Stephen James
@sjames1958gm
Aug 18 2017 11:53
@jimtryon to reject the promise you call the reject function passed to the promise callback.
promise.then(null, onReject); is the second part
Jim Tryon
@jimtryon
Aug 18 2017 11:54
@alpox That task is written by my instructor
alpox
@alpox
Aug 18 2017 11:54
@sjames1958gm @jimtryon mkay i somehow didn't know that .then takes a second argument which can be used like catch
@jimtryon But usually, .catch is used for this
Jim Tryon
@jimtryon
Aug 18 2017 11:55
@sjames1958gm You are passing null because we only want the reject not the fulfill
@sjames1958gm is that correct?
Stephen James
@sjames1958gm
Aug 18 2017 11:55
yes
Jim Tryon
@jimtryon
Aug 18 2017 11:55
Is the first part right where I create an error object in setTimeout?
alpox
@alpox
Aug 18 2017 11:56
@jimtryon Almost. You will have to use reject(...) instead of throw for rejecting with the error
Stephen James
@sjames1958gm
Aug 18 2017 11:56
I think you just need to call reject with the string - I am trying it but not getting the result I expected
Jim Tryon
@jimtryon
Aug 18 2017 11:57
I thought to create an error object I had to use Error
alpox
@alpox
Aug 18 2017 11:57
@sjames1958gm Thats because then, the error is just a string. reject doesn't create an error implicitely.
reject(new Error("REJECTED!")); passes the error
Jim Tryon
@jimtryon
Aug 18 2017 11:57
That is how I saw it done in other tutorials
Blauelf
@Blauelf
Aug 18 2017 11:57
@sjames1958gm I'd wrap the string in an error, like setTimeout(()=>reject(new Error('REJECTED!')), 300)
Stephen James
@sjames1958gm
Aug 18 2017 11:58
@jimtryon With help from @Blauelf and @alpox
var promise = new Promise((fulfill, reject) => {
setTimeout(function() {
reject(new Error("REJECTED!"));
}, 300);
});

function onReject (error) {
console.log(error.message);
}

promise.then(null, onReject);
Jim Tryon
@jimtryon
Aug 18 2017 12:00
Almost...
✗ Submission results did not match expected!
✓ Used the Promise constructor
✓ Used reject method with Error object
✓ Used then method

ACTUAL EXPECTED
────────────────────────────────────────────────────────────────────────────────

"REJECTED" != "REJECTED!"
"" == ""

────────────────────────────────────────────────────────────────────────────────

I’m not sure how the two are different
oh, I forgot the !
that was it, thanks @Blauelf @sjames1958gm and @alpox… starting to get the hang of promises even though I was reading I should be using .catch which I haven’t encountered yet
CamperBot
@camperbot
Aug 18 2017 12:02
jimtryon sends brownie points to @blauelf and @sjames1958gm and @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1304 | @alpox |http://www.freecodecamp.com/alpox
:star2: 8336 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 4573 | @blauelf |http://www.freecodecamp.com/blauelf
Stephen James
@sjames1958gm
Aug 18 2017 12:03
catch works just as well
promise.then(null).catch(onReject);
Jim Tryon
@jimtryon
Aug 18 2017 12:03
Is there a preferred way to do it or does it matter?
Blauelf
@Blauelf
Aug 18 2017 12:03
@sjames1958gm Is the .then(null) adding anything?
Stephen James
@sjames1958gm
Aug 18 2017 12:04
@Blauelf Nah, just copied from the previous example.
Jim Tryon
@jimtryon
Aug 18 2017 12:04
I think it’s just a placeholder for that parameter
Stephen James
@sjames1958gm
Aug 18 2017 12:04
promise.catch(onReject) should be enough for this reject only case
Jim Tryon
@jimtryon
Aug 18 2017 12:04
I didn’t realize it but in my notes, I have Promise.reject(new Error('error message'));
Blauelf
@Blauelf
Aug 18 2017 12:05
@jimtryon Promise.reject creates a promise that's rejected instantaneously. Useful for testing, but probably not outside.
Jim Tryon
@jimtryon
Aug 18 2017 12:06
let me know if that link works
I’ll change it to .catch and see if it still pass the tests
Blauelf
@Blauelf
Aug 18 2017 12:07
Jim Tryon
@jimtryon
Aug 18 2017 12:08
No, that failed
Your solution to Reject a promise didn't pass. Try again!
alpox
@alpox
Aug 18 2017 12:12
@Blauelf Promise.reject is also useful in case of functions which should return a promise but fail before they do an async task:
function doSomething(url) {
if(!url)
return Promise.reject(new Error("The given url was invalid!"));
return fetch(url);
}
Blauelf
@Blauelf
Aug 18 2017 12:14
OK... so fetch would not return a rejected promise but throw an error? Or why would I want to do it that way?
alpox
@alpox
Aug 18 2017 12:15
@Blauelf Thats maybe a weak example :D fetch would probably reject here as well, it was just to show that there could be something happening before, so you'd already have to reject
It could be useful like this to give your own error message though
Blauelf
@Blauelf
Aug 18 2017 12:19

I've seen this stuff used in demonstration of unit tests.

BTW, how does debugging work for promises? Will I be able to generate some kind of stack trace with the various promises in there?

Jim Tryon
@jimtryon
Aug 18 2017 12:19
@alpox Ok, got another one for you… I think I’m close
'use strict';

require('es6-promise');

var promise = new Promise((fulfill, reject) => {
fulfill('I FIRED');
reject('I DID NOT FIRE');
});

function onRejected (error) {
console.log(error.message);
}

console.log(onRejected);

First, create a promise using the Promise constructor as we have been doing.

In the promise’s executor, immediately attempt to fulfill the promise with a
value of 'I FIRED'.

Then, after the fulfill call, immediately try to reject the promise with an
Error created with parameter 'I DID NOT FIRE'.

After the promise creation, create a function onRejected with one parameter
error that prints the Error’s message with console.log.

Lastly, pass console.log and the function you just created as the success
and rejection handlers respectively.

If successful, your script should only log “I FIRED” and should not log
“I DID NOT FIRE”.

Note that unlike the prior exercises, you do not have to use setTimeout with
this.

I think my last line is wrong
alpox
@alpox
Aug 18 2017 12:20
@Blauelf Thats one really bad thing about promises. Stack traces are as good as useless and you don't have anything similar. You just go place your breakpoints in the .then callbacks or place .catch at the right places to get some good logging
@Blauelf If we are honest, javascript was never debugging friendly ^^
Blauelf
@Blauelf
Aug 18 2017 12:22
@jimtryon Looks like promise.then(console.log.bind(console)).catch(onRejected) is the one you should use.
Jim Tryon
@jimtryon
Aug 18 2017 12:22
What is .bind?
Blauelf
@Blauelf
Aug 18 2017 12:23
bind binds a function to a specific object and optionally a list of arguments.
Jim Tryon
@jimtryon
Aug 18 2017 12:23
Do you have to bind the function or can I just call console.log?
alpox
@alpox
Aug 18 2017 12:24
You can also just use promise.then(console.log, console.log)
Jim Tryon
@jimtryon
Aug 18 2017 12:24
Ok, that is what I was wondering
Blauelf
@Blauelf
Aug 18 2017 12:26
console.log("Hey");
// is equivalent to
console.log.call(console, "Hey");

var log = console.log;

log("Hey");
// is equivalent to
console.log.call(undefined, "Hey");

With the bind, you enforce console, so the effective call is the same as if you called console.log in your callback.

In this case, console.log does not use this, and therefore is not affected by undefined being passed for this.

alpox
@alpox
Aug 18 2017 12:26
@jimtryon Sry for clearing, but as i read the exercise again, it seems that Blauelf was more precise - they want console.log as fulfill and onRejected as error handler
Jim Tryon
@jimtryon
Aug 18 2017 12:26
Where are you binding it?
You used .call, is that another one?
alpox
@alpox
Aug 18 2017 12:27
@jimtryon Yes, that also binds the function - and calls it the same time
Jim Tryon
@jimtryon
Aug 18 2017 12:27
There are so many ways to do things… hmm
alpox
@alpox
Aug 18 2017 12:27
@jimtryon .apply would be another - which does the same as .call but takes the function arguments as an array
Blauelf
@Blauelf
Aug 18 2017 12:28
There's not only call and bind, but also apply. The internal function calling most closely resembles apply.
Jim Tryon
@jimtryon
Aug 18 2017 12:28
I should probably get in the practice of using .bind, .call, or .apply
alpox
@alpox
Aug 18 2017 12:28
@jimtryon But try to avoid it if possible ;-)
Jim Tryon
@jimtryon
Aug 18 2017 12:29
Try to avoid .bind?
alpox
@alpox
Aug 18 2017 12:29
These functions are mostly used because of the need but not because it would be good practice
Blauelf
@Blauelf
Aug 18 2017 12:30

@jimtryon Those often make code harder to read, and ES6 made many usages obsolete.
Example "Find largest number in array"
ES5:

var largest = Math.max.apply(Math, array);

ES6:

var largest = Math.max(...array);
Jim Tryon
@jimtryon
Aug 18 2017 12:30
So good practice is to write your code without these functions depending on what you are trying to do?
alpox
@alpox
Aug 18 2017 12:31
@jimtryon Go without them whenever you can, but use them when you feel the need
Jim Tryon
@jimtryon
Aug 18 2017 12:31
@Blauelf I’ve seen that syntax before. That is using the spread operator.
@Blauelf ES6 feature if I remember
Blauelf
@Blauelf
Aug 18 2017 12:31
Yes, it is. Before, it was often emulated by using apply
Owais Ahmed
@owaisehmed
Aug 18 2017 12:32
How can i make one button appear before the other using jQuery?
Or do i have to just place them accordingly in html code?
Jim Tryon
@jimtryon
Aug 18 2017 12:32
Just to clarify, in this particular problem, I want to use .bind for the console in the success handler and .catch in the error handler
alpox
@alpox
Aug 18 2017 12:32
@jimtryon It works with just promise.then(console.log, onRejection); in your case
Jim Tryon
@jimtryon
Aug 18 2017 12:33
✓ Submission results match expected
✓ Used the Promise constructor
✗ You used reject method with non-Error
✓ Used reject method after calling fulfill
✓ Used then method with both callbacks specified
Does that mean I need an Error object again?
alpox
@alpox
Aug 18 2017 12:33
@owaisehmed Probably http://api.jquery.com/insertbefore/ ?
Blauelf
@Blauelf
Aug 18 2017 12:34
@jimtryon In ES5, where we had no Map, we might create objects without a prototype chain using Object.create(null). That one obviously has no hasOwnProperty, so one would have to use Object.prototype.hasOwnProperty.call(obj, prop)

@jimtryon Forgot the new Error? It's required as per instructions.

Then, after the fulfill call, immediately try to reject the promise with an
Error created with parameter 'I DID NOT FIRE'.

Jim Tryon
@jimtryon
Aug 18 2017 12:35
var promise = new Promise((fulfill, reject) => {
fulfill('I FIRED');
reject new Error('I DID NOT FIRE');
});
Is that right?
Stephen James
@sjames1958gm
Aug 18 2017 12:35
@jimtryon reject is function need ()
You should have gotten a syntax error
Blauelf
@Blauelf
Aug 18 2017 12:36
reject is not an operator but a function.
Jim Tryon
@jimtryon
Aug 18 2017 12:36
That was it! Thanks @Blauelf @sjames1958gm @alpox
CamperBot
@camperbot
Aug 18 2017 12:36
jimtryon sends brownie points to @blauelf and @sjames1958gm and @alpox :sparkles: :thumbsup: :sparkles:
:warning: jimtryon already gave alpox points
:warning: jimtryon already gave sjames1958gm points
:warning: jimtryon already gave blauelf points
Jim Tryon
@jimtryon
Aug 18 2017 12:36
I got to remember the new Error
I keep thinking when I do reject('error message'), that automatically creates an error object
Blauelf
@Blauelf
Aug 18 2017 12:36
Just read the instructions more closely.
Jim Tryon
@jimtryon
Aug 18 2017 12:42
'use strict';

require('es6-promise');

var promise = new Promise((fulfill, reject) => {
fulfill('PROMISE VALUE');
});

promise.then(console.log, null);

console.log('MAIN PROGRAM');
I passed on the first try the challenge: Always synchronous!
Joseph
@Big-jo
Aug 18 2017 12:42
please does anyone know what this error means
Uncaught TypeError: Cannot read property 'appendChild' of undefined
Blauelf
@Blauelf
Aug 18 2017 12:43
You called the appendChild method of something, but that thing did not exist (was undefined)
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 12:43

@jimtryon

(fulfill, reject)

why not (resolve, reject)? you need to follow the conventions

Jim Tryon
@jimtryon
Aug 18 2017 12:44
@khanh2003 The exercise has me use fulfill, reject
I’m not sure why it isn’t resolve

Fulfilling a Promise

Promises have an important internal property: its state. A promise is one of:

• fulfilled,
• rejected, or
• pending, which is the state of a promise waiting to be fulfilled or rejected.
this is where fulfill comes from @khanh2003
Blauelf
@Blauelf
Aug 18 2017 12:47
Completely unrelated: Codeschool free weekend again. Starts at 2017-08-18 14:00 UTC
Markus Kiili
@Masd925
Aug 18 2017 12:49
@Blauelf Do you know of any good courses there?
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 12:49
@jimtryon is that exercise from promise-it-wont-hurt workshop?
Jim Tryon
@jimtryon
Aug 18 2017 12:49
@khanh2003 I think that is where my instructor got it from, yeah
Blauelf
@Blauelf
Aug 18 2017 12:52
@Masd925 I used them to get a brief overview over a few things. The songs suck.
Jim Tryon
@jimtryon
Aug 18 2017 12:52
There is also no issues about the wording
@khanh2003 so I wonder if fulfilled/resolved are used interchangeably
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 12:57

@jimtryon

fulfilled/resolved are used interchangeably

they are not used interchangeably. no one say fullfill("RETURN_VALUE"). conventions

BTW, developers dont use reject(new Error(...)) very often, unless they want a stack trace to log to console.

new Error() means get stack trace

Stephen James
@sjames1958gm
Aug 18 2017 12:57
@Masd925 I was a subscriber, but I found the pace a bit too slow
Jim Tryon
@jimtryon
Aug 18 2017 12:58
@khanh2003 I don’t see any mention of resolve in the course
Markus Kiili
@Masd925
Aug 18 2017 12:58
@Blauelf About brief overviews. I just read through "The art of software testing" by Mayers. I took 50 pages of notes. Hard subject.
@sjames1958gm Ok.
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 12:59
@jimtryon you can always ask developers on Stack Overflow Chat if you don't trust me :smile: https://chat.stackoverflow.com/rooms/17/javascript
Jim Tryon
@jimtryon
Aug 18 2017 13:00
@khanh2003 It’s not that I don’t trust you. I’m curious why then the whole course is using fulfilled and not resolved
alpox
@alpox
Aug 18 2017 13:01
@jimtryon I wonder too, because the convention is to use resolve for the fulfillment of a promise. But when you talk about promises, i often hear about fulfilling the promise - but written its resolve
Jim Tryon
@jimtryon
Aug 18 2017 13:02
I need 20 reputation to talk in the chat room @khanh2003
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 13:04
@jimtryon i thought you already have a 20+ rep Stack Overflow account :(
Jim Tryon
@jimtryon
Aug 18 2017 13:04
@khanh2003 I have 3 rep on SO
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:06
i think its because.
A promise is said to be in 3 states.
Fulfilled pending or rejected
doesnt matter what your naming convention is , the first argument you pass to a promise executor function is the resolve callback
the second one is reject
alpox
@alpox
Aug 18 2017 13:07
@abhinav-thinktank Yes. I think the term Fulfilled holds for promises which are already fulfilled, maybe resolve only gets used for the act of transition from pending to fulfilled
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:09
Jim Tryon
@jimtryon
Aug 18 2017 13:10
Can one of you ask for me in the JS Stack Overflow chat? lol
Well, if you have 20+ rep
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:11
@alpox so reading up a bit on MDN , it's a property of the promise object
Promise.reject(reason)
Returns a Promise object that is rejected with the given reason.
Promise.resolve(value)
Returns a Promise object that is resolved with the given value. If the value is a thenable (i.e. has a then method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise the returned promise will be fulfilled with the value. Generally, if you don't know if a value is a promise or not, Promise.resolve(value) it instead and work with the return value as a promise.
methods *
Jim Tryon
@jimtryon
Aug 18 2017 13:13
my instructor really should have put it as resolve not fulfill?
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:14
@khanh2003 can you give me the promise link you were reffering to?
i need to study it a bit.
@jimtryon im not sure actually..
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 13:15
@abhinav-thinktank npm install -g promise-it-wont-hurt@latest
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:15
ooh ok
cool ty @khanh2003
CamperBot
@camperbot
Aug 18 2017 13:15
abhinav-thinktank sends brownie points to @khanh2003 :sparkles: :thumbsup: :sparkles:
Tai Jones
@taiJones00
Aug 18 2017 13:26
what is wrong with this javascript code
$(document).ready(function() {$("#search").on("search", function(event) {
event.preventDefault();
console.log("it works");
var searchVal = $("#search").val; //I was told to use the wiki link because mediawiki points to all the wikis.$.getJSON(https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&list=prefixsearch&titles=Main+Page&rvprop=content&pssearch=${searchVal}, function(json) { console.log("the JSON got got!");$("#wiki-results").write(json[query][prefixsearch][title]);
});
});
});
Stephen James
@sjames1958gm
Aug 18 2017 13:30
@taiJones00 cross origin error.
you can add origin=* to the URL and wikipedia will send correct headers
Tai Jones
@taiJones00
Aug 18 2017 13:30
what do you mean
in school and going to next class
Stephen James
@sjames1958gm
Aug 18 2017 13:31
@taiJones00 AJAX requests to another domain have to be explicitly allowed by headers returned in response.
Without origin=* wikipedia will not send those headers to just any requestor.
XMLHttpRequest cannot load https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&…:(c=e.value,%22string%22==typeof%20c?c.replace(rb,%22%22):null==c?%22%22:c)}}. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.
this error is in the console without the origin=* query parameter
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:35
@sjames1958gm but to allow cross-origin request won't wikipedia have to enable * on it's requests
sorry, this topic always confuses me.
Stephen James
@sjames1958gm
Aug 18 2017 13:36
@abhinav-thinktank it is a special parameter that tells wikipedia to send the header in the responses
Its in the response that the header is required.
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:37
@sjames1958gm oh so you mean by appending to the query string, we tell wikipedia that this is a cross-origin request, and it allows the request
it won't if we dont use origin = * in the query parameter
also, this is specific to the wikipedia API.
@matrixersp
Aug 18 2017 13:38
What am I supposed to use in the last switch case?
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
re = /[\s_A-Z]/g;
str = str.replace(re,function(match) {
switch(match) {
case ' ':
case '_':
return '-'
case :
return ' ' + ;
}
}).toLowerCase();
return str;
}
spinalCase('ThisIs Spi_nal Tap');
Stephen James
@sjames1958gm
Aug 18 2017 13:39
@abhinav-thinktank Well, sort of, It knows it is cross-origin because it came from another domain.
What that parameter says is send the Access-Control-Allow-Origin header to allow the response to be accepted.
This is specific to wikipedia
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:39
aah ok , much better.
so if i wanted to make a cors request with a server which didnt have this
i could use JSONP
or a proxy server
@sjames1958gm thanks :)
CamperBot
@camperbot
Aug 18 2017 13:40
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8337 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
Aug 18 2017 13:40
@Masd925 As far as I went (the free weekend ended before I could finish it last time) I liked this one (except the songs ofc) https://www.codeschool.com/courses/javascript-best-practices
Stephen James
@sjames1958gm
Aug 18 2017 13:40
@abhinav-thinktank :+1:
@abhinav-thinktank Assuming the remote site supported JSONP of course
Abhinav Mishra
@abhinav-m
Aug 18 2017 13:41
aah yes.
there was an iframe thing which can be used too, but im not too aware of that.
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 13:44
jsonp. jsonp everywhere. never use jsonp.
ozimanik
@ozimanik
Aug 18 2017 13:44
is there someone who can explain me some code
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 13:45
ozimanik
@ozimanik
Aug 18 2017 13:45
its too much code
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 13:46
ozimanik
@ozimanik
Aug 18 2017 13:48
@khanh2003 i sent it private
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 13:48
kumquatfelafel
@kumquatfelafel
Aug 18 2017 13:48
that seems like a lot of code to explain also... I'm hoping you mean it in the context of "what do a couple of these lines mean" or "why is this breaking"? :p
@zanisis
Aug 18 2017 14:01
i want to know, minus to using promise?.
marcus dylan johnson
@mdjohns
Aug 18 2017 14:31
Anyone want to critique my code? Just finished the Find the Longest Word in a String challenge. Here’s my solution
function findLongestWord(str) {
var splitter = str.split(/ /g);
splitter.sort(function(a, b){
return b.length - a.length;
});
return splitter[0].length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Marius Nicolae
@bytao7mao
Aug 18 2017 14:35
it returns a number, what if you have 2 similar words like august and october, and you want to return the string and not the number?
Blauelf
@Blauelf
Aug 18 2017 14:35
str.split(/ /g) could be str.split(' '). Using sort is overly complex ($\mathcal{O}(n \log n)$), while only a complexity of $\mathcal{O}(n)$ is required.
@bytao7mao Here, the length is required. The word doesn't matter.
Marius Nicolae
@bytao7mao
Aug 18 2017 14:36
i see
Blauelf
@Blauelf
Aug 18 2017 14:36
BTW, august is 6 letters, october is 7.
marcus dylan johnson
@mdjohns
Aug 18 2017 14:37
@Blauelf Yeah, I just realized that reading MDN again. I was using str.split(“”) and couldn’t understand why that wasn’t working. I think I was on a RegEx kick from the last challenge ha.
Marius Nicolae
@bytao7mao
Aug 18 2017 14:37
august and abcdef , it was just an example
marcus dylan johnson
@mdjohns
Aug 18 2017 14:38
If sort is too complex, I’m trying to think of another solution. I originally was using a for loop to iterate.
Marc
@MWBauer
Aug 18 2017 14:38
Can I get a review of this line and tell me what you see and if it's valid?
var lcArray = [lowerCase.match(/\s\W/g)];
Blauelf
@Blauelf
Aug 18 2017 14:38
Finding a maximum can be done in a linear way.
Kelechi Chinaka
@ke1echi
Aug 18 2017 14:38
than he would not need the length property...array[0] gets the longest string @bytao7mao
thats after been sorted descending order
Blauelf
@Blauelf
Aug 18 2017 14:43
I tried that in a variation that required me to pick the first word of that length. Won't work, as sort wasn't stable (elements with same length did not all keep their relative order). Depends on implementation which order those elements end up.
Marius Nicolae
@bytao7mao
Aug 18 2017 14:43
yeah, i know, i was refeering to the fact that it would be more efficient to return the array and not the number because in a string we can have similar numbers
Stephen James
@sjames1958gm
Aug 18 2017 14:51
@MWBauer You are looking for a space followed by a non-word character
then each match will be put into the array
@Blauelf Hmm, I thought returning 0 from the sort function was supposed to maintain the same order
@Blauelf nvm - mdn says The sort is not necessarily stable
Blauelf
@Blauelf
Aug 18 2017 14:54
@sjames1958gm It's not necessarily, but in Firefox it once got its own bug, as stable sorting is not in the standard, but most browsers do it. You cannot trust that, however.
@sjames1958gm I looked into the source code, and the implementation treated 0 like a negative number, which somewhat makes sense, given that some implementations of the sort callback only return true or false, and never negative.
Stephen James
@sjames1958gm
Aug 18 2017 15:00
@Blauelf :+1: Went to the spec and it reads like a college graduate math text book
Blauelf
@Blauelf
Aug 18 2017 15:02
No idea what that means, but the spec is pretty confusing, I think. All those conversion rules, which are same, but when looked at closely have slight but meaningful differences.
Sometimes finding all the relevant information can take a while.
Marc
@MWBauer
Aug 18 2017 15:03
@sjames1958gm I'm trying to remove the spaces and punctuations.
Stephen James
@sjames1958gm
Aug 18 2017 15:04
@MWBauer Then you want to select (match) on not these you are matching on what you want to remove not on what you want to keep.
lowerCase.match(/[a-z0-9]/g)
Marc
@MWBauer
Aug 18 2017 15:07
Ok. So doing that I return one letter.
function palindrome(x) {
var lowerCase = x.toLowerCase();
var lcArray = [lowerCase.match(/[a-z0-9]/)];
returns "m"
marcus dylan johnson
@mdjohns
Aug 18 2017 15:08
you forgot the global
Marc
@MWBauer
Aug 18 2017 15:08
oy
awesome. thx
marcus dylan johnson
@mdjohns
Aug 18 2017 15:08
:+1:
Marc
@MWBauer
Aug 18 2017 15:08
so now I have an array, and I need to check if it's the same forward as back.
or back to forward.
however you wanna' think of it.
how does map work?
kumquatfelafel
@kumquatfelafel
Aug 18 2017 15:09
@MWBauer you don't need to put match in []. It already returns an array.
Marc
@MWBauer
Aug 18 2017 15:09
thx
Marc
@MWBauer
Aug 18 2017 15:15
I keep getting an error about a null reference. Is it saying that I'm referencing the wrong variable?
Or that the variable is empty?
marcus dylan johnson
@mdjohns
Aug 18 2017 15:17
Share the code?
Blauelf
@Blauelf
Aug 18 2017 15:17
match, when not being able to find anything that matches, returns null instead. Could that be the case?
kumquatfelafel
@kumquatfelafel
Aug 18 2017 15:17
:point_up: This would be my first guess.
Stephen James
@sjames1958gm
Aug 18 2017 15:18
@MWBauer reduce would be better than map for this.
Marc
@MWBauer
Aug 18 2017 15:18
Ok. the hints said maybe use map.
how does reduce work?
function palindrome(x) {
var lowerCase = x.toLowerCase();
//a variable that takes the string and makes it all lowercase//
var lcArray = lowerCase.match(/[a-z0-9]/g);
//this .match takes the string that is lc and makes an array of just the letters//
lcArray.prototype.map.call(lowerCase, function(y) {
return y;
}).reverse().join('');
return lcArray;
Stephen James
@sjames1958gm
Aug 18 2017 15:20
@MWBauer You are calling map on lowerCase not lcArray
kumquatfelafel
@kumquatfelafel
Aug 18 2017 15:20
Blauelf
@Blauelf
Aug 18 2017 15:20
lcArray.prototype is nothing you should use, did you mean Array.prototype? Also, either use match or another regex-taking method or loop over lowerCase. Not both.
Stephen James
@sjames1958gm
Aug 18 2017 15:20
Blauelf
@Blauelf
Aug 18 2017 15:22
I cannot imagine a good use for map on palindrome exercise.
Marc
@MWBauer
Aug 18 2017 15:22
Ok. Again, just trying to look into the hints they give.
kumquatfelafel
@kumquatfelafel
Aug 18 2017 15:22
yeah.
Blauelf
@Blauelf
Aug 18 2017 15:22
I once used filter, also tried reduce, but never map.
Marc
@MWBauer
Aug 18 2017 15:23
@Blauelf the lcArray.prototype is supposed to be the Array.prototype but i'm never sure if I'm supposed to substitute my array or if that's just the name of the command.
kumquatfelafel
@kumquatfelafel
Aug 18 2017 15:23

I guess...

Never mind, wouldn't work.

Marc
@MWBauer
Aug 18 2017 15:24
I'm trying to read on .reduce but it isn't making sense yet.
Blauelf
@Blauelf
Aug 18 2017 15:26

The

var lcArray = lowerCase.match(/[a-z0-9]/g) || [];

could be done with filter using

var lcArray = Array.prototype.filter.call(lowerCase, function(ch) {
return "a" <= ch && ch <= "z" || "0" <= ch && ch <= "9";
});

regex-free version I once built just to prove it's possible :P

Marc
@MWBauer
Aug 18 2017 15:28
why wouldn't it be >= a && <= z
kumquatfelafel
@kumquatfelafel
Aug 18 2017 15:28
@Blauelf so 'a', 'z', etc. coerce in that case? I could have sworn I tried something like that but it complained. I guess scenario I put forward must have been slightly different.
Moisés Man
@moigithub
Aug 18 2017 15:28
ch >= "a" is the same as "a" <= ch
Marc
@MWBauer
Aug 18 2017 15:29
gotcha. positions...
Huỳnh Trần Khanh
@khanh2003
Aug 18 2017 15:29
@MWBauer not position, it's unicode code point
Marc
@MWBauer
Aug 18 2017 15:29
ok
by doing it that way, i'm not using Regexp which would allow more maneuverability in using code?
Blauelf
@Blauelf
Aug 18 2017 15:32
I just like it as "a" <= ch && ch <= "z" to visually imitate the Python way of "a" <= ch <= "z"
Marc
@MWBauer
Aug 18 2017 15:33
Does it return an array?
Blauelf
@Blauelf
Aug 18 2017 15:33

Filter does return an array.

Regular expressions allow for really short solutions on palindrome. But most use replace method to replace the non-alphanumeric characters with empty strings.

It's by far not the only way.

Marc
@MWBauer
Aug 18 2017 15:35
There's hardly a time where there's just 1 way to do a thing.
I do well to figure out where I am, where I'm going, and figure out each step along the way. My trouble is that I'm very unlearned about ALL of the different commands and how they are used. So, as I'm asking myself questions, I have answers in my head, but trying to code those answers is a problem.
But then, I figure most newbs are just like that.
var lowerCase = x.toLowerCase();
//a variable that takes the string and makes it all lowercase//
var lcArray = Array.prototype.filter.call(lowerCase, function(ch) {
return "a" <= ch && ch <= "z" || "0" <= ch && ch <= "9";
}
Now I have an array of lowercase letters
I need to compare front and back.
Marc
@MWBauer
Aug 18 2017 15:40
The .filter will make a new array of every instance that is true.
So, I would want to compare the first index to the last index, if it's true it will be placed in the new array, right?
Stephen James
@sjames1958gm
Aug 18 2017 15:42
You could just join and compare to reverse and join
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 15:43
hello everyone im doing a exercise that the idea is check tghe given array and if there is missign consecutive numbers liek array [2,3,5,7] number 4 6 missing so that's 2 numbers so return 2
function makeArrayConsecutive2(statues) {
var input = statues.sort();
var result = 0;
var temp = 0;
for(var i = 0; i < input.length; i++){
if(input[i] + 1 !== input[i+1]){
temp = input[i] + 1;
while(temp < input[i+1]){
temp ++;
result += 1;
}
temp = 0;
}
}
return result;
}
got this so far
but seems im missign something
Input:
statues: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Output:
8
Expected Output:
0
Console Output:
Empty
Christopher McCormack
@cmccormack
Aug 18 2017 15:44
@tiagocorreiaalmeida sort needs a callback to compare numbers
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 15:45
does it?it normally just sorts them cause they are only numbers nothign special about it
Stephen James
@sjames1958gm
Aug 18 2017 15:46

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].sort()

>
[1, 10, 2, 3, 4, 5, 6, 7, 8, 9]

Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 15:46
I allready found out the problem yeah
Stephen James
@sjames1958gm
Aug 18 2017 15:46
It sorts them as strings without the callback
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 15:46
aaa ok
Christopher McCormack
@cmccormack
Aug 18 2017 15:46
yes it normally needs it, by default it only sorts lexicographically I believe
Stephen James
@sjames1958gm
Aug 18 2017 15:46
@tiagocorreiaalmeida Also you are going to go past the end of the array
with input[i+1]
Christopher McCormack
@cmccormack
Aug 18 2017 15:46
https://mdn.io/sort explains it nicely
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 15:47
thanks @sjames1958gm , thanks @cmccormack
CamperBot
@camperbot
Aug 18 2017 15:47
tiagocorreiaalmeida sends brownie points to @sjames1958gm and @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1155 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 8338 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Christopher McCormack
@cmccormack
Aug 18 2017 15:48
np
Tiago Correia
@tiagocorreiaalmeida
Aug 18 2017 15:49
really helfpull
@matrixersp
Aug 18 2017 15:52
I know I made it a bit complicated. Someone critic my code
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
re = /[\s_A-Z]/g;
str = str.replace(re,function(match, p) {
switch(match) {
case ' ':
case '_':
return '-';
default :
if(p > 1) {
if(str[p] == str[p].toUpperCase()) {
return '-' + str[p];
} else {
return str[p];
}
} else {
return str[p];
}
}
}).toLowerCase();
str = str.split('');
for(var i = 0; i < str.length; i++) {
if(str[i] == '-' && str [i+1] == '-') {
str.splice(i, 1);
}
}
str = str.join('');
return str;
}
spinalCase('This Is Spinal Tap');
Christopher McCormack
@cmccormack
Aug 18 2017 15:54
@Tekkie7 if you handled the easy cases first, would you still have to do your for loop?
Blauelf
@Blauelf
Aug 18 2017 15:59
That str.split->for-loop->str.join could be replaced by str.replace(/-+/g, '-') (optionally using a character set, like /[\- _]+/g, to lighten the work of the first replace)
Blauelf
@Blauelf
Aug 18 2017 16:10
Then the first replace could be like str.replace(/(?!^)[A-Z]/g, "-$&") without complicated logic. Explanation for $& on MDN
@matrixersp
Aug 18 2017 16:14
Thank you @Blauelf
CamperBot
@camperbot
Aug 18 2017 16:14
tekkie7 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4574 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Aug 18 2017 16:15
If you don't like lookaheads (like the negative lookahead (?!^) meaning "not at the beginning of the string"), you can still go str.replace(/(.)([A-Z])/g, "$1-$2")
Aakriti
@Aakriti94
Aug 18 2017 16:25
Ryan Williams
@Ryanwfile
Aug 18 2017 16:28

I'm in the start a node.js FCC tutorial, section titled your first i/o and the instructions read "The full path to the file to read will be provided as the first
command-line argument (i.e., process.argv[2]) " my code looks like

var fs = require('fs');
console.log(process.argv[2]);

and when I run node filename.js the console shows process.argv[2] is undefined. I have no clue how to parse an undefined value and this isn't explained anywhere, when I look on youtube the tutorial there uses the line

var newLineFile = fs.readFileSync(process.argv[2], "utf8");

and the code works fine, so I'm wondering if readFileSync works on an undefined value or if something is not working on my end and I shouldn't be getting console.log(process.argv[2]) to be undefined.

Moisés Man
@moigithub
Aug 18 2017 16:30
wht if u remove [2] @Ryanwfile (for testing)
Ryan Williams
@Ryanwfile
Aug 18 2017 16:32
@moigithub yes the argv is working fine and if I execute node filename.js test then test shows up so argv[2] is defined, it's just there's no file being provided as the instructions state
Moisés Man
@moigithub
Aug 18 2017 16:33
node ....... filename.js ...1111.... 2222 .....
argv[0] .... argv[1].......argv[2]....argv[3]...
Ryan Williams
@Ryanwfile
Aug 18 2017 16:33
@moigithub yes all of that works perfectly well, it's just the instructions say they are providing a file to parse and I have no idea how to access that file. Thanks for the help
CamperBot
@camperbot
Aug 18 2017 16:33
ryanwfile sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3597 | @moigithub |http://www.freecodecamp.com/moigithub
Ryan Williams
@Ryanwfile
Aug 18 2017 16:38

Has anyone been able to finish the Start a Node.js Server my first io recently? If you copy the code directly from the tutorial video

var fs = require('fs');

console.log(newLineFile.toString().match(/\n/g).length);

You get this error

fs.js:549
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

TypeError: path must be a string
at TypeError (native)
at Object.fs.openSync (fs.js:549:18)
at Object.<anonymous> (/home/ubuntu/workspace/myfirstio/io.js:3:22)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
I'm just wondering if these tutorials are obsolete or being worked on because there was 2 broken sections of the how-to-npm as well
mauriciodeleonc
@mauriciodeleonc
Aug 18 2017 16:45
Hii community, i just started studying CS and for a homework i need to interview someone from another country that is already working in this area (im from mexico so anyone that´s not from mexico will help
would really appreciate any help
Moisés Man
@moigithub
Aug 18 2017 16:51
those "learnto**" tutorials provide a "verify" option..
ie: learnyounode verify urProgram.js
if u wanna test urself.. then u need to provide ur own arguments node program.js 1 2 3
@Ryanwfile
Ryan Williams
@Ryanwfile
Aug 18 2017 16:53
@moigithub I am aware of the verify and that fails every time because the file they were supposed to provide as process.argv[2] is undefined. I have no idea how to progress if I can't access the file I'm supposed to parse
Ryan Williams
@Ryanwfile
Aug 18 2017 17:06
@moigithub I got it working, thanks again for the help
CamperBot
@camperbot
Aug 18 2017 17:06
ryanwfile sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: ryanwfile already gave moigithub points
Fareed F
@IamFareel
Aug 18 2017 17:22
I completed the JS course and am on intermediate algorithm scripting but im still not really getting it. Should I just retake the JS course or does anyone have any other suggestions?
Christopher McCormack
@cmccormack
Aug 18 2017 17:24
@IamFareel what aren't you getting? Maybe we can help smooth some edges
Mark Kubik
@KUBIX90
Aug 18 2017 17:25
function chunkArrayInGroups(arr, size) {
// Break it up.

var newArray = [];

for(var i = arr.length-1; i < arr.length; i++){

var slicedArray = arr.slice(0,size);

newArray.push(slicedArray);

}

return newArray;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Fareed F
@IamFareel
Aug 18 2017 17:25
@cmccormack tbh im not being able to approach challenges/projects the correct way. I am not able to think "ok this is what i gotta do first to start working on this"
Mark Kubik
@KUBIX90
Aug 18 2017 17:27
Anyone know how to slice and push the next set of sliced array values in the new array after the first loop? I can only get it to repeat itself over and over
I put arr.length-1 as the i value to ensure it just runs once
Christopher McCormack
@cmccormack
Aug 18 2017 17:30
@IamFareel then maybe you should go through the js exercises again, that's a good way to solidify your understanding. Read through carefully, read the docs for each suggested method, make sure you really understand
Mark Kubik
@KUBIX90
Aug 18 2017 17:30
otherwise i just get "a" and "b" over and over
Christopher McCormack
@cmccormack
Aug 18 2017 17:30
@KUBIX90 you can do i+=size
work off of that to determine what size should be in your slice as well
Fareed F
@IamFareel
Aug 18 2017 17:32
@cmccormack thanks man. i think im gonna retake the course and just take it slow until it sinks in. i'll utilize this chatroom more and try to get in the right mindset of how to think in JS
CamperBot
@camperbot
Aug 18 2017 17:32
iamfareel sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1157 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 18 2017 17:32
your current code is basically saying "for the each item in arr, push a slice of arr starting at 0 and ending at size
Jason Luboff
@JLuboff
Aug 18 2017 17:33
@cmccormack Yo
Mark Kubik
@KUBIX90
Aug 18 2017 17:33
@cmccormack I'll give this a try, thanks
CamperBot
@camperbot
Aug 18 2017 17:33
kubix90 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1158 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 18 2017 17:36
@JLuboff hey! :wave:
@JLuboff how you been?
Mark Kubik
@KUBIX90
Aug 18 2017 17:39
@cmccormack I have tried what you suggested but it is not returning any values in the array?
function chunkArrayInGroups(arr, size) {
// Break it up.

var newArray = [];

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

var slicedArray = arr.slice(i,size);

newArray.push(slicedArray);

}

return newArray;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Christopher McCormack
@cmccormack
Aug 18 2017 17:40
I think you misunderstood the first thing I said @KUBIX90 , the i+= size was for the step (rightmost part of for loop declaration)
Mark Kubik
@KUBIX90
Aug 18 2017 17:41
@cmccormack ahhhh right I see, my bad
Christopher McCormack
@cmccormack
Aug 18 2017 17:45
Also my bad for being a bit opaque :D
Stephen James
@sjames1958gm
Aug 18 2017 17:46
@KUBIX90 Also the second parameter to slice is not length of slice but index after the end of the slice, so it needs to change each loop
Mark Kubik
@KUBIX90
Aug 18 2017 17:47
@cmccormack No worries, I'm having a lot of trouble with this one but I've got to leave it for tomorrow, thanks for your help
CamperBot
@camperbot
Aug 18 2017 17:47
kubix90 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: kubix90 already gave cmccormack points
Christopher McCormack
@cmccormack
Aug 18 2017 17:47
np good luck
Mark Kubik
@KUBIX90
Aug 18 2017 17:48
@sjames1958gm Thanks, i'll make a note and try tomorrow, I'll probably end up back on here anyhow haha
CamperBot
@camperbot
Aug 18 2017 17:48
kubix90 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8339 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jason Luboff
@JLuboff
Aug 18 2017 17:49
@cmccormack Eh..ok. Been a tough week. You?
Christopher McCormack
@cmccormack
Aug 18 2017 17:49
Good, too much work to make up for everyone on vacation the past few months but otherwise good
Eric Hasegawa
@EricHasegawa
Aug 18 2017 17:50
Can someone help me figure out how to put the image icon for the weather on the page?
Jason Luboff
@JLuboff
Aug 18 2017 17:50
Thats why you just leave it until they get back :joy:
Eric Hasegawa
@EricHasegawa
Aug 18 2017 17:50
The pathway to access the image link from the json is json.weather[0].icon
Jason Luboff
@JLuboff
Aug 18 2017 17:51
@EricHasegawa So put that in a img tag
"<img src=' + json.weather[0].icon + '>"
Christopher McCormack
@cmccormack
Aug 18 2017 17:52
@JLuboff i like to save my PTO until the winter holidays- I get tons of it and it's like I don't have a job for almost a month
Jason Luboff
@JLuboff
Aug 18 2017 17:53
@cmccormack I only get 2 weeks per year so.. but technically I'll get some extra this year sort of
Eric Hasegawa
@EricHasegawa
Aug 18 2017 17:53
@JLuboff I pasted that into my code, but it's still not working
Jason Luboff
@JLuboff
Aug 18 2017 17:54
@EricHasegawa You need to do that in your Javascript, not your html, your html doesn't know what the property is
Christopher McCormack
@cmccormack
Aug 18 2017 17:54
@JLuboff study time?
Jason Luboff
@JLuboff
Aug 18 2017 17:54
@cmccormack baby time lol I'll be taking 2-3 weeks off when he's born
Eric Hasegawa
@EricHasegawa
Aug 18 2017 17:55
@JLuboff It's in my javascript, I'm not sure what I've done wrong
Jason Luboff
@JLuboff
Aug 18 2017 17:56
@EricHasegawa Do the same thing you did for the condition/humidity/etc where you have a span in your html
with an ID, etc
Eric Hasegawa
@EricHasegawa
Aug 18 2017 17:58
@JLuboff Okay I tried that, still no dice
Jason Luboff
@JLuboff
Aug 18 2017 18:00
@EricHasegawa Ok. I made a minor mistake, it should be $("#icon").html("<img src='" + json.weather[0].icon + "'>"); and in your html it should be <span id="icon"> not <span id="#icon"> Eric Hasegawa @EricHasegawa Aug 18 2017 18:01 @JLuboff ahh thank you that works CamperBot @camperbot Aug 18 2017 18:01 erichasegawa sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles: :star2: 2159 | @jluboff |http://www.freecodecamp.com/jluboff Eric Hasegawa @EricHasegawa Aug 18 2017 18:01 And yeah that was my bad Christopher McCormack @cmccormack Aug 18 2017 18:04 @JLuboff that's great if the company is providing that leave! Jason Luboff @JLuboff Aug 18 2017 18:07 @cmccormack Sort of. It's technically part of the Family leave act, where I can take up to 6 weeks off within the first year and recieve up to 55% of my pay. But with work, I can use my remaining vacation to make up for the percent difference Christopher McCormack @cmccormack Aug 18 2017 18:12 @JLuboff that's pretty boss. Dads need time with their kids too :) Jason Luboff @JLuboff Aug 18 2017 18:13 Yup! Man...3 months to go. Christopher McCormack @cmccormack Aug 18 2017 18:17 Then your life completely changes! I hope you can code with one hand Valentin @valentinlybmin Aug 18 2017 18:19 Hey guys, I am trying to slove the "Exact Change" algorithm but I fail to understand something. Thats a link to the taskt : https://www.freecodecamp.org/challenges/exact-change Christopher McCormack @cmccormack Aug 18 2017 18:21 What's that something? @valentinlybmin Valentin @valentinlybmin Aug 18 2017 18:21 Hey guys, I am trying to slove the "Exact Change" algorithm but I fail to understand something. Thats a link to the taskt : https://www.freecodecamp.org/challenges/exact-change What I dont understand is why this: checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]) should return "Insufficient Funds" , when the change is 0.50 and the cash in register 1.01. Can someone explain this to me? ^ I am sorry, I forgot to press shift with enter Christopher McCormack @cmccormack Aug 18 2017 18:21 @valentinlybmin because there is only a one dollar bill and a penny in the drawer how would you return 50 cents with only those denominations Valentin @valentinlybmin Aug 18 2017 18:22 @cmccormack ahhh right. I am just substracting @cmccormack hahaha makes so much sense, thanks man lol CamperBot @camperbot Aug 18 2017 18:22 valentinlybmin sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles: :star2: 1159 | @cmccormack |http://www.freecodecamp.com/cmccormack Christopher McCormack @cmccormack Aug 18 2017 18:22 @valentinlybmin np Valentin @valentinlybmin Aug 18 2017 18:22 @cmccormack may I ask you another quick question related to this algorithm? This is my second attempt to slove it. Before I was almost there, but I saw that many times when I substracted a penny, like when I had 0.09 change to return and I substracted 9 times a penny , it resulted not in 0 to be returned but 0.009232424259 for example. and I used a simple while loop in which the highest possible currency is substracted while nothing is left to be returned Christopher McCormack @cmccormack Aug 18 2017 18:25 @valentinlybmin one tip may be to multiple everything by 100, then when you return the final value shift it back by dividing by 100 Jason Luboff @JLuboff Aug 18 2017 18:26 @cmccormack :joy: Luckily I do most coding at work haha. But ya life will be very different, but I'm excited. Its crazy to think that I've helped create another human. Just mind blowing really Christopher McCormack @cmccormack Aug 18 2017 18:26 that should help with Javascripts's notorious floating point handling @JLuboff and hopefully your kid will get all the good genes from its mother :p @JLuboff imagine all the things you get to do, teach them, train them to fight with swords, take them on adventures... no limit! Valentin @valentinlybmin Aug 18 2017 18:28 @cmccormack thats smart. Thanks man CamperBot @camperbot Aug 18 2017 18:28 valentinlybmin sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles: :warning: valentinlybmin already gave cmccormack points Christopher McCormack @cmccormack Aug 18 2017 18:29 @valentinlybmin you can also use number.toFixed(2) to cut off some digits For some reason I used this function in my code but I don't remember why... function rounded(number) { return Math.round(number * 100) / 100; } Moisés Man @moigithub Aug 18 2017 18:31 toFixed returns a string Christopher McCormack @cmccormack Aug 18 2017 18:34 Number(1.009.toFixed(2)) then! @moigithub :) kumquatfelafel @kumquatfelafel Aug 18 2017 18:34 @JLuboff @cmccormack and then one day, they avenge your death at the hands of a draconian space fiend with zebra markings and a notable lisp. ... What were we talking about? :o Christopher McCormack @cmccormack Aug 18 2017 18:34 @kumquatfelafel you were on track kumquatfelafel @kumquatfelafel Aug 18 2017 18:35 Well, yes, for a time... but I quit the team. Jason Luboff @JLuboff Aug 18 2017 18:35 @cmccormack I know! Lots of stuff to teach him! Lots of stuff to be scared of too, but I'll get over that lol Christopher McCormack @cmccormack Aug 18 2017 18:37 @kumquatfelafel quitter @JLuboff teach them not to quit track at least. Don't be like that felafel person Jason Luboff @JLuboff Aug 18 2017 18:38 :joy: I doubt he'll do track in the first place neither his mother or I are runners lol Christopher McCormack @cmccormack Aug 18 2017 18:38 But that's where all the cool kids go after school my parents weren't the least but athletic but I ended up being a runner for a time Jason Luboff @JLuboff Aug 18 2017 18:39 I'm not saying we're not athletic, I'm just saying we're not runners :D Christopher McCormack @cmccormack Aug 18 2017 18:41 Start throwing apples at the kid, that will get them running! Jason Luboff @JLuboff Aug 18 2017 18:41 And my ass kicked by his mother! kumquatfelafel @kumquatfelafel Aug 18 2017 18:41 @cmccormack That just teaches them to run away from their problems! Christopher McCormack @cmccormack Aug 18 2017 18:41 OK OK let her throw the first apple Is the real answer to take the apple head-on? Jason Luboff @JLuboff Aug 18 2017 18:42 If you can dodge an apple you can dodge a wrench? kumquatfelafel @kumquatfelafel Aug 18 2017 18:42 No. To eat it. One must eat their problems. Christopher McCormack @cmccormack Aug 18 2017 18:43 When life throws apples at you... @kumquatfelafel they won't be running much with that mantra Alexander Køpke @alexanderkopke Aug 18 2017 18:43 hamsters have movember all year kumquatfelafel @kumquatfelafel Aug 18 2017 18:43 And, occasionally, get their stomach pumped because they ate a poo. Christopher McCormack @cmccormack Aug 18 2017 18:44 And I thought @kumquatfelafel was off track! kumquatfelafel @kumquatfelafel Aug 18 2017 18:44 Y'know, poo problems. Christopher McCormack @cmccormack Aug 18 2017 18:44 That's something @JLuboff will be dealing with for the next few years, that's for sure! kumquatfelafel @kumquatfelafel Aug 18 2017 18:45 Well @JLuboff will have a lot on his plate then. :p ;) Christopher McCormack @cmccormack Aug 18 2017 18:45 haha gross and with that ends the banter kumquatfelafel @kumquatfelafel Aug 18 2017 18:47 I'll admit, I know my limits. And by that, I mean I don't have any. :/ Jason Luboff @JLuboff Aug 18 2017 18:47 @cmccormack I'm pretty sure you're older then me...when are you having kids? Christopher McCormack @cmccormack Aug 18 2017 18:47 Probably never, might adopt at some point though The Fiancee is still getting her career going and doesn't have much interest in that, and I never really have, although would welcome it if it did happen Jason Luboff @JLuboff Aug 18 2017 18:50 Fair enough. I put it off for a long time (I've been married 7 years). I wanted to be in a finicially good place, have a home (that didn't happen but prices here are ridicilious) and have my wife have her career (hasn't exactly happened...but her new job looks to be promising) but at some point you gotta not worry about half that shit. I said I wanted to have a kid around 30, I'll be 29 when he is born so thats close enough for me Christopher McCormack @cmccormack Aug 18 2017 18:51 I was the same way about fiscal responsibility, but as I've gotten older my want for additional responsibilities has waned. We'll see though, I"m not THAT old yet Jason Luboff @JLuboff Aug 18 2017 18:52 How old are you anyhow? Christopher McCormack @cmccormack Aug 18 2017 18:52 according to my calculator I'm 34 I had actually forgotten if I was 34 or 35, it doesn't come up much Jason Luboff @JLuboff Aug 18 2017 18:53 :joy: Ya you got time kumquatfelafel @kumquatfelafel Aug 18 2017 18:53 I had actually forgotten I'm glad to hear others are in same boat. :laughing: Christopher McCormack @cmccormack Aug 18 2017 18:53 it's funny how when we're young our age is so important, but at a certain point nobody gives a rip anymore until you're old I guess kumquatfelafel @kumquatfelafel Aug 18 2017 18:54 When you're little... beat met to it :point_up: Christopher McCormack @cmccormack Aug 18 2017 18:54 haha I'm gonna run for a bit, later all Jason Luboff @JLuboff Aug 18 2017 18:55 See ya kumquatfelafel @kumquatfelafel Aug 18 2017 18:55 see ya off as well for time. Been sitting in airport for about seven hours, and really hungry haha Jason Luboff @JLuboff Aug 18 2017 18:58 Seven hours? lay over? gulptech @gulptech Aug 18 2017 19:03 or just a love of airports :) BrianWilliams28 @BrianWilliams28 Aug 18 2017 19:08 can someone recommend a regular expression that will turn this string 'This Is Spinal Tap' into "This", "Is", "Spinal", "Tap"' but it also needs to separate "AllThe-small Things" into "All, "The","-small" Pieter Stokkink @forkerino Aug 18 2017 19:09 @BrianWilliams28 why a regexp? Why not .split() ? ah ok yeah, you actually won't have to convert to an array of words for that BrianWilliams28 @BrianWilliams28 Aug 18 2017 19:10 this algorithm is driving my crazy i make one code that works for like 4 out 6 of them or 5 out 6 but then one doesnt pass =( Pieter Stokkink @forkerino Aug 18 2017 19:11 a regex makes sense in this case, but you need to use | (OR) inside it if you are using a single .replace() Diego Mayer @Chrono79 Aug 18 2017 19:11 :wave: Pieter Stokkink @forkerino Aug 18 2017 19:12 or are you going by a different path? @BrianWilliams28 @Chrono79 hey! Jason Luboff @JLuboff Aug 18 2017 19:12 @forkerino @Chrono79 :wave: Diego Mayer @Chrono79 Aug 18 2017 19:13 Taking a breath of work and doing some https://www.codeschool.com courses for free while it's free weekend Pieter Stokkink @forkerino Aug 18 2017 19:13 @JLuboff :metal: Jason Luboff @JLuboff Aug 18 2017 19:13 How's it going Pieter Stokkink @forkerino Aug 18 2017 19:13 @Chrono79 yeah, I was gonna do some of them as well. I really enjoyed their last free weekend back in November. Gersho @Gersho Aug 18 2017 19:14 hello here ! Diego Mayer @Chrono79 Aug 18 2017 19:14 Sad thing is once you finished them (and free weekend is over) you don't have access, so this time maybe I'll try to download the slides at least kumquatfelafel @kumquatfelafel Aug 18 2017 19:14 @JLuboff burst of rain, resulting in flight I had to catch being diverted, resulting in not going on flight since I'd already missed connecting flight, so had to book a new flight and blah blah blah. Jason Luboff @JLuboff Aug 18 2017 19:15 @kumquatfelafel Oh man...that sucks Gersho @Gersho Aug 18 2017 19:15 someone knows how much time left before they release the new certification ? i wonder if i can grab front end before they remove it Jason Luboff @JLuboff Aug 18 2017 19:15 @Gersho Quincy made a forum post, you'll still be able to complete the front end cert Gersho @Gersho Aug 18 2017 19:15 oh okay Jason Luboff @JLuboff Aug 18 2017 19:15 As long as your account is created prior to Dec. 31, 2017 Gersho @Gersho Aug 18 2017 19:16 the new ones look really cool well it is obviously :D Applied Responsive Web Design Projects (150hours) i know already i'll hate that one ^^ Kelechi Chinaka @ke1echi Aug 18 2017 19:18 any ideas when beta fcc goes live @Gersho :wave: guys Gersho @Gersho Aug 18 2017 19:18 nope, i only learned it was that far done in the newsletter Kelechi Chinaka @ke1echi Aug 18 2017 19:19 can i see the newsletter @Gersho kumquatfelafel @kumquatfelafel Aug 18 2017 19:23 @JLuboff Honestly, it could be much worse haha. I once was traveling with my sister's cat as a favor, and connecting flight was cancelled. Wound up waiting for 8 hours, which... would have still been fine really... except cat pissed all over the carrier, and ... well... the stench :laughing: Jason Luboff @JLuboff Aug 18 2017 19:24 @kumquatfelafel Ugh...thats truly terrible. kumquatfelafel @kumquatfelafel Aug 18 2017 19:25 Makes for good story at least And plenty of empty seats! :o Jason Luboff @JLuboff Aug 18 2017 19:28 :D Gersho @Gersho Aug 18 2017 19:28 @kumquatfelafel back in march, a friend of mine had his sister coming from paris, the day she was supposed to take the plane, some guy attacked security and the airport was locked for the day kumquatfelafel @kumquatfelafel Aug 18 2017 19:31 yikes. Gersho @Gersho Aug 18 2017 19:33 yeah kumquatfelafel @kumquatfelafel Aug 18 2017 19:36 yeah. nothing so severe here. Gersho @Gersho Aug 18 2017 19:37 worst airport situation was when some volcano was in a bad mood a few years ago but never had any trouble in an airport myself, but i'm ~1m90 so the trouble is more IN the plane >.> Pieter Stokkink @forkerino Aug 18 2017 19:39 yeah, especially on cheap flights length can be a problem... Gersho @Gersho Aug 18 2017 19:40 did i mention that's a 8h+ flight ? 8h 35m duration Paris, France (all airports) to Pointe-à-Pitre, Guadeloupe (PTP) google got really good with understanding what you want Alexander Køpke @alexanderkopke Aug 18 2017 19:42 well, at least one can sleep and wake up well rested at the arrival Jason Luboff @JLuboff Aug 18 2017 19:42 WOW is cheap...but damn are the seats super uncomfortable kumquatfelafel @kumquatfelafel Aug 18 2017 19:47 Best airport/plane situation for me was when returning from visit sister in Germany, they accidentally booked our return flight a month later than it was supposed to be, and when they fixed it we wound up with first class seats. I never realized that like... every second they're either giving you a meal or a drink. It's ... actually kind of annoying o.O But still... was pretty cool and... I mean... free upgrade :laughing: Sooo... any coding questions? :laughing: Margaret @Margaret2 Aug 18 2017 20:10 wow ... an actual conversation ... happening in the JS room :astonished: Pieter Stokkink @forkerino Aug 18 2017 20:12 lol it happens a lot actually Jason Luboff @JLuboff Aug 18 2017 20:12 There's convo's in here all the time! Pieter Stokkink @forkerino Aug 18 2017 20:12 just not when people are asking questions Jason Luboff @JLuboff Aug 18 2017 20:12 Except its just always slow moving now :( Pieter Stokkink @forkerino Aug 18 2017 20:12 which they don't do anymore Jason Luboff @JLuboff Aug 18 2017 20:12 :joy: kumquatfelafel @kumquatfelafel Aug 18 2017 20:13 Oh, how the mighty (JS room) hath fallen! :o Pieter Stokkink @forkerino Aug 18 2017 20:13 We had a good run At least I learned a lot from helping n00bs Bradley Sands @sandsbe Aug 18 2017 20:16 Oh, I've got questions if you've got answers If I ever see a game of tic tac toe after this exercise I'm going to be sick Pieter Stokkink @forkerino Aug 18 2017 20:17 lol Stephen James @sjames1958gm Aug 18 2017 20:18 :crickets: Pieter Stokkink @forkerino Aug 18 2017 20:18 :tumbleweed: @sandsbe what's the question ? Bradley Sands @sandsbe Aug 18 2017 20:18 Ya. Ok. So I have stupid complicated logic. What the hell am I missing? Tic tac toe should be easy I went down a few awful rabbit holes Pieter Stokkink @forkerino Aug 18 2017 20:25 I see. I don't really understand the flow of your code, can you explain what it is supposed to do, step by step? @sandsbe Jason Luboff @JLuboff Aug 18 2017 20:25 Simon was easy(ish)... TicTacToe was hard but very satisfying to complete Bradley Sands @sandsbe Aug 18 2017 20:27 Ok. So first you pick X or O. Have functions established to run opening stanzas for either option. Then, once the option is most likely 2 inline and need to block, the goal is to block. However, each time you click a box, it has to check to see that the box hasn't previously been clicked. Last function, still to be written, is a pure random option for when a block isn't necessary. My logic issue was I couldn't think of a way to continually check to see if I had 2 inline. I tried different loop options and ended up with some slow, buggy code. Decided since there are only a few options, that I'd solve the problem with arrays and simply count. if 2 in top row, cpu blocks, if 2 in right col, cpu blocks, etc. also, I tried to pull all my logic out of my buttons and call functions there so I can "see" what the heck is going on. kumquatfelafel @kumquatfelafel Aug 18 2017 20:32 what do you mean by inline? oh... wait... nvm! Sorry, been a long day haha Bradley Sands @sandsbe Aug 18 2017 20:36 Ya dude. This thing broke my head. I'm sure there is a super simple way to solve it, or at least simpler, I just keep going down rabbit holes. Terrible planning on my part. Pieter Stokkink @forkerino Aug 18 2017 20:36 @sandsbe what makes it hard to analyze at the moment is that you have a lot of duplicate (or rather very similar) code. All those if/else blocks can be radically simplified if you think a bit more about the way you structure your data. One way to organize it is to have an array with Xs and Os and a nested array with all possible winning combinations, consisting of indexes of the first array (i.e. [0,1,2] for the top row, for example). I think reorganizing your code in such a way, makes it easier to reason about and therefore easier to solve. Bradley Sands @sandsbe Aug 18 2017 20:37 @forkerino the if/else blocks are awful. So, nest arrays with for loops to run through them maybe? Mohammed Boudad @matrixersp Aug 18 2017 20:38 I think I complicated things, no? function sumFibs(num) { if(num === 1) { return num; } var sum = [1, 1]; for(var i = 1; sum[i-1] + sum[i] <= num; i++) { sum.push(sum[i-1] + sum[i]); } for(var i = 2; i < num; i++) { if(sum[i] % 2 == 0) { sum.splice(i, 1); } } sum = sum.reduce(function(acc, cur) { return acc + cur; }); return sum; } sumFibs(4); Pieter Stokkink @forkerino Aug 18 2017 20:43 @sandsbe for loops or other array methods, yes. that way you can quickly check if the board has a row with 2 fields that are occupied by the same sign and the third field that is free. Which is an opportunity to block, for example. Stephen James @sjames1958gm Aug 18 2017 20:43 @Tekkie7 yes. you can just have one loop and sum while you go (no arrays needed) Bradley Sands @sandsbe Aug 18 2017 20:46 ty @forkerino Pieter Stokkink @forkerino Aug 18 2017 20:47 :+1: cbot, you there? CamperBot @camperbot Aug 18 2017 20:47 you called? Jason Luboff @JLuboff Aug 18 2017 20:53 I heard cbot's been drinking on the job again kumquatfelafel @kumquatfelafel Aug 18 2017 20:53 find booze CamperBot @camperbot Aug 18 2017 20:53 find booze nothing found Jason Luboff @JLuboff Aug 18 2017 20:53 He's lieing Gersho @Gersho Aug 18 2017 20:53 nop Jason Luboff @JLuboff Aug 18 2017 20:53 That or he drank it all Gersho @Gersho Aug 18 2017 20:53 he drank it already ^^ kumquatfelafel @kumquatfelafel Aug 18 2017 20:55 Tis a pity. I could really use a stiff one right about now :laughing: Eric Hasegawa @EricHasegawa Aug 18 2017 21:08 Could someone help me to fix the Celsius to Fahrenheit converter in my program? https://codepen.io/erichasegawa/pen/brdYKd?editors=1010 I think it's a scoping error because the JSON was parsed in a non-global scope or something but I'm not sure Pieter Stokkink @forkerino Aug 18 2017 21:13 What you can do is get the current displayed temperature from the page directly, or indeed store the temperature in a global variable. Also try to implement it switching back to celsius. @EricHasegawa Jason Luboff @JLuboff Aug 18 2017 21:17 @forkerino So any plans to finish the FCC certs or have you decided not to? Eric Hasegawa @EricHasegawa Aug 18 2017 21:19 @forkerino How could I get the current displayed temperature from the page? Diego Mayer @Chrono79 Aug 18 2017 21:26 @EricHasegawa document.getElementById() or $('#id')
Pieter Stokkink
@forkerino
Aug 18 2017 21:26
@EricHasegawa same way as you set it, in a way. $('#temperature').html() will get the full string, then it's a matter of finding the numbers in there. @JLuboff I continued on my Game of Life last saturday. Will see, it's not top priority for me at the moment. Eric Hasegawa @EricHasegawa Aug 18 2017 21:28 @forkerino How could I go about finding the numbers though, thats what I'm confused about Pieter Stokkink @forkerino Aug 18 2017 21:28 @EricHasegawa one way would be a Regular Expression Jason Luboff @JLuboff Aug 18 2017 21:29 @forkerino Fair enough. I'm almost done with my Stock Chart app. Haven't worked on it today but yesterday got my chart working with all the stocks so was stoked about that (it took me a couple days to wrap my head around dynamically adding additional items to the chart) Pieter Stokkink @forkerino Aug 18 2017 21:31 Cool! Jason Luboff @JLuboff Aug 18 2017 21:32 I kept overlooking that the datasets property is an array...and I thought it was just objects... I wasn't thinking very good lol Pieter Stokkink @forkerino Aug 18 2017 21:36 :smile: Jason Luboff @JLuboff Aug 18 2017 21:36 @forkerino Everything good, life wise? Pieter Stokkink @forkerino Aug 18 2017 21:40 yeah, had a look at a couple houses today. They probably won't be our top pick, but at least I got to know the territory a bit more. you? Jason Luboff @JLuboff Aug 18 2017 21:44 Thats good. Its alright. My grandma ended up passing away on Sunday, so that was a bit tough but life will go on, and my memories/experiences with her won't go anywhere. Still have my baby to look forward to, 3 months to go. Jake @JakeDVirus Aug 18 2017 21:56 In the given codepen, the degree celsius symbol code &#8451; is not working, given in javascript code in line 33 https://codepen.io/neel111/pen/NvXNjN Pieter Stokkink @forkerino Aug 18 2017 21:58 @JLuboff My condolences Jason Luboff @JLuboff Aug 18 2017 22:02 @forkerino Thanks CamperBot @camperbot Aug 18 2017 22:02 jluboff sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles: :star2: 2922 | @forkerino |http://www.freecodecamp.com/forkerino Gersho @Gersho Aug 18 2017 22:05 @NeelDVirus why not use °C ? Jake @JakeDVirus Aug 18 2017 22:06 @Gersho yeah i want to use exactly this. but how? Gersho @Gersho Aug 18 2017 22:06 also you've misspelled temperature ;) Jake @JakeDVirus Aug 18 2017 22:06 hehe well thanks for pointing it out. i am habituated with typos :D Gersho @Gersho Aug 18 2017 22:06 well it's on my keyboard, it's shift+) in azerty layout Jake @JakeDVirus Aug 18 2017 22:07 i guess there is an equivalent ASCII code i should use Gersho @Gersho Aug 18 2017 22:08 Jake @JakeDVirus Aug 18 2017 22:09 @Gersho This is much precise. i used the code from here for the symbol but not working Gersho @Gersho Aug 18 2017 22:09 and that's how i discovered i don't know how to do alt codes on linux Jake @JakeDVirus Aug 18 2017 22:11 well i think i will figure it out latter. wil move to next now Gersho @Gersho Aug 18 2017 22:12 try adding <meta charset="UTF-8"> to <head> ? (no idea if it'll help) Jake @JakeDVirus Aug 18 2017 22:14 @Gersho i just discovered it do work but if i write that in the html page, unlike in the javascript page Gersho @Gersho Aug 18 2017 22:16 got it to work in js, wait a min Jake @JakeDVirus Aug 18 2017 22:16 @Gersho hey it is solved man. i just needed to use .html() instead of .text(). Eric Hasegawa @EricHasegawa Aug 18 2017 22:16 Can anyone tell me why me ceToFa function returns NaN? Gersho @Gersho Aug 18 2017 22:17  function convertUnit() { var farenheit = (celsius * (9/5)) + 32; if ($convertUnit.text() === "Convert to Farenheit"){
$("#loc").html(farenheit+"&#8457;");$convertUnit.text("Convert to Celsius");
} else {
$("#loc").html(celsius +" &#8451;");$convertUnit.text("Convert to Farenheit");
}
}
it works after the first clic, didn't check the rest of your code guess you need to make a similar change somewhere else too
@NeelDVirus
Pieter Stokkink
@forkerino
Aug 18 2017 22:20
@EricHasegawa put the var extractedStr... line inside the ceToFa function
Jake
@JakeDVirus
Aug 18 2017 22:20
@Gersho it do work now. i replaced the statement $temp.text(celsius +" &#8451;"); with $temp.html(celsius +" &#8451;");
Gersho
@Gersho
Aug 18 2017 22:21
@EricHasegawa why would you want to grab the temperature inside the element when you already have that data in json.main.temp ?
Eric Hasegawa
@EricHasegawa
Aug 18 2017 22:23
@Gersho It's out of scope, so I need to figure it out another way
@forkerino Got it, thanks!
CamperBot
@camperbot
Aug 18 2017 22:24
erichasegawa sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2923 | @forkerino |http://www.freecodecamp.com/forkerino
aRtoo
@artoodeeto
Aug 18 2017 22:46

guys. what is this shift doing here??

function dropElements(arr, func) {
// drop them elements.
var times = arr.length;
for (var i = 0; i < times; i++) {
if (func(arr[0])) {
//console.log(arr);
break;
} else {
arr.shift();
}
}
return arr;
}
dropElements([0, 1, 0, 1], function(n) {return n === 1;}); //should return [1, 0, 1].

if the loop takes the zero index which is 0 its goes to shift then goes back to the loop then what is the shift doing when arr.shift will be the same?

John
@flyboy1565
Aug 18 2017 23:13
Hello All!!!!!
need someone with the understanding of the Magical Javascrip

I have this

    $('.topLoader').each(function(){ var$topLoader = $(this).percentageLoader({ value: 0, width: 100, height: 100, controllable : false, progress : 0.0, });$topLoader.increment = 0;
$topLoader.topLoaderRunning = false;$topLoader.score = parseInt($(this).data('value'));$topLoader.max_score = parseInt($(this).data('max'));$topLoader.setProgress(0);
$topLoader.setValue('');$topLoader.animateFunc = function() {
this.increment += 2
this.setProgress(this.increment/this.max_score);
if (this.increment < this.score) {
setTimeout(this.animateFunc, 50);
}
else {
}
setTimeout(this.animateFunc, 50);
}
icons.push($topLoader); }) basically the goal is to call a new$topLoader.animateFunc() and have it animate a "PercentageLoader" object

John
@flyboy1565
Aug 18 2017 23:19
I'm getting the following error when i run this
VGkWNnOEBbVA:80 Uncaught TypeError: this.setProgress is not a function
at \$topLoader.animateFunc (VGkWNnOEBbVA:80)`
Stephen James
@sjames1958gm
Aug 18 2017 23:19