These are chat archives for FreeCodeCamp/Help

20th
Jun 2018
Tyler Fleming
@TylerFleming
Jun 20 2018 00:38 UTC
Hey guys, can someone help me with a very basic ajax request? I'm not getting anything returned in my console.log from this api. The api documentation only said to pass the auth key through a header. I've never done this before but I think I am doing it right as I am getting no errors, just no data is being returned to me via console.log
        var fortnite = $.ajax({
url: "https://api.fortnitetracker.com/v1/profile/{pc}/{unspeaking}",
method: "GET",
headers:{ "TRN-Api-Key:":"100c1fd5-6e82-4b14-b78c-e28ff05c8fa3" },
dataType: "json",
})

fortnite.done(function(data){
    console.log(data)
})
Kyle Holm
@thekholm80
Jun 20 2018 00:54 UTC
@TylerFleming i don't really use jQuery, but their docs show the done() method being chained onto the initial call
.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  $( this ).addClass( "done" );
});
Kyle Holm
@thekholm80
Jun 20 2018 01:21 UTC
@TylerFleming i did try it in codepen using axios and got back 404 errors, cors and corb errors
mstellaluna
@mstellaluna
Jun 20 2018 02:04 UTC
@anthonygallina1 :wave:
anthonygallina1
@anthonygallina1
Jun 20 2018 02:06 UTC
@mstellaluna :wave:
mstellaluna
@mstellaluna
Jun 20 2018 02:07 UTC
@anthonygallina1 vagrant in a cluster? I haven't tried it.. I just basic VMs with it
anthonygallina1
@anthonygallina1
Jun 20 2018 02:07 UTC
ya data science
No making cluster with sec in the vm and controlling the vm with vagrant
Kicking my you know what
:smile:
mstellaluna
@mstellaluna
Jun 20 2018 02:08 UTC
interesting
right now im ready to delete this bash script im learning to write
annoying af
anthonygallina1
@anthonygallina1
Jun 20 2018 02:09 UTC
ya but sh is worth it when it runs right
mstellaluna
@mstellaluna
Jun 20 2018 02:09 UTC
exactly
also gitter has a vagrant room too.. not very active but eventually someone might answer
ugh I found my problem
anthonygallina1
@anthonygallina1
Jun 20 2018 02:10 UTC
oh I aced the first week But been 16 hour seat times
mstellaluna
@mstellaluna
Jun 20 2018 02:11 UTC
what do you mean "16 hour seat times" ?
the class plus assignment?
anthonygallina1
@anthonygallina1
Jun 20 2018 02:11 UTC
working 16 straight day after day
mstellaluna
@mstellaluna
Jun 20 2018 02:11 UTC
day it will get exhausting.. but keep it up and try to nap when u can
anthonygallina1
@anthonygallina1
Jun 20 2018 02:11 UTC
Ummm.... like seat time at the computer
mstellaluna
@mstellaluna
Jun 20 2018 02:12 UTC
yea I know
it hurts your back being seated for 16 hrs
anthonygallina1
@anthonygallina1
Jun 20 2018 02:12 UTC
YA between the shoulder blades.
mstellaluna
@mstellaluna
Jun 20 2018 02:12 UTC
I take late night courses on Fridays and Saturdays so im at the computer longer and my back kills me after too long
anthonygallina1
@anthonygallina1
Jun 20 2018 02:13 UTC
@mstellaluna You would like this class though Especially with your background
mstellaluna
@mstellaluna
Jun 20 2018 02:14 UTC
im not at db's yet
I have too many things going on at once
your taking which one .. mongo for JS ?
anthonygallina1
@anthonygallina1
Jun 20 2018 02:15 UTC
Not of much good though I suppose unless you get to work with Mongo Enterprise in RL
YEs mongo security 3wks
mstellaluna
@mstellaluna
Jun 20 2018 02:15 UTC
in my situation its rare I deal directly with databases per say .. normally that's left to the DBA's if there is one
majority of the time it would be MS SQL not Mongo
anthonygallina1
@anthonygallina1
Jun 20 2018 02:16 UTC
So not forever But thinking it should be 3 months right now
mstellaluna
@mstellaluna
Jun 20 2018 02:16 UTC
how long is that course?
anthonygallina1
@anthonygallina1
Jun 20 2018 02:16 UTC
3wks
mstellaluna
@mstellaluna
Jun 20 2018 02:16 UTC
ok
anthonygallina1
@anthonygallina1
Jun 20 2018 02:17 UTC
I was thinking of picking up some sql at stanford online
mstellaluna
@mstellaluna
Jun 20 2018 02:17 UTC
which SQL?
anthonygallina1
@anthonygallina1
Jun 20 2018 02:17 UTC
I have done forums etc
MS I hope not MySQL there is a diff right
I kinda know MySQL
Bjorn van de Peut
@bjorno43
Jun 20 2018 02:19 UTC
For the web MySQL or SQLlite is usually used. Simply because they're free. MSSQL is not if I remember correctly
mstellaluna
@mstellaluna
Jun 20 2018 02:19 UTC
MS SQL is $$
anthonygallina1
@anthonygallina1
Jun 20 2018 02:19 UTC
@bjorno43 i like the tools in the interface
for querys
etc
mstellaluna
@mstellaluna
Jun 20 2018 02:20 UTC
it used to be per seat based or per processor.. don't remember anymore.. its been a longggggggggggg time since I dealt with MS SQL directly
Bjorn van de Peut
@bjorno43
Jun 20 2018 02:20 UTC
That just depends on which interface you use. For MySQL you can install all kinds of programs to make it easy
anthonygallina1
@anthonygallina1
Jun 20 2018 02:21 UTC
Oh the C note one. Well Mongo Enterprise is pricy too but I think they Umm they are letting us students use it free in class
@bjorno43 Yes tons of docs available
Bjorn van de Peut
@bjorno43
Jun 20 2018 02:23 UTC
Ye I know. I use MySQL all the time. I admit it's not as fast as MSSQL, but it's more than enough for normal websites
But I also believe that MSSQL shines a lot more with native app development
mstellaluna
@mstellaluna
Jun 20 2018 02:24 UTC
MS SQL is more production HighAvailability Clustering
anthonygallina1
@anthonygallina1
Jun 20 2018 02:27 UTC
I never worked on it is language similar?
Bjorn van de Peut
@bjorno43
Jun 20 2018 02:27 UTC
Ye MS SQL is simular to MySQL. A few differences though
I had to study a bit of MS SQL during my course in C#. I honestly didn't really like it. But that's because I'm way too used to MySQL
anthonygallina1
@anthonygallina1
Jun 20 2018 02:30 UTC
The per seat made not look more into it
Kyle Holm
@thekholm80
Jun 20 2018 02:30 UTC
most of my dislike of sql is the query structure. but i like graphql and it's in the same ballpark - maybe i'm okay with it because it uses {} to create logical separators?
well and graphql lets you define your own queries
anthonygallina1
@anthonygallina1
Jun 20 2018 02:31 UTC
Yes Mongo too made me say thats why I have been learning this JS and JSON
Kyle Holm
@thekholm80
Jun 20 2018 02:32 UTC
i love the node driver api for mongo
i love that instead of writing queries you use methods. feels very JS
anthonygallina1
@anthonygallina1
Jun 20 2018 02:33 UTC
:smile:
Thats true
Bjorn van de Peut
@bjorno43
Jun 20 2018 02:33 UTC
Anyway, gotta go guys. Way too late here already (4:33 am). Gn8!
Kyle Holm
@thekholm80
Jun 20 2018 02:33 UTC
@bjorno43 :wave:
anthonygallina1
@anthonygallina1
Jun 20 2018 02:34 UTC
~Rest well :)
Bjorn van de Peut
@bjorno43
Jun 20 2018 02:34 UTC
Thanks :)
Adegoke Fred
@Frediflexta
Jun 20 2018 04:08 UTC
Hi guys
Please guys, i need some help with an error i'm getting when i run my test
a bit of context, So, i'm just practicing with express n mocha, learning to write tests for an api
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
import chai from 'chai';
import chaiHttp from 'chai-http';
import app from '../../app';

chai.use(chaiHttp);
chai.should();

describe('Route GET/api/v1/rides', () => {
  it('should return a status 200', async (done) => {
    try {
      const res = await chai.request(app)
      .get('/api/v1/rides');
      res.should.have.status(200);
      done();
    } catch (err) {
      throw err;
    }
  });
});
Adegoke Fred
@Frediflexta
Jun 20 2018 04:13 UTC
and there is my code, hope i'm not using the async - await wrongly?
Plus i tried trying this out with postman, but my socket keeps hanging up
Any feedback would be appreciated guys...
Claudio Restifo
@Marmiz
Jun 20 2018 05:16 UTC
are you sure that chai.request is a promise?
async/awaitreturn a promise, so if request is not resolving any promise you are hanging with one
Claudio Restifo
@Marmiz
Jun 20 2018 05:25 UTC
or better, if it's a promise... why you need the done cb? the promise should be resolved
nalinpuri
@nalinpuri
Jun 20 2018 10:07 UTC
Sir do i need to do Applied Visual design and later topics like Applied Accesibity to learn CSS
In Basic CSS module
Adegoke Fred
@Frediflexta
Jun 20 2018 10:57 UTC
@Marmiz Thanks for the feedback, I have removed the done() i found out that async await, is a better way of handling asynchronous code and i don't need done
@Marmiz but the error message still persists
Jose Pagan
@josepagan
Jun 20 2018 12:00 UTC
after some months away I am back into fcc and a lot of things have changed!
Wes Gray
@wesgray76
Jun 20 2018 12:53 UTC
morning everyone
can someone please explain what this is and possibly how to fix it?792185
image.png
Janith Olagama
@JoleDev
Jun 20 2018 13:10 UTC

Can any one clarify how to access the element from this type of a ajax response

response({
"coord":{"lon":145.77,"lat":-16.92},
"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],
"base":"stations",
"main":{"temp":292.15,"pressure":1021,"humidity":59,"temp_min":292.15,"temp_max":292.15},
"visibility":10000,
"wind":{"speed":4.1,"deg":170},
"clouds":{"all":0},"dt":1529492400,
"sys":{"type":1,"id":8166,"message":0.0022,
"country":"AU","sunrise":1529441096,
"sunset":1529481125},
"id":2172797,
"name":"Cairns",
"cod":200
})

This is the ajax response i am receiving from OpenWeatherMap API, but response is not withing {} , Hence when i am trying to access element using response.coord.lan etc, does not give me anything. The response it self is not an Object. So anyone know how to access these elements.

Thanks in advance
Janith

@josepagan I think the curriculum is now more comprehensive and focused.
Jose Pagan
@josepagan
Jun 20 2018 13:16 UTC
is not?
@JoleDev so what format is the response
Janith Olagama
@JoleDev
Jun 20 2018 13:55 UTC
@moT01 when I console.log (response), it gives me response ({something inside curly braces})
Ankit Tiwari
@anku255
Jun 20 2018 13:56 UTC
@JoleDev To know the type of a variable in javascript you can do console.log(typeof variablename)
@JoleDev Also, I suspected the response you are getting may be a JSON. you can parse the JSON to a javascript object using the function JSON.parse(jsonStringtoParse). Read more about it here
Janith Olagama
@JoleDev
Jun 20 2018 14:01 UTC
@anku255 console.log(typeof response) returns it is a String
@anku255 , Yes you are correct it is a JSON response
Ankit Tiwari
@anku255
Jun 20 2018 14:01 UTC
@JoleDev Use JSON.parse to parse the json into an object. Ask for help if you get stuck.
Janith Olagama
@JoleDev
Jun 20 2018 14:33 UTC

@anku255 No brother it does not

var generateQuote = function () {
$.ajax ({
url : "http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=xxxxxxxxxxxxxxxxxxxxx&callback=data",
dataType = "json"
success : function (data) {
var dataObj = JSON.parse(data)
console.log(dataObj)
}
});
}

It returns undefined

Janith Olagama
@JoleDev
Jun 20 2018 14:43 UTC

@anku255 This is exact ajax query that I am running

var generateWeather = function () {
$.ajax ({
url : "http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=zzzzzzxxxxxx&callback=data",
dataType : " text json",
success : function (data) {
var dataObj = JSON.parse(data);
console.log(dataObj)
}
});
}

Below code also does not make any different

var generateWeather = function () {
$.ajax ({
url : "http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=zzzzzzxxxxxx&callback=data",
dataType : " text json",
success : function (data) {
console.log(data)
}
});
}

Both code returns undefined

whats the api key
Janith Olagama
@JoleDev
Jun 20 2018 14:46 UTC
@moT01 APIKEY is just a dummy one
are you using one though? cause those urls are giving invalid api key responses
koder3
@koder3
Jun 20 2018 14:47 UTC
image.png
can someone explain why im gettting a decimal value
Janith Olagama
@JoleDev
Jun 20 2018 14:48 UTC
@moT01 No brother there is not issue with my API key, I just cannot convert the response into a Object properly, Other-wise i am getting response correctly in String format
Bjorn van de Peut
@bjorno43
Jun 20 2018 14:49 UTC
@JoleDev Please show us the string returned
Ankit Tiwari
@anku255
Jun 20 2018 14:49 UTC
@JoleDev Can you make a codepen for your code? I am having trouble getting a response from your provided code.
Bjorn van de Peut
@bjorno43
Jun 20 2018 14:51 UTC
@JoleDev Also, there's no need to hide your APIKEY. This is normally available inside your Javascript and can be read out by anyone. It's not a security vulnerability
Ankit Tiwari
@anku255
Jun 20 2018 14:51 UTC
I think we would be able to help everyone a lot better and faster if we can get the required code in codepen. What do you guys think?
well brother - ill just test it with my key then
Bjorn van de Peut
@bjorno43
Jun 20 2018 14:52 UTC
@anku255 Although it is prefferable, we do not force anyone to create a Codepen or any other simular type of service when requesting help ;)
try removing the &callback=data at the end of your url
Janith Olagama
@JoleDev
Jun 20 2018 14:54 UTC

@moT01

var generateQuote = function () {
$.ajax ({
url : "http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=7fd40ce79dd4346321aa6b68dd4717a0&callback=data",
success : function (data) {
console.log(data)
}
});
}

This is the response (I removed dataType = "text json", as it wont give me any response)

data({"coord":{"lon":145.77,"lat":-16.92},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":289.15,"pressure":1020,"humidity":72,"temp_min":289.15,"temp_max":289.15},"visibility":10000,"wind":{"speed":5.7,"deg":140},"clouds":{"all":0},"dt":1529503200,"sys":{"type":1,"id":8166,"message":0.0325,"country":"AU","sunrise":1529441098,"sunset":1529481126},"id":2172797,"name":"Cairns","cod":200})

Ankit Tiwari
@anku255
Jun 20 2018 14:55 UTC
@JoleDev What's the output of console.log(Object.keys(data)) ?
Janith Olagama
@JoleDev
Jun 20 2018 14:56 UTC
@anku255 Anikit i dont have full code block, I just write this function code block in Chrome Dev Tools to get something out of the function before incorporating the same in my app, I just stuck with this function now
Bjorn van de Peut
@bjorno43
Jun 20 2018 14:56 UTC

@JoleDev That's working perfectly fine for me:

console.log(JSON.parse('{"coord":{"lon":145.77,"lat":-16.92},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":289.15,"pressure":1020,"humidity":72,"temp_min":289.15,"temp_max":289.15},"visibility":10000,"wind":{"speed":5.7,"deg":140},"clouds":{"all":0},"dt":1529503200,"sys":{"type":1,"id":8166,"message":0.0325,"country":"AU","sunrise":1529441098,"sunset":1529481126},"id":2172797,"name":"Cairns","cod":200}'));

Returns:
Object { coord: {…}, weather: (1) […], base: "stations", main: {…}, visibility: 10000, wind: {…}, clouds: {…}, dt: 1529503200, sys: {…}, id: 2172797, … }

Janith Olagama
@JoleDev
Jun 20 2018 14:58 UTC

@anku255 This is what i got for console.log(Object.keys(data))

(451) ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", …]

did you try what I suggested? and look at the two links I gave?
Janith Olagama
@JoleDev
Jun 20 2018 15:00 UTC
@moT01 JSON.parse (data) is not working with this response bro, It just returns an error Uncaught SyntaxError: Unexpected token d in JSON at position 0
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:02 UTC
@JoleDev Alright, in this case I have to agree with @anku255 and suggest you make a Codepen for us with your code. You're clearly messing something up and we can't pinpoint the exact issue without looking at your code ourselves
Janith Olagama
@JoleDev
Jun 20 2018 15:04 UTC

@moT01 Surprise bro, It just worked, I removed callback=data from the endpoint url

That simply done the job, Thanks Tom

I think one we add callback=data response automatically append the same to the response

Ankit Tiwari
@anku255
Jun 20 2018 15:05 UTC
@JoleDev Congrats! Good job @moT01 :thumbsup:
thanks - team effort
@koder3 there's a bunch of posts on stackoverflow that deal with this problem https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:07 UTC
Great that it's solved, but I don't get why exactly. I mean, if you got the JSON string returned as you said and it gets parsed perfectly fine, it makes no sense that it's giving an error
Janith Olagama
@JoleDev
Jun 20 2018 15:07 UTC

@anku255 @moT01 @bjorno43

Thanks friends, Removing that shitty callback=data directly returns the object

Ankit Tiwari
@anku255
Jun 20 2018 15:08 UTC
@bjorno43 The respone is a string which is like data(obj). As a whole the response is string but not a valid object . That's why it was not parsed as an object. However, my JSON viewer extension still parsed it as valid object. I am now trying to find out how it did it.
Janith Olagama
@JoleDev
Jun 20 2018 15:08 UTC
@bjorno43 No the thing is for some reason it is not parsing perfectly
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:09 UTC
@anku255 Yes, that's exactly what I mean. I can parse it just fine myself as well, that's why it isn't making any sense to me
Ankit Tiwari
@anku255
Jun 20 2018 15:10 UTC

My JSON viewer extension parsed it perfectly.

image.png

@bjorno43 When I tried to parse it locally, it didn't parse it. I kept getting the invalid json error.
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:12 UTC
Ok I'm disappointed in my Corsair K95 rgb keyboard now. Damn thing cost me 200 euros and it doesn't even have an extra usb port..
afbeelding.png
Working fine for me locally @anku255
Ankit Tiwari
@anku255
Jun 20 2018 15:14 UTC
@bjorno43 But, you object is not enclosed in data. the response I got was like "data(theJSONobject)"
Janith Olagama
@JoleDev
Jun 20 2018 15:15 UTC

@anku255 , @bjorno43 , I tried exactly below code

var generateQuote = function () {
$.ajax ({
dataType : "json",
url : "http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=7fd40ce79dd4346321aa6b68dd4717a0",
success : function (data) {
var dataObj = JSON.parse(data)
console.log(dataObj)
}
});
}

It returned

VM157:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at Object.success (<anonymous>:6:23)
at u (jquery-3.3.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.3.1.min.js:2)
at k (jquery-3.3.1.min.js:2)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.min.js:2)

Ankit Tiwari
@anku255
Jun 20 2018 15:15 UTC

My JSON viewer extension parsed it perfectly.

image.png

see the response in my screenshot.

Bjorn van de Peut
@bjorno43
Jun 20 2018 15:16 UTC
Ah, ye I see now
callback=data is actually returning a callback function data() instead of just the JSON string. That's what's causing the issue
Janith Olagama
@JoleDev
Jun 20 2018 15:17 UTC

Ok I'm disappointed in my Corsair K95 rgb keyboard now. Damn thing cost me 200 euros and it doesn't even have an extra usb port..

@bjorno43 , You manually pass the response here, it not the response directly for the AJAX request

Ankit Tiwari
@anku255
Jun 20 2018 15:17 UTC
@JoleDev Its already an object. Don't parse it again. Just remove the JSON.parse and you will be fine.
@bjorno43
var generateQuote = function() {
  $.ajax({
    dataType: 'json',
    url:
      'http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=7fd40ce79dd4346321aa6b68dd4717a0',
    success: function(data) {
      console.log('type of data', typeof data); // It's object
      console.log(Object.keys(data)); // Returns the keys
    }
  });
};
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:19 UTC
@anku255 Ye that's what I said. It's returning a callback function (which is an object)
Basicly it's passing a function towards the data parameter
Janith Olagama
@JoleDev
Jun 20 2018 15:20 UTC
@anku255 , Thanks bro. @moT01 suggection to remove callback=data give me the object as the reponse, I just try to figure out this JSON.parse method
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:21 UTC
@JoleDev Ye, because you removed that, it's no longer returning an object. It's now just returning the JSON string. That's what made JSON.parse work
Ankit Tiwari
@anku255
Jun 20 2018 15:23 UTC
@bjorno43 Actually, its returning an object and JSON.parse will not work on objects. He is getting an error above.
@JoleDev Read more about JSON.parse here.
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:24 UTC
@anku255 I was talking about after he removed callback=data
Ankit Tiwari
@anku255
Jun 20 2018 15:26 UTC

@anku255 , @bjorno43 , I tried exactly below code

var generateQuote = function () {
$.ajax ({
dataType : "json",
url : "http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=7fd40ce79dd4346321aa6b68dd4717a0",
success : function (data) {
var dataObj = JSON.parse(data)
console.log(dataObj)
}
});
}

It returned

VM157:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at Object.success (<anonymous>:6:23)
at u (jquery-3.3.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.3.1.min.js:2)
at k (jquery-3.3.1.min.js:2)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.min.js:2)

@bjorno43 I was talking about this.

Janith Olagama
@JoleDev
Jun 20 2018 15:27 UTC

@bjorno43 Actually, its returning an object and JSON.parse will not work on objects. He is getting an error above.

Yes, you are correct, one we remove callback=data it returns an object, so if you execute JSON.parse it is not working, However if you add callback=data it returns a String which cannot be converted into an Object with JSON.parse.

I do not know why

Bjorn van de Peut
@bjorno43
Jun 20 2018 15:28 UTC
@anku255 That's because you have dataType : "json" in there
@JoleDev It's combination of multiple problems. dataType : "json" already makes the returned data an object. So if you remove callback=data, the dataType makes it an object and you longer have to use JSON.parse. If you add callback=data, it returns you a function, which obviously you can't parse as JSON
Janith Olagama
@JoleDev
Jun 20 2018 15:31 UTC
Anyway, Seems I have lot of things to learn about AJAX requests, I am just experimenting with API request and learned lot today thanks to you guys @anku255 @bjorno43 @moT01
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:33 UTC
@JoleDev You're welcome :)
Janith Olagama
@JoleDev
Jun 20 2018 15:41 UTC

@bjorno43 , thanks bro, Yes i add this callback=data just because it was there in OpenWeatherMap API docs, so i was getting the response in String format however I had no way the access the elements within this since it is a String, then i am searching on web for this error i saw an stackoverflow article saying we need add dataType="json" or dataType="text json" to convert the string into object automatically then i add the same in my code, however it was also did not resolve my issue.

Finally the callback=data parameter was the issue.

Anyway, Why OpenWhetherMap describe to add callback=callBackFunctionName as url parameter, which mess-up the whole response. I cannot understand why

Bjorn van de Peut
@bjorno43
Jun 20 2018 15:43 UTC
@JoleDev To understand that, you first need to understand what callback functions are
In principle, it's the same as a phonecall. You pass a function as a parameter towards another function and JS tells that function: When you're done, call this function
Bjorn van de Peut
@bjorno43
Jun 20 2018 15:50 UTC

@JoleDev Take this for example:

function greeting(name) {
    alert('Hello ' + name);
}

function processUserInput(callback) {
    var name = prompt('Please enter your name.');
    callback(name);
}

processUserInput(greeting);

First you call processUserInput() and you pass the function greeting() as a parameter to it: processUserInput(greeting). The function processUserInput() asks the user for his name. Then it calls the callback parameter, which is the function greeting() and passes the name towards it.

Bjorn van de Peut
@bjorno43
Jun 20 2018 15:56 UTC
So when you have callback=data, it returns data({ json string }). If you would use callback=myCustomFunction it would return myCustomFunction({ json string }). So it's calling the function data() or myCustomFunction() for you and returns the JSON string towards that function. But if you don't have that function, nothing happens. The data variable will return undefined because it is never set.
Alexander R Bott
@Abott1222
Jun 20 2018 16:20 UTC
a callback is just calling someone back when you are ready hahaha
lmilliken
@lmilliken
Jun 20 2018 19:10 UTC
image.png
Hi all, I'm trying to start the npm tutorials such as this one: https://learn.freecodecamp.org/apis-and-microservices/managing-packages-with-npm/how-to-use-package-json-the-core-of-any-node-js-project-or-npm-package. But what do I put in for the Solution URL? I've tried https://glitch.com/edit/#!/windy-seat but it's erroring:
Kyle Holm
@thekholm80
Jun 20 2018 19:11 UTC
@lmilliken click on the live view button and use the url from the page that opens
image.png
this button
lmilliken
@lmilliken
Jun 20 2018 19:12 UTC
awesome, thanks @thekholm80 !
Kyle Holm
@thekholm80
Jun 20 2018 19:13 UTC
:+1:
mstellaluna
@mstellaluna
Jun 20 2018 19:18 UTC
@bjorno43 in case when you are online and people are asking for PHP tutorial. FCC just released this on their YT channel full php course
Kyle Leonard
@kdleonard93
Jun 20 2018 19:34 UTC
Hello Folks. Im trying to pass the tests for the "Responsive Web Design Projects - Build a Survey Form” project and i cant seem to figure out my last 2 test.
Survey Form tests

Technology Stack

  1. You can use HTML, JavaScript, and CSS to complete this project. Plain CSS is recommended because that is what the lessons have covered so far and you should get some practice with plain CSS. You can use Bootstrap or SASS if you choose. Additional technologies (just for example jQuery, React, Angular, or Vue) are not recommended for this project, and using them is at your own risk. Other projects will give you a chance to work with different technology stacks like React. We will accept and try to fix all issue reports that use the suggested technology stack for this project. Happy coding!

    Content

  2. I can see a title with id="title" in H1 sized text.
  3. I can see a short explanation with id="description" in P sized text.
  4. I can see a <form> with id="survey-form".
  5. Inside the form element, I am required to enter my name in a field with id="name".
  6. Inside the form element, I am required to enter an email in a field with id="email".
  7. If I enter an email that is not formatted correctly, I will see an HTML5 validation error.
  8. Inside the form, I can enter a number in a field with id="number".
  9. If I enter non-numbers in the number input, I will see an HTML5 validation error.
  10. If I enter numbers outside the range of the number input, I will see an HTML5 validation error.'
  11. For the name, email, and number input fields inside the form I can see corresponding labels that describe the purpose of each field with the following ids: id="name-label", id="email-label", and id="number-label". AssertionError: #name-label is not defined : expected null to not equal null
    at Function.assert.isNotNull (https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:17889:37)
    at n.<anonymous> (https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:21830:23)
    at r (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:7852)
    at r.run (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:8853)
    at i.runTest (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13553)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:14192
    at r (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13024)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13000
    at n (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:12791)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:12855
  12. For the name, email, and number input fields, I can see placeholder text that gives me a description or instructions for each field.' AssertionError: The number input field should have a placeholder attribute : expected false to equal true
    at Function.assert.strictEqual (https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:17641:33)
    at n.<anonymous> (https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:21850:23)
    at r (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:7852)
    at r.run (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:8853)
    at i.runTest (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13553)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:14192
    at r (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13024)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13000
    at n (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:12791)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:12855
  13. Inside the form element, I can select an option from a dropdown that has corresponding id="dropdown".'
  14. Inside the form element, I can select a field from one or more groups of radio buttons. Each group should be grouped using the name attribute.
  15. Inside the form element, I can select several fields from a series of checkboxes, each of which must have a value attribute.
  16. Inside the form element, I am presented with a <textarea> at the end for additional comments.'
    16.

<!doctype html>

<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Survey Form</title>
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<h1 id="title">Survey Form</h1>
<div id="form-outer">
<p id="description">Please tell us how we can improve!</p>
<form id="survey-form">
<div class= "grid-container">
<div class="grid-x grid-padding-x">
<div class="medium-6 cell">
<label id="name-lable" for="name">Name
<input type="text" name="name" id="name" class="input-field" placeholder="name" required>
</label>
</div>
<div class="medium-6 cell">
<label id="email-lable" for="email">
Email
<input type="email" name="email" id="email" placeholder="email" required >
</label>
</div>
</div>
<div class="medium-6 cell">
<label id="number-lable" for="age">Age
<input type="number" name="age" id="number" value="1" min="1" max="120">
</label>
</div>
<div class="medium-6 cell">
<label> What are you interested in hearing about?
<select class="dropdown" name="intrests" id="dropdown">
<option value="Computer Science">Computer Science</option>
<option value="Crypto">Crypto</option>
<option value="Video Games/Television">Video Games/Television</option>
<option value="Food/Cooking">Food/Cooking</option>
</select>
</label>
</div>
<div class="grid-y grid-padding-y">
<fieldset class="small-12 large-6 cell">
<legend>Choose Your Preffered Style of Learning.</legend>
<input type="radio" name="learning" value="Online" id="online" required><lable for="online"> Online</lable>
<input type="radio" name="learning" value="Institution" id="institution"><lable for="institution"> Institution</lable>
<input type="radio" name="learning" value="Self-taught" id="self-tought"><lable for="self-tought"> Self-Taught</lable>
</fieldset>
<fieldset>
<legend>Select the areas you wish to learn about.</legend>
<input id="checkbox1" type="checkbox" value="checkbox1"><label for="checkbox1">Front-End Developement</label>
<input id="checkbox2" type="checkbox" value="checkbox2"><label for="checkbox2">Back-End Developement</label>
<input id="checkbox3" type="checkbox" value="checkbox3"><label for="checkbox3">Data Science</label>
<input id="checkbox4" type="checkbox" value="checkbox4"><label for="checkbox4">Cyber Security</label>
<input id="checkbox5" type="checkbox" value="checkbox5"><label for="checkbox5">Ethical Hacking</label>
<input id="checkbox6" type="checkbox" value="checkbox6"><label for="checkbox6">Game Industry</label>
<input id="checkbox7" type="checkbox" value="checkbox7"><label for="checkbox7">Cryptocurrency</label>
</fieldset>
</div>
<div class="grid-y grid-padding-y">
<label for="free-text"> Give me your opinion on how I can improve this site for everyone :)
<textarea placeholder="Your thoughts!"></textarea>
<button id="submit" type="submit" class="success button" name="button" >Submit</button>
</label>
</div>
</div>
</form>
</div>

<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/what-input/dist/what-input.js"></script>
<script src="node_modules/foundation-sites/dist/js/foundation.js"></script>
<script src="js/app.js"></script>
</body>
</html>

Christopher McCormack
@cmccormack
Jun 20 2018 19:34 UTC
@kdleonard93 maybe paste just the one you're having an issue with
Kyle Holm
@thekholm80
Jun 20 2018 19:34 UTC
yikes
Kyle Leonard
@kdleonard93
Jun 20 2018 19:35 UTC
@cmccormack agreed. My apologies
Christopher McCormack
@cmccormack
Jun 20 2018 19:35 UTC
@kdleonard93 and it's label not lable
Kyle Leonard
@kdleonard93
Jun 20 2018 19:35 UTC
  1. For the name, email, and number input fields, I can see placeholder text that gives me a description or instructions for each field.'
  1. For the name, email, and number input fields inside the form I can see corresponding labels that describe the purpose of each field with the following ids: id="name-label", id="email-label", and id="number-label"
@cmccormack i missed that speling error. Maybe thats the issue. Ill try it!
Christopher McCormack
@cmccormack
Jun 20 2018 19:36 UTC
@kdleonard93 try to read the error message on those as well - #name-label is not defined : expected null to not equal null you misspelled label in your id attribute
Kyle Leonard
@kdleonard93
Jun 20 2018 19:42 UTC
Thank you @cmccormack! I corrected my speeling errors and realised that i was just missing a placeholder for the age. Everything passed!
Christopher McCormack
@cmccormack
Jun 20 2018 19:44 UTC
@kdleonard93 nice!
Eddie Cervello
@eddiecervello
Jun 20 2018 19:50 UTC
anyone have a clue what all this means?
Error in ./pages/index.js
Module build failed: TypeError: Cannot read property '1' of undefined
    at Plugin.manipulateOptions (/Users/Eddy/Desktop/nextjs-starter-dimension/node_modules/babel-plugin-module-resolver/lib/index.js:88:9)
    at normalizeOptions (/Users/Eddy/Desktop/nextjs-starter-dimension/node_modules/@babel/core/lib/transformation/normalize-opts.js:80:17)
    at runSync (/Users/Eddy/Desktop/nextjs-starter-dimension/node_modules/@babel/core/lib/transformation/index.js:34:84)
    at runAsync (/Users/Eddy/Desktop/nextjs-starter-dimension/node_modules/@babel/core/lib/transformation/index.js:25:14)
    at /Users/Eddy/Desktop/nextjs-starter-dimension/node_modules/@babel/core/lib/transform.js:32:34
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
Christopher McCormack
@cmccormack
Jun 20 2018 19:55 UTC
@eddiecervello wild guess but is something expecting an array argument?
Kyle Holm
@thekholm80
Jun 20 2018 20:00 UTC
looks like maybe a array.1 instead of array[1] somewhere?
oh wait, it's undefined
Christopher McCormack
@cmccormack
Jun 20 2018 20:01 UTC
@thekholm80 yeah that would be accurate
if array were undefined then you'd get that error
I think
Bjorn van de Peut
@bjorno43
Jun 20 2018 20:49 UTC
@mstellaluna Awesome! Thanks a lot for letting me know :smile:
Eddie Cervello
@eddiecervello
Jun 20 2018 20:53 UTC
I found the issue, there was a problem with updating babel-plugin-module-resolver. Just updated it and the problem was resolved. thanks
Eunice Park
@eunicode
Jun 20 2018 22:02 UTC

I'm doing an FCC ES6 exercise https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-concise-object-literal-declarations-using-simple-fields/
And I'm puzzled by the parentheses. Not the parameter parentheses, but the parentheses after the arrow and before the semicolon.
Can anyone shed some light?

const getMousePosition = (x, y) => ({
   x: x,
   y: y
});

It is a function that returns an object.

Kyle Holm
@thekholm80
Jun 20 2018 22:04 UTC
@eunipa arrow functions have implicit return, meaning you don't have to explicitly state return, unless you use a code block { ... }. so wrapping everything after the arrow in parens ( ... ) means everything inside the parens is the returned value
Eunice Park
@eunicode
Jun 20 2018 22:05 UTC
@thekholm80 Thank you very much!
Kyle Holm
@thekholm80
Jun 20 2018 23:09 UTC
oh JavaScript, you crazy
image.png
anthonygallina1
@anthonygallina1
Jun 20 2018 23:32 UTC
lol
Bjorn van de Peut
@bjorno43
Jun 20 2018 23:39 UTC
@thekholm80 Allow me to make that worse:
console.log(typeof {}); // object
console.log(typeof []); // object
console.log(typeof 0); // number
console.log({} + []); // [Object object]
console.log(typeof ({} + [])); // string
Christopher McCormack
@cmccormack
Jun 20 2018 23:41 UTC
weird
> typeof {} + []
'object'
> {} + []
0
Bjorn van de Peut
@bjorno43
Jun 20 2018 23:43 UTC
My best guess is that it's somehow returning 0 on a default constructor for each object? Just thinking out loud here
Bjorn van de Peut
@bjorno43
Jun 20 2018 23:49 UTC