Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pl" dir="ltr">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JavaScript - obiekty i klasy</title>
  6. <script type="text/javascript">
  7. class Samochod {
  8. constructor(marka, model, rocznik, cena) {
  9. this.marka = marka;
  10. this.model = model;
  11. this.rocznik = rocznik;
  12. this.cena = cena;
  13. }
  14. wejdz() {
  15. document.write("wszedł do samochodu ... ");
  16. }
  17. wyjdz() {
  18. document.write("wyszedł z samochodu ... ");
  19. }
  20. }
  21.  
  22. class Silnik extends Samochod {
  23. constructor(typ, obroty) {
  24. super();
  25. this.typ = typ;
  26. this.obroty = obroty;
  27. }
  28. zwiekszObroty() {
  29. this.obroty = this.obroty+100;
  30. }
  31. zmniejszObroty() {
  32. this.obroty = this.obroty-100;
  33. }
  34. }
  35.  
  36. class EGR extends Silnik {
  37. otworzZaworEGR() {
  38. document.write("EGR otwarty ... ");
  39. }
  40. zamknijZaworEGR() {
  41. document.write("EGR zamknięty ... ");
  42. }
  43. }
  44.  
  45. const osoba = {
  46. imie: "Jan",
  47. nazwisko: "Kowalski",
  48. wiek: 24
  49. }
  50.  
  51. function Samolot(producent, model, oznaczenie, zasieg) {
  52. this.producent = producent;
  53. this.model = model;
  54. this.oznaczenie = oznaczenie;
  55. this.zasieg = zasieg;
  56. this.liczba_silnikow = 2;
  57. }
  58. let lokomotywa = {
  59. nazwa: 'lokomotywa',
  60. predkosc: 60,
  61. max_predkosc: 180,
  62. typ: 'parowy',
  63. rok_produkcji: 2019,
  64. przyspiesz: function() {
  65. return this.predkosc +=10;
  66. },
  67. zwolnij: function() {
  68. return this.predkosc -=10;
  69. },
  70. zatrzymaj: function() {
  71. return this.predkosc = 0;
  72. }
  73. }
  74.  
  75. function zmien(){
  76. delete lokomotywa.predkosc;
  77. lokomotywa.ciezar = 20;
  78. lokomotywa.zatrzymaj()
  79. console.log(lokomotywa);
  80. }
  81. function rusz(){
  82. if (lokomotywa.predkosc <20) {
  83. lokomotywa.przyspiesz()
  84. console.log(lokomotywa)
  85. } else (alert(lokomotywa.predkosc))
  86. }
  87. boeing = new Samolot('Boeing Company', 'Boeing 747', '747-8', 14815)
  88. document.write(boeing.producent, boeing.model)
  89.  
  90. porsche = new Samochod('Porsche', '911', '1963', 2000)
  91. document.write(osoba.imie + ' '+ osoba.nazwisko + porsche.wejdz())
  92.  
  93.  
  94.  
  95.  
  96. </script>
  97. </head>
  98. <body>
  99. <center>
  100. <button type="button" onclick="zmien()">Zmień</button>
  101. <button type="button" onclick="rusz()">Rusz</button>
  102. </center>
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement