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

119
Views
Javascript que intenta crear mi propia validación de formulario no funciona

Tengo este formulario con el que puedes crear una matriz. No quiero que se cree el formulario cuando hay algunas circunstancias específicas. Tengo esta matriz y en ella puedes crear preguntas y respuestas con un formulario, pero tengo algunas reglas. La matriz solo se puede crear cuando hay más de 3 preguntas y cuando cada pregunta tiene al menos 3 respuestas.

Mi código:

 Checker() { /** * @type {Question[]} */ let questions = NewArray.structure.questions; for (let i = 0; i < questions.length; i++) { if (questions[i].answers.length <= 2) { console.log(questions[i]) alert('Question number ' + i + ' has to few answers') } else if (questions.length <= 2) { alert('You need at least 3 questions!'); } else { return true; } } } if (NewArray.Checker() === true) { Do something } else { Do nothing }

Aquí está la matriz de preguntas con las preguntas y las preguntas [i]. responde las respuestas de las preguntas.

Cuando me da el mensaje correcto cuando hay menos de 3 preguntas y cuando la primera pregunta tenía menos de 3 respuestas, pero cuando hay 3 preguntas y solo la primera tiene respuestas, todavía funciona lo que no debería. ¿Alguien sabe por qué?

Imagen del formulario

Estructura

 class Question { /** * @param {string} question * @param {string} prefix * @param {string} description * @param {string} display * @param {string} answerType * @param {string} multiSelect * @param {Answer[]} answers */ constructor(question = "", prefix = "", description = "", display = "", answerType = "", multiSelect = "", answers = []) { this.question = question; this.prefix = prefix; this.description = description; this.display = display; this.answerType = answerType; this.multiSelect = multiSelect; this.answers = answers; } } class Answer { constructor(id = "", name = "") { this.id = id; this.name = name; } }
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!