Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull #57

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

pull #57

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
63 changes: 60 additions & 3 deletions classes/exercises/ClassExercises.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,67 @@
// Define your Book class here:
class Book {
constructor(title, author, copyright, isbn, pages, timesCheckedOut, discarded) {
this.title = title;
this.author = author;
this.copyright = copyright;
this.isbn = isbn;
this.pages = pages;
this.timesCheckedOut = timesCheckedOut;
this.discarded = discarded;

}
checkout() {
this.timesCheckedOut += 1
}
}


// Define your Manual and Novel classes here:
class Manual extends Book {
constructor(title, author, copyright, isbn, pages, timesCheckedOut, discarded) {
super(title, author, copyright, isbn, pages, timesCheckedOut, discarded)
}
dispose(currentYear = new Date().getFullYear()) {
if (currentYear - this.copyright > 5) {
this.discarded = true;
}
}
}

class Novel extends Book {
constructor(title, author, copyright, isbn, pages, timesCheckedOut, discarded) {
super(title, author, copyright, isbn, pages, timesCheckedOut, discarded)
}
dispose() {
if (this.timesCheckedOut > 100) {
this.discarded = true;
}
}
}

// Declare the objects for exercises 2 and 3 here:


// Code exercises 4 & 5 here:
let pride = new Novel(
'Pride and Prejudice',
'Jane Austen',
1813,
'11111111111',
432,
32,
'false'
);
let top = new Manual('Top Secret Shuttle Building Manual',
'Redacted',
2013,
'00000000000',
1147,
1,
'false'
);
// Code exercises 4 & 5 here:
top.dispose();
pride.checkout(5);
console.log(pride.timesCheckedOut);
top.dispose();
pride.dispose();
console.log(top.discarded);
console.log(pride.discarded);
46 changes: 43 additions & 3 deletions classes/studio/ClassStudio.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
//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.
class CrewCandidate {
constructor(name, mass, scores){
this.name = name;
this.mass = mass;
this.scores = scores;
}
addScore(newScore){
this.scores.push(newScore);
}

average(){
const sum = this.scores.reduce((acc, score) => acc + score, 0);
const avg = sum / this.scores.length;
return avg.toFixed(1)
}



status(){
const avg = this.average();
if (avg >= 90){
return "Accepted";
} else if (avg >= 80){
return "Reserve";
} else if (avg >= 70){
return "Probationary";
} else{
return "Rejected";
}
}
}
const bubbaBear = new CrewCandidate('Bubba Bear', 135, [88, 85, 90])
const merryMaltese = new CrewCandidate('Merry Maltese', 1.5, [93, 88, 97])
const gladGator = new CrewCandidate('Glad Gator', 225, [75, 78, 62])
bubbaBear.addScore(83);
console.log(bubbaBear.scores);
console.log(`Merry's average test score of ${merryMaltese.average()}% and has a status of ${merryMaltese.status()}.`);
console.log(`Bubba's average test score of ${bubbaBear.average()}% and has a status of ${bubbaBear.status()}.`);
console.log(`Gator's average test score of ${gladGator.average()}% and has a status of ${gladGator.status()}.`);
//Add methods for adding scores, averaging scores and determining candidate status as described in the studio activity.



//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%.
//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%.
while (gladGator.status() !== 'Accepted') {
gladGator.addScore(100);
}

console.log(`${gladGator.name} earned an average test score of ${gladGator.average()}% and has a status of ${gladGator.status()}.`);

20 changes: 19 additions & 1 deletion dom-and-events/exercises/script.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
function init () {
const missionAbort = document.getElementById("abortMission");
missionAbort.addEventListener("mouseover", event => {
event.target.style.backgroundColor = "red";
})
missionAbort.addEventListener("mouseout", event => {
event.target.style.backgroundColor = "lightblue";
})
missionAbort.addEventListener("click", event => {
window.alert("Are you sure you want to abort the mission?")
paragraph.innerHTML = "Mission aborted! Damn! Space shuttle returning home..."
})

const button = document.getElementById("liftoffButton");
button.addEventListener("click", event => {
paragraph.innerHTML = "Houston! We have liftoff!";

})
const paragraph = document.getElementById("statusReport");

// Put your code for the exercises here.

}

window.addEventListener("load", init);
window.addEventListener("load", init)



71 changes: 71 additions & 0 deletions dom-and-events/studio/scripts.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,73 @@
// Write your JavaScript code here.
// Remember to pay attention to page loading!
function init(){
const background = document.getElementById("shuttleBackground");
const button = document.getElementById("takeoff");
const landing = document.getElementById("landing");
const missionAbort = document.getElementById("missionAbort");
const up = document.getElementById("up");
const down = document.getElementById("down");
const left = document.getElementById("left");
const right = document.getElementById("right");
const flightStatus = document.getElementById("flightStatus");
const shuttleHeight = document.getElementById("spaceShuttleHeight");
const rocket = document.getElementById("rocket")


button.addEventListener("click", () => {
let confirm = window.confirm("Confirm that the shuttle is ready for takeoff.");
if(confirm){
flightStatus.innerHTML = "Shuttle in flight.";
background.style.backgroundColor = "blue";
let currentHeight = parseInt(shuttleHeight.innerHTML);
shuttleHeight.innerHTML = currentHeight + 10000
}
})
landing.addEventListener("click", () => {
window.alert("The shuttle is landing. Landing gear engaged.");
flightStatus.innerHTML = "The shuttle has landed.";
background.style.backgroundColor = "green"
shuttleHeight.innerHTML = 0
rocket.style.left = "0px";
rocket.style.bottom = "0px" ;

})
missionAbort.addEventListener("click", () => {
let confirm = window.confirm( "Confirm that you want to abort the mission.");
if (confirm){
flightStatus.innerHTML = "Mission aborted.";
background.style.backgroundColor = "green"
shuttleHeight.innerHTML = 0
rocket.style.left = "0px";
rocket.style.bottom = "0px" ;

}

})

rocket.style.position = "absolute";
rocket.style.left = "0px";
rocket.style.bottom = "0px" ;


up.addEventListener("click", () => {
let currentBottom = parseInt(rocket.style.bottom);
rocket.style.bottom = (currentBottom + 10) + "px";
shuttleHeight.innerHTML = parseInt(shuttleHeight.innerHTML) + 10000;
})
down.addEventListener("click", () => {
let currentBottom = parseInt(rocket.style.bottom);
rocket.style.bottom = (currentBottom - 10) + "px";
shuttleHeight.innerHTML = parseInt(shuttleHeight.innerHTML) - 10000;
})
left.addEventListener("click", () => {
let currentBottom = parseInt(rocket.style.left);
rocket.style.left = (currentBottom - 10) + "px";
})
right.addEventListener("click", () => {
let currentLeft = parseInt(rocket.style.left);
rocket.style.left = (currentLeft + 10) + "px";
})
}

window.addEventListener("load", init);
89 changes: 86 additions & 3 deletions functions/studio/studio-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
// 4. Below the function, define and initialize a variable to hold a string.
// 5. Use console.log(reverseCharacters(myVariableName)); to call the function and verify that it correctly reverses the characters in the string.
// 6. Optional: Use method chaining to reduce the lines of code within the function.
function reverseCharacters(str){
return str.split('').reverse().join('');
}
let stringy = "hello, world!"

console.log(reverseCharacters(stringy));




// Part Two: Reverse Digits

Expand All @@ -17,6 +26,26 @@
// 4. Return the reversed number.
// 5. Be sure to print the result returned by the function to verify that your code works for both strings and numbers. Do this before moving on to the next exercise.

function reverseCharacters(input) {
if(typeof input === 'string'){
return input.split('').reverse().join('');
}else if(typeof input === 'number'){
const reversedString = input.toString().split('').reverse().join('');
return parseFloat(reversedString) * Math.sign(input);
} else {
return 'Unsupported type';
}
}

let baby = "Hello, Lilah";
let number = 5224;
let negativeNumber = -5224;

console.log(reverseCharacters(baby));
console.log(reverseCharacters(number));
console.log(reverseCharacters(negativeNumber));


// Part Three: Complete Reversal - Create a new function with one parameter, which is the array we want to change. The function should:

// 1. Define and initialize an empty array.
Expand All @@ -25,17 +54,46 @@
// 4. Add the reversed string (or number) to the array defined in part ‘a’.
// 5. Return the final, reversed array.
// 6. Be sure to print the results from each test case in order to verify your code.
function completeReversal(arrayToReverse){
let reversedArray = [];

for(let index of arrayToReverse){
let reversedIndex = reverseCharacters(index);

reversedArray.push(reversedIndex);
}
return reversedArray;
}

let arrayTest1 = ['apple', 'potato', 'Capitalized Words'];
let arrayTest2 = [123, 8897, 42, 1168, 8675309];
let arrayTest3 = ['hello', 'world', 123, 'orange'];
let testArray1 = ["Hello", "Lilah", "12345"];
let testArray2 = [123, -456, "Lauren", 0];
let testArray3 = ["Racecar", 9876, -54321];

console.log(completeReversal(testArray1)); // Output: [ 'olleH', 'dlroW', '54321' ]
console.log(completeReversal(testArray2)); // Output: [ 321, -654, 'cba', 0 ]
console.log(completeReversal(testArray3));
// Bonus Missions

// 1. Have a clear, descriptive name like funPhrase.
// 2. Retrieve only the last character from strings with lengths of 3 or less.
// 3. Retrieve only the first 3 characters from strings with lengths larger than 3.
// 4. Use a template literal to return the phrase We put the '___' in '___'. Fill the first blank with the modified string, and fill the second blank with the original string.
function funPhrase(inputString){
let modifiedString;

if (inputString.length <= 3){
modifiedString = inputString.slice(-1);
}else{
modifiedString = inputString.slice(0,3);
}

return `We put the '${modifiedString}' in '${inputString}'.`;
}
console.log(funPhrase("cat"));
console.log(funPhrase("banana"));
console.log(funPhrase("dog"));
console.log(funPhrase("elephant"));


// Test Function

Expand All @@ -49,3 +107,28 @@ let arrayTest3 = ['hello', 'world', 123, 'orange'];
// 3. Call your area function by passing in two arguments - the length and width.
// 4. If only one argument is passed to the function, then the shape is a square. Modify your code to deal with this case.
// 5. Use a template literal to print, “The area is ____ cm^2.”

let str = "Functions rock!";

console.log(funPhrase(str));

function funPhrase(inputString){
let modifiedString;
if (inputString.length <= 3){
modifiedString = inputString.slice(-1);

}else{
modifiedString = inputString.slice(0,3);
}
return `We put the '${modifiedString}' in '${inputString}'.`;
}

function calculateArea(length, width = length){
return length * width;
}

let rectangleArea = calculateArea(10, 5);
console.log(`The area is '${rectangleArea}' cm^2.`);

let squareArea = calculateArea(7);
console.log(`The area is '${squareArea}' cm^2.`);
Loading