2021/10/15下午9:07CS 105: Introduction Computing: Non-Technology home126/129ThegetSummaryForecast()function loops through the forecast data retrieved from the forecastAPI and creates a map of 5 or 6 objects that contain the highest and lowest temperature for each dayand weather summary string like "Clear", "Rain", or "Snow".// Display forecast recevied from JSONfunctionresponseReceived(xhr,cityId,city){// No longer loadinghideElement("loading-"+cityId);// 200 status indicates forecast successfully receivedif(xhr.status===200){showElement("results-"+cityId);constcityName=xhr.response.city.name;showText(cityId+"-name",cityName);// Get 5 day forecastconstforecast=getSummaryForecast(xhr.response.list);// Put forecast into the city's tableletday=1;for(constdateinforecast){// Only process the first 5 daysif(day<=5){showText(`${cityId}-day${day}-name`,getDayName(date));showText(`${cityId}-day${day}-high`,Math.round(forecast[date].high) +"°");showText(`${cityId}-day${day}-low`,Math.round(forecast[date].low) +"°");showImage(`${cityId}-day${day}-image`,forecast[date].weather);}day++;}}else{// Display appropriate error messageconsterrorId="error-loading-"+cityId;showElement(errorId);showText(errorId,`Unable to load city"${city}".`);}}// Convert date string into Mon, Tue, etc.functiongetDayName(dateStr){constdate=newDate(dateStr);returndate.toLocaleDateString("en-US",{weekday:'short',timeZone:'UTC'});}// Show the weather image that matches the weatherTypefunctionshowImage(elementId,weatherType){// Images for various weather typesconstweatherImages={Clear:"clear.png",Clouds:"clouds.png",Drizzle:"drizzle.png",Mist:"mist.png",Rain:"rain.png",Snow:"snow.png"};constimgUrl="";constimg=document.getElementById(elementId);img.src=imgUrl+weatherImages[weatherType];img.alt=weatherType;}