Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zad1
- function Student(imie, nazwisko, oceny){
- this.imie = imie;
- this.nazwisko = nazwisko;
- this.oceny = [];
- }
- var student1 = new Student('Weronika', 'Baranowska');
- var a = [];
- Student.prototype.dodajOcene = function(a){
- this.oceny[this.oceny.length] = a;
- }
- student1.dodajOcene(3.5);
- student1.dodajOcene(5);
- student1.dodajOcene(4.5);
- console.log(student1);
- var suma = 0;
- Student.prototype.sredniaOcen = function(){
- for(var i = 0; i < this.oceny.length; i++)
- suma+=this.oceny[i];
- var srednia = suma/this.oceny.length;
- console.log(this.imie, this.nazwisko, srednia);
- }
- student1.sredniaOcen();
- //zad2
- class StudentX{
- constructor(imie, nazwisko, oceny){
- this.imie = imie;
- this.nazwisko = nazwisko;
- this.oceny = [];
- }
- sredniaOcenX(a){
- var suma = 0;
- for(var i = 0; i < this.oceny.length; i++)
- suma+=this.oceny[i];
- var srednia = suma/this.oceny.length;
- return srednia;
- }
- dodajOceneX(a){
- this.oceny[this.oceny.length] = a;
- }
- weekend(d)
- {
- var c = 'Jest weekend';
- console.log(c);
- console.log(d);
- }
- }
- var student2 = new StudentX('Katarzyna', 'Kowalska');
- student2.dodajOceneX(2);
- student2.dodajOceneX(4);
- student2.dodajOceneX(3.5);
- console.log(student2);
- console.log(student2.imie, student2.nazwisko, student2.sredniaOcenX());
- //zad3
- class PilnyStudent extends StudentX{
- constructor(imie, nazwisko, oceny){
- super(imie, nazwisko, oceny)
- this.imie = imie;
- this.nazwisko = nazwisko;
- this.oceny = [];
- }
- /*
- weekend(){
- super.weekend('Jest weekend.');
- }
- */
- uczSie(){
- super.weekend('Ucz siÄ™.');
- }
- }
- class RozrywkowyStudent extends StudentX{
- constructor(imie, nazwisko, oceny){
- super(imie, nazwisko, oceny)
- this.imie = imie;
- this.nazwisko = nazwisko;
- this.oceny = [];
- }
- /*
- weekend(){
- super.weekend('Jest weekend.');
- }
- */
- balanguj(){
- super.weekend('Balanguj.');
- }
- }
- var student3 = new PilnyStudent('Agnieszka', 'Nowak', [5, 5, 4.5]);
- var student4 = new RozrywkowyStudent('Monika', 'Kwiatkowska', [4, 3, 3.5]);
- console.log(student3.imie);
- student3.uczSie();
- console.log(student4.imie);
- student4.balanguj();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement