solved Task 2

This commit is contained in:
schrom01 2022-11-04 11:28:55 +01:00
parent a8257389ad
commit 514197ee34
1 changed files with 24 additions and 0 deletions

24
code/currentTemp.js Normal file
View File

@ -0,0 +1,24 @@
const https = require('node:https');
const getCurrentTemp = function (response) {
let body = "";
response.on("data", (data) => {
body += data;
});
response.on("end", () => {
try {
let json = JSON.parse(body);
console.log(json.current_condition[0].temp_C + "°")
} catch (error) {
console.error(error.message);
};
});
}
const requestWeather = function () {
let url = "https://wttr.in/" + process.argv[2] + "?format=j1"
https.get(url, getCurrentTemp)
}