A more complete game


#1

The program does not check if the age is a valid number, for i example if the user just type a text doing the way the instructions we were told would give some errors.

// Check if the user is ready to play!
confirm('Are you ready to play?');

var age = prompt('What\'s your age?');

        if (isNaN(age)) {
            console.log('NOT A VALID AGE');
        }
        else if (age<13) {
            console.log("You can play but I take no responsability");
            console.log('You are at a Justin Bieber concert, and you hear                this lyric \'Lace my shoes off, start racing.\'');
            console.log("Suddenly, Bieber stops and says, 'Who wants to race             me?'");
        var userAnswer = prompt("Do you want to race Bieber on stage?");
            if (userAnswer=="yes"){
            console.log("You and Bieber start racing. It's neck and neck!             You win by a shoelace!");
            }
        else {
            console.log("Oh no! Bieber shakes his head and sings 'I set a             pace, so I can race without pacing.'");
        }
        }
        else {
        console.log('ENJOY and have lots of fun');
        console.log('You are at a Justin Bieber concert, and you hear this           lyric \'Lace my shoes off, start racing.\'');
        console.log("Suddenly, Bieber stops and says, 'Who wants to race me          ?'");
        var userAnswer = prompt("Do you want to race Bieber on stage?");
                if (userAnswer=="yes"){
                    console.log("You and Bieber start racing. It's neck                       and neck! You win by a shoelace!");
                    }
                else {
                    console.log("Oh no! Bieber shakes his head and sings                      'I set a pace, so I can race without pacing.'");
                }

        }

var feedback=prompt('please rate my game and help me make it better');
if (feedback>8) {
    console.log("Thank you! We should race at the next concert!");
}
else {
    console.log("I'll keep practicing coding and racing.");
}
/*console.log('You are at a Justin Bieber concert, and you hear this lyric \'Lace my shoes off, start racing.\'');
*/


#2

isNaN doesn't test whether a value is a number, it tests if a number is the value NaN


#3

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