scrimba
Note at 1:41
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

Note at 1:41
AboutCommentsNotes
Note at 1:41
Expand for more info
index.js
run
preview
console
const string = document.querySelector('#string');
const counterTotalDisplay = document.querySelector('.countTotal');
const currentCountDisplay = document.querySelector('.currentCount');
const btn = document.querySelector('#btn');
const allowedCount = 140; // So the allowed count can be changed
let currentCount = 0;
const changeArray = [counterTotalDisplay, currentCountDisplay];
counterTotalDisplay.textContent = `/ ${allowedCount}`
currentCountDisplay.textContent = allowedCount ;

string.addEventListener('input', (event) => {
let count = string.value.length;
currentCount = allowedCount - count;
currentCountDisplay.textContent = currentCount;

if (currentCount <= 20) {
for (let element of changeArray) {
element.style.color = "red";
}
} else {
for (let element of changeArray) {
element.style.color = "white";
}
}

if (currentCount < 0) {
btn.disabled = true;
btn.classList.add('buttonDisabled');
} else {
btn.disabled = false;
btn.classList.remove('buttonDisabled');
}
});

Console
/index.html
LIVE