Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>Dworzak to pies</title>
  6. </head>
  7. <body>
  8.  
  9. Rasa: <div id="name">...</div>
  10. <br>
  11. Kolor:
  12. <div id="color">...</div>
  13. <br>
  14. Wiek:
  15. <div id="age">...</div>
  16. <br>
  17. <input type="button" value="Labrador" onclick="createDog(1)"/>
  18. <input type="button" value="Pudel" onclick="createDog(2)"/>
  19. <input type="button" value="Buldog" onclick="createDog(3)"/>
  20. <input type="button" value="Owczarek" onclick="createDog(4)"/>
  21. <input type="button" value="Beagle" onclick="createDog(5)"/>
  22.  
  23.  
  24.  
  25. <script>
  26.  
  27. function Dog(name, color, age) {
  28. this.name = name;
  29. this.color = color;
  30. this.age = age;
  31. this.initialize = function() {
  32. document.getElementById("name").innerHTML = this.name;
  33. document.getElementById("color").innerHTML = this.color;
  34. document.getElementById("age").innerHTML = this.age;
  35. }
  36. }
  37.  
  38.  
  39. function createDog(x) {
  40. if (x == 1) {
  41. const dog = new Dog("Labrador", "Biały", "12 lat");
  42. dog.initialize();
  43. }
  44.  
  45. if (x == 2) {
  46. const dog = new Dog("Pudel", "Brązowy", "4 lata");
  47. dog.initialize();
  48. }
  49.  
  50. if (x == 3) {
  51. const dog = new Dog("Buldog", "Czarny", "8 lat");
  52. dog.initialize();
  53. }
  54.  
  55. if (x == 4) {
  56. const dog = new Dog("Owczarek", "Biało-brązowy", "5 lat");
  57. dog.initialize();
  58. }
  59.  
  60. if (x == 5) {
  61. const dog = new Dog("Beagle", "Brązowy", "3 lata");
  62. dog.initialize();
  63. }
  64. }</script>
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement