Problem with program using objects | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Problem with program using objects

This program should display something like Flight NGT 929 has landed, I added a readline() variable (letters) that should hold the NGT letters, please look at the remarks, I am getting a syntax error, and I have no clue about what I'm doing. Here's the code: function main() { //take flight number and its status var flightNumber = readLine(); var flightStatus = readLine(); // ***** I added var letters below**** var letters = readLine(); var flight1; //assign a flight object to flight1 variable //output console.log('The flight ' flight1.letters + flight1.number + ' is ' + flight1.status) } function Flight(flightNumber, status, letters) { //fix the constructor this.number = flightNumber; this.status = flightStatus; this.letters = flight1; }; /*****REMARKS TO HELP WITH SYNTAX******** function person (name, age) { this.name = name; this.age = age; } var John = new person("John", 25); */

3rd Sep 2021, 3:19 PM
Natanael
3 Respostas
+ 4
First of all you cannot take an input of your own using the readLine() because they are already defined for the code. function main() { //take flight number and its status var flightNumber = readLine(); var status = readLine(); //assign a flight object to flight1 variable var flight1 = new Flight (flightNumber, status); //output console.log('The flight ' + flight1.number + ' is ' + flight1.status) } function Flight(flightNumber, status) { //fix the constructor this.number = flightNumber; this.status = status; }
3rd Sep 2021, 3:43 PM
Avinesh
Avinesh - avatar
+ 1
In the first answer I was told I cannot take input using readline() because it is already defined for something else. No problem, but there are other things that I am missing, I am not asking you to solve the problem for me, just asking to point me in the right direction. At this point without any help Sololearn will be useless to me because I cannot move forward unless I can clearly understand this.
3rd Sep 2021, 7:25 PM
Natanael
0
I'm getting this message "flight is undefined" Here's the new code: 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, 10:33 PM
Natanael