Skip to content

Commit e6769ed

Browse files
committed
Updated
2 parents 5a57592 + 36be95c commit e6769ed

File tree

75 files changed

+1113
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1113
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store
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%.

css/exercises/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>CSS Exercises</title>
7+
<link href="style.css" rel="stylesheet" type="text/css" />
8+
</head>
9+
<body>
10+
<script src="script.js"></script>
11+
<!-- You do not need to do anything with script.js right now! Later, we will learn how to add JavaScript to websites! --->
12+
<h1>My Very Cool Web Page</h1>
13+
<h2>Why this Website is Very Cool</h2>
14+
<ol>
15+
<li>I made it!</li>
16+
<li>This website is colorful!</li>
17+
</ol>
18+
<h2 id="cool-text">Why I love Web Development</h2>
19+
<p>Web Development is a very cool skill that I love learning!</p>
20+
<p>I love making websites because all I have to do is reload the page to see the changes I have made!</p>
21+
</body>
22+
</html>

css/exercises/script.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// You do not need to do anything with script.js right now! Later, we will learn how to add JavaScript to websites!

css/exercises/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Start adding your styling below! */

errors-and-debugging/exercises/DebuggingRuntimeErrors2.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
let launchReady = false;
23
let fuelLevel = 27000;
34

@@ -18,4 +19,27 @@ if (launchReady) {
1819
console.log("Liftoff!");
1920
} else {
2021
console.log("Launch scrubbed.");
21-
}
22+
}
23+
=======
24+
let launchReady = false;
25+
let fuelLevel = 27000;
26+
27+
if (fuelLevel >= 20000) {
28+
console.log('Fuel level cleared.');
29+
launchReady = true;
30+
} else {
31+
console.log('WARNING: Insufficient fuel!');
32+
launchReady = false;
33+
}
34+
35+
if (launchReady) {
36+
console.log("10, 9, 8...");
37+
console.log("Fed parrot...");
38+
console.log("6, 5, 4...");
39+
console.log("Ignition...");
40+
consoul.log("3, 2, 1...");
41+
console.log("Liftoff!");
42+
} else {
43+
console.log("Launch scrubbed.");
44+
}
45+
>>>>>>> 36be95c67064095bbbb24a9080443ed8779023cd
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const input = require('readline-sync');
2+
3+
let animals = [{name: 'cat'}, {name: 'dog'}];
4+
let index = Number(input.question("Enter index of animal:"));
5+
6+
try {
7+
console.log('animal at index:', animals[index].name);
8+
} catch(TypeError) {
9+
console.log("We caught a TypeError, but our program continues to run!");
10+
} finally {
11+
console.log("You tried to access an animal at index:", index);
12+
}
13+
14+
console.log("the code goes on...");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "control-flow-type-error-finally",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"readline-sync": "^1.4.10"
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw Error('You cannot divide by zero!');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "control-flow-type-error",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"readline-sync": "^1.4.10"
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const input = require('readline-sync');
2+
3+
let animals = [{name: 'cat'}, {name: 'dog'}];
4+
let index = Number(input.question("Enter index of animal:"));
5+
6+
try {
7+
console.log('animal at index:', animals[index].name);
8+
} catch(TypeError) {
9+
console.log("We caught a TypeError, but our program continues to run!");
10+
console.log("You tried to access an animal at index:", index);
11+
}
12+
13+
console.log("the code goes on...");

exceptions/exercises/divide.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Write a function called 'divide' that takes two parameters: a numerator and a denominator.
2+
3+
// Your function should return the result of numerator / denominator.
4+
5+
// However, if the denominator is zero you should throw the error, "Attempted to divide by zero."
6+
7+
// Code your divide function here:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function gradeLabs(labs) {
2+
for (let i=0; i < labs.length; i++) {
3+
let lab = labs[i];
4+
let result = lab.runLab(3);
5+
console.log(`${lab.student} code worked: ${result === 27}`);
6+
}
7+
}
8+
9+
let studentLabs = [
10+
{
11+
student: 'Carly',
12+
runLab: function (num) {
13+
return Math.pow(num, num);
14+
}
15+
},
16+
{
17+
student: 'Erica',
18+
runLab: function (num) {
19+
return num * num;
20+
}
21+
}
22+
];
23+
24+
gradeLabs(studentLabs);

html/exercises/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>HTML Exercise</title>
7+
<link href="style.css" rel="stylesheet" type="text/css" />
8+
<!-- DON'T TOUCH ANYTHING ABOVE THIS LINE -->
9+
</head>
10+
<body>
11+
<!-- h1 goes here -->
12+
<!-- ol goes here -->
13+
<!-- a goes here -->
14+
<!-- p goes here -->
15+
</body>
16+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function averageForStudent(nameIndex,scores){
2+
let sum = 0;
3+
for (let i=0; i<scores.length; i++){
4+
sum += scores[nameIndex][i];
5+
}
6+
let average = sum/scores[nameIndex].length;
7+
return average;
8+
}
9+
10+
function averageForTest(testIndex,scores){
11+
let sum = 0;
12+
for (let i=0; i<scores.length; i++){
13+
sum += scores[i][testIndex];
14+
}
15+
let average = sum/scores[0].length;
16+
return average;
17+
}
18+
19+
//TODO: Export all functions within an object.

modules/exercises/display.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//TODO: Export ONLY the printAll function.
2+
3+
function printAll(names, tests, scores){
4+
let header = 'Name';
5+
let row = '';
6+
7+
for (let i = 0; i<tests.length; i++){
8+
header += '\t'+tests[i];
9+
}
10+
console.log(header);
11+
12+
for (let name = 0; name<names.length; name++){
13+
row = names[name];
14+
for (let score = 0; score<scores[name].length;score++){
15+
row += '\t'+scores[name][score];
16+
}
17+
console.log(row);
18+
}
19+
return;
20+
}
21+
22+
function printStudentScores(index,students,tests,scores){
23+
console.log(`Test results for ${students[index]}:`);
24+
for (let i = 0; i<tests.length; i++){
25+
console.log(`${tests[i]} = ${scores[index][i]}%.`);
26+
}
27+
return;
28+
}
29+
30+
function printTestScores(index,test,students,scores){
31+
console.log(`Class results for ${test} test:`);
32+
for (let i = 0; i<students.length; i++){
33+
console.log(`${students[i]} = ${scores[i][index]}%.`);
34+
}
35+
return;
36+
}

modules/exercises/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//Import modules:
2+
const input = //Import readline-sync.
3+
const averages = //Import functions from averages.js.
4+
const printAll = //Import function from display.js.
5+
const randomSelect = //Import function from randomSelect.js.
6+
7+
//Candidate data:
8+
let astronauts = ['Fox','Turtle','Cat','Hippo','Dog'];
9+
10+
const testTitles = ['Math','Fitness','Coding','Nav','Communication'];
11+
12+
let scores = [[95, 86, 83, 81, 76],[79, 71, 79, 87, 72],[94, 87, 87, 83, 82],[99, 77, 91, 79, 80],[96, 95, 99, 82, 70]];
13+
14+
//User interface:
15+
let prompts = ['display all scores', 'average the scores for each test', 'average the scores for each astronaut','select the next spacewalker'];
16+
17+
for (let i = 0; i<prompts.length; i++){
18+
let response = input.question(`Would you like to ${prompts[i]}? Y/N: `);
19+
if (response.toLowerCase()==='y'){
20+
if (i===0){
21+
//Call 'printAll' here and pass in all necessary arguments.
22+
} else if (i===1){
23+
for (let j = 0; j<testTitles.length; j++){
24+
let avg = //Call 'averageForTest' here. Pass in j and scores as arguments.
25+
console.log(`${testTitles[j]} test average = ${avg}%.`);
26+
}
27+
} else if (i===2){
28+
for (let j = 0; j<astronauts.length; j++){
29+
let avg = //Call 'averageForStudent' here. Pass in j and scores as arguments.
30+
console.log(`${astronauts[j]}'s test average = ${avg}%.`);
31+
}
32+
} else {
33+
let walker = //Call 'randomSelect' to pick a spacewalker from the astronauts array.
34+
console.log(`${walker} is the next spacewalker.`);
35+
}
36+
} else {
37+
console.log("Option skipped.");
38+
}
39+
}

0 commit comments

Comments
 (0)