In: Computer Science
Create an application that calculates mph or (Miles Per Hour). There should be 2 textboxes for input, and 2 labels to label the input textboxes. The first textbox should be the miles driven. And the other textbox should be hours taken.
There should be a button to calculate miles per hour. And a label or textbox for the results of the calculate.
1textbox for miles [input]
2textbox for hours (time used) [input]
3label for miles textbox
4label for hours textbox
button for calculate mph [to start program]
label or textbox to get results [output]
NEED CS FILE PLS
<html>
<head>
</head>
<body align="center">
<form method="post"><br><br>
<label>Enter no.of miles:</label>
<input id="miles" type="text" name="miles" required><br><br>
<label>Enter no.of hours:</label>
<input id="hours" type="text" name="hours" required><br><br>
<button onclick="calculate()" type="button" name="button">Submit</button>
</form>
<p id="res"></p>
<script>
function calculate() {
var miles = document.getElementById('miles');
var hrs = document.getElementById('hours');
console.log(miles.value);
if(miles.value=="" && hrs.value==""){
document.getElementById('res').innerHTML = "Enter no of miles and no of hours";
miles.focus();
}
else if (miles.value=="") {
document.getElementById('res').innerHTML = "Enter no of miles";
miles.focus();
}
else if (hrs.value=="") {
document.getElementById('res').innerHTML = "Enter no of hours";
hrs.focus();
}
else {
document.getElementById('res').innerHTML = (miles.value/hrs.value)+" mile/hour";
}
}
</script>
</body>
</html>