Where is the issue in the constructor | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Where is the issue in the constructor

Where is the issue in that code and how we fix the. Constructor function Flight(flightNumber, status) { //fix the constructor this.number = flightNumber; this.status = status; };

29th Mar 2023, 7:24 PM
Ali Alrahem
Ali Alrahem - avatar
8 Answers
+ 2
Please show the completed code. Look at the given code, it says: //assign a flight object to flight1 variable
29th Mar 2023, 7:31 PM
Lisa
Lisa - avatar
+ 2
Is this the complete code? could it be that you accidentally deleted function main()
29th Mar 2023, 7:49 PM
Lisa
Lisa - avatar
+ 1
Which error do you get?
29th Mar 2023, 7:43 PM
Lisa
Lisa - avatar
+ 1
function Flight(flightNumber, status) { if (typeof flightNumber !== "string") { throw new TypeError("flightNumber must be a string"); } if (!["delayed", "on time", "cancelled"].includes(status)) { throw new TypeError("status must be one of 'delayed', 'on time', or 'cancelled'"); } this.number = flightNumber; this.status = status; };
31st Mar 2023, 5:48 PM
Abdul Azeez Naseer Khan
Abdul Azeez Naseer Khan - avatar
0
No l will show the code main() { //take flight number and its status var flightNumber = readLine(); var flightStatus = readLine(); var flight1 = new Flight(flightNumber, flightStatus); //assign a flight object to flight1 variable //output console.log('The flight ' + flight1.number + ' is ' + flight1.status) }
29th Mar 2023, 7:36 PM
Ali Alrahem
Ali Alrahem - avatar
0
It already assigned
29th Mar 2023, 7:38 PM
Ali Alrahem
Ali Alrahem - avatar
0
It fixed function main() { //take flight number and its status var flightNumber = readLine(); var flightStatus = readLine(); var flight1 = new Flight(flightNumber, flightStatus); //assign a flight object to flight1 variable //output console.log('The flight ' + flight1.number + ' is ' + flight1.status) } class Flight { constructor(flightNumber,status){ this.number = flightNumber; this.status = status; } };
29th Mar 2023, 7:56 PM
Ali Alrahem
Ali Alrahem - avatar
0
Bro or sis it is very simple just give a look at the given code 😎😎
31st Mar 2023, 1:43 PM
Jasmine Randhawa
Jasmine Randhawa - avatar