Skip to content

Commit 23b55bc

Browse files
Setting up starter code for classes chapter
1 parent 67f2c53 commit 23b55bc

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//Try adding new properties inside constructor.
2+
class Astronaut {
3+
constructor(name, age, mass){
4+
this.name = name;
5+
this.age = age;
6+
this.mass = mass;
7+
}
8+
}
9+
10+
let fox = new Astronaut('Fox', 7, 12);
11+
12+
console.log(fox);
13+
console.log(fox.age, fox.color);
14+
15+
fox.age = 9;
16+
fox.color = 'red';
17+
18+
console.log(fox);
19+
console.log(fox.age, fox.color);
20+
21+
//Try modifying or adding properties below.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Use terminal commands to see what happens when we call Astronaut but do not pass in 3 arguments.
2+
3+
// Next, set default values for 1 or more of the parameters in constructor.
4+
5+
class Astronaut {
6+
constructor(name, age, mass){
7+
this.name = name;
8+
this.age = age;
9+
this.mass = mass;
10+
}
11+
}
12+
13+
let tortoise = new Astronaut('Speedy', 120);
14+
15+
console.log(tortoise.name, tortoise.age, tortoise.mass);
16+
17+
// What happens if we call Astronaut and pass in MORE than 3 arguments? TRY IT!
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Here we assign the method inside the constructor
2+
class AstronautI {
3+
constructor(name, age, mass){
4+
this.name = name;
5+
this.age = age;
6+
this.mass = mass;
7+
this.reportStats = function() {
8+
let stats = `${this.name} is ${this.age} years old and has a mass of ${this.mass} kg.`;
9+
return stats;
10+
}
11+
}
12+
}
13+
14+
// Here we assign the method outside of the constructor
15+
class AstronautO {
16+
constructor(name, age, mass){
17+
this.name = name;
18+
this.age = age;
19+
this.mass = mass;
20+
}
21+
22+
reportStats() {
23+
let stats = `${this.name} is ${this.age} years old and has a mass of ${this.mass} kg.`;
24+
return stats;
25+
}
26+
}
27+
28+
let fox = new AstronautI('Fox', 7, 12);
29+
let hippo = new AstronautO('Hippo', 25, 1000);
30+
31+
console.log(fox);
32+
console.log(hippo);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Felidae {
2+
constructor() {
3+
this.claws = "retractable";
4+
}
5+
}
6+
7+
class Panthera extends Felidae {
8+
constructor() {
9+
super();
10+
this.roar = "loud";
11+
}
12+
}
13+
14+
class Tiger extends Panthera {
15+
constructor() {
16+
super();
17+
this.hasStripes = "true";
18+
}
19+
}
20+
21+
let tigger = new Tiger();
22+
23+
console.log(tigger);

classes/exercises/ClassExercises.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Define your Book class here:
2+
3+
4+
// Define your Manual and Novel classes here:
5+
6+
7+
// Declare the objects for exercises 2 and 3 here:
8+
9+
10+
// Code exercises 4 & 5 here:

classes/studio/ClassStudio.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//Declare a class called CrewCandidate with a constructor that takes three parameters—name, mass, and scores. Note that scores will be an array of test results.
2+
3+
4+
5+
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.
6+
7+
8+
9+
//Part 4 - Use the methods to boost Glad Gator’s status to Reserve or higher. How many tests will it take to reach Reserve status? How many to reach Accepted? Remember, scores cannot exceed 100%.

0 commit comments

Comments
 (0)