js
// 상수 정의
const smallCups = ( 클래스 cup-small 전체 )
const liters = (아이디 liters )
const percentage = ( 아이디 percentage)
const remained = (아이디 remained );
//큰컵물채우기();
//forEach( (아이템,인덱스) => {})
smallCups.forEach((cup, idx) => {
cup.addEventListener('click', () => 작은컵들채우기(idx));
});
function 작은컵들채우기(idx) {
//console.log(idx);
if (idx === 7 && smallCups[idx].classList.contains('full')) idx--;
else if (
smallCups[idx].classList.contains('full') &&
!smallCups[idx].nextElementSibling.classList.contains('full')
) {
idx--;
}
smallCups.forEach((cup, idx2) => {
if (idx2 <= idx) {
cup.classList.add('full');
} else {
cup.classList.remove('full');
}
});
//큰컵물채우기();
}