[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 a function in JavaScript

👩‍💻 Technical question

what is .join method in javascript

👩‍💻 Technical question

What is the purpose of using the let keyword in JavaScript?

👩‍💻 Technical question

what is the difference between let and const

👩‍💻 Technical question

What is a recursive function?

👩‍💻 Technical question

how do you get the system to ignore spaces in the response to a prompt question js

👩‍💻 Technical question

What character defines or gives access to jQuery?

👩‍💻 Technical question

how to comment on javascript

👩‍💻 Technical question

what is var in javescript?

👩‍💻 Technical question

what is a trim in javascript

👩‍💻 Technical question

What is a Template literal

👩‍💻 Technical question

How do you declare objects in JavaScript?

👩‍💻 Technical question

what is js math?

👩‍💻 Technical question

what is template literals?

👩‍💻 Technical question

what is the difference between == and ===? in javascript

👩‍💻 Technical question

what is "Identifier has already been declared" ?

👩‍💻 Technical question

When the button is clicked, replace button label by ‘18 degrees’

👩‍💻 Technical question

how To display a phone number card when pressing an icon

👩‍💻 Technical question

what is cache expire date 10368000 ?

👩‍💻 Technical question

JavaScript functions

👩‍💻 Technical question

how to declare a function in javascript

👩‍💻 Technical question

what is the main use of filter method in js

👩‍💻 Technical question

How do I use backtick in javascript

👩‍💻 Technical question

what is hasOwnProperty in js

👩‍💻 Technical question

What is await in js

👩‍💻 Technical question

what is .toLowerCase()

👩‍💻 Technical question

what does .reduce() do?

👩‍💻 Technical question

explain toFixed method in javascript

👩‍💻 Technical question

how to acces to an object property inside an object

👩‍💻 Technical question

What is the infinity global property in Javascript and when is it used?

👩‍💻 HTML, CSS and JavaScript Code instructions

// Question: // Create a function that takes a string as a parameter // and alternates the casing of each individual letter // within the string. // Eg. Hello World! => hELLO wORLD!

👩‍💻 Technical question

what is a javascript function

👩‍💻 Technical question

what is forEach in javascript?

👩‍💻 Technical question

What is a comment in JavaScript?

👩‍💻 Technical question

how can I link my javascript file to a separate HTML file?

👩‍💻 Technical question

How to append the header to a html table in javascript?

👩‍💻 Technical question

how to get matching data from a prompt on an existing object

👩‍💻 Technical question

what are arguments in a function? Like what's a function that takes 2 arguments, name and email, look like?

👩‍💻 Technical question

can you nest objects javascript

👩‍💻 Technical question

What is the difference between setTimeout and setInterval?

👩‍💻 Technical question

Can you use forEach with an array of objects?

👩‍💻 Technical question

what are data types

👩‍💻 Technical question

how to make an svg image using javascript

👩‍💻 Technical question

How to iterate through numbers and return a string message if the sum is negative

👩‍💻 Technical question

Can you iterate through numbers decreasing?

👩‍💻 Technical question

how to sum all numbers in a range

👩‍💻 Technical question

how to use setTimeout

👩‍💻 Technical question

what is trim in javascript