Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ This challenge takes a look at callbacks and closures as well as scope.

## Task 3: Prototypes
Create constructors, bind methods, and create cuboids in this prototypes challenge.
* [ ] Use the [prototypes.js](challenges/prototypes.js) link to get started. Read the instructions carefully!
* [x] Use the [prototypes.js](challenges/prototypes.js) link to get started. Read the instructions carefully!

## Task 4: Classes
Once you have completed the prototypes challenge, it's time to convert all your hard work into classes.
* [ ] Use the [classes.js](challenges/classes.js) link to get started. Read the instructions carefully!
* [x] Use the [classes.js](challenges/classes.js) link to get started. Read the instructions carefully!

In your solutions, it is essential that you follow best practices and produce clean and professional results. Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work. It is better to submit a challenge that meets MVP than one that attempts too much and does not.

Expand Down
52 changes: 51 additions & 1 deletion challenges/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,54 @@
// console.log(cuboid.volume()); // 100
// console.log(cuboid.surfaceArea()); // 130

// Stretch Task: Extend the base class CuboidMaker with a sub class called CubeMaker. Find out the formulas for volume and surface area for cubes and create those methods using the dimension properties from CuboidMaker. Test your work by logging out your volume and surface area.
// Stretch Task: Extend the base class CuboidMaker with a sub class called CubeMaker. Find out the formulas for volume and surface area for cubes and create those methods using the dimension properties from CuboidMaker. Test your work by logging out your volume and surface area.

/* THIS IS THE OLD VERSION */
/*
function CuboidMaker(attr) {
this.lengthA = attr.lengthA;
this.widthA = attr.widthA;
this.heightA = attr.heightA;
};
CuboidMaker.prototype.volume = function() {
return this.lengthA * this.widthA * this.heightA;
};
CuboidMaker.prototype.surfaceArea = function() {
return 2 * (this.lengthA * this.widthA + this.lengthA * this.heightA + this.widthA * this.heightA);
};

const cuboid = new CuboidMaker({
lengthA: 4,
widthA: 5,
heightA: 5,
});
console.log(cuboid); // checking to see if this worked. It did.
*/

/* THIS IS THE CLASS VERSION with changed names so there is no conflict with the previous file and it's variables names*/
class ClassyCuboidMaker {
constructor(lengthA, widthA, heightA) {
this.lengthA = lengthA;
this.widthA = widthA;
this.heightA = heightA;
}
volume() {
return this.lengthA * this.widthA * this.heightA;
}
surfaceArea() {
return 2 * (this.lengthA * this.widthA + this.lengthA * this.heightA + this.widthA * this.heightA);
}
}

/* this is the OLD cuboid object
const cuboid = new CuboidMaker({
lengthA: 4,
widthA: 5,
heightA: 5,
});
*/
const classyCuboid = new ClassyCuboidMaker(4, 5, 5);

/**this is a test */
console.log(classyCuboid.volume()); // 100
console.log(classyCuboid.surfaceArea()); // 130
18 changes: 10 additions & 8 deletions challenges/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<!doctype html>

<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Sprint Challenge</title>
<title>Sprint Challenge</title>

<script src="objects-arrays.js"></script>
<script src="functions.js"></script>
<script src="prototypes.js"></script>
<script src="classes.js"></script>
<script src="objects-arrays.js"></script>
<script src="functions.js"></script>
<script src="prototypes.js"></script>
<script src="classes.js"></script>
</head>

<body>
<h1>Sprint Challenge - Check your work in the console!</h1>
<h1>Sprint Challenge - Check your work in the console!</h1>
</body>

</html>
22 changes: 11 additions & 11 deletions challenges/objects-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ dino1.roar()

// Given an array of college graduates. Complete the following requests using any array method you like

const graduates = [{ "id": 1, "first_name": "Cynde", "university": "Missouri Southern State College", "email": "ctorry0@macromedia.com" },
const graduates = [
{ "id": 1, "first_name": "Cynde", "university": "Missouri Southern State College", "email": "ctorry0@macromedia.com" },
{ "id": 2, "first_name": "Saundra", "university": "The School of the Art Institute of Chicago", "email": "swhal1@state.gov" },
{ "id": 3, "first_name": "Lambert", "university": "Marian College", "email": "lparham2@techcrunch.com" },
{ "id": 4, "first_name": "Modestine", "university": "International Medical & Technological University", "email": "mdolder3@symantec.com" },
Expand Down Expand Up @@ -98,14 +99,14 @@ console.log(contactInfo);

/* Request 3: Find out how many universities have the string "Uni" included in their name. Create a new array called uni that contains them all. Log the result. */

/*************I HAVE TO SKIP THIS ONE THE INCLUDE IS NOT WORKING LIKE EXPECTED*******************/
const uni = [];
graduates.filter((graduates) => {
graduates.university.includes("Uni", 0);
return uni.push(`${graduates.university}`);
});
console.log(uni);

let uniSchools = []; //make a array with all universities
for (let i = 0; i < graduates.length; i++) {
uniSchools.push(graduates[i].university);
}
var uniFilter = uniSchools.filter((uniSchools) => { //filter it
return uniSchools.includes("Uni"); //true vs false test
}); //there has got to be a better way to do this!!!
console.log(uniFilter);

// ==== ADVANCED Array Methods ====

Expand Down Expand Up @@ -172,8 +173,7 @@ const populationTotal = zooAnimals.reduce((animTotal, animalZoo) => {
return animTotal += animalZoo.population;
}, 0);
console.log(populationTotal);
//this was the solution that I was shown after the thing.

//------------------------------------------------
const populationTotalArray = [];
zooAnimals.forEach(makeArray);

Expand Down
6 changes: 3 additions & 3 deletions challenges/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function CuboidMaker(attr) {
this.lengthA = attr.lengthA;
this.widthA = attr.widthA;
this.heightA = attr.heightA;
}
};

/* == Step 2: Volume Method ==
Create a method using CuboidMaker's prototype that returns the volume of a given cuboid's length, width, and height

Formula for cuboid volume: length * width * height
*/
CuboidMaker.prototype.volume = function() {
console.log(lengthA * widthA * heightA);
return this.lengthA * this.widthA * this.heightA;
};

/* == Step 3: Surface Area Method ==
Expand All @@ -26,7 +26,7 @@ CuboidMaker.prototype.volume = function() {
Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height)
*/
CuboidMaker.prototype.surfaceArea = function() {
console.log(2 * (lengthA * widthA + lengthA * heightA + widthA * heightA));
return 2 * (this.lengthA * this.widthA + this.lengthA * this.heightA + this.widthA * this.heightA);
};

/* == Step 4: Create a new object that uses CuboidMaker ==
Expand Down