Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let health = 100
- let bitcoins = 0
- const rooms = input.split("|")
- const totalRooms = rooms.length
- let room = ""
- let word = ""
- let n = 0
- let roomsVisited = 0
- while (rooms.length > 0) {
- roomsVisited++
- room = rooms.shift().split(" ")
- word = room[0]
- n = Number(room[1])
- if (word === "potion") {
- health += n
- if (health > 100) {
- n = n - (health - 100)
- health = 100
- }
- console.log(`You healed for ${n} hp.`)
- console.log(`Current health: ${health} hp.`)
- continue
- }
- if (word === "chest") {
- bitcoins += n
- console.log(`You found ${n} bitcoins.`)
- continue
- }
- health -= n
- if (health > 0) {
- console.log(`You slayed ${word}.`)
- } else {
- console.log(`You died! Killed by ${word}.`)
- console.log(`Best room: ${roomsVisited}`)
- return
- }
- }
- if (roomsVisited === totalRooms) {
- console.log(`You've made it!`)
- console.log(`Bitcoins: ${bitcoins}`)
- console.log(`Health: ${health}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement