This is my code for the moment (HTML):
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ejercicio 1 para practicas de fechas</title>
<script src="main.js"></script>
</head>
<!-- Busca todos los 1 de enero que sean domingo de 2014 a 2050. Muestras las fechas por pantalla o en la consola. -->
<body>
<h2>Aquí puedes consultar todos los 1 de enero que fueron o que serán domingo de 2014 a 2050</h2>
<button type="button" id="consultar()">Consúltalo aquí</button>
</body>
</html>
And this one for JavaScript:
function consultar(){
var fecha=new Date();
fecha=01/01/2014;
//var dias=["D", "L", "M", "X", "J", "V", "S"];
var diaSemana=fecha.getDay();
console.log (diaSemana);
// for (let i = 2014; i <= 2050; 2014++) {
// let anioDomingo=0;
//}
}
The case that I am doing that to see if it takes me at least the day of the week of 01/01/2014 but the program does not do anything to me (so that it does not enter the function) and although I look at the debugger and such, it does not I see the error nowhere.
On the other hand, I'm also stuck with how to find out how many January 1s will be Sunday from 2014 to 2050. Once I see that the getDay(); It works for me, I understand what it means to do a for (like the one I have commented on), but I don't know how to apply the getDay in a for when I am incrementing a year that in turn goes inside a date. Should I do a day/month/year split?
And another thing... Is putting it in European format like I'm putting it okay or should I put American?
Thank you very much, I'm super busy.
You have more or less the idea. What you need is to add a year to the date and check if it is Sunday. Something like that: