@miroslaw-mroczkowski
Posted
Hi Charles,
Your design looks great :)
Few tips about JS:
Instead of using addEventListener for each button, you could create:
- static NodeList with querySelectorAll on your num-btn class,
- variable (e.g. let scoreValue) to keep clicked value (but you have to set a value on each of your button)
- use forEach method to iterate through your NodeList
const btns = document.querySelectorAll('.num-btn)
let scoreValue = '';
const score = () => {
btns.forEach(score => {
score.addEventListener('click', e => {
scoreValue = e.target.value
})
})
}
Then you can use your scoreValue to put it in your sub-container, but you won't need to put the index of your numArr
array.
thankEl.textContent = 'You selected ${scoreValue} out of ${btns.length}'
You could also add an error message in case of not choosing any score. To do this you need to create e.g. if...else statement.
In case of any questions feel free to ask :)
Marked as helpful
@charlesmambo
Posted
@miroslaw-mroczkowski thanks a lot