Please help me to correct this | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Please help me to correct this

//getting output "The flight undefined is undefined" 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) } function Flight(flightNumber, status) { //fix the constructor... number = flightNumber; status = status; };

22nd Aug 2022, 1:27 PM
bijay swarnakar
bijay swarnakar - avatar
2 Antworten
+ 1
you need to use 'this' to refer object property.. Use this.number = flightNumber; this.status = status; Share code link if not work, instead copy paste.
22nd Aug 2022, 1:35 PM
Jayakrishna 🇮🇳
+ 1
The this keyword refers to the current object. Note that this is not a variable. It is a keyword, and its value cannot be changed. this.number = flightNumber; this.status = status;
22nd Aug 2022, 1:35 PM
SoloProg
SoloProg - avatar