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

140
Views
La instrucción Else sigue ejecutándose después de que la instrucción If sea verdadera (JavaScript)

var b = ['a', 'e', 'i', 'o', 'u']

var inp = prompt('Ingrese cualquier alfabeto para verificar si es vocal o no').toLowerCase()

for (i = 0; i < b.longitud; i++) {

 if(b[i]===inp){ alert('The entered value is vowel') }else{ alert('The entered value is not vowel') }

}

Intenté usar la instrucción break after else, pero luego el ciclo no está iterando todos los índices en la matriz. Gracias

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

0

El ciclo for se ejecuta una vez para cada índice de la matriz y, por lo tanto, también se else al menos cuatro veces. Una mejor construcción sería verificar si la matriz contiene el valor usando .indexOf() :

 var b = ['a', 'e', 'i', 'o', 'u'] var inp = prompt('Enter any alphabet to check if its vowel or not').toLowerCase() if(b.indexOf(inp) > -1){ alert('The entered value is vowel') }else{ alert('The entered value is not vowel') }

Alternativamente, se podría usar array.includes() :

 var b = ['a', 'e', 'i', 'o', 'u'] var inp = prompt('Enter any alphabet to check if its vowel or not').toLowerCase() if(b.includes(inp)){ alert('The entered value is vowel') }else{ alert('The entered value is not vowel') }
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!