0
Getting error message
Error : flight is undefined function main() { //take flight number and its status var flightNumber = readLine(); var flightStatus = readLine(); var flight1; //assign a flight object to flight1 variable flight1 = new Flight; //output console.log('The flight '+ flight1.flightId + flight1.number + ' is ' + flight1.status) } function Flight(flightNumber, status) { //fix the constructor this.number = flightNumber; this.status = status; this.flightId = flightNumber; };
2 ответов
+ 1
You have to define the function flight before you try to use it
function Flight(flightNumber, status) {
//fix the constructor
this.number = flightNumber;
this.status = status;
this.flightId = flightNumber;
};
function main() {
//take flight number and its status
var flightNumber = readLine();
var flightStatus = readLine();
var flight1;
//assign a flight object to flight1 variable
flight1 = new Flight;
//output
console.log('The flight '+ flight1.flightId + flight1.number + ' is ' + flight1.status)
}
0
Thank you, I have used functions before just to jump around the code, but I'm trying to learn how to use objects within a function.