From 02cf9667f8fd5cba3686690a3196beea13a2cbe7 Mon Sep 17 00:00:00 2001 From: Kilokem Date: Sat, 21 Sep 2024 11:10:25 +0200 Subject: [PATCH] Classes --- FunctionalFun/script.js | 21 ++++++++- ObjectiveMadness/index.html | 13 ++++++ ObjectiveMadness/script.js | 92 +++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 ObjectiveMadness/index.html create mode 100644 ObjectiveMadness/script.js diff --git a/FunctionalFun/script.js b/FunctionalFun/script.js index 172d0df..b868e2a 100644 --- a/FunctionalFun/script.js +++ b/FunctionalFun/script.js @@ -97,4 +97,23 @@ let total = numberok.reduce(summa) //reduce() console.log(total) -//https://youtu.be/lfmg-EJ8gm4?feature=shared&t=17107 \ No newline at end of file +//https://youtu.be/lfmg-EJ8gm4?feature=shared&t=17107 + + + +//Funcion Expressions + +const hello = function(){ + console.log("HELLO"); +} +hello(); + + +setTimeout(function(){ + console.log("HOLA"); +}, 3000); + + +//Arrow functions + +const squaros = numberok.map((element) => Math.pow(element, 2)); \ No newline at end of file diff --git a/ObjectiveMadness/index.html b/ObjectiveMadness/index.html new file mode 100644 index 0000000..e5b3e15 --- /dev/null +++ b/ObjectiveMadness/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/ObjectiveMadness/script.js b/ObjectiveMadness/script.js new file mode 100644 index 0000000..e437a44 --- /dev/null +++ b/ObjectiveMadness/script.js @@ -0,0 +1,92 @@ +//my first objectsű + +const person = { + firstname: "Spongebob", + lastname: "Squarepants", + age: 30, + isemployed: true, + sayHello: function(){ + console.log("HELOOOOOOO Im sponge!") + }, + sayBye : () => console.log("BBBBYYEEEEEEEEEE!!!") +}; + +console.log(person.age); +console.log(person.firstname); +console.log(person.lastname); +person.sayHello(); +person.sayBye(); + +//The "this" keyword!!! +const person2 = { + firstname: "Spongebob", + lastname: "Squarepants", + age: 30, + isemployed: true, + sayHello: function(){ + console.log(`HELOOOOOOO I am ${this.firstname}!`) + }, + sayBye : () => console.log(`BBBBYYEEEEEEEEEE I was ${this.firstname}`), // "this" CANT BE USED WITH ARROW FUNCTIONT!!!! + sayBye1 : () => console.log(`BBBBYYEEEEEEEEEE I was ${person2.firstname}`), + sayBye2 : () => console.log(`BBBBYYEEEEEEEEEE I was ${firstname}`), //WRONG!!!!!!!! +}; + +person2.sayHello(); +person2.sayBye(); +person2.sayBye1(); +//person2.sayBye2(); + + +function car(make, model, year, color){ + this.make = make, + this.model = model, + this.year = year, + this.color = color, + this.drive = function(){ + console.log(`You drive a ${this.make}!!`) + } +}; + +const car1 = new car("Tesla", "Y", 2015, "black"); +const car2 = new car("Ford", "Mustang", 2020, "red"); + +console.log(car1.color); + +const carList = []; //ObjectArray +carList.push(car1); +carList.push(car2); + +console.log(carList); +carList[0].drive(); + +//CLASSES!!!!!!!!!! + +class Products{ + static tax = 1.27; + constructor(name, price){ + this.name = name; + this.price = price; + } + + displayProduct(){ + console.log(`Product name: ${this.name}`); + } + + displayPrice(){ + console.log(`Theprice: ${this.price}`); + } + + calculateTotal(){ + console.log(`The taxed price will be: ${this.price * Products.tax}`); + } +} + +const shirt = new Products("Shirt", 19.99); +const pants = new Products("Pants", 22.50); +const underwear = new Products("Underwear", 122.50); + +underwear.displayProduct(); +underwear.displayPrice(); +underwear.calculateTotal(); + +//https://youtu.be/lfmg-EJ8gm4?si=KJ_EBH2FxCEtonyR&t=19910 \ No newline at end of file