0
In Zeilen, 34-41 Ich versuche es so zu machen, wenn der Benutzer in Spiele eingibt wird es automatisch ein Spiel aus einer anderen Datei laden, und das gleiche für das Gespräch. Wie kann ich das mit js machen?Loading eine andere Datei, wenn der Benutzer sagt, die richtige Antwort
var storeUsersInfo = [];
var amountOfUsers = prompt("How many users do you want?");
amountOfUsers = parseInt(amountOfUsers);
function returnUserInput() {
var askFirstName = prompt("What is your first name?");
var askLastName = prompt("What is your last name" + " " + titleCase(askFirstName) + "?");
while(true) {
var askAge = prompt("How old are you" + " " + titleCase(askFirstName) + " " + titleCase(askLastName) + "?");
if(Number.isInteger(Number.parseInt(askAge))) break;
alert("Not a valid input, please enter your response as a number.");
};
return {
firstName: titleCase(askFirstName),
lastName: titleCase(askLastName),
age: askAge
};
};
function titleCase(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
};
for(var i = 0; i < amountOfUsers; i++) {
storeUsersInfo[i] = returnUserInput();
}
console.log("Your information has been stored in the object below.");
console.log(storeUsersInfo);
var askUserToDoSomethingElse = prompt("Do you want to do something else?"); // Yes or No
if(askUserToDoSomethingElse = "yes") {
var chooseSomethingElse = prompt("If you want to play a game type game, or if you just want to talk type talk.");
if(chooseSomethingElse === "game") {
alert("Okay!");
} else if (chooseSomethingElse === "talk") {
alert("Okay!");
}
};
Verwenden ajax conten laden t in die Seite, wenn Sie nicht möchten, dass die Seite neu geladen wird – charlietfl