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

196
Views
Javascript obteniendo una función para ejecutar basada en y/o

Mi código:

 let buttonScore = document.querySelector('.button-score'); let paraScore = document.querySelector('.para-score'); buttonScore.addEventListener('click', scoreEntry); function scoreEntry() { let scoreOne = Number(prompt('Enter first score')); let scoreTwo = Number(prompt('Enter second score')); if (scoreOne > scoreTwo) { scoreCheck(); } } function scoreCheck() { if (scoreOne > 9) { paraScore.textContent = 'Excellent!'; } else if (scoreOne < 7) { paraScore.textContent = 'Not enough'; } else { paraScore.textContent = 'Good'; } }

Una vez que el usuario ingrese los dos puntajes, quiero que el script seleccione el puntaje más alto de los dos y ejecute scoreCheck() en él. Supongo que mi problema tiene que ver con variables no globales. En caso de que esto también se pueda hacer con una función en lugar de dos, también me gustaría saberlo, por favor.

Agradecería mucho la aclaración, gracias de antemano.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe hacer que la variable sea un parámetro para la segunda función.

En lugar de probar si una puntuación es más alta que la otra, use Math.max() para seleccionar la puntuación más alta y pásela como argumento.

 function scoreEntry() { let scoreOne = Number(prompt('Enter first score')); let scoreTwo = Number(prompt('Enter second score')); scoreCheck(Math.max(scoreOne, scoreTwo)); } function scoreCheck(score) { if (score > 9) { paraScore.textContent = 'Excellent!'; } else if (score < 7) { paraScore.textContent = 'Not enough'; } else { paraScore.textContent = 'Good'; } }
about 4 years ago · Juan Pablo Isaza Report
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!