0

I'm working on a project in JavaScript and I need to fetch the text from the URL and sort it into objects. For example, their name, address, phone, and course.

class Studenti {
  constructor(name, address, phone, course) {
    this.name = name;
    this.address = address;
    this.phone = phone;
    this.course = course;
  }

  getInfo() {
    return "Name: " + this.name + "\n" + "Address: " + this.address + "\n" + "Phone: " + this.phone + "\n" + "Course: " + this.course
  }
}

fetch("https://v-dresevic.github.io/Advanced-JavaScript-Programming/data/students.txt")
  .then(res => res.text())
  .then(text => text.split("\n"))

var student1 = new Studenti(text[0], text[1], text[2], text[3]);

console.log(student1);

When I do this all it says is that text is not defined

Michael M.
  • 10,486
  • 9
  • 18
  • 34

1 Answers1

0

It gives an error "Text is not defined" because you didn't properly define text by putting something like var text = []; Before you can use a variable called "text", you need to properly define it.

henxdl
  • 118
  • 14