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
19 lines (15 loc) · 697 Bytes
/
Copy pathwarriors.js
File metadata and controls
19 lines (15 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function Warriors (name, gender) {
this.names = name;
this.gender = gender;
this.level = 1;
this.weapon = 'wooden sword';
this.power = Math.random()*100;
this.salutation = function(){ if (gender === 'M'){ return 'his'} else { return 'her' }};
}
Warriors.prototype = {
fight: function(){return this.names + " rushes to the arena with " + this.salutation() + ' ' +this.weapon + '! '},
faceoff: function(opponant){ if (opponant.power > this.power) { return 'Not strong enough' } else { return "You won the battle!"}}
};
var warrior1 = new Warriors('dan', 'M');
var warrior2 = new Warriors('zelda', 'F');
console.log(warrior1.fight() + warrior1.faceoff(warrior2));