Skip to content

Week 3 class assignment Joann Cahill #8

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 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Push initial work iincluding attack game
  • Loading branch information
jcahill53 committed Feb 6, 2022
commit 1c108fe5ed765fca030f2b2d7f74e66e955a7c8a
29 changes: 29 additions & 0 deletions battleGame.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
// 1. Create attack function below. This will take the following parameters:
// attackingPlayer, defendingPlayer, baseDamage, variableDamage

// const attack2 = function (attackingPlayer, defendingPlayer, baseDamage, variableDamage) {

// const randomValue = Math.floor(Math.random() * variableDamage);
// const totalDamage = baseDamage + randomValue;
// defendingPlayer.health = defendingPlayer.health - totalDamage;

// console.log( `${attackingPlayer.name}' hits '${defendingPlayer.name} 'for '${totalDamage}' damage'`)
// }


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

let player1 = {
name: 'Joe',
health: 10,
};

let player2 = {
name: 'Jane',
health: 10,
};

console.log(player1)
console.log(player2)

// 3. Refactor attack function to an arrow function. Comment out function above.
const attack = (attackingPlayer, defendingPlayer, baseDamage, variableDamage) => {
const randomValue = Math.floor(Math.random() * variableDamage);
const totalDamage = baseDamage + randomValue;
defendingPlayer.health = defendingPlayer.health - totalDamage;

// console.log( randomValue );
// console.log( totalDamage );
// console.log( defendingPlayer.health );
console.log(`${attackingPlayer.name}' hits '${defendingPlayer.name} 'for '${totalDamage}' damage'`)
}



Expand Down
24 changes: 19 additions & 5 deletions itemizedReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@


// Check
logReceipt(
{ descr: 'Burrito', price: 5.99 },
{ descr: 'Chips & Salsa', price: 2.99 },
{ descr: 'Sprite', price: 1.99 }
);
const burrito = {
descr: 'Burrito',
price: 5.99

{
descr: 'Chips & Salsa',
price: 2.99
}
}
logReceipt(, {
descr: 'Chips & Salsa',
price: 2.99
}, {
descr: 'Sprite',
price: 1.99
});
// should log something like:
// Burrito - $5.99
// Chips & Salsa - $2.99
// Sprite - $1.99
// Total - $10.97

}
}
15 changes: 15 additions & 0 deletions 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;

}
usetopSpeed(){
const{name, topSpeed} = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! Yes, this destructuring from this is a great strategy for methods, it makes them quite readable, BUT . . . . . .

console.log( `${this.name} moving to ${this.topSpeed}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't use the destructured values, it becomes moot. You can probably see in VSCode that name and topSpeed on line 14 are kind of greyed out, or you can hove and see they are 'declared but never read' . . . . and that is because on line 15 you are accessing using this. .. . Now either way is totally valid, but it's a one-or-the-other kind of thing 😉

}

}


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

const spaceX = new SpaceShip('SpaceXShip', '500 mph');
spaceX.usetopSpeed()+;