scrimba
Frontend Career Path
Essential JavaScript concepts
Meme Picker
Add colour to the selected emotion
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Add colour to the selected emotion
AboutCommentsNotes
Add colour to the selected emotion
Expand for more info
index.js
run
preview
console
import { catsData } from '/data.js'

const emotionRadios = document.getElementById('emotion-radios')

emotionRadios.addEventListener('change', function(e){
console.log(e.target.id)
})

/*
Challenge:
1. highlightCheckedOption should take control
of the selected radio input and add the CSS
class of "highlight" to its classlist
*/

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)




Console
"sad"
,
/index.html
-5:50