Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
How to i add date validation to this javascript code using getfullyear

Create a function to validate the movie release year using the following business rules: • Release year must be in the range between 1930 to the current year

I want to add a validation to my code to validate year between 1930 and the current year and if it's not correct it should print an error

var movieTitle = [];
var movieReleaseYear = [];
function init() {
var add = document.getElementById("add");
add.onclick = () => addMovie();
var show = document.getElementById("show");
show.onclick = () => displayData();
}

function addMovie() {
var name = document.getElementById("movie");
var year = document.getElementById("year");
movieTitle.push(name.value);
movieReleaseYear.push(year.value);
}

function displayData() {
if (movieTitle.length == 0) {
document.getElementById("list").innerHTML = "there is no data";
} else {
var output = "";
movieTitle.forEach(
(element, index) =>
(output +=
" " + (index+1) + ". " + element + "\t\t" + movieReleaseYear[index] + "<br />")
);
document.getElementById("list").innerHTML = output;
}
}
window.onload = init;
<!DOCTYPE html>
<html lang="en">
<head>
 
 <title>Week 07 Pass Submission</title>
<script src="./w7p.js"></script>
</head>
<body>
<header>
<h1>Week 07 Pass Submission</h1>
</header>
<article>
<form>
<label for="movie">Movie title</label>
<input type="text" id="movie" /><br /><br />
<label for="year">Release year</label>
<input type="text" id="year" /><br /><br />
<input type="button" id="add" value="Add">
<input type="button" id="show" value="List All">
</form><br />
<div style="padding-left: 20px;" id="list"></div>

</article>
 
</body>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

    <!DOCTYPE html>
    <html lang="en">
    <head>
     
     <title>Week 07 Pass Submission</title>
    <script src="./w7p.js"></script>
    </head>
    <body>
    <header>
    <h1>Week 07 Pass Submission</h1>
    </header>
    <article>
    <form>
    <label for="movie">Movie title</label>
    <input type="text" id="movie" /><br /><br />
    <span id="yearValidation" style="color: red"></span>
     <br />
    <label for="year">Release year</label>
    <input type="text" id="year" /><br /><br />
    <input type="button" id="add" value="Add">
    <input type="button" id="show" value="List All">
    </form><br />
    <div style="padding-left: 20px;" id="list"></div>
    
    </article>
     
    </body>
    </html>

var movieTitle = [];
var movieReleaseYear = [];
function init() {
  var add = document.getElementById('add');
  add.onclick = () => addMovie(2022);
  var show = document.getElementById('show');
  show.onclick = () => displayData();
}

function addMovie(currentYear) {
  var name = document.getElementById('movie');
  var year = document.getElementById('year');
  var year = document.getElementById('year').value;
  if (year <= 1930 || year >= currentYear) {
    document.getElementById('yearValidation').innerHTML = 'Error';
  } else {
    document.getElementById('yearValidation').innerHTML = '';
  }
  movieTitle.push(name.value);
  movieReleaseYear.push(year.value);
}

function displayData() {
  if (movieTitle.length == 0) {
    document.getElementById('list').innerHTML = 'there is no data';
  } else {
    var output = '';
    movieTitle.forEach(
      (element, index) =>
        (output +=
          ' ' +
          (index + 1) +
          '. ' +
          element +
          '\t\t' +
          movieReleaseYear[index] +
          '<br />')
    );
    document.getElementById('list').innerHTML = output;
  }
}
window.onload = init;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda