Skip to content

Commit

Permalink
Completed Chapter LinkedInLearning#3 Practice files.
Browse files Browse the repository at this point in the history
  • Loading branch information
pperepa committed Apr 19, 2021
1 parent 771d855 commit 6219e8e
Show file tree
Hide file tree
Showing 7 changed files with 2,040 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Practice/03_07/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@
* - Find an object that has another object inside of it to create a nested object.
* - Test your objects in the browser console by accessing the entire object and its specific properties.
*/

const Battery = {
volts: 1.2,
milAmpHours: 1900,
color: "white",
brand: "Eneloop",
rechargeable: true,
type: "Ni-MH",
};

const Mug = {
color: "grey",
handle: true,
tea: {
brand: "Tazo",
flavor: "China Green Tips",
heat: "warm",
},
weight: "8.6oz",
};
17 changes: 17 additions & 0 deletions Practice/03_09/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,28 @@ const backpack = {
left: 26,
right: 26,
},
lidOpen: false,
toggleLid: function (lidStatus) {
this.lidOpen = lidStatus;
},
newStrapLength: function (lengthLeft, lengthRight) {
this.strapLength.left = lengthLeft;
this.strapLength.right = lengthRight;
},
rename: function (newName) {
this.name = newName;
},
changeVolume: function (newVol) {
this.volume = newVol;
},
recolor: function (newColor) {
this.color = newColor;
},
changePockets: function (newNumber) {
this.pocketNum = newNumber;
},
};
backpack.changePockets(50);
backpack.toggleLid(true);
backpack.changeVolume(75);
backpack.recolor("green");
26 changes: 26 additions & 0 deletions Practice/03_12/Battery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const Battery = class {
constructor(volts, milAmpHours, color, brand, rechargeable, type) {
this.volts = volts;
this.milAmpHours = milAmpHours;
this.color = color;
this.brand = brand;
this.rechargeable = rechargeable;
this.type = type;
}
changeVolts = function (newVolts) {
this.volts = newVolts;
};
flipChargeable = function (toggle) {
this.rechargeable = toggle;
};
changeType = function (newType) {
this.type = newType;
};
recolor = function (newColor) {
this.color = newColor;
};
rebrand = function (newBrand) {
this.brand = newBrand;
};
};
export default Battery;
28 changes: 28 additions & 0 deletions Practice/03_12/Mug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const Mug = class {
constructor(color, handle, teaBrand, teaFlavor, teaWarmth, weight) {
this.color = color;
this.handle = handle;
this.tea = {
brand: teaBrand,
flavor: teaFlavor,
warmth: teaWarmth,
};
this.weight = weight;
}
changeColor = function (newColor) {
this.color = newColor;
};
toggleHandle = function (handleType) {
this.handle = handleType;
};
changeTeaBrand = function (newBrand) {
this.tea.brand = newBrand;
};
changeTeaFlavor = function (newFlav) {
this.tea.flavor = newFlav;
};
teaTemp = function (newTemp) {
this.tea.heat = newTemp;
};
};
export default Mug;
2 changes: 2 additions & 0 deletions Practice/03_12/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Practice: Making classes and objects</title>
<script type="module" src="Backpack.js"></script>
<script type="module" src="Battery.js"></script>
<script type="module" src="Mug.js"></script>
<script type="module" src="script.js"></script>
</head>
<body></body>
Expand Down
60 changes: 60 additions & 0 deletions Practice/03_12/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,63 @@
* - Create several objects using the class.
* - Test the objecs by calling their properties and using their methods in the console.
*/

// Import Custom Classes
import Backpack from "./Backpack.js";
import Battery from "./Battery.js";
import Mug from "./Mug.js";

// Instantiation of Different Classes
const greenBackpack = new Backpack(
"Green School Backpack",
55,
"green",
23,
22,
33,
true
);
const greenMug = new Mug("white", false, "Tazo", "Earl Grey", "Cold", "15.2oz");
const greenBattery = new Battery(
3.6,
2100,
"green",
"Energizer",
false,
"Li-ion"
);

// Battery Method Testing
greenBattery.changeVolts(0.8);
greenBattery.changeType("Ni-MH");
greenBattery.rebrand("Duracell");
greenBattery.flipChargeable(true);
greenBattery.recolor("black");
console.log("greenBattery volts: ", greenBattery.volts);
console.log("greenBattery type: ", greenBattery.type);
console.log("greenBattery brand: ", greenBattery.brand);
console.log("greenBattery rechargeable: ", greenBattery.rechargeable);
console.log("greenBattery color: ", greenBattery.color);

// Mug Method Testing
greenMug.changeColor("red");
greenMug.toggleHandle(false);
greenMug.changeTeaBrand("Arizona");
greenMug.changeTeaFlavor("Ginseng");
greenMug.teaTemp("warm");
console.log("greenMug color: ", greenMug.color);
console.log("greenMug handle: ", greenMug.handle);
console.log("greenMug Tea Brand: ", greenMug.tea.brand);
console.log("greenMug Tea Flavor: ", greenMug.tea.flavor);
console.log("greenMug Tea Temp: ", greenMug.tea.warmth);

// Backpack Method Testing
greenBackpack.toggleLid(false);
greenBackpack.newStrapLength(17.5, 19.5);
console.log("greenBackpack name: ", greenBackpack.name);
console.log("greenBackpack lid: ", greenBackpack.lidOpen);
console.log(
"greenBackpack strap(left, right)",
greenBackpack.strapLength.left,
greenBackpack.strapLength.right
);
Loading

0 comments on commit 6219e8e

Please sign in to comment.