From 514197ee34860d143596309391f12dfe7ed5bf89 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 4 Nov 2022 11:28:55 +0100 Subject: [PATCH] solved Task 2 --- code/currentTemp.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 code/currentTemp.js diff --git a/code/currentTemp.js b/code/currentTemp.js new file mode 100644 index 0000000..1e8a12a --- /dev/null +++ b/code/currentTemp.js @@ -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) +}