Created
May 7, 2015 00:42
-
-
Save matthaxby/abc8f65840f3b0e9cba1 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/nerayuhogu
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> | |
| <meta charset="utf-8"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| var orcA = { | |
| name: "walrus", | |
| strength: 10, | |
| specialMove: "epic mustaches", | |
| health: 120 | |
| }; | |
| var orcB = { | |
| name: "Mango", | |
| strength: 15, | |
| specialMove: "sticky punches", | |
| health: 100 | |
| }; | |
| var fight = function(orcA, orcB, healthA, healthB) { | |
| if (Math.random() < 0.8) { | |
| healthA = healthA - orcB.strength; | |
| console.log(orcB.name + " " + orcB.specialMove + " " + orcA.name + " Health at" + healthA); | |
| } | |
| else { | |
| console.log(orcB.name + " missed!"); | |
| } | |
| if (Math.random()) | |
| healthB = healthB - orcA.strength; | |
| console.log(orcA.name + " " + orcA.specialMove + " " + orcB.name + " Health at" + healthB); | |
| if(healthA <= 0) { | |
| return orcA.name + " is dead"; | |
| } | |
| else if (healthB <= 0) { | |
| return orcB.name + " is dead"; | |
| } | |
| else { | |
| return fight(orcA, orcB, healthA, healthB); | |
| } | |
| }; | |
| console.log(fight(orcA, orcB, orcA.health, orcB.health)); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript"> | |
| var orcA = { | |
| name: "walrus", | |
| strength: 10, | |
| specialMove: "epic mustaches", | |
| health: 120 | |
| }; | |
| var orcB = { | |
| name: "Mango", | |
| strength: 15, | |
| specialMove: "sticky punches", | |
| health: 100 | |
| }; | |
| var fight = function(orcA, orcB, healthA, healthB) { | |
| if (Math.random() < 0.8) { | |
| healthA = healthA - orcB.strength; | |
| console.log(orcB.name + " " + orcB.specialMove + " " + orcA.name + " Health at" + healthA); | |
| } | |
| else { | |
| console.log(orcB.name + " missed!"); | |
| } | |
| if (Math.random()) | |
| healthB = healthB - orcA.strength; | |
| console.log(orcA.name + " " + orcA.specialMove + " " + orcB.name + " Health at" + healthB); | |
| if(healthA <= 0) { | |
| return orcA.name + " is dead"; | |
| } | |
| else if (healthB <= 0) { | |
| return orcB.name + " is dead"; | |
| } | |
| else { | |
| return fight(orcA, orcB, healthA, healthB); | |
| } | |
| }; | |
| console.log(fight(orcA, orcB, orcA.health, orcB.health)); | |
| </script></body> | |
| </html> |
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
| var orcA = { | |
| name: "walrus", | |
| strength: 10, | |
| specialMove: "epic mustaches", | |
| health: 120 | |
| }; | |
| var orcB = { | |
| name: "Mango", | |
| strength: 15, | |
| specialMove: "sticky punches", | |
| health: 100 | |
| }; | |
| var fight = function(orcA, orcB, healthA, healthB) { | |
| if (Math.random() < 0.8) { | |
| healthA = healthA - orcB.strength; | |
| console.log(orcB.name + " " + orcB.specialMove + " " + orcA.name + " Health at" + healthA); | |
| } | |
| else { | |
| console.log(orcB.name + " missed!"); | |
| } | |
| if (Math.random()) | |
| healthB = healthB - orcA.strength; | |
| console.log(orcA.name + " " + orcA.specialMove + " " + orcB.name + " Health at" + healthB); | |
| if(healthA <= 0) { | |
| return orcA.name + " is dead"; | |
| } | |
| else if (healthB <= 0) { | |
| return orcB.name + " is dead"; | |
| } | |
| else { | |
| return fight(orcA, orcB, healthA, healthB); | |
| } | |
| }; | |
| console.log(fight(orcA, orcB, orcA.health, orcB.health)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment