Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function muOnline(input) {
- let health = 100, bitcoins = 0;
- var rooms = input.split('|');
- for (let i = 0; i < rooms.length; i++) {
- var tokens = rooms[i].split(' ');
- let command = tokens[0];
- let amount = Number(tokens[1]);
- if (command == "potion") {
- if (health + amount > 100) {
- amount = 100 - health;
- }
- health += amount;
- console.log(`You healed for ${amount} hp.\nCurrent health: ${health} hp.`);
- } else if (command == "chest") {
- bitcoins += amount;
- console.log(`You found ${amount} bitcoins.`);
- } else {
- health -= amount;
- if (health <= 0) {
- console.log(`You died! Killed by ${command}.\nBest room: ${i + 1}`);
- break;
- }
- console.log(`You slayed ${command}.`);
- }
- }
- if (health > 0) {
- console.log(`You've made it!\nBitcoins: ${bitcoins}\nHealth: ${health}`);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement