Created
January 11, 2020 11:00
-
-
Save debonx/b1fee5aff629adc9e609ba0ddadd7204 to your computer and use it in GitHub Desktop.
Javascript: random Dog - Cat fight.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = class Cat { | |
constructor(name, clawStrength) { | |
this.name = name; | |
this.clawStrength = clawStrength; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = class Dog { | |
constructor(name, toothStrength) { | |
this.name = name; | |
this.toothStrength = toothStrength; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Author
debonx
commented
Jan 11, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment