50projects50days/good-cheap-fast/script.js
2020-10-15 11:23:13 -04:00

22 lines
626 B
JavaScript

const toggles = document.querySelectorAll('.toggle')
const good = document.querySelector('#good')
const cheap = document.querySelector('#cheap')
const fast = document.querySelector('#fast')
toggles.forEach(toggle => toggle.addEventListener('change', (e) => doTheTrick(e.target)))
function doTheTrick(theClickedOne) {
if(good.checked && cheap.checked && fast.checked) {
if(good === theClickedOne) {
fast.checked = false
}
if(cheap === theClickedOne) {
good.checked = false
}
if(fast === theClickedOne) {
cheap.checked = false
}
}
}