- Code: Select all
//Check if user is ready to play!
confirm("Are you ready to play?");
//Checking age for increased difficulty
var age = prompt("What is your age?");
//Selecting Difficulty for even more increased difficulty
var difficulty = prompt("Type your difficulty: easy, medium, or hard");
//Creating a confirm difficulty box
confirm("Please confirm that you want to play on " + difficulty + "?");
//Here we will create Variables of all sorts (questions, answers, and winning / losing output) to help us with our statements
/*Create math problems for difficulties
People under 18 are given questions easy, medium, and hard
People over 18 are given questions easy2, medium2, and hard2
*/
var easy = "What is 5+5?";
var easy2 = "What is 15+15?";
var medium = "What is 8*6?";
var medium2 = "What is 22*19?";
var hard = "What is 105 % 18?";
var hard2 =" What is 1893 % 12?";
//Creating answers for math problems
var easy_A = "10";
var easy2_A = "30";
var medium_A = "48";
var medium2_A = "418";
var hard_A = "15";
var hard2_A = "9";
/*Creating variables for winning and losing output,
since it will be used multiple times
*/
var winner = "Congratulations, not bad for a " + age + " year old, you won!";
var loser = "I am sorry, you failed... Maybe " + difficulty + " is too hard for you!";
//Creating if else statement for easy
if (age < 18 && difficulty === "easy")
//Creating Variable to store user's answer for easy
var easyA = prompt(easy);
//Did the player win
if (easyA === easy_A)
{
console.log(winner);
}
else
{
console.log(loser);
}
//Creating if else statement for easy2
if (age >= 18 && difficulty === "easy")
//Creating variable to store user's answer for easy2
var easy2A = prompt(easy2);
//Did the player win
if (easy2A === easy2_A)
{
console.log(winner);
}
else
{
console.log(loser);
}
//Creating if else statement for medium
if (age < 18 && difficulty === "medium")
//Creating variable to store user's answer for medium
var mediumA = prompt(medium);
//Did the player win
if (mediumA === medium_A)
{
console.log(winner);
}
else
{
console.log(loser);
}
//Creating if else statement for medium2
if (age >= 18 && difficulty === "medium")
//Creating variable to store user's answer for medium2
var medium2A = prompt(medium2);
//Did the player win
if (medium2A === medium2_A)
{
console.log(winner);
}
else
{
console.log(loser);
}
//Creating if else statement for hard
if (age < 18 && difficulty === "hard")
//Creating variable to store user's answer for hard
var hardA = prompt(hard);
//Did the player win
if (hardA === hard_A)
{
console.log(winner);
}
else
{
console.log(loser);
}
//Creating if else statement for hard2
if (age >= 18 && difficulty === "hard")
//Creating variable to store user's answer for hard2
var hard2A = prompt(hard2);
//Did the player win
if (hard2A === hard2_A)
{
console.log(winner);
}
else
{
console.log(loser);
}
Basically, I can only make the game based on what we have already overviewed:
Data Types: numbers, strings, booleans
Variables
If else Statements
console.log
substring
.length
Math
prompt
confirm
comments
The issue is that it executes all five of the "Did the player win" if else statements
Anyone know a quick fix?