Home > OS >  im trying to change the value of a text inside an if statement but it doesnt work i think i use wron
im trying to change the value of a text inside an if statement but it doesnt work i think i use wron

Time:06-08

So i have made this code that when i click the check button it changes the text of message every time , depending on the number input in guess variable .

Though my logic to declare the variables in the beggining and then use them seems okey to me, it doesnt work Can someone explain why my logic is wrong?

// for example i declared 
let message = document.querySelector('.message').textContent;

//and then i used message inside if to change the text
message = '‼ Type a Number';

why is this wrong?

document.querySelector('.check').addEventListener('click', function () {
      let score = 20;
      const guess = Number(document.querySelector('.guess').value);
      let message = document.querySelector('.message').textContent;
      if (!guess) {
        message = '‼ Type a Number';
      } else if (secretNumber === guess) {
        message = 'You Won            
  • Related