Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
change div to increase progress bar

I'm working to have my progress bar increase when a specific word is said (Bingo) This is a conversation between a user and a chatbot, where the user is trying to guess a secret that the chatbot olds. Every time the user gets it right, the chatbot replies with "Bingo! " I was hoping to increase the progress bar every time the chatbot replies with "Bingo! " and when the progress bare hits 100% it should restart back to 0%. I get the progress bar shows, but it does not increase. I was thinking of having to loop through the div to look for "Bingo" and change the div in the progress bar. Or simply have a "Bingo" as a variable and match it to the div="bingo1" and then increase the progress bar. What would be the most efficient way? enter image description here

I'm using chatterbot which contains the conversation between the user and chatbot in a .yml file, so it is possible to do something there

function myBingo(){
  if (document.getElementById('bingo1').innerHTML.indexOf("Bingo")){ 
    // change progress bar to 10%
  } 
}
#progress {
 width: 500px;   
 border: 1px solid black;
 position: relative;
 padding: 3px;
}
#percent {
 position: absolute;   
 left: 50%;
}
#bar {
 height: 20px;
 background-color: green;
 width: 0%;
}
<!-- I added an id here -->
<div class="msg-text" id="bingo1">Bingo! The secret is Garfield</div>

<div id="progress">
    <span id="percent">0%</span>
    <div id="bar"></div>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

He might have given a different answer as he didn't quite understand what he wanted. In the solution below, the progress bar will be increased by the number of Bingo expressions entered into the item whose id value is bingo1.

If you're asking something different, please edit the question or comment below this answer.

enter image description here

let percent = document.getElementById('percent');
let bar = document.getElementById('bar');
let input = document.getElementById('bingo1');
let counter = 0;

function update() {
  if (input.value.indexOf("Bingo") != -1)
  { 
    var count = (input.value.match(/Bingo/g) || []).length;
    counter = count * 10;
    
    if(counter >= 100)
      counter = 100;
      
    percent.innerHTML = `${counter}%`;
    bar.style.width = `${counter}%`;
  } 
}

input.addEventListener('input', update);
#progress {
 width: 500px;   
 border: 1px solid black;
 position: relative;
 padding: 3px;
}

#percent {
 position: absolute;   
 left: 50%;
}

#bar {
 height: 20px;
 background-color: green;
 width: 0%;
}
<label>Input: </label>
<input class="msg-text" id="bingo1"><br><br>

<div id="progress">
    <span id="percent">0%</span>
    <div id="bar"></div>
</div><br><br>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda