Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
¿Puedo comparar la respuesta de un aviso con las propiedades de los objetos en una matriz?

Estoy tratando de hacer coincidir el resultado de un aviso con las propiedades de varios objetos en una matriz. (Es decir, si la ciudad ingresada coincide con el nombre de uno de los objetos enumerados, devuelve la temperatura coincidente)

 let cities = [ { name: "San Luis Obispo", temp: 16, uv: 1, humidity: 5, elevation: 28, wind: 2, }, { name: "Morro Bay", temp: 11, uv: 2, humidity: 8, elevation: 1, wind: 8, }] let city = prompt("Enter a city"); if (city === cities.name){ alert(`It is currently ${temp}°C in ${city}`); }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

let cities = [ { name: "San Luis Obispo", temp: 16, uv: 1, humidity: 5, elevation: 28, wind: 2, }, { name: "Morro Bay", temp: 11, uv: 2, humidity: 8, elevation: 1, wind: 8, }] let cityName = prompt("Enter a city"); const city = cities.find(cityX => { return cityName === cityX.name }) if (city){ alert(`It is currently ${city.temp}°C in ${cityName}`); }
about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto

 let city = prompt("Enter a city"); Cities.forEach(current=>{ if (city.trim() === current.name){ alert(`It is currently ${current.temp}°C in ${city}`); } })
about 4 years ago · Juan Pablo Isaza Report

0

ejecute un ciclo for sobre la matriz de objetos ( cities ), verificando cada ciudad en la matriz:

 let cities = [{ name: "San Luis Obispo", temp: 16, uv: 1, humidity: 5, elevation: 28, wind: 2, }, { name: "Morro Bay", temp: 11, uv: 2, humidity: 8, elevation: 1, wind: 8, } ] let city = prompt("Enter a city"); for (let i = 0; i < cities.length; i++) { if (city == cities[i].name) { alert(`It is currently ${cities[i].temp}°C in ${city}`); } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!