I'm stuck on a part of my JavaScript lab where I need to:
- Prompt for user input
- Then use a switch statement to display alert based on what was entered
- Then check that its text and not a number
My teacher said to put it in a loop and I've used all of them so far on this problem but I just made myself more confused.
Here is my code:
<script>
//array to compare input to
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
do
{
//prompt user for input
var response = prompt("Choose a day of the week: ");
//loop through all array elements
for(i in days)
{
//choices that I will use to compare input to
switch(response)
{
case days[0]:
case days[1]:
case days[2]:
case days[3]:
case days[4]:
case days[5]:
case days[6]:
alert("You have chosen day: " + days[i]);
break;
default:
alert("That is not a choice!");
}
}
}//condition while input doesn't equal exactly array element prompt user again
while(response !=== days[i]);
</script>