JSFiddle - React, Tailwind, and code Playground
JavaScript
//A better code for hansi ;)
function start(){
confirm("Are you ready to play!");
age();
}
function age(){
var age = prompt("What's your age");
if(parseInt(age).toString() === "NaN"){
alert("ERROR: Not a number");
start();
}else{
if(age < 13){
confirm("you are allowed to play but i do not take any responsibility");
}else{
confirm("Good luck on your adventure");
}
}
race();
}
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!");
feedbackk();
}else if(userAnswer.toLowerCase() === "no"){
confirm("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
feedback();
}else{
confirm("ERROR: Unexpected Input ");
start();
}
}
function feedback(){
var feedback = prompt("Rate the game from 0-10");
if(parseInt(feedback).toString() === "NaN"){
alert("ERROR: Not a number");
start();
}else{
if(feedback >= 8){
confirm("Thank you! We should race at the next concert");
}else{
confirm("I'll keep practicing coding and racing.");
}
}
}
start();