[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

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 9 days 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 13 days 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 16 days ago in JavaScript by Nomthandazo

How can I loop an object in javascript

πŸ‘©β€πŸ’» Technical question

Asked 17 days 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?

πŸ‘©β€πŸ’» Technical question

What does textcontent mean in javascript

πŸ‘©β€πŸ’» Technical question

What is the logical AND operator in JavaScript?

πŸ‘©β€πŸ’» Technical question

What does parse float mean in JavaScript

πŸ‘©β€πŸ’» Technical question

what are break statements in javascript

πŸ‘©β€πŸ’» Technical question

what does .push mean ?

πŸ‘©β€πŸ’» Technical question

What does console.log mean in JavaScript?

πŸ‘©β€πŸ’» Technical question

how to use trim in js

πŸ‘©β€πŸ’» Technical question

What is const

πŸ‘©β€πŸ’» Technical question

Math functions in js

πŸ‘©β€πŸ’» Technical question

what does setInterval(() mean?