Code your own adventur e


#1

I am getting syntax problems with this code and I don’t know what. I started codecademy a couple days ago as a “Why not?” So can someone point out the syntax issue? Also I don’t know how to contain the code in this post, can someone help with that to?

var user = prompt(“You encounter a thief, what will you do? Run, fight or pay him off?”).toLowerCase();
var youHit = Math.floor(Math.random()*2)
var totalDmg = 0
var dmgDealt = Math.floor(Math.random()*3 + 20)
var run = Math.floor(Math.random()*2)
var thief = false
var attack = “no”

switch (user) {
case ‘run’:
if (run || thief ) {
console.log(“You successfully out-ran the thief!”);
} else {
console.log(“You were killed by the thief! Try again.”);
}
break;
case ‘fight’:
if (youHit) {
console.log(“You hit!”);
youHit += totalDmg
if(totalDmg >= 22) {
console.log(“You killed the thief!”);
} else {
attack = prompt(“Attack again? y/n”).toLowerCase()
}
if (attack === “y”) {
Math.floor(Math.random()*2 + 2) + totalDmg
if (totalDmg >= 22) {
console.log(“You killed the thief!”);
} else {
console.log(“You died!”);
}
} else {
console.log(“You died!”);
}

        } else {
            console.log("You were killed by the thief! Try again.")
            }
    break;
case 'pay':
    return "You paid off the thief and escaped alive"
    break;
default:
console.log("Incorrect response. Try again.");
}

#2

look at here

return "You paid off the thief and escaped alive"

return only makes sense inside function.There is no function in your code. so use console.log instead.



Follow this link it’ll help you to make a good topic :slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.