Skip to content

week 3 completed assignments #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
15 changes: 11 additions & 4 deletions battleGame.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
// 1. Create attack function below. This will take the following parameters:
// attackingPlayer, defendingPlayer, baseDamage, variableDamage

// function attack(attackingPlayer, defendingPlayer, baseDamage, variableDamage) {

// };

// 2. Create player1 and player2 objects below
// Each should have a name property of your choosing, and health property equal to 10


const player1 = {
name: 'Leia',
health: 10
}
const player2 = {
name: 'Leia',
health: 10
};

// 3. Refactor attack function to an arrow function. Comment out function above.


let attack = (attackingPlayer, defendingPlayer, baseDamage, variableDamage) => { };

// DO NOT MODIFY THE CODE BELOW THIS LINE
// Set attacker and defender. Reverse roles each iteration
Expand Down
9 changes: 8 additions & 1 deletion itemizedReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
// i.e. {descr: 'Coke', price: 1.99}
// function should log each item to the console and log a total price


const logReceipt = function (...menuItems) {
let totalPrice = 0;
menuItems.forEach(function (menuItem) {
totalPrice += menuItem.price;
console.log(`${menuItem.descr} costs ${menuItem.price}`)
console.log(`Total = ${totalPrice}`);
})
};

// Check
logReceipt(
Expand Down
17 changes: 15 additions & 2 deletions phoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
// '206 333 4444'
// Returns true if valid, false if not valid


function testPhoneNumber(phoneNumber1) {
const validPhoneNumber = new RegExp('^(\+0?1\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$');
if (validPhoneNumber.test(phoneNumber1)) {
return true;
} else {
return false;
}
};

// Explanation of RegExp
// ^ start of line
Expand All @@ -30,7 +37,13 @@ console.log(testPhoneNumber('(206) 33-4444')); // should return false, missing a
// the phone number.
// Returns an object in the format {areaCode, phoneNumber}


function parsePhoneNumber(phoneNumber2) {
// const areaCodeRegex = ('(\+0?1\s)?\(?\d{3}\)');
// const phoneNumberRegex = ('\d{3}[\s.-]\d{4}$'').exec(phoneNumber2);
const areaCode = /(\+0?1\s)?\(?\d{3}\)/.exec(phoneNumber2);
const phoneNumber = /\d{3}[\s.-]\d{4}$/.exec(phoneNumber2);
return (areaCode, phoneNumber)
};

// Check parsePhoneNumber
console.log(parsePhoneNumber('206-333-4444'));
Expand Down
14 changes: 13 additions & 1 deletion soccer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ const getPointsFromResult = function getPointsFromResult(result) {
// including wins, draws, and losses i.e. 'wwdlw'
// Returns total number of points won


function getTotalPoints(results) {
const seasonResults = results.split('');
let totalPoints = 0;
seasonResults.forEach(function (gameResult) {
if (gameResult == 'w') {
totalPoints += 3;
}
if (gameResult == 'd') {
totalPoints += 1;
}
});
return totalPoints;
}

// Check getTotalPoints
console.log(getTotalPoints('wwdl')); // should equal 7
Expand Down
17 changes: 16 additions & 1 deletion spaceShip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
// - should have a method accelerate that logs to the console
// `${name} moving to ${topSpeed}`


class SpaceShip {
constructor(name, topSpeed) {
this.name = name;
this.topSpeed = topSpeed;
}
accelerate() {
const { name, topSpeed } = this;
console.log(`${name} moving to ${topSpeed} u/s`)
};
};

// 2. Call the constructor with a couple ships,
// and call accelerate on both of them.

const rasamama = new SpaceShip('Rasamama S36', '100');
rasamama.accelerate;

const rocinante = new SpaceShip('Rocinante, 250');
rocinante.accelerate;