Advertisement
JakubJaneczek

JS obiekty

Feb 10th, 2021 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. document.write("<br>Zadanie 1<br><br>");
  3.  
  4. const prod1={
  5.     name: "Seler",
  6.     price: 2.39,
  7.     weight: 0.5,
  8. }
  9. const prod2={
  10.     name: "Pietruszka",
  11.     price: 4.99,
  12.     weight: 0.17
  13. }
  14.  
  15. document.write("Produkt numer jeden to: "+prod1.name+"<br>");
  16. document.write("Produkt numer dwa to: "+prod2.name+"<br>");
  17. document.write("Produkty kosztują razem: "+(prod1.price*100+prod2.price*100)/100+"<br>");
  18. document.write("Produkty ważą razem: "+(prod1.weight*100+prod2.weight*100)/100+"<br>");
  19.  
  20. document.write("<br>Zadanie 2<br><br>");
  21.  
  22. const currentUser={
  23.     name:"Jakub",
  24.     surname:"Kowalski",
  25.     email:"jakubkowalski@pocztapolska.pl",
  26.     www:"kowalskigotuje.pl",
  27.     userType:"użytkownik standardowy",
  28.     show(){
  29.         return "Imie: "+this.name + "<br>" + "Nazwisko: " +this.surname + "<br>" + "Email: " +this.email + "<br>" + "Strona: " +this.www + "<br>" + "Rodzaj użytkownika: " +this.userType+ "<br>";
  30.     }
  31. }
  32.  
  33. document.write(currentUser.show());
  34.  
  35. document.write("<br>Zadanie 3<br><br>");
  36.  
  37. const book={
  38.     title:"Matrioszka Rosja",
  39.     author:"Maciej Jastrzębski",
  40.     pageCount: 285,
  41.     publisher:"editio",
  42.     showDetails(){
  43.         for(const key in book)
  44.         {document.write((key)+": "+(book[key])+"<br>");}
  45.     }
  46. }
  47. book.showDetails();
  48. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement