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

252
Visualizações
Been facing an issue when trying to run the html file on Chrome. It keeps showing me the error "Cannot set properties of null (setting 'textcontent')"

I've tried changing the .textcontent to .innertext and then i get the error message "Cannot set properties of null (setting 'innertext')". Could it be that it's the HTML that is faulty or what because they are all showing the same error when run on chrome. What can I do please? ta

let cards = [];
let firstcard = randomNumber();
let secondcard = randomNumber();
let sum = firstcard + secondcard;
let blackjackvalue = false; // checks for blackjack value
let isalive = true; //to check if the user can play only when the game is true
let message = "";
let gamestate = document.getElementById(message); // get the gamestate
let sumEl = document.getElementById(sum); //holding the sum
let cardEl = document.getElementById("card"); //holding the card
let playerEl = document.getElementById("player"); //holding the player details
let playerdetails = {
  name: "John",
  wins: 5,
  amount: "$" + 500,
};
playerEl.innertext = playerdetails.name + playerdetails.wins + playerdetails.amount;

function randomNumber() {
  let jacknumbers = Math.floor(Math.random() * 14) + 1; //produces random numbers between 1 and 13 to be used by first and second card
  return jacknumbers;
  if (jacknumbers == 1) {
    return 11;
  } //these if conditions are for setting the ace card to either 1 or 11...not really sure
  else if (jacknumbers > 10) {
    return 10;
  } else {
    return jacknumbers;
  }
}


function start() {
  // let firstcard = randomNumber();
  // let secondcard = randomNumber();
  let cards = [firstcard, secondcard];
  let sum = [firstcard + secondcard];
  rendergamestate();
} //when this is called, it triggers the rendergamestate function
function rendergamestate() {
  card.innertext = "cards:" + " " + firstcard + " " + secondcard;
  for (i = 0; i < card.length; i += 1) {
    card.innertext += cards[i] + " ";
    //using the for loop to display the card contents
  }
  sumEl.innertext = "sum:" + " " + sum;
  if (sum <= 20) {
    message = "Do you want to draw a new card?";
    blackjackvalue = false;
  } else if (sum === 21) {
    message = "Blackjack!";
    blackjackvalue = true;
  } else {
    message = "You are out";
    isalive = false;
    blackjackvalue = false;
  }
  gamestate.innertext = message;
}
function newcard() {
  //this button is for the user to add a new card to the already existing cards
  if (isalive === true && blackjackvalue === false) {
    let thirdcard = randomNumber();
    sum += thirdcard; // sum=sum+thirdcard;
    cards.push(thirdcard);
    rendergamestate(); //calling the function to start the game
  }
}

about 4 years ago · Juan Pablo Isaza
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