I am new to how loops work. I want the loop to end if the input is N, for "Do you play minecraft?" If the user inputs Y, after the user inputs how many hours, I need it to continue to the calculation part and have it display. My program does not do that. I'm not sure why it continues looping and doesn't go on to the next part.
//Variables
var hours;
var total;
var keepLooping = "Y";
var askingAQuestion = true;
userInput = "";
//calculation and conversion
total = hours * 7;
hours = Number(hours);
// Get the input from the user
function myFunction() {
while (keepLooping === "Y") {
userInput = prompt("Do you play minecraft?" + " Y or N");
if (userInput === "N") {
askingAQuestion = false;
document.write("You should download the free trial!");
} else if (userInput === "Y") {
document.write("That's great!");
hours = prompt("how many hours a day do you play minecraft?")
} else if (hours >= 3) {
document.write("if You play minecraft" + hours + "a day");
document.write("You play minecraft" + total + "hours a week!");
}
}
}
myFunction();
Change the keepLooping value when meet conditions
//Variables
var hours;
var total;
var keepLooping = "Y";
var askingAQuestion = true;
userInput = "";
//calculation and conversion
total = hours * 7;
hours = Number(hours);
// Get the input from the user
function myFunction() {
while (keepLooping === "Y") {
userInput = prompt("Do you play minecraft?" + " Y or N");
if (userInput === "N") {
askingAQuestion = false;
keepLooping = "N";
document.write("You should download the free trial!");
} else if (userInput === "Y") {
document.write("That's great!");
hours = prompt("how many hours a day do you play minecraft?")
} else if (hours >= 3) {
document.write("if You play minecraft" + hours + "a day");
document.write("You play minecraft" + total + "hours a week!");
}
}
}
myFunction();