Functions, prompt, and var declarations


#1

I am stuck at the part where I am supposed to answer yes or no to a race and I thought I could create a function so sift through all of the popular confirmation words and phrases so that the program would understand any form of saying "yes". But unfortunately it's not working.

I was also trying to avoid hard coding a bunch of if statements b/c that sounded ridiculously tedious and awful. So if anyone has a better option I am all ears!!

I am also confused why it printed out my affirmation function in it's entirety AFTER IT EXECUTED THE PROMPT PART!!! Very strange

also, my rating part needs some work. I am a little confused as to how java saves a var type. Is it saved as a string? is it saved as whatever? can we declare a bunch of var types and use them as integers, booleans, strings, etc interchangeably (probably not).

So I guess I am wondering what the var declaration means/does


This is what is displayed after I run the program

Yeah your old enough apparently
You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'
Suddenly, Bieber stops and says, 'Who wants to race me?'
Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'
Thank you! We should race at the next concert!

BELOW IS STILL PART OF MY CONSOLE READOUT

var feedback = prompt("Rate the game 1-10");
if(feedback < 8){
console.log("I'll keep practicing coding and racing.");
}
else{
console.log("Thank you! We should race at the next concert!");
}
THIS IS THE END OF THE CONSOLE READOUT, why does it print out my code????


confirm("Ready to play?");
var age = prompt("Enter your age");
if(age < 13){
    console.log("i guess you're under 13");   
}
else{
    runGame();
    rateGame();
}

function affirmation(someString){
    if(someString ===( 
        ("yes")||("Yes")||("sure")||("Sure")||("yeah")||("Yeah")||            ("why not")||("Why not")
        )){
        return true;
    }   
    else{
        return false;
    }
}
function runGame(){
        console.log("Yeah your old enough apparently"); 
        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(affirmation(userAnswer) === true){
            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.'");
       
        }
}

function rateGame(){
    var feedback = prompt("Rate the game 1-10");
        if(feedback < 8){
        console.log("I'll keep practicing coding and racing.");
        }
        else{
            console.log("Thank you! We should race at the next                                  concert!");
        }
}


#2

You never close your console.log statement in the else branch of runGame.


#3

ahahaha thx that's all it was


#4

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