Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(array) {
- if (typeof array !== 'object') {
- array = [array];
- }
- let initialHealth = 100;
- let health = initialHealth;
- let amount = 0;
- let room = 0;
- let copyAraay = array[0].split('|');
- let count = 0;
- for (let i = 0; i < copyAraay.length; i++) {
- let command = copyAraay[i].split(' ');
- let [dungeons, points] = command;
- if (health > 0) {
- switch (dungeons) {
- case 'potion':
- count++;
- if (initialHealth >= health + Number(points)) {
- health += Number(points);
- room = health;
- console.log(`You healed for ${points} hp.`);
- console.log(`Current health: ${health} hp.`);
- } else {
- count++
- console.log(`You healed for ${initialHealth - health} hp.`);
- health = initialHealth;
- room = health;
- console.log(`Current health: ${health} hp.`);
- }
- break;
- case 'chest':
- count++;
- amount += Number(points);
- console.log(`You found ${points} bitcoins.`);
- break;
- default:
- count++;
- if (health >= 0) {
- health -= Number(points);
- if (health > 0) {
- console.log(`You slayed ${dungeons}.`);
- } else {
- console.log(`You died! Killed by ${dungeons}.`);
- console.log(`Best room: ${i + 1}`);
- }
- }
- }
- }
- }
- if (copyAraay.length + 1 === count) {
- console.log(`You've made it!\nBitcoins: ${amount}\nHealth: ${health}`);
- }
- }
- solve('cat 10|potion 30|orc 10|chest 10|snake 25|chest 110');
- //solve(['rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement