In: Computer Science
~ JavaScript Only ~
Suppose you want to create selection menu for a comic book library that looks like the following:
-----------Comic Library Menu----------
(L)oad Library
(S)earch Library
(A)nalyze Library
(P)rint Library
(Q)uit
The menu is displayed and THEN a WHILE LOOP is entered to display the following command prompt: "Please enter a command (press (m) for menu): "
A scanner reads the user selection. Menu commands should be case insensitive ('L' and 'l' both load the library). A SWITCH STATEMENT is then used to process the menu selection. If user selects 'm,' the menu should be printed again. If an invalid command is entered, display invalid selection message and display the command prompt once again. If the user selects 'q', the selection loop should exit and display a goodbye message.
Please provide a solution. Thank you.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var menu = "-----------Comic Library Menu----------<br> (L)oad Library<br>(S)earch Library<br>(A)nalyze Library<br>(P)rint Library<br>(Q)uit"
document.getElementById("demo").innerHTML = menu ;
ch='y';
while(ch=='y')
{
var x = prompt("Please enter a command (press (m) for menu):");
switch (x) {
case 'm':
case 'M':
document.getElementById("demo").innerHTML = menu ;
break;
case 'l':
case 'L':
alert("Load Library");
break;
case 's':
case 'S':
alert("Search Library");
break;
case 'a':
case 'A':
alert("Analyze Library");
break;
case 'p':
case 'P':
alert("Print Library");
break;
case 'Q':
case 'q':
alert("Exiting");
ch='n'
break;
default: window.alert("Invalid Selection");
}
}
</script>
</body>
</html>