I am trying to solve this question from w3 resources. QUESTION: Write a JavaScript program to find 1st January is being a Sunday between 2014 and 2050. I tried solving it and attached the code below. I can correctly log the answers but when I am trying to update the textNodes.data with setInterval only the year 2043 but I want it to change through all the years (answers) that are being logged every 100 milliseconds. I guessed there is a for loop and setInterval together thus the problem although the years are being logged correctly the problem remains that the target DOM with id="target" shows
console.log('January 1 Sunday for the following years:');
let getLeaps=(id)=>{
let target =document.getElementById(id);
let textNode =target.childNodes[0];
let text= textNode.data ;
let dates=new Date();
for(x=2014;x<=2050;x++){
dates.setFullYear(x, 01, 01);
let day = dates.getDay();
if (day==0){
let year0 = dates.getFullYear()
text=year0;
console.log(text);
textNode.data=text;
console.log(textNode.data);
}
}
}
getLeaps('target');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id="target"> </p>
</body>
</html>