forked from kaylafortin/javascript-part-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarriors.js
More file actions
35 lines (30 loc) · 1.15 KB
/
warriors.js
File metadata and controls
35 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function Warrior(name, gender){
this.name = name;
this.gender = gender;
this.level = 1;
this.weapon = "wooden sword";
this.power = Math.floor(Math.random()*100 + 1);
}
Warrior.prototype = {
fight: function(){
if (this.gender === "male"){
console.log(this.name + " rushes to the arena with his " + this.weapon);
}
else{
console.log(this.name + " rushes to the arena with her " + this.weapon);
}
},
faceoff: function(opponent){
if (opponent.power > this.power){console.log("You fought a hardy battle, but you died against " + opponent.name + " just be better")}
else if (opponent.power === this.power){console.log("It's a tie! You're both terrible!")}
else {console.log("You won against " + opponent.name + "! Fight even better next time")}
}
}
var zelda = new Warrior("Zelda", "female");
var link = new Warrior("Link", "male");
var optimus = new Warrior("Optimus", "male");
var decodator = new Warrior("decodator", "male");
var jeanne = new Warrior("Jeanne d'Arc", "female");
zelda.fight();
zelda.faceoff(jeanne);
zelda.faceoff(optimus);