I have been trying for days to get this to work. I have the basic code but every time I try to get the last requirement added, I break the code. I’m sure I am missing a lot and that’s why I can’t add the alert box with the count of displays. So it asks the users name, the number of times they want to see and alert box and if they enter invalid answers they see alert boxes telling them to enter a correct value. The last part that I am stuck on is the value the user enters determines how many alert boxes show their name and the box needs to say which box it is. So, <Name> this is time number <count of displays> of <total time to display>. I was trying different things with limiting and FOR , with the user Y variable being the limiter. Any clues or help would be greatly appreciated.
<!DOCTYPE html>
<html>
<body>
<p>Please enter your name followed by how many times you would like to be alerted.</p>
<button onclick="myFunction()">Start</button>
<script>
function myFunction() {
var x;
var name = prompt("Please enter your name", "");
if (name == null || name == "") {
alert("Please input a name.");
return false;
}
else {
var y;
var y = prompt("Please enter a number between 1-10");
if (y == null || y == "") {
alert("Please input a number for the times to alert the name.");
return false;
}
if (y > 10) {
alert("Please input a number between 1 and 10.")
var y = prompt("Please enter a number between 1-10");
}
if (y <= 0) {
alert("Please input a number great than zero.")
var y = prompt("Please enter a number between 1-10");
}
}
}
</script>
</body>
</html>
This gets rid of most of your
alertstatements and keepsprompt‘ing until a valid value is submitted.Working example:
http://jsfiddle.net/DwxmT/