user1796771
user1796771

Reputation:

Function relative to "switch" won't work

I don't have a clue why this is not working. Everything is declared the right way, and the syntax seems perfect. Can anyone tell me what's wrong? The difficulty is received from a radio selection, but I've declared it here. The function bot won't get to the alerts.

    var difficulty = "easy";
    var botchance = 0;
    var botroll = 0;
    var botscore = 0;


function bot(){
    botchance =  Math.floor(Math.random() * (10 - 1 + 1)) + 1;

    switch(difficulty){
    case "easy":
        if (botchance <= 6){
            botroll = Math.floor(Math.random() * (10 - 3 + 1)) + 3;
        }
        else botroll=10;
        break;
    case "medium":
        if (botchance <= 7){
            botroll = Math.floor(Math.random() * (9 - 2 + 1)) + 2;
        }
        else botroll=10;
        break;
    case "hard":
        if (botchance <= 8){
            botroll = Math.floor(Math.random() * (8 - 1 + 1)) + 1;
        }
        else botroll=10;
        break;
    default:
        if (botchance <= 9){
            botroll = Math.floor(Math.random() * (7 - 1 + 1)) + 1;
        }
        else botroll=10;
    }

alert(botscore);
alert(botroll);
}

Upvotes: 0

Views: 115

Answers (2)

Duke
Duke

Reputation: 3583

Remove the alert(botscore); or declare it;

Upvotes: 0

Esailija
Esailija

Reputation: 140234

If you look at the developer console, you see:

ReferenceError: botscore is not defined

Which stops the execution and you won't see the alerts.

Upvotes: 2

Related Questions