Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda