Created
March 21, 2016 15:01
-
-
Save icemancast/621daab1e06bc91a16b3 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Javascript</title> | |
</head> | |
<body> | |
<script> | |
// (function() { | |
"use strict"; | |
var player_name = prompt('What is your name'); | |
// Create empty object | |
var player_1 = {}; | |
// Create properties (variables) | |
player_1.name = player_name; | |
player_1.power = 100; | |
player_1.speed = 100; | |
player_1.stamina = 20; | |
player_1.defense = 20; | |
// Create methods (functions) | |
player_1.intro = function() { | |
console.log('Hello ' + this.name); | |
console.log('We are being attacked on all sides and we need your help'); | |
} | |
player_1.attack = function() { | |
console.log('attacking'); | |
} | |
player_1.run = function () { | |
console.log('running'); | |
} | |
player_1.injured = function() { | |
this.power--; | |
console.log('You have been attacked'); | |
} | |
player_1.showPower = function() { | |
console.log(this.power); | |
} | |
// })(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment