Someone please help. JavaScript: Logical Operators. Code your own adventure 2


#1


JavaScript: Code your own adventure 2


SyntaxError: Unexpected token case


var userInput = prompt("Good afternoon, young knight! Here's a question, what would you like to do today? We can cook a tasty meal, or we can slay a beastly troll, or maybe search for a dragon's hoard of gold...").toLowerCase();
var cookingSkills = prompt("On a scale of 1-15, rate your cooking skills.").toLowerCase();
var recipeSkills = prompt("Rate 1-15, how well can you follow a recipe?").toLowerCase();
var intelligence = prompt("How smart are you, rate 1-15.").toLowerCase();
var strength = prompt("On a scale of 1-15, how strong are you?").toLowerCase();
var agility = prompt("How agile are you when running or fighting? 1-15.").toLowerCase();
var theiving = prompt("On a scale from 1-15, how well would you be able to steal something without someone else realizing?").toLowerCase();

switch (userInput) {
    
    case 'cooking':
        
        if(cookingSkills >= 8 && recipeSkills >= 8) {
            console.log("FANTASTIC! Come with me young one, and we will be off to this kitchens!");
        } else if (cookingSkills <= 5 || recipeSkills <= 5) {
            console.log("Perhaps we can go about this very catiously. We wouldn't want to burn the village down now!");
        }
        
        break;
    
    case 'trollBattle':
           if (strength >=8 || intelligence >= 8) {
               console.log("Perhaps we can outsmart the troll! Then we wouldn't have to worry about getting ourselves killed in the process. Or, maybe... Perhaps we can face him head on, we may possibly win if we're smart enough!");
           } else {
               console.log("So you're neither witty nor strong... What a pity. Perhaps you have the hands of a theif. Are you daring to go into a dragon's lair just to get rich?");

        break;
    
    case 'dragonGold':
        if (agility >= 8 && theiving >= 8){
            console.log("Well, well, well... It would seem you have the buildup of a master theif. You can sprint really fast, and you can snag things without anyone suspecting you. Perhaps you wouldn't mind making a little gold off of a weary, old dragon. What do you say?");
        } else if (agility >= 8 || theiving >= 8) {
            console.log("If the dragon wakes up, you can always just run for your life in the faintest hope that you'll make it out alive without being burned alive... If that's what you want to do.");
        } else {
            console.log("I'm sorry, I can't offer any quests to you at this time. Come back later when you have gained more knowledge or agility.");
        }

        break;

    default:
    console.log("You must work on your stats before being able to gain access to more quests.");
};


#2

check your curly braces( { } ) .maybe you missed :slight_smile:


#3

firstly same as @rcodeman said you missed curly brace in the case 'trollbattle', and then in your case there are camelcase word, but in your prompt you make toLowerCase method, i think it's wrong.

lastly you must make prompt cooking, recipe, intel, strength, agility and theiving must inside the case. not outside switch, and also you forgot to add else in case 'cooking' . so like this.

var userInput = prompt("Good afternoon, young knight! Here's a question, what would you like to do today? We can cook a tasty meal, or we can slay a beastly troll, or maybe search for a dragon's hoard of gold...").toLowerCase();

switch (userInput) {
    
    case 'cooking':
            
        var cookingSkills = prompt("On a scale of 1-15, rate your cooking skills.").toLowerCase();
        var recipeSkills = prompt("Rate 1-15, how well can you follow a recipe?").toLowerCase();
            
        if(cookingSkills >= 8 && recipeSkills >= 8) {
            console.log("FANTASTIC! Come with me young one, and we will be off to this kitchens!");
        } else if (cookingSkills <= 5 || recipeSkills <= 5) {
            console.log("Perhaps we can go about this very catiously. We wouldn't want to burn the village down now!");
        } else {
            console.log('nothing else');
        }
        break;
    
    case 'trollbattle':
        var intelligence = prompt("How smart are you, rate 1-15.").toLowerCase();
        var strength = prompt("On a scale of 1-15, how strong are you?").toLowerCase();
        
       if (strength >=8 || intelligence >= 8) {
           console.log("Perhaps we can outsmart the troll! Then we wouldn't have to worry about getting ourselves killed in the process. Or, maybe... Perhaps we can face him head on, we may possibly win if we're smart enough!");
       } else {
           console.log("So you're neither witty nor strong... What a pity. Perhaps you have the hands of a theif. Are you daring to go into a dragon's lair just to get rich?");
       }
        break;
    
    case 'dragongold':
        
        var agility = prompt("How agile are you when running or fighting? 1-15.").toLowerCase();
        var theiving = prompt("On a scale from 1-15, how well would you be able to steal something without someone else realizing?").toLowerCase();
        
        if (agility >= 8 && theiving >= 8){
            console.log("Well, well, well... It would seem you have the buildup of a master theif. You can sprint really fast, and you can snag things without anyone suspecting you. Perhaps you wouldn't mind making a little gold off of a weary, old dragon. What do you say?");
        } else if (agility >= 8 || theiving >= 8) {
            console.log("If the dragon wakes up, you can always just run for your life in the faintest hope that you'll make it out alive without being burned alive... If that's what you want to do.");
        } else {
            console.log("I'm sorry, I can't offer any quests to you at this time. Come back later when you have gained more knowledge or agility.");
        }
        break;

    default:
    console.log("You must work on your stats before being able to gain access to more quests.");
};

hope this help you. :slight_smile:


#4

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