The goal of this code is to display the current numbers of death, recoveries and critical for covid 19 around the world.
The search function codes are as follows:
const search = (e) => {
e.preventDefault() //to avoid page redirection
const countryMatch = countryCollection.find(country => country.country_name === targetCountry)
if (!countryMatch || countryMatch === null|| countryMatch === 'undefined') {
alert("Country Does Not Exist, use another name.")
setName("")
setTargetCountry("")
} else {
setName(countryMatch.country_name)
setDeathCount(toNum(countryMatch.deaths))
setCriticalCount(toNum(countryMatch.serious_critical))
setRecoveryCount(toNum(countryMatch.total_recovered))
}
}
Our task is to find a country regardless if its in upper or lower case. Eg: Malaysia vs malaysia.