I have a inline javascript problem that i could use help wit
I have a inline javascript problem that i could use help with
Create a JavaScript program to record a marathon runner’s information. Include your name and Marathon Runner in the <Title> tag. Don’t forget to add documentation to your program.
You must call a function to ask for the runner’s identification number. If the marathon runner’s number is not numeric, continue to ask the for the runner’s number.
Call a second function to ask for the runner’s experience level (1 for beginner, 2 for Intermediate, and 3 for Advanced). Be sure to include a loop in the function so if 1, 2, or 3 is not entered, the prompt will repeat asking for the experience level until the user enters a valid number.
After the user has entered the runner’s identification number and runner’s experience level, you will use a loop to ask for the various marathon times. (How long it took to run each marathon.) The runner has run 3 marathons. You must place a loop in the <body> tag to get the times for each marathon. Each marathon time must be greater than 0. To test your program use 3, 4, and 3.26 for the 3 marathon times.
After the user has entered three times, you will determine the average time for the marathons. (Divide the total of all marathon times by 3.)
When displaying the runner’s experience level in the output, use a selection statement to display Beginner if the experience level is 1, Intermediate if the experience level is 2, and Advanced if the experience level is 3.
When displaying the Total Time and the Average Time, please display with 2 decimal places.
Your output should look like the following.
Runner\'s Report
Runner\'s Number: 123
Runner\'s Level: Beginner
Total Time: 10.26
Average Time: 3.42
Solution
The HTML code with inline Javascript code is given below
<html>
 <head>
 <title>Your Name - Runner Name</title>
 <script type=\"text/javascript\">
 var IDNumber = 0;
 var expreience = 0;
 var totalTime = 0.0;
function askIDNumber()
 {
 var value = prompt(\"Enter Identification Number: \")
 if(isNaN(value))
 {
 askIDNumber();
 }
 IDNumber = value;
 }
 
 function askExperience()
 {
 var value = prompt(\"Enter Experience Level: \ 1 for Beginner\ 2 for Intermediate\ 3 for Advanced\")
 if(isNaN(value))
 {
 askExperience();
 }
 else if(value>3 || value<=0)
 {
 askExperience();
 }
 expreience = parseInt(value);
 }
</script>
 </head>
 <body>
 <script>
 askIDNumber() // Function call for asking identification number
askExperience() // Function call for asking experience level
// Looping number of times for getting the marathon time
 for(var i=0; i<3; i++)
 {
 var marathonTime = 0.0;
 marathonTime = prompt(\"Enter Marathon time: \");
 if(isNaN(marathonTime))
 --i;
 else if(marathonTime == 0)
 --i;
 else
 totalTime = totalTime + parseFloat(marathonTime);
 }
 var averageTime = totalTime/3;
// Printing the report on the screen
 function getReport()
 {
 var x = \"Runner\'s Report \\ Runner\'s Number: \"+IDNumber+\" \\ \";
 switch(expreience)
 {
 case 1: x=x+\"Runner\'s Level: Beginner \\ \";
 break;
 case 2: x=x+\"Runner\'s Level: Intermediate \\ \";
 break;
 case 3: x=x+\"Runner\'s Level: Advanced \\ \";
 break;
 }
 x = x + \"Total Time: \"+ parseFloat(Math.round(totalTime * 100) / 100).toFixed(2); + \" \\ \";
 x = x + \"Average Time: \" + parseFloat(Math.round(averageTime * 100) / 100).toFixed(2); + \" \\ \";
 document.getElementById(\"demo\").innerHTML = x;
 }
 </script>
 <button onclick = \"getReport()\">Generate Report</button>
 <p id = \"demo\"> </p>
 </body>
 </html>
OUTPUT on screen :
Runner\'s Report
 Runner\'s Number: 12
 Runner\'s Level: Intermediate
 Total Time: 69.00
 Average Time: 23.00


