Advertisement
teofarov13

Untitled

Feb 18th, 2023
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unction dark(string) {
  2.     let health = 100;
  3.     let healed;
  4.     let bitcoins = 0;
  5.     let curr = string.split("|")
  6.     let curr1;
  7.     let room = 0;
  8.     let currHealt = 0
  9.  
  10.  
  11.  
  12.  
  13.     for (let j = 0; j < curr.length; j++) {
  14.         room++
  15.         curr1 = curr[j].split(" ");
  16.         let token1 = curr1[0];
  17.         let token2 = Number(curr1[1]);
  18.  
  19.         if (token1 == "potion") {
  20.             healed = health + token2
  21.  
  22.             if (healed > 100) {
  23.                 currHealt = 100 - health;
  24.                 health = 100
  25.                 console.log(`You healed for ${currHealt} hp.`);
  26.             } else if (health < 100) {
  27.                 health += token2;
  28.                 console.log(`You healed for ${token2} hp.`);
  29.             }
  30.             console.log(`Current health: ${health} hp.`);
  31.         } else if (token1 == "chest") {
  32.             bitcoins += token2;
  33.             console.log(`You found ${token2} bitcoins.`)
  34.         } else if (token1 !== "potion" && token1 !== "chest") {
  35.             health -= token2;
  36.             if (health > 0) {
  37.                 console.log(`You slayed ${token1}.`);
  38.             } else {
  39.                 console.log(`You died! Killed by ${token1}.`)
  40.                 console.log(`Best room: ${room}`)
  41.                 break;
  42.             }
  43.         }
  44.  
  45.     }
  46.     if (room = curr.length && health > 0) {
  47.         console.log("You've made it!");
  48.         console.log(`Bitcoins: ${bitcoins}`);
  49.         console.log(`Health: ${health}`);
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement