Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Returns null even if it is declared in react

So here's my code, I was wondering on why whenever I click on the button, it always return a Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')? How can I resolve this case?

import React from "react";

export default function GameApp() {
  const score = 0;
  const firstNum = document.getElementById("card1");
  const secondNum = document.getElementById("card2");
  const thirdNum = document.getElementById("card3");

  // starting the game
  function start() {
    firstNum.innerHTML = "First number: " + Math.floor(Math.random() * 13 + 1);
    secondNum.innerHTML =
      "Second number: " + Math.floor(Math.random() * 13 + 1);
  }

  function deal() {
    thirdNum.innerHTML = "Third number: " + Math.floor(Math.random() * 13 + 1);
  }

  return (
    <div>
      <button onClick={start}> Start the game </button>
      <p id="card1"> </p>
      <p id="card2"> </p>
      <p id="card3"> </p>
      <button onClick={deal}> Deal </button>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!