Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unction dark(string) {
- let health = 100;
- let healed;
- let bitcoins = 0;
- let curr = string.split("|")
- let curr1;
- let room = 0;
- let currHealt = 0
- for (let j = 0; j < curr.length; j++) {
- room++
- curr1 = curr[j].split(" ");
- let token1 = curr1[0];
- let token2 = Number(curr1[1]);
- if (token1 == "potion") {
- healed = health + token2
- if (healed > 100) {
- currHealt = 100 - health;
- health = 100
- console.log(`You healed for ${currHealt} hp.`);
- } else if (health < 100) {
- health += token2;
- console.log(`You healed for ${token2} hp.`);
- }
- console.log(`Current health: ${health} hp.`);
- } else if (token1 == "chest") {
- bitcoins += token2;
- console.log(`You found ${token2} bitcoins.`)
- } else if (token1 !== "potion" && token1 !== "chest") {
- health -= token2;
- if (health > 0) {
- console.log(`You slayed ${token1}.`);
- } else {
- console.log(`You died! Killed by ${token1}.`)
- console.log(`Best room: ${room}`)
- break;
- }
- }
- }
- if (room = curr.length && health > 0) {
- console.log("You've made it!");
- console.log(`Bitcoins: ${bitcoins}`);
- console.log(`Health: ${health}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement