I've been having some issues trying to complete my homework assignment to create a weather app for a long while. We are assigned a Javascript Data Types challenge to develop a prompt that "asks the user to "Enter a city" (example: Paris), then alert "It is currently 19°C (66°F) in Paris with a humidity of 80%". If the city doesn't exist in the object (i.e: Sydney), alert "Sorry, we don't know the weather for this city, try going to https://www.google.com/search?q=weather+sydney". Since this is an alert, the link shouldn't be clickable. Please round the values in the Alert to the nearest whole number (no decimal points, e.g. 5.45 should be rounded to 5).
My code has undergone many variations over the past month and I am throwing in the towel to seek assistance. My main concern is to have the alert specify the temperature and humidity of each object, but I may have overcomplicated the code. The console describes errors pertaining to an unexpected assignment within the "if" statement.
Here is my code attached:
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,
},
};
window.onload = function cityWeather() {
let city = prompt("Enter a city.");
if ((city = "paris")) {
alert(
`It is currently ${weather[0].temp}°C in ${city} with a humidity of ${weather[0].humidity}`
);
}
if ((city = "tokyo")) {
alert(
`It is currently ${weather[1].temp}°C in ${city} with a humidity of ${weather[1].humidity}`
);
}
if ((city = "lisbon")) {
alert(
`It is currently ${weather[2].temp}°C in ${city} with a humidity of ${weather[2].humidity}`
);
}
if ((city = "san francisco")) {
alert(
`It is currently ${weather[3].temp}°C in ${city} with a humidity of ${weather[3].humidity}`
);
}
if ((city = "oslo")) {
alert(
`It is currently ${weather[4].temp}°C in ${city} with a humidity of ${weather[4].humidity}`
);
} else {
alert(
"Sorry, we don't know the weather for this city, try going to https://www.google.com/search?q=weather+sydney"
);
}
let weather = math.ciel(weather.humidity);
};