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

209
Vistas
¿Cómo puedo hacer que una declaración if incluya un rango de números en javascript?

Esta es la primera vez que codifico y tengo algunos problemas. Aquí está mi código hasta ahora (javascript)

 var userName = prompt("Hi! What is your name?"); // The answer the user gives for this prompt will be used later in the program var hoursWorked = prompt("How many hours have you worked this week?"); //The answer the user gives for this prompt will be multiplied by 15 to determine the amount that they will be paid var pay = ("$" + hoursWorked * 15) var hoursLeft = (40 - hoursWorked); //This equation determines how many hours of work the user has left to complete if (hoursLeft < 0) { alert("Uh oh! " + userName + "! That's too many hours!") }; //If the user enters an amount of hours that is over 40 they will recieve an error message if (hoursLeft === 0) { alert("Congratulations, " + userName + "! You have completed all 40 hours of work!"); //If the user has completed 40 hours of work they will be given this message alert(userName + ", your pay will be: " + pay) }; if (hoursLeft => 0 && hoursLeft = < 39) { alert(userName + ", you have " + hoursLeft + " more hours to work this week."); //If the user has completed <40 hours of work they will be given this message, along with how many hours they have left to complete alert(userName + ", your pay so far is: " + pay) }; if (hoursLeft > 40) { alert(userName + "! That is not possible!") } //If the user enters a negative amount of hours they will be given this message

Mi problema es con esta línea "if (hoursLeft => 0 && hoursLeft =< 39){ "

¿Cómo puedo hacer que si las horas son más de 0 y menos de 40 me devuelva las alertas? Gracias

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

0

El problema es que debe usar >= en lugar de => (esto se analizará como expresión para la función de flecha) y usar <= en lugar de =< .

<= Operador menor o igual.

>= Operador mayor o igual.

Ver más aquí

 var userName = prompt("Hi! What is your name?"); // The answer the user gives for this prompt will be used later in the program var hoursWorked = prompt("How many hours have you worked this week?"); //The answer the user gives for this prompt will be multiplied by 15 to determine the amount that they will be paid var pay = ("$" + hoursWorked * 15) var hoursLeft = (40 - hoursWorked); //This equation determines how many hours of work the user has left to complete if (hoursLeft < 0){ alert ("Uh oh! " + userName + "! That's too many hours!")}; //If the user enters an amount of hours that is over 40 they will recieve an error message if (hoursLeft === 0){ alert ("Congratulations, " + userName + "! You have completed all 40 hours of work!"); //If the user has completed 40 hours of work they will be given this message alert ( userName + ", your pay will be: " + pay)}; if (hoursLeft >= 0 && hoursLeft <= 39 ){ alert (userName + ", you have " + hoursLeft + " more hours to work this week."); //If the user has completed <40 hours of work they will be given this message, along with how many hours they have left to complete alert ( userName + ", your pay so far is: " + pay)}; if (hoursLeft > 40){ alert (userName + "! That is not possible!")}

about 4 years ago · Juan Pablo Isaza Denunciar

0

Mostrar mayor o igual en js con operador >= , y mostrar menor o igual con operador <= , vea este enlace para mayor que e igual y este para menor que e igual.

 >= greater than and equal <= less than and equal
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