Advertisement
PiotrJurek

zadania js objekty

Feb 10th, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7. </head>
  8. <body>
  9.     <script>
  10.  
  11.         //Zad1
  12.         {
  13.         function Prod(name, price, weight)
  14.         {
  15.             this.name = name;
  16.             this.price = price;
  17.             this.weight = weight;
  18.         };
  19.  
  20.         let prod1 = new Prod("Pasztet Piekło w gębie", 5.50, 1);
  21.         let prod2 = new Prod("Kiełbasa Długa", 22.45, 5);
  22.  
  23.         document.write("Produkt numer jeden to: "+prod1.name+"</br>");
  24.         document.write("Produkt numer dwa to: "+prod2.name+"</br>");
  25.         document.write("Produkty kosztują razem: "+(prod1.price+prod2.price)+"</br>");
  26.         document.write("Produkty ważą razem: "+(prod1.weight+prod2.weight)+"</br>");
  27.         }
  28.  
  29.         //Zad2
  30.         {
  31.         currentUser = {
  32.             name: "Piotr",
  33.             surname: "Jurek",
  34.             email: "scisle@tajne.com",
  35.             www: "www.www.com.edu.pl",
  36.             userType: "ja",
  37.  
  38.             show()
  39.             {
  40.                 document.write("Imię: "+this.name+"</br>");
  41.                 document.write("Nazwisko: "+this.surname+"</br>");
  42.                 document.write("Email: "+this.email+"</br>");
  43.                 document.write("Strona internetowa: "+this.www+"</br>");
  44.                 document.write("Typ użytkownika: "+this.userType+"</br>");
  45.             }
  46.         }
  47.  
  48.         currentUser.show();
  49.         }
  50.  
  51.         //Zad3
  52.         {
  53.         book = {
  54.             title: "Pani Tadeusz",
  55.             author: "Adam Małysz",
  56.             pageCount: 999,
  57.             publisher: "Adam Małysz wielkim poetą był",
  58.  
  59.             showDetails()
  60.             {
  61.                 for(const x in this)
  62.                 {
  63.                     document.write(x+": "+this[x]+"</br>");
  64.                 }
  65.             }
  66.         }
  67.  
  68.         book.showDetails();
  69.         }
  70.        
  71.     </script>
  72. </body>
  73. </html>
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement