TZinovieva

Mu Online JS Fundamentals

Feb 15th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function muOnline(input) {
  2.     let initialHealth = 100;
  3.     let bitcoins = 0;
  4.     let tokens = input.split("|");
  5.     let isCompleted = true;
  6.     let tempHealth = 100;
  7.  
  8.     for (let i = 0; i < tokens.length; i++) {
  9.    
  10.         let [command, number] = tokens[i].split(" ");
  11.         number = Number(number);
  12.        
  13.         if (command == "potion") {
  14.             if (initialHealth + number < 100) {
  15.                 initialHealth += number;
  16.             } else if (initialHealth + number > 100) {
  17.                 number = 100 - initialHealth;
  18.                 initialHealth += number;
  19.             } else if (initialHealth + number === 100) {
  20.                 number = 0;
  21.             }
  22.             console.log(`You healed for ${number} hp.`);
  23.             console.log(`Current health: ${initialHealth} hp.`);
  24.         } else if (command == "chest") {
  25.             bitcoins += number;
  26.             console.log(`You found ${number} bitcoins.`);
  27.         } else {
  28.             initialHealth -= number;
  29.             if (initialHealth > 0) {
  30.                 console.log(`You slayed ${command}.`);
  31.             } else {
  32.                 isCompleted = false;
  33.                 console.log(`You died! Killed by ${command}.`);
  34.                 console.log(`Best room: ${i + 1}`);
  35.                 break;
  36.             }
  37.         }
  38.     }
  39.     if (isCompleted) {
  40.         console.log("You've made it!");
  41.         console.log(`Bitcoins: ${bitcoins}`);
  42.         console.log(`Health: ${initialHealth}`);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment