dimanche 11 décembre 2022

how can i generate a program that guess a word and apply by a button?

i made a button in an html document, that suppose to chose one word from a 20 words i defiend in a what supposed to be a nice guessing program that include a search bar which the user of the program guess one of the words at the search bar (from the 20 i defiend) and the program picks one word randomly and shows that after the user made his guess.
i did the button and search bar but when the user write a word and press the button to get the word that picked by the program nothing happens .
i guess that the problem is at the script i wrote.

 let teams = ["atalanta", "Bologna", "Cremonese", "Empoli", "Fiorentina", 
"Verona", "Inter", "Juventus", "Lazio", "Lecce", "Milan", "Monza",
 "Napoli", "Roma", "Salernitana", "Sampdoria", "Sassuolo", "Spezia",
  "Torino", "Udinese"];

  let secretTeam = teams[Math.floor(Math.random() * 20)];
  console.log(secretTeam);

document.querySelector('.search').addEventListener('.click' , function() {
const guess = teams(document.querySelector('.guess').value);

    if(guess === secretTeam) {
        document.querySelector('.messege').textContent = (secretTeam),'you right!';
        document.querySelector('body').style.backgroundColor = '#4ceb34';}
     
   else{
        document.querySelector('.messege').textContent = (secretTeam),'wrong answer';
        document.querySelector('body').style.backgroundColor = '#f71505';
   }
    
    
})

this is my script




Aucun commentaire:

Enregistrer un commentaire