Skip to content

Update weather.js #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ let url;
}
},
},

{
name: "tempunit",
type: "input",
message: "Enter wheather you need temprature in farenieght or degree celcius?(c or f):",
validate: function (value) {
if (value == 'c' || value == 'f') {
return true;
} else {
return "Please enter unit of the temprature.";
}
},
},


{
name: "apiKey",
type: "input",
Expand All @@ -45,6 +60,7 @@ let url;
},
]);
url = `https://api.openweathermap.org/data/2.5/weather?q=${answers.city}&appid=${answers.apiKey}&units=metric`;
let tempunit = ${answers.tempunit};

// Initiazlizing Loader and Starting it.
const loader = new Spinner(`Checking Weather of ${answers.city}...`);
Expand All @@ -59,6 +75,9 @@ let url;
const data = JSON.parse(body);

const temp = data.main.temp;
if(tempunit == 'f'){
temp = (temp × 9/5) + 32;
}
const feels_like = data.main.feels_like;
const description = data.weather[0].description;
const temp_min = data.main.temp_min;
Expand Down