Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use the following code as a starting point: <!DOCTYPE html> <html> <head>

ID: 3607528 • Letter: P

Question

Please use the following code as a starting point:

<!DOCTYPE html>

<html>

<head>

<script>

//this is the syntax to create a function.

function myJavaScriptCode()

{

//This is the syntax to declare a variable.

var myName;

var displayMessage;

//Get a value from the user and assign the variable.

myName = window.prompt("Please enter your name","Harry Potter");

//Modify the value for different cases.

switch(myName){

case "Phil":

displayMessage = "I know you! What do you want?";

break;

case "":

displayMessage = "Hey! You can't be nobody. Try again...";

break;

default:

displayMessage = "hello " + myName

}

//display the results of the operation.

window.alert(displayMessage);

}

</script>

</head>

<body>

<button>Do it</button>

</body>

</html>

code will be viewed in a browser. please make sure it runs properly.

Description: Users will be presented with instructions telling them to enter a digit from 1 to 4. When the user executes the function, they will see text that says "You have called Menu Option " and the number they entered. If users enter anything other than digits from 1 to 4, the function should not fail or cause errors. Rather, users will receive the message, " You have not entered a number from 1 to 4."

Please make sure it meets the following criteria.
•Function works and produces the results requested by the specifications
•Algorithms are clearly written and embedded into the code as comments.
•Variables and functions have useful names which follow a naming convention
•The code layout will include tabs that clearly indicate each working sub-units and spaces between lines at appropriate points.
•Error handling will be used.

Explanation / Answer

=====

<!DOCTYPE html>

<html>

<head>

<script>

//this is the syntax to create a function.

function myJavaScriptCode()

{

//This is the syntax to declare a variable.

var value;

var displayMessage;

//Get a value from the user and assign the variable.

value = window.prompt("Please Enter a digit from 1 to 4");

try{
value = parseInt(value);
}catch(err){
displayMessage = "You have not entered a number from 1 to 4."
}

if(value <1 || value >4){
displayMessage = "You have not entered a number from 1 to 4."
}else{

displayMessage = "You have called Menu Option"
}


//Modify the value for different cases.
switch(value){

case 1:
   displayMessage += 1;
   break;
case 2:
   displayMessage += 2;
   break;
case 3:
   displayMessage += 3;
   break;
case 4:
   displayMessage += 4;
   break;
default:
   displayMessage = "You have not entered a number from 1 to 4."
   break;
}

//display the results of the operation.

window.alert(displayMessage);

}

</script>

</head>

<body>

<button>Do it</button>

</body>

</html>

=====

Thanks

===

Let me know if you need more information.

==