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
28 changes: 25 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Section 2: JavaScript Language Basics</title>
<title>Section 7: Get Ready for the Future: ES6 / ES2015</title>

<style>
.box {
width: 200px;
padding: 60px;
text-align: center;
font-size: 30px;
margin-top: 50px;
}

.green { background-color: green; }
.blue { background-color: dodgerblue; }
.orange { background-color: orangered; }

</style>

</head>

<body>
<h1>Section 2: JavaScript Language Basics</h1>
<h1>Section 7: Get Ready for the Future: ES6 / ES2015</h1>

<div class="box green">I'm green!</div>
<div class="box blue">I'm blue!</div>
<div class="box orange">I'm orange!</div>

<script src="script.js"></script>
</body>
</html>
</html>
95 changes: 95 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
class Park {
constructor(name, area, numberOfTrees, age) {
this.name = name,
this.area = area,
this.numberOfTrees = numberOfTrees,
this.age = age
}
getTreeDensity(park) {
return park.numberOfTrees / park.area;
}
}

class Street {
constructor(name, length, yearBuilt, size) {
this.name = name,
this.length = length,
this.yearBuilt = yearBuilt,
this.size = size,
this.sizeClassification = this.sizeClassification();
}

sizeClassification() {
const streetSize = this.size;
if (!streetSize) {
return 'normal';
}
if (streetSize > 20) {
return 'huge';
}
if (streetSize > 10 ) {
return 'big'
}
return 'small';
}
}

class Town {
constructor(name, parks, streets) {
this.name = name,
this.parks = parks,
this.streets = streets
}
getAverageAges() {
let avrg = 0;
this.parks.forEach(park => {
avrg += park.age;
});
return avrg;
}

getParkWith1000Trees() {
const park = this.parks.find(({numberOfTrees}) => numberOfTrees >= 1000);
return park.name;
}

getTotalLenghtOfStreets() {
let total = 0;
this.streets.forEach(street => {
total += street.length;
});
return total;
}
getAvergLenghtOfStreets() {
return this.getTotalLenghtOfStreets() / this.streets.length;
}
}

{
const park1 = new Park('Green Park', 156, 50, 500);
const park2 = new Park('National Park', 156, 50, 200);
const park3 = new Park('Naional Park', 156, 1000, 1100);

const allParks = [park1, park2, park3];

const street1 = new Street('Ocean Avenue', 20, 1999, 11);
const street2 = new Street('Evergreen Street', 20, 2008, 10);
const street3 = new Street('4th Street', 20, 2015);
const street4 = new Street('Sunset Boulevard', 20, 1982, 21);

const allStreets = [street1, street2, street3, street4];

const town = new Town('The Town', allParks, allStreets);

console.log('-----------------------PARKS REPORT-------------------------------------');
console.log(`Our ${town.parks.length} parks have an average age of ${town.getAverageAges()} years.`)
town.parks.forEach(park => {
console.log(`${park.name} has a tree density of ${park.getTreeDensity(park)} trees per square km.`);
});
console.log(`${town.getParkWith1000Trees()} has more than 1000 trees.`)
console.log('----------------------STREETS REPORT------------------------------------');
console.log(`Our ${town.streets.length} streets have a total lenght of ${town.getTotalLenghtOfStreets()} km, with an average of ${town.getAvergLenghtOfStreets()} km.`);
town.streets.forEach(street => {
console.log(`${street.name}, built in ${street.yearBuilt}, is a ${street.sizeClassification} street`);
});
}