[JavaScript] - How to get rounded weather data for a city | SheCodes

[JavaScript] - How to get rounded weather data for a city in JavaScript

Learn how to retrieve and round weather data for a city using JavaScript, with prompts, alerts, and console.log statements.

👩‍💻 JavaScript Code instructions

let weather = { paris: { temp: 19.7, humidity: 80 }, tokyo: { temp: 17.3, humidity: 50 }, lisbon: { temp: 30.2, humidity: 20 }, "san francisco": { temp: 20.9, humidity: 100 }, oslo: { temp: -5, humidity: 20 } }; // write your code here let roundedWeather = {}; for (let city in weather) { roundedWeather[city] = {}; roundedWeather[city].temp = Math.ceil(weather[city].temp); roundedWeather[city].humidity = Math.ceil(weather[city].humidity); } console.log(roundedWeather); let city = prompt("Enter a city"); if (weather[city] !== undefined) { city = city.toLowerCase(); alert( `It is currently ${roundedWeather[city].temp}°C in ${city} with a humidity of ${roundedWeather[city].humidity}%` ); } else { alert( `Sorry we don't know the weather for this city, try going to https://www.google.com/search?q=weather+${[ city ]}` ); }

More coding questions about JavaScript

👩‍💻 Technical question

what is try and catch statement in javascript

👩‍💻 Technical question

what is Uncaught runtime errors and how to fix it

👩‍💻 Technical question

what is the difference between AJAX and axios ?

👩‍💻 Technical question

Im learning about the AJAX thing in the API thing and I am so confused. I'm really confused about how API exactly works and what exactly AJAX and Axios means. I'm really confused. What is this thing and where do I find it? can you explain this really easily and simply for me like explain as if I'm a child. Give easy real life examples and analogies

👩‍💻 Technical question

what does setinterval do in js?

👩‍💻 JavaScript Code instructions

Write a function that takes in a single number. It should return the string even if the number is even, and the string odd if the number is odd.

👩‍💻 Technical question

how to log number of milliseconds in current time

👩‍💻 Technical question

whats the difference between const and let

👩‍💻 Technical question

what is !== in javascript

👩‍💻 Technical question

meaning of !== in java script

👩‍💻 Technical question

how do i loop through an array and object until the max question has been reached?

👩‍💻 Technical question

how to display milliseconds timer in realtime with javascript

👩‍💻 Technical question

on a page with just a button, how can I change the color of the whole background? It should be responsive

👩‍💻 HTML, CSS and JavaScript Code instructions

Asked 8 months ago in JavaScript by Sarah-Leigh

Log the number of milliseconds in the current time

👩‍💻 Technical question

how to return a random object from an array

👩‍💻 Technical question

how to remove duplicate characters in a string

👩‍💻 Technical question

how to display the number of milliseconds only the last 3 digits

👩‍💻 Technical question

reverse a string

👩‍💻 Technical question

how do i show only the first option in the loop through an array?

👩‍💻 Technical question

how to sort letters in a string in alphabetical order

👩‍💻 Technical question

can you explain to me the .map function please

👩‍💻 Technical question

how can i add a class to an element via js selectors?

👩‍💻 Technical question

what are objects in JavaScript

👩‍💻 Technical question

How to delete an upload in your github

👩‍💻 Technical question

Asked 8 months ago in JavaScript by Sarah-Leigh

what is the purpose of using console log in javascript?

👩‍💻 Technical question

How to create an array of 3 cities with a few properties and console log each city temperature

👩‍💻 Technical question

what is the difference between an object and an array

👩‍💻 Technical question

difference between an object and an array

👩‍💻 Technical question

how I can make a five minute timer in java script?

👩‍💻 Technical question

for each in java script

👩‍💻 Technical question

else if in java script

👩‍💻 Technical question

str length

👩‍💻 Technical question

loop through the str

👩‍💻 Technical question

capitalize str

👩‍💻 Technical question

append with strings

👩‍💻 Technical question

string length in java script

👩‍💻 Technical question

string length in JS

👩‍💻 Technical question

split () and join() java script

👩‍💻 Technical question

how can i use the reverse() and the join() methods together on an array?

👩‍💻 Technical question

Asked 8 months ago in JavaScript by Nomthandazo

How can I loop an object in javascript

👩‍💻 Technical question

Asked 8 months ago in JavaScript by Amanda Ntumba

how to add two alerts on one prompt in javascript for html

👩‍💻 Technical question

what's the not equal comparison operator?

👩‍💻 Technical question

what is \r\n

👩‍💻 Technical question

how to use ".innerhtml"

👩‍💻 Technical question

what is greater sign in javascript?

👩‍💻 JavaScript Code instructions

greater than sign in javascript and how to use it

👩‍💻 Technical question

what does head mean in the context of git?

👩‍💻 Technical question

what's the difference between git fetch and git pull?

👩‍💻 Technical question

what's square bracket notation in js?

👩‍💻 Technical question

what's DOM?