Skip to content

Instantly share code, notes, and snippets.

@debonx
Created January 11, 2020 11:00
Show Gist options
  • Save debonx/b1fee5aff629adc9e609ba0ddadd7204 to your computer and use it in GitHub Desktop.
Save debonx/b1fee5aff629adc9e609ba0ddadd7204 to your computer and use it in GitHub Desktop.
Javascript: random Dog - Cat fight.
module.exports = class Cat {
constructor(name, clawStrength) {
this.name = name;
this.clawStrength = clawStrength;
}
};
module.exports = class Dog {
constructor(name, toothStrength) {
this.name = name;
this.toothStrength = toothStrength;
}
};
// Require modules in:
let Cat = require('./cat.js');
let Dog = require('./dog.js');
let fight = (dog, cat) => {
if (dog.toothStrength > cat.clawStrength) {
console.log(`${dog.name} wins!`);
}
else if (dog.toothStrength < cat.clawStrength) {
console.log(`${cat.name} wins!`);
}
else {
console.log(`${dog.name} and ${cat.name} are equally skilled fighters!`);
}
}
const myDog = new Dog('Rex', Math.random());
const myCat = new Cat('Tabby', Math.random());
fight(myDog, myCat);
@debonx
Copy link
Author

debonx commented Jan 11, 2020

Fight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment