- 1
HELP with Landed problem
The result says flightStatus 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(number, status) { //fix the constructor this.number= flightNumber; this.status= flightStatus; }
5 Answers
+ 2
Inside the Flight constructor the variable names dont match with the arguments
+ 1
The below code should work,
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
this.number = flightNumber;
this.status = status;
};
0
Thank you, this has been resolved
this.number = number
this.status = status
0
can you please explain why my code is not working properly?
I've tried to rebuild the proposal from practice, so that is more like from the course. I wanted to define "object constructor", and build (via "var...") new object with certain properties...
Bob was hired as an airport information officer and needs to generate status messages for each flight†Letâs help him!
Complete the given program by fixing the constructor, making a flight object, and assign it to given variable to correctly execute the corresponding message.
Flight ID and the flight status(landed, on time, delayed, etc.) are taken as input.
Sample Input
NGT 929
landed
Sample Output
Flight NGT 929 has landed
Use new keyword to create a new object using constructor.
--------------
Code to use from course:
function main() {
//take flight number and its status
var flightNumber = readLine();
var flightStatus = readLine();
var flight1;
//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;
};
---------------------
My attempt:
function main() {
//take flight number and its status
var flightNumber = readLine();
var flightStatus = readLine();
}
function Flight(flightNumber, flightStatus) {
//fix the constructor
this.number = flightNumber;
this.status = flightStatus;
}
var flight1 = new Flight(flightNumber,flightStatus);
console.log('The flight ' + flight1.number + ' is ' + flight1.status);
0
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(number, status) {
//fix the constructor
this.number= number;
this.status= status;
}