for (let radio of radios){
radio.classList.remove('highlight')
}
document.getElementById(e.target.id).parentElement.classList.add('highlight')
}
function getMatchingCatsArray(){
if(document.querySelector('input[type="radio"]:checked')){
const selectedEmotion = document.querySelector('input[type="radio"]:checked').value
const isGif = gifsOnlyOption.checked
/*
Challenge:
1. Use the .filter() and .includes() methods to get
an array of cats which have the selected emotion
in their emotionTags array.
2. Store this array in a const and log it out to check
it's working. Think: what would be a good name for the
const?
*/
}
}
function getEmotionsArray(cats){
const emotionsArray = []
for (let cat of cats){
for (let emotion of cat.emotionTags){
if (!emotionsArray.includes(emotion)){
emotionsArray.push(emotion)
}
}
}
return emotionsArray
}
function renderEmotionsRadios(cats){
let radioItems = ``
const emotions = getEmotionsArray(cats)
for (let emotion of emotions){
radioItems += `
<div class="radio">
<label for="${emotion}">${emotion}</label>
<input
type="radio"
id="${emotion}"
value="${emotion}"
name="emotions"
>
</div>`
}
emotionRadios.innerHTML = radioItems
}
renderEmotionsRadios(catsData)
import { catsData } from '/data.js'
const emotionRadios = document.getElementById('emotion-radios')
const getImageBtn = document.getElementById('get-image-btn')
const gifsOnlyOption = document.getElementById('gifs-only-option')
emotionRadios.addEventListener('change', highlightCheckedOption)
getImageBtn.addEventListener('click', getMatchingCatsArray)
function highlightCheckedOption(e){
const radios = document.getElementsByClassName('radio')