Jump to content

ioksan

Members
  • Posts

    1
  • Joined

  • Last visited

ioksan's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Hy guys. I have a homework that says something like that: "Create a class called Person with the attributes id, name, surname. Create another class called Student that inherits the class Persons and also has it`s own two attributes: id_card and average.Implement at least 2 methods in Person class and 1 method in Student class.Call all 3 methods after creating the instance of Student class." I managed to create this: "<html> <head> <script>// Definim clasa persoanafunction persoana(nume, prenume, cnp) { this.nume = nume; this.prenume = prenume; this.cnp = cnp;}// definim o metoda pentru afisarea numelui completpersoana.prototype.arataNume = function() {return this.nume + " " + this.prenume;};// definim o metoda pentru afisarea cnp-uluipersoana.prototype.arataCNP = function() {return this.cnp;};// Definim clasa studentfunction student(nume, prenume, cnp, nr_carnet, medie) {// constructor parintepersoana.call(this, nume, prenume, cnp);// proprietati publice si proprii pentru student this.nr_carnet = nr_carnet; this.medie = medie;}// Mostenim de la clasa persoanastudent.prototype = Object.create(persoana.prototype);// Definim o metoda pentru clasa student metoda prin care de fapt suprascriem metoda parinte arataNume si afisam in plus si numarul de carnetstudent.prototype.arataNume = function() {return "Student: " + this.nume + " " + this.prenume + " - Numar carnet: " + this.nr_carnet;};// Definire metoda pentru afisare medie studentstudent.prototype.medieStudent = function() {return this.medie;};// instantiem si rulam metodelevar unStudent = new student("xyz","abc","7432943929393", "122", "8");alert(unStudent.arataNume());alert("CNP student: " + unStudent.arataCNP());alert("Medie student: " + unStudent.medieStudent());</script></head><body></body></html>" The problem is that my professor refused my homework because I didn`t use PrototypeJS. Can you help me converting this code? I didn`t understood his request and by browsing this page I could`t understand much: "http://prototypejs.org/learn/class-inheritance.html"
×
×
  • Create New...