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

524
Views
Unable to fix cannot fix properties of null(setting:innerText) error

I'm trying to write the output I got to a paragraph defined as <p id="output-text"></p> in my html file. However I keep getting an error that says Uncaught:TypeError:Cannot set properties of null(setting:innerText). What can I do to fix this? I tried checking if there is a difference in the id is used in my HTML file and the 'id' I used to reference it in the .js file . I don't find any difference in that aspect.

const dob=document.querySelector("#dob");
const luckyNumber=document.querySelector("#lucky-num");
const checkButton=document.querySelector("#check");
checkButton.addEventListener("click",clickHandler);
const result=document.querySelector("#output-text");

function clickHandler()
{
    var sumOfDigits=sum(dob);
    testLuck(sumOfDigits,luckyNumber);
}

function sum(dob)
{
    dob=dob.value.replaceAll("-","");
    console.log(dob);
    dob=parseInt(dob);
    var sum=0;
    while(dob > 0)
    {
        var digit=dob%10;
        sum+=digit;
        dob=Math.trunc(dob/10);
    }
    return sum;
}

function testLuck(sumOfDigits,luckyNumber)
{
    if(sumOfDigits%luckyNumber.value === 0)
    {
        result.innerText="Yayy🥳Your Birthday is Lucky";
    }
    else
    {
        result.innerText="Uff your Birthday is not sooo lucky it seems😭";
    }
}

enter image description here

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!