Soy nuevo en cómo funcionan los bucles. Quiero que el ciclo termine si la entrada es N, para "¿Juegas Minecraft?" Si el usuario ingresa Y, después de que el usuario ingrese cuántas horas, lo necesito para continuar con la parte de cálculo y hacer que se muestre. Mi programa no hace eso. No estoy seguro de por qué continúa en bucle y no pasa a la siguiente parte.
//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();Cambie el valor de keepLooping cuando cumpla las condiciones
//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();