Getting error message | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; };

3rd Sep 2021, 11:46 PM
Natanael
2 Answers
+ 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) }
4th Sep 2021, 1:13 AM
BlueTiger435
BlueTiger435 - avatar
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.
4th Sep 2021, 2:02 PM
Natanael