Javascript error: "Uncaught TypeError: isTripDay is not a function"

3

var tripDay = prompt('Porfavor ingrese el numero de dia en el que desea viajar');

while (!isTripDay() || !confirmDay()){

function isTripDay(){
  if (tripDay >= 1){
    return true;
  }else{
    return false;
  }
}

function confirmDay(){

  return confirm('Realmente desea comprar un pasaje para el dia '+tripDay+' ?');
  }

}
    
asked by Santiago D'Antuoni 21.12.2016 в 23:55
source

3 answers

1

Tells you this error because you are defining the functions within the loop and are not detecting them as being declared. You would have to take them outside to be detected.

Your corrected example:

var tripDay = prompt('Porfavor ingrese el numero de dia en el que desea viajar');

while (!isTripDay() || !confirmDay()){
   alert("hemos entrado");

}

function isTripDay(){
  if (tripDay >= 1){
    return true;
  }else{
    return false;
  }
}


function confirmDay(){

  return confirm('Realmente desea comprar un pasaje para el dia '+tripDay+' ?');
  }
    
answered by 22.12.2016 в 00:00
0

If Rene was right, but I could really solve it in this way. Now it works as I wanted

do {
 
var tripDay = prompt('Porfavor ingrese el numero de dia en el que desea viajar');


function confirmDay(){

  return confirm('Realmente desea comprar un pasaje para el dia '+tripDay+' ?');
  } 

function isTripDay(){
  if (tripDay >= 1 && tripDay <= 25){
    alert('Perfecto su viaje esta programado para el dia '+tripDay);
    return true;
  }else{
    alert('Lo sentimos, el dia seleccionado no tiene viajes programados');
    return false;
  }
}


}while (!confirmDay() || !isTripDay())
    
answered by 22.12.2016 в 17:36
-2

As the error says:

  

TypeError: isTripDay is not a function

is a variable and therefore () is enough

var tripDay = prompt('Porfavor ingrese el numero de dia en el que desea viajar');

function confirmDay(){

  return confirm('Realmente desea comprar un pasaje para el dia '+tripDay+' ?');
  }

while (!isTripDay || !confirmDay()){

function isTripDay(){
  if (tripDay >= 1){
    return true;
  }else{
    return false;
  }
}


}
    
answered by 21.12.2016 в 23:59