50projects50days/good-cheap-fast/script.js

22 lines
626 B
JavaScript
Raw Normal View History

2020-10-15 15:23:13 +00:00
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
}
}
}