Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let intialHealt = 100;
- let bitcoins = 0;
- let array = input.split('|')
- let count = 0;
- let flag = true;
- health = intialHealt;
- array.forEach(element => {
- if (health > 0) {
- count++;
- let [dungeons, score] = element.split(' ');
- score = Number(score);
- if (dungeons === 'potion' && health + score >= intialHealt) {
- console.log(`You healed for ${(intialHealt - health)} hp.`);
- health = intialHealt;
- console.log(`Current health: ${health} hp.`);
- } else if (dungeons === 'potion' && health + score < intialHealt) {
- health += score;
- console.log(`You healed for ${score} hp.`);
- console.log(`Current health: ${health} hp.`);
- } else if (dungeons === 'chest') {
- bitcoins += score;
- console.log(`You found ${score} bitcoins.`);
- } else {
- health -= score;
- if (health > 0) {
- console.log(`You slayed ${dungeons}.`);
- }
- if (health <= 0) {
- console.log(`You died! Killed by ${dungeons}.`);
- console.log(`Best room: ${count}`);
- flag = false;
- }
- }
- }
- });
- if (flag) {
- console.log(`You've made it!\nBitcoins: ${bitcoins}\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