Advertisement
Spocoman

09. Dungeonest Dark

Jan 22nd, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let rooms = arr[0].split("|");
  3.     let health = 100;
  4.     let coins = 0;
  5.     let isKilled = false;
  6.     for (let i = 0; i < rooms.length; i++) {
  7.         let room = rooms[i].split(" ");
  8.         if (room[0] === "potion") {
  9.             health + Number(room[1]) > 100 ? room[1] = 100 - health : room[1];
  10.             health += Number(room[1]);
  11.            console.log(`You healed for ${room[1]} hp.\nCurrent health: ${health} hp.`);
  12.         } else if (room[0] === "chest") {
  13.             coins += Number(room[1]);
  14.             console.log(`You found ${room[1]} coins.`)
  15.         } else {
  16.             health -= Number(room[1]);
  17.             if (health > 0) {
  18.                 console.log(`You slayed ${room[0]}.`)
  19.             } else {
  20.                 console.log(`You died! Killed by ${room[0]}.\nBest room: ${i + 1}`);
  21.                 isKilled = true;
  22.                 break;
  23.             }
  24.         }
  25.     }
  26.     console.log(isKilled ?``: `You've made it!\nCoins: ${coins}\nHealth: ${health}`);
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement