The following JavaScript code below is interactive where it interacts with user.
Name of file: raceway.js
// Check if the user is ready to play!
// The following var ready is how you declare a variable in JS. The confirm function will print out a messagevar ready = confirm("Are you ready to play")//The prompt will ask for an input from the user.var age = prompt("What's your age?")if (age < 13){//The console.log will log all message into the browser console in the developers section.console.log("You allowed to play but we take no responsibility")}else{console.log("Get ready to play and win big")}console.log("You are at a 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")if (feedback > 8){console.log("Thank you! We should race at the next concert!")}else{console.log("I'll keep practicing coding and racing.")}
Simple html page. This will show you now I can call the
For example:
<html><head><p>This is my first race game</p><script type="text/javascript" language="javascript" src="raceway.js"></script></head><body></body><footer></footer></head>
No comments:
Post a Comment