JSFiddle - React, Tailwind, and code Playground
JavaScript
//A better code for hansi ;)
function start(){
confirm("Are you ready to play!");
age();
}
function startRace(){
race();
}
function startAge(){
age();
}
function startFeedback(){
feedback();
}
function age(){
var age = prompt("What's your age");
if(parseInt(age).toString() === "NaN"){
alert("ERROR: Not a number");
startAge();
}else{
if(age < 13){
confirm("you are allowed to play but i do not take any responsibility");
}else{
confirm("Good luck on your adventure");
}
}
startRace();
}
function race(){
confirm("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
confirm("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer = prompt("Do you want to race Bieber on stage?");
if(userAnswer.toLowerCase() === "yes"){
confirm("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
startFeedback();
}else if(userAnswer.toLowerCase() === "no"){
confirm("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
startFeedback();
}else if (userAnswer.toLowerCase() === "secret"){
confirm("Secret :D");
startRace();
}else{
confirm("ERROR: Unexpected Input ");
startRace();
}
}
function feedback(){
var feedback = prompt("Rate the game from 0-10");
if(parseInt(feedback).toString() === "NaN"){
alert("ERROR: Not a number");
startFeedback();
}else{
if(feedback >= 8){
confirm("Thank you! We should race at the next concert");
}else{
confirm("I'll keep practicing coding and racing.");
}
}
}
start();